Change the border coloring of window - colors

I am trying to create a window with custom coloring. I can see how to change the background color of the window when using something like FL_BORDER_BOX (how to change the background color of Fl_Window by pressing Fl_Button), but I can not find out how to change the border color from black. Any help would be appreciated!
Thanks!
This is using C/C++ and FLTK btw.

Instead of using FL_BORDER_BOX, use FL_BORDER_FRAME. The foreground colour of the frame can be changed.
Fl_Box changeling = new Fl_Box(10, 10, 100, 20);
changeling.box(FL_BORDER_FRAME);
changeling.color(FL_RED);
A list of the box types can be found in http://www.fltk.org/doc-1.1/common.html under Box Types
EDIT
If you wish to have a different colour inside, then draw two boxes
int x = 10, y = 10, w = 180, h = 100;
Fl_Box box(x, y, w, h);
box.box(FL_BORDER_FRAME);
box.color(FL_BLUE, FL_RED);
Fl_Box inner(x + 1, y + 1, w - 2, h - 2);
inner.box(FL_FLAT_BOX);
inner.color(FL_YELLOW);

Related

How to randomize between two set colors?

I want to know how to be able to have my program generate random color between two set colors and all inbetween the two. For example just the way that I would say:
fill(random(255),0,0));
in order to get a range reds.
I want to be able to choose two colors, let's say orange and blue, and have it generate colors from these two sets of colors. So for it to randomly generate a color from that shade of blue, any shade in between that and into a specific shade of orange.
How do I go about doing that?
Let's say you have 3 variables that hold the "base" color:
float baseR = 50;
float baseG = 100;
float baseB = 200;
You could then add a random number to those values to get a new shade "around" that color:
float shadeDistance = 10;
float r = baseR + random(-shadeDistance, shadeDistance);
float g = baseG + random(-shadeDistance, shadeDistance);
float b = baseB + random(-shadeDistance, shadeDistance);
fill(r, g, b);
Or if you have two colors that you want to blend, you can use the lerpColor() function:
stroke(255);
background(51);
color from = color(204, 102, 0);
color to = color(0, 102, 153);
color interA = lerpColor(from, to, .33);
color interB = lerpColor(from, to, .66);
fill(from);
rect(10, 20, 20, 60);
fill(interA);
rect(30, 20, 20, 60);
fill(interB);
rect(50, 20, 20, 60);
fill(to);
rect(70, 20, 20, 60);
(source: processing.org)

How to add window padding in NCurses?

I have my window
WINDOW *win = newwin(40, 40, 3, 3);
When some text is entered and is spanning more lines, what is the best way to preserve the neat whitespace around the inner borders of the window? I cannot seem to find a way to give a window this kind of property in NCurses.
I guess a way to make padding is to create another window inside this one. There must be a cleaner way.
William McBrine is absolutely sure. The simplest way to retain a box around a window is to create the box in a window which surrounds it. That is because
changes to the inner box have no effect on the box
there is a function box which draws a box along the edges of a given window.
Several of the ncurses test-programs use this feature. For instance, one of the menu entries in the main test-program (in ncurses.c) responds to a w by creating a window to hold the box, then a window to hold its contents, and draws a box in the former before continuing to accept input in the new inner box:
} else if (c == 'w') {
int high = getmaxy(win) - 1 - first_y + 1;
int wide = getmaxx(win) - first_x;
int old_y, old_x;
int new_y = first_y + getbegy(win);
int new_x = first_x + getbegx(win);
getyx(win, old_y, old_x);
if (high > 2 && wide > 2) {
WINDOW *wb = newwin(high, wide, new_y, new_x);
WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
box(wb, 0, 0);
wrefresh(wb);
wmove(wi, 0, 0);
remember_boxes(level, wi, wb);
wgetch_test(level + 1, wi, delay);
delwin(wi);
delwin(wb);
wgetch_help(win, flags);
wmove(win, old_y, old_x);
touchwin(win);
wrefresh(win);
doupdate();
}

How to get color (r, g, b ,a) of every pixel in Three.js

I'm using Particle to draw irregular shapes in Three.js, the code snippet is like:
var hearts = function(context){
context.globalAlpha = 0.5;
var x = 0, y = 0;
context.scale(0.1, -0.1); // Scale so canvas render can redraw within bounds
context.beginPath();
context.bezierCurveTo(x + 2.5, y + 2.5, x + 2.0, y, x, y);
context.bezierCurveTo(x - 3.0, y, x - 3.0, y + 3.5, x - 3.0, y + 3.5);
...
context.closePath();
context.lineWidth = 0.1; //0.05
context.stroke();
}
var material = new THREE.ParticleCanvasMaterial({
program: heart,
blending: THREE.AdditiveBlending
});
material.color.setRGB(255, 0, 0);
var particle = new THREE.Particle(material);
what I want to do is select the irregular shape properly, my question is, if I draw shape this way, how can I get the color of every pixel so I can used in the picking algorithm
Thanks.
Have you looked into toDataURL()?
I use that in my three.js logic to grab and save the canvas out of the browser. From looking at this:
http://www.patrick-wied.at/blog/how-to-create-transparency-in-images-with-html5canvas
It looks to me like toDataURL() can also be used to peer into the RGB and A of each pixel, if need be change them and write it back to the visible framebuffer.

How to create a hue (saturation) picker in cocos2d

I'm trying to create a simplified hue/saturation picker for cocos2d. I want to create a gradient and to pick from it. I need to recolor a black/white image gradient for every color like blue, red and others. So I need to create many gradients. I know that I should use some blend functions to achieve this.
But I'm still a little bit confused about what is the best way to proceed.
Should I use blend functions at all ?
My problem basically is that I use a gradient from black to transparent or to white but with
sprite.setColor(color);
I get a gradient from black to the desired color but I need a gradient from the desired darker color to white.
What you need to do is create a 2D gradient that goes from unsaturated to saturated left-to-right, and from dark to light bottom-to-top. I'd do it by creating a new bitmap (or if you're using OpenGL, a texture). I'd then color each pixel using the following pseudocode:
hue = <whatever the user set the hue to>
for (row = 0; row < height; row++)
{
for (col = 0; col < width; col++)
{
sat = col / width;
val = row / height;
rgb = HSVToRGB(hue, sat, value);
setPixel (col, row, rgb);
}
}

GDI: How to fill RoundRect with color?

While the question title seems dumb, that's not exactly what I need. To fill whole area with color, one needs to select appropriate brush - that's trivial. But I want to fill upper half of it with different color, and bottom half of it with the different one. If it was the normal (not round) rectangle, I could draw two rectangles (with different brushes). But with RoundRect I don't have any ideas how to do it.
Here is what I need it for: I draw each node in my graph visualization with RoundRect, and those nodes should have several compartments (cells) that should be filled with different colors.
I hope you get the idea what I mean :)
If you have to use legacy GDI instead of GDI+, here I wrote you a function to draw such a (cell) as you needed I hope it is what you have expected !
The basic idea is to create upper and lower regions (which they were both full overlapping rounded rectangles, then each has one of its halves cut off)
I have prepared the above illustration to show how the cell could be produced. It's for the upper side only, but you should have got the idea of creating the lower one.
Here is a wrapping function to create the cell you need:
void DrawCell(HDC& hdc, const RECT& rcTarget,const HBRUSH& hbrUpper, const HBRUSH& hbrLower)
{
HRGN hRgnUpper = CreateRoundRectRgn(rcTarget.left, rcTarget.top, rcTarget.right, rcTarget.bottom, 42, 38);
HRGN hRgnLower = CreateRoundRectRgn(rcTarget.left, rcTarget.top, rcTarget.right, rcTarget.bottom, 42, 38);
HRGN hRgnCutFromUpper = CreateRectRgn(rcTarget.left, rcTarget.top + ((rcTarget.bottom - rcTarget.top) / 2), rcTarget.right, rcTarget.bottom);
HRGN hRgnCutFromLower = CreateRectRgn(rcTarget.left, rcTarget.top , rcTarget.right, rcTarget.bottom - ((rcTarget.bottom - rcTarget.top) / 2));
CombineRgn(hRgnUpper, hRgnUpper,hRgnCutFromUpper, RGN_DIFF);
CombineRgn(hRgnLower, hRgnLower,hRgnCutFromLower, RGN_DIFF);
FillRgn( hdc, hRgnUpper, hbrUpper);
FillRgn( hdc, hRgnLower, hbrLower);
DeleteObject(hRgnCutFromLower);
DeleteObject(hRgnCutFromUpper);
DeleteObject(hRgnLower);
DeleteObject(hRgnUpper);
}
call this function from within your WM_PAINT handler:
RECT rcTarget;
rcTarget.left = 20;
rcTarget.top = 20;
rcTarget.right = 275;
rcTarget.bottom = 188;
HBRUSH hRed = CreateSolidBrush( RGB(255, 0, 0) );
HBRUSH hGreen = CreateSolidBrush( RGB(0, 255, 0) );
DrawCell(hdc, rcTarget, hRed, hGreen);

Resources