first of all i'm actually lame at gtk programming and i'm just building some simple examples so far, and I have this:
GdkColor color;
gtk_widget_realize(window);
gtk_style_lookup_color(gtk_widget_get_style(window), "bg_color", &color);
gtk_widget_modify_base(data->text, GTK_STATE_NORMAL, &color);
which makes my textview gray, just like the default background of an empty window. but now i'm trying to change it to yellow and i can't figure out how to do that, i've read some other way to do it which is not like the one that im using, but it doesn't even work.
yes, i suck. but any help would be grateful!
btw i'm programming in C.
So if I understood correctly, this is just about initializing a GdkColor and not really a problem with the textview? Try something like this
if (!gdk_color_parse ("yellow", &color)) {
g_print ("Failed to parse color\n");
} else {
gtk_widget_modify_base (data->text, GTK_STATE_NORMAL, &color);
}
You can also use rgb hex values (like "#FFFF00") instead of colour names.
Related
I'm using the wl-pprint-extras package. I'm trying to pretty-print LaTeX, improving on HaTeX, or at least tweaking it to my needs.
An example of the output I'm looking for is:
\foo{bar}{
\baz{\quux}
}{
\fizz
}
and
\foo{
bar
}{
\baz{\quux}
}{
\fizz
}
I would prefer to avoid, when possible,
\foo{
bar
}{\baz{\quux}}{
\fizz
}
The output that's driving me up a wall is
\foo{
bar
}{\baz{
\quux
}}{
\fizz
}
The data I have to work with is TeXComm String [TeXArg].
Does anyone have any idea how to get the first and the second while completely avoiding the fourth?
EDIT:
A gist of what I have so far; the two files are the modified pretty printer and some sample LaTeX I'm trying to pretty print.
I'm currently trying to learn ray-tracing in C++. I am getting help from two books: one is Ray Tracing from the Ground Up by Kevin Suffern, and the other one is Physically Based Rendering by Matt Pharr. These two books are great for learning basics and, later, advanced stuff.
I could create some basic shapes using user interface of Suffern's book. However when I tried to write all code on my own, things have gone wild. I realized that I don't even know how to open a window and fill pixels on that. Do you have any good resource to recommend that could teach me the basics of drawing in C++.
You could generate image files instead of drawing to windows. The PPM format is the simplest one to generate. Browsers usually can display PPM. Safari does.
If you want to generate PNG files use libpng.
SDL might work for you: http://www.libsdl.org/
You can allocate your own image buffer, write your pixels to it, and then save to file/draw to window as needed. I expect the Pharr book has its own version of this tucked away somewhere, courtesy of Literate Programming.
More concretely: GUI API's and image file format libraries will typically be able to read simple image buffer data, stored in row-major array order. I would recommend an RGBA pixel format, something like the following:
template<class T> class image_rgba {
unsigned m_rows, m_cols;
T *m_data;
public:
image_rgba(unsigned rows, unsigned columns)
: m_rows(rows)
, m_cols(columns)
, m_data(new T[rows*columns*4])
{}
~image_rgba() { delete[] m_data; }
typedef T pixel[4];
pixel index_pixel_ref(unsigned row, unsigned col) {
assert(row<m_rows && col<m_cols);
return m_data + (m_cols*row+col)*4;
}
}
(note that I have not tested the above -- best to treat it as pseudocode...)
I am in the process of learning LWJGL and also OpenGL. I have done the tutorials on quads, and also succesfully drawn polygons on a display. I am trying to draw lines using the same methods, but the lines are not created, or they are made invisible, possibly with a pixel width of 0? I have googled for an answer or a tutorial, but so far all of them seems to claim that I am doing the right thing. my method is as follows:
private void drawLine(Point point, Joint Point2) {
GL11.glColor3f(0.0f, 1.0f, 0.2f);
GL11.glBegin(GL11.GL_LINE);
GL11.glVertex2d(point.getX(), point.getY());
GL11.glVertex2d(point2.getX(), point2.getY());
GL11.glEnd();
}
I also tried to put this one in the middle, but no effect.
GL11.glLineWidth(3.8f);
As stated in the comments, The answer was that GL11.GL_LINE is not accepted as a constant in this case. GL11.LINE_STRIP however works like a charm.
I've already know how to dark-down a CCSprite object by:
sprite.color = ccc3(x, x, x); // x is a value less then 255
(As far as i know, it should be a direct mapping of openGL functions, so its easy to achieve.)
But when it comes to light-up, my current solution is adding another mask sprite (same shape but all in white), changing its blendFunc to { GL_SRC_ALPHA, GL_ONE } and overlaying it onto the target. Besides all the codes added, there should be a mask image for each need-to-light-up one.
Is there a way to do light-up as easily as dark-down?
However, not as easy as setColor, in Cocos2d 2.x, with OpenGL ES 2.0 support, you can achieve this by using custom shaders. You can get started here:
http://www.raywenderlich.com/10862/how-to-create-cool-effects-with-custom-shaders-in-opengl-es-2-0-and-cocos2d-2-x
You may also try inverting the sprite's darker color to get a lighter one.
I want to use DirectWrite for mixed-colour text formatting (syntax highlighting, to be precise), but can't seem to find a way to do it, either in the Layout or Typography options. The only option is passing a Brush when rendering the text, which doesn't work for me because I basically have just one Layout. Help!
Use IDWriteTextLayout::SetDrawingEffect to apply drawing effects on subranges. If you're using DWrite with D2D DrawTextLayout, which it sounds like you are, then that drawing effect would just be a brush (such as ID2D1Brush via CreateSolidColorBrush or one of the gradient brushes). If you have implemented your own IDWriteTextRenderer for IDWriteTextLayout::Draw, then the drawing effect can be whatever you interpret it to be. In the IDWriteTextRenderer::DrawGlyphRun callback, you then call QueryInterface on the drawingEffect parameter, or if you are certain it is your own type, just static_cast it directly.
// ... create the colored brushes and determine where to draw ...
wchar_t const* text = L"Red Green";
dwriteFactory->CreateTextLayout(....., OUT &textLayout);
DWRITE_TEXT_RANGE textRange1 = {0,3}, textRange2 = {4,5};
textLayout->SetDrawingEffect(redBrush, textRange1);
textLayout->SetDrawingEffect(greenBrush, textRange2);
renderer->DrawTextLayout(point, textLayout, defaultBrush);