Jump to content
  • Advertisement
Sign in to follow this  
XDaWNeDX

creating a colour selector

This topic is 2611 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Currently I have a toolbox on my paint application that allows you to type the RGB values into it, however I would like to upgrade that to a colour selector thing. Like a colour wheel. How would I do this, or would it be too much code to explain?

Share this post


Link to post
Share on other sites
Advertisement

Currently I have a toolbox on my paint application that allows you to type the RGB values into it, however I would like to upgrade that to a colour selector thing. Like a colour wheel. How would I do this, or would it be too much code to explain?


What programming language and GUI framework/library are you using?

Many operating/windowing systems provide a "standard" color selection dialog. Most GUI frameworks I've used provide interfaces to create and interact with such dialogs.

Share this post


Link to post
Share on other sites
Oh, sorry. C++ and it's just a dialog application. Yeah, should've mentioned those, oh well. I know it's possible to create it by using something like
OnMouseMove(){
if(point.x++){ RED++ GREEN++ }
if(point.y++){ BLUE++ GREEN++ }
SetPixel(100,100,RGB(RED,GREEN,BLUE);
UpdateData(FALSE); }

or somethin like that..
and then also for point.x and point.y going down, but I forgot to type that in there, and I'm using a shitty keyboard and don't want to.

Share this post


Link to post
Share on other sites
I'm using visual studio 2010 ultimate
I hit file > new > MFC application
select dialog application and hit finish.

Sorry for my noobyness, I'm new to programming. Although I know how to learn, I don't actually know much..

Share this post


Link to post
Share on other sites
Here's a quick example of what I normally put in quickly when I need it. Might be that you need to include some headers and link something, that is for you to figure out ;)

CHOOSECOLOR pick_color; // common dialog box structure
static COLORREF acrCustClr[16]; // array of custom colors
static DWORD rgbCurrent; // initial color selection

// Initialize CHOOSECOLOR
ZeroMemory(&pick_color, sizeof(pick_color));
pick_color.lStructSize = sizeof(pick_color);
pick_color.hwndOwner = hDlg;
pick_color.lpCustColors = (LPDWORD) acrCustClr;
pick_color.rgbResult = rgbCurrent;
pick_color.Flags = CC_FULLOPEN | CC_RGBINIT;

// If picked set the color
if (ChooseColor(&pick_color))
{
Color_light = pick_color.rgbResult;
flipIt(&Color_light);
sprintf_s(values,"%#.6x", Color_light);
SetDlgItemText(hDlg,IDC_LIGHT_COLOR, values );
}


the flipit() function is done because I used this in OpenGL, to satisfy the colors in openGL you need to swap them.

Here's the function if you need it.
void flipIt(void* buffer)
{
void* b = buffer; // Pointer To The Buffer
__asm // Assembler Code To Follow
{
mov ebx, b // Points ebx To Our Data (b)
label: // Label Used For Looping
mov al,[ebx+0] // Loads Value At ebx Into al
mov ah,[ebx+2] // Loads Value At ebx+2 Into ah
mov [ebx+2],al // Stores Value In al At ebx+2
mov [ebx+0],ah // Stores Value In ah At ebx
}
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!