I need to implement a MouseOver effect on some listbox items and I need to use a light blue as the highlight color.
Does anyone know from the winuser.h file what constant is the light blue color ? I tested over 20 of them, cannot find the correct one, maybe someone here knows.
Thanks.
If you don't need a specific "light blue", open Paint, or any other program that handles colors, and move the color sliders until you get the RGB values you need. Then do:
COLORREF myLightBlue = RGB(R, G, B);
I think you'll find you need a high B value, to make it blue, and quite high R and B values, to make it light. For example, you can try RGB(200, 230, 255);
Anyway, it would probably be advisable to use some system color, taken with ::GetSysColor()
EDIT:
If you are using visual styles, I think you have to use GetThemeColor() to get the color defined by the current theme. Ive never used it myself, so I cannot help with that.
Related
being a complete OpenGL newbie, I have a problem I do not understand how to solve. I am using JOGL, and trying to draw a disk, filled with a solid color and a different border color. My problem is obvious in the following image:
What I cannot understand is why I can still see the lines produced by GLU. The code that draws this is the following:
glColor3ub(r, g, b); // purple
gluDisk(quadric, 0, 50, 32, 2);
glColor3ub(r, g, b); // dark gray
gluDisk(quadric, 49, 50, 32, 2);
I suspect I have done something wrong with blending/anti-aliasing. When I disable anti-aliasing, the shape is drawn with solid color; however I need AA. I have set up AA and blending as shown below:
glEnable(GL2.GL_BLEND);
glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL2.GL_LINE_SMOOTH);
glHint(GL2.GL_LINE_SMOOTH_HINT, GL2.GL_NICEST);
glEnable(GL2.GL_POLYGON_SMOOTH);
glHint(GL2.GL_POLYGON_SMOOTH_HINT, GL2.GL_NICEST);
Finally, my GLCanvas is created with the following GLCapabilities:
caps.setAlphaBits(16);
caps.setDoubleBuffered(true);
caps.setHardwareAccelerated(true);
Other than that, the Quadric rendering properties are the default. Does anybody understand what have I done wrong? I apologize for any information that might be missing! Thanks for reading!
Ilias
The culprit is GL_POLYGON_SMOOTH. Smoothing never worked painfree and artifacs like those you see are a result from that. A far better antialiasing method is multisampling. There's a tutorial at http://www.opengl.org/wiki/Multisampling
I'm drawing a color selection button and I'm looking for a nice and simple formula to get a good text color (foreground) for a given background color in RGB.
A simple try would be to just take the complement color but this will produce an odd looking button for colors like pure blue or pure red.
Is there something well known that does this?
If it matters at all, I'm using QT.
For maximum legibility, you want maximum brightness contrast without getting into hues which don't work together. The most consistent way to do this is to stick with black or white for the text color. You might be able to come up with more aesthetically pleasing schemes, but none of them will be more legible.
To pick between black or white, you need to know the brightness of the background. This gets a little more complicated, due to two factors:
The perceived brightness of the individual primaries red, green, and blue are not identical. The quickest advice I can give is to use the traditional formula to convert RGB to gray - R*0.299 + G*0.587 + B*0.114. There are lots of other formulas.
The gamma curve applied to displays makes the middle gray value higher than you'd expect. This is easily solved by using 186 as the middle value rather than 128. Anything less than 186 should use white text, anything greater than 186 should use black text.
I'm no expert on programming things related to RGB, but from a designer's perspective, often the most readable color will be just a much lighter (if the background color is dark) or darker (if the background color is light) version of the same shade.
Basically you'd take your RGB values and if they're closer to 0 (dark) you'd push them each up by an equal amount for your foreground color, or vice versa if it's a light BG.
Complement colors can actually be really painful on the eyes for readability.
Leverage an outline for legibility
If by "good text color (foreground)" you intend it for legibility purposes when the user chooses any background colour, you can always produce white text having a black outline. It will be legible on any solid, patterned or gradient background, from black through white and anything in between.
Even if this doesn't hit the mark of your intention, I think it worthwhile posted here because I came looking for similar solutions.
Building on top of Mark's response, here's some Ruby code that'll do the work
rgbval = "8A23C0".hex
r = rgbval >> 16
g = (rgbval & 65280) >> 8
b = rgbval & 255
brightness = r*0.299 + g*0.587 + b*0.114
return (brightness > 160) ? "#000" : "#fff"
You are better off with a high difference in luminosity. In general, colored backgrounds with colored text suck for readability, hurting the eyes over time. Lightly tinted colors (e.g. in HSB, S~10%, B>90%) with black text work fine, or lightly tinted text over a black background. I'd stay away from coloring both. Dark text (b~30%, s>50%) with a subtle coloration over a white background can also be fine. Yellow (amber) text on a deep blue background has excellent readability, as does amber or green on black. This is why old dumbterms (vt100, vt52, etc.) went for these colors.
If you really need to do color-on-color for the 'look', you could reverse both H and B, while pinning saturation at a moderate to low level.
And one last note: if you have a 50% gray background, rethink your interface. You're robbing yourself of half your dynamic range! You're alienating low-visibility users, including anyone over 35...
Color combinations often look terrible when not carefully chosen. Why not use either white or black for the text, depending on the Brightness of the color. (Will need to convert to HSB first.)
Or let the user choose either black or white text.
Or use pre-defined combinations. This is what Google does in their calendar product.
I've been looking for a simailr answer and came across this post and some others that I thought I'd share. According to http://juicystudio.com/services/luminositycontrastratio.php#specify the "Success Criterion 1.4.3 of WCAG 2.0 requires the visual presentation of text and images of text has a contrast ratio of at least 4.5:1" with some exceptions. That site lets you put in foreground and background colors to compute their contrast, although it would be helpful if it would suggest alternatives or ranges.
One of the best sites I've found for visualizing color contrast is http://colorizer.org/ It lets you adjust almost all manner of color scales (RGB, CMYK, etc.) at the same time and then shows you the result on the screen, such as white text on a yellow background.
I usually look at color complements, they also have color complement wheels to help
http://www.makart.com/resources/artclass/cwheel.html
If your color is HSL, flip the Hue by 180 degrees for a decent calculation
I wanted to put #MarkRansom's answer into use and managed to create this snippet:
I got the values From seeing how sRGB converts to CIE XYZ and built upon that.
The script simply tracks the position of the foreground item and it's position regarding the colored background items.
Then based on background luminosity it gradually changes the foreground text color to either black or white.
Open the codepen for full example
https://codepen.io/AndrewKnife/pen/XWBggQq
const calculateLight = (colorItem: number) => {
let c = colorItem / 255.0;
if (c <= 0.03928) {
c /= 12.92;
} else {
c = Math.pow((c + 0.055) / 1.055, 2.4);
}
return c;
};
const calculateLuminosity = (color: RGBColor) => {
return (
0.2126 * calculateLight(color.r) +
0.7152 * calculateLight(color.g) +
0.0722 * calculateLight(color.b)
);
};
const getContrastColor = (color: RGBColor) => {
if (calculateLuminosity(color) > LUMINOSITY_LIMIT) {
return FONT_COLOR_DARK;
}
return FONT_COLOR_LIGHT;
};
I thing that converting to HSV might be the way, but IMO changing hue would look weird. I'd try keeping the hue and fiddling with value and maybe saturation (light red buttons with dark red text ... hm sounds scary :-) ).
I'm making an iOS game using cocos2d libraries.
Lets say you have two objects that have two separate colours - defined in RGB as
Blue: 0,0,255
Yellow: 255,255,0
I want to add blue and yellow to make green.
To over complicate things, let's say that the Blue object is bigger than the Yellow object (for the sake of argument let's say that the ratio is 2:1), I'm adding twice as much blue as yellow - how to I calculate this new (light green) colour correctly.
I understand LAB * Color Space is useful for this sort of 'natural colour' kind of thing, but I'm not sure how to use it - especially in the context of a cocos2d object which (AFAIK) is limited to using RGB in its colour schemes.
I'd really appreciate practical help on how to implement this. Thanks heaps!
21/4 Update: So in LAB* blue+yellow ≠ green (which makes sense when you see they're at opposite ends of the same channel). It's actually quite a tricky problem with a little bit of discussion on SO. It seems that the ultimate answer is to use the Kubelka-Munk method that a piece of open source software called Krita uses. I can't find that anywhere (either the formula or the code itself).
This question has a link which uses HSL to work in a similar method to paint. I'm going to try to see if it works, and I'll feed back the result here.
In the meantime if anyone knows how to implement Kubelka-Munk or where I can find code to do this, or another solution, I would be very, very stoked!
There is no color model where mixing blue and yellow makes green. Try it yourself with gouache, the only way it works is cyan and yellow. This is why you should try switching from RGB to CMYK, and back if you need. Here is how it's done
void toCMYK(float red, float green, float blue, float* cmyk)
{
float k = MIN(255-red,MIN(255-green,255-blue));
float c = 255*(255-red-k)/(255-k);
float m = 255*(255-green-k)/(255-k);
float y = 255*(255-blue-k)/(255-k);
cmyk[0] = c;
cmyk[1] = m;
cmyk[2] = y;
cmyk[3] = k;
}
void toRGB(float c, float m, float y, float k, float *rgb)
{
rgb[0] = -((c * (255-k)) / 255 + k - 255);
rgb[1] = -((m * (255-k)) / 255 + k - 255);
rgb[2] = -((y * (255-k)) / 255 + k - 255);
}
And then in your code, mix the cyan and yellow
float cmyk1[4];
toCMYK(255, 255, 0, cmyk1); // yellow
float cmyk2[4];
toCMYK(0, 255, 255, cmyk2); // cyan
// Mixing colors is as simple as adding
float cmykMix[] = { cmyk1[0] + cmyk2[0], cmyk1[1] + cmyk2[1], cmyk1[2] + cmyk2[2], cmyk1[3] + cmyk2[3] };
float rgb[3];
toRGB(cmykMix[0], cmykMix[1], cmykMix[2], cmykMix[3], rgb);
NSLog(#"RGB mix = (%f, %f, %f)", rgb[0], rgb[1], rgb[2]);
Running the code will yield: RGB mix = (0.000000, 255.000000, 0.000000)
Check the formulas on this site: http://www.easyrgb.com/index.php?X=MATH
I've been doing similar thing, and it can be achieved by converting RGB->XYZ->Lab. However the computation is quite expensive(if you doing it for a lot of pixels).
And forget about RGB math when trying to mix colors if you want to obtain results similar to human eye
I think, it is worth to try HSL color space. When adding colors we interpolate their Hue values (even taking in account objects weights). If the colors are 100% saturated, Luminance and Saturation values will be equal.
Dyes don't work in the real world quite like subtractive-color models suggests. The dyes used for CYMK printing are pretty close, since they're formulated for that purpose, but many dyes made from naturally-occurring substances can behave somewhat oddly. The difficulty is that while white light is perceived as a combination of red, green, and blue, it actually consists of many different wavelengths--literally "all the colors of the rainbow"--each of which will stimulate the red, green, and blue receptors in the eye by different amounts. It is possible for two colors which appear identical to in fact contain different combinations of wavelengths; likewise, two dyes may appear identical when viewed in white light, but absorb different combinations of wavelengths. Such dyes may look identical to each other when used alone, but may yield very different-seeming results when combined with something else.
Although dyes can sometimes be tricky, however, paints are even worse. Paints contain reflective particles, and some of the light which hits a painted surface will be reflected back off the surface by the first particle it hits; in that regard, they mix like additive colors. For example, if the paint contains 20% green particles, then a significant amount of green light will be reflected, regardless of what other colors it might contain. On the other hand, some of the light which hits a painted surface will bounce around and hit multiple particles. If any of those particles absorbs a photon of some color, that photon won't be reflected. In that regard, paints behave more like subtractive colors. In practice, paints behave somewhat like additive colors, somewhat like subtractive colors, and sometimes like something weird and wacky and totally unlike either.
Actually it seems that converting RGB->XYZ->LAB does exatly the same thing as RGB->LAB
I'm learning to use Allegro. I'm trying to make my character cut out. How do I key out a certain color from my bitmap? which way is used for allegro?
Thanks
These might be places to start:
http://www.allegro.cc/manual/api/blitting-and-sprites/draw_trans_sprite
http://wiki.allegro.cc/index.php?title=Alpha_channel#Drawing_to_the_alpha_channel_in_Allegro
http://www.allegro.cc/manual/api/blitting-and-sprites/draw_sprite
"Transparent pixels are marked by a zero in 256-color modes or bright pink for truecolor data (maximum red and blue, zero green)."
I want to develop a program which recolors the input image based on the given theme the same way as ms-powerpoint application does.
I am giving following link that shows what exactly i want to do.
I want to generate images same as images in below link under the Dark Variations and light Variations title based on the current theme.
http://blogs.msdn.com/powerpoint/archive/2006/07/06/658238.aspx
Can anybody give me idea,info regarding how to achieve it efficiently ??
You can give a look to the HSL colorspace to be able to have the same result. HSL means Hue, Saturation, Lightness.
You can keep the lightness of each pixel of your image and change only the hue. I think this will allow you to achieve what you want. You can find the RGB to HSL conversion on the wiki page.
Hope that helps.
Step 1: Choose the colors you want to represent black and white. For the dark variations, choose black and a light color; for the light variations, choose a dark color and white.
Step 2: Convert a pixel to gray. A common formula for this is L = R*0.3 + G*0.59 + B*0.11.
Step 3: Interpolate between the colors using the gray value. output.R = (L/255)*light.R + (1-(L/255))*dark.R and likewise for green and blue.
You can use a library like CxImage and convert the image to grayscale, then use the mix command with another image that you have made that is the same size as the original, and mix the two with the Mix command, using the filters. You can do mix-screen, and this should tint the pixels the color of the second image in the resultant image. Try playing with CxImage a bit, see if it will do what you want it to do. This is all coming off the top of my head, and its been a while since I have tried to do anything like this. YMMV, but this would be the simplest implementation. You could always look at how CxImage does the blend, and apply it to the image yourself.
I must say thanks to Mark and Patrice for ur guidance which helped me achieved it.
For light variation, I have done it by converting the theme colors to HSV colorspace and found relation between output color and theme color for black color (input) .
The relation was found to be linear for saturation and value and hue was almost constant.
I have used interpolation formula to make it generic for any given theme.
I have also make use of color matrix to achieve desired result.
Similarly for dark variation i have used white color as input and apply the same technique.