Added GuiColorPicker() -IN PROGRESS-

This commit is contained in:
raysan5
2017-09-08 09:37:08 +02:00
parent bee3f5694e
commit d077f4f18a
2 changed files with 93 additions and 19 deletions

View File

@ -140,6 +140,8 @@ int main(int argc, char *argv[0])
DrawRectangleLines(10, 10, SCREEN_WIDTH - 20, SCREEN_HEIGHT - 20, GuiLinesColor());
GuiColorPicker((Rectangle){ 100, 100, 200, 200 }, RED);
if (texture.id != 0)
{
DrawTextureEx(texture, (Vector2){ SCREEN_WIDTH/2 - texture.width*imageScale/2, SCREEN_HEIGHT/2 - texture.height*imageScale/2 }, 0, imageScale, WHITE);
@ -159,7 +161,7 @@ int main(int argc, char *argv[0])
GuiLabel((Rectangle){ panel.x + 10, panel.y + 30, 0, 0 }, FormatText("File size: %i bytes", dataSize));
// ----- Resolution panel-----
GuiPanel((Rectangle){ panel.x + 10, panel.y + 55, 180, 80 }, "Resolution");
GuiGroupBox((Rectangle){ panel.x + 10, panel.y + 55, 180, 80 }, "Resolution");
GuiLabel((Rectangle){ panel.x + 20, panel.y + 80, 0, 0 }, "Width:");
GuiLabel((Rectangle){ panel.x + 150, panel.y + 80, 0, 0 }, "pixels");
@ -172,7 +174,7 @@ int main(int argc, char *argv[0])
GuiTextBox((Rectangle){ panel.x + 60, panel.y + 100, 80, 20 }, textImageHeight, 4);
// ----- Pixel data panel -----
GuiPanel((Rectangle){ panel.x + 10, panel.y + 155, 180, 110 }, "Pixels Data");
GuiGroupBox((Rectangle){ panel.x + 10, panel.y + 155, 180, 110 }, "Pixels Data");
GuiLabel((Rectangle){ panel.x + 20, panel.y + 170, 0, 0 }, "Channels:");
GuiLabel((Rectangle){ panel.x + 20, panel.y + 215, 0, 0 }, "Bit Depth:");
@ -181,7 +183,7 @@ int main(int argc, char *argv[0])
buttonToggleDepth = GuiToggleGroup((Rectangle){ panel.x + 20, panel.y + 230, 51, 20 }, 3, arrayDepth, buttonToggleDepth);
// ----- Header panel -----
GuiPanel((Rectangle){ panel.x + 10, panel.y + 285, 180, 50 }, "Header");
GuiGroupBox((Rectangle){ panel.x + 10, panel.y + 285, 180, 50 }, "Header");
GuiLabel((Rectangle){ panel.x + 20, panel.y + 305, 0, 0 }, "Size:");
GuiLabel((Rectangle){ panel.x + 150, panel.y + 305, 0, 0 }, "bytes");
@ -205,18 +207,6 @@ int main(int argc, char *argv[0])
return 0;
}
// Draw a lines panel with name
void GuiPanel(Rectangle bounds, const char *text)
{
DrawLineEx((Vector2){ bounds.x + 1, bounds.y }, (Vector2){ bounds.x, bounds.y + bounds.height }, 1, GuiLinesColor());
DrawLineEx((Vector2){ bounds.x, bounds.y + bounds.height }, (Vector2){ bounds.x + bounds.width, bounds.y + bounds.height }, 1, GuiLinesColor());
DrawLineEx((Vector2){ bounds.x + bounds.width, bounds.y + bounds.height }, (Vector2){ bounds.x + bounds.width, bounds.y }, 1, GuiLinesColor());
DrawLineEx((Vector2){ bounds.x, bounds.y }, (Vector2){ bounds.x + 10, bounds.y }, 1, GuiLinesColor());
DrawLineEx((Vector2){ bounds.x + bounds.width, bounds.y }, (Vector2){ bounds.x + 20 + MeasureText(text, 10), bounds.y }, 1, GuiLinesColor());
DrawText(text, bounds.x + 14, bounds.y - 5, 10, GuiTextColor());
}
// Get pointer to filename data in the string
char *GetFileName(char *path)
{

View File

@ -264,6 +264,8 @@ RAYGUIDEF float GuiSliderBar(Rectangle bounds, float value, float minValue, floa
RAYGUIDEF float GuiProgressBar(Rectangle bounds, float value, float minValue, float maxValue); // Progress Bar control, shows current progress value
RAYGUIDEF int GuiSpinner(Rectangle bounds, int value, int minValue, int maxValue); // Spinner control, returns selected value
RAYGUIDEF void GuiTextBox(Rectangle bounds, char *text, int textSize); // Text Box control, updates input text
RAYGUIDEF void GuiGroupBox(Rectangle bounds, const char *text); // Group Box control with title name
RAYGUIDEF Color GuiColorPicker(Rectangle bounds, Color color); // Color Picker control
#if defined RAYGUI_STANDALONE
// NOTE: raygui depend on some raylib input and drawing functions
@ -1305,7 +1307,7 @@ RAYGUIDEF void GuiTextBox(Rectangle bounds, char *text, int textSize)
//--------------------------------------------------------------------
}
// Button control, returns true when clicked
// Texture button control, returns true when clicked
RAYGUIDEF bool GuiTexture(Rectangle bounds, Texture2D texture)
{
ControlState state = NORMAL;
@ -1315,9 +1317,7 @@ RAYGUIDEF bool GuiTexture(Rectangle bounds, Texture2D texture)
// Update control
//--------------------------------------------------------------------
// Check button state
if (CheckCollisionPointRec(mousePoint, bounds))
if (CheckCollisionPointRec(mousePoint, bounds)) // Check button state
{
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = PRESSED;
else if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) clicked = true;
@ -1355,6 +1355,90 @@ RAYGUIDEF bool GuiTexture(Rectangle bounds, Texture2D texture)
else return false;
}
// Group Box control with title name
void GuiGroupBox(Rectangle bounds, const char *text)
{
DrawLineEx((Vector2){ bounds.x + 1, bounds.y }, (Vector2){ bounds.x, bounds.y + bounds.height }, 1, GuiLinesColor());
DrawLineEx((Vector2){ bounds.x, bounds.y + bounds.height }, (Vector2){ bounds.x + bounds.width, bounds.y + bounds.height }, 1, GuiLinesColor());
DrawLineEx((Vector2){ bounds.x + bounds.width, bounds.y + bounds.height }, (Vector2){ bounds.x + bounds.width, bounds.y }, 1, GuiLinesColor());
DrawLineEx((Vector2){ bounds.x, bounds.y }, (Vector2){ bounds.x + 10, bounds.y }, 1, GuiLinesColor());
DrawLineEx((Vector2){ bounds.x + bounds.width, bounds.y }, (Vector2){ bounds.x + 20 + MeasureText(text, 10), bounds.y }, 1, GuiLinesColor());
DrawText(text, bounds.x + 14, bounds.y - 5, 10, GuiTextColor());
}
// Color Picker control
// TODO: It can be divided in multiple controls:
// Color GuiColorPicker()
// unsigned char GuiColorBarAlpha()
// unsigned char GuiColorBarHue()
// Color GuiColorBarSat() [WHITE->color]
// Color GuiColorBarValue() [BLACK->color]), HSV / HSL
// unsigned char GuiColorBarLuminance() [BLACK->WHITE]
Color GuiColorPicker(Rectangle bounds, Color color)
{
ControlState state = NORMAL;
Vector2 mousePoint = GetMousePosition();
// NOTE: bounds define only the color picker box, extra bars at right and bottom
// Update control
//--------------------------------------------------------------------
// TODO: Check mousePoint over colorSelector and right/bottom bars
if (CheckCollisionPointRec(mousePoint, bounds)) // Check button state
{
}
//--------------------------------------------------------------------
// Draw control
//--------------------------------------------------------------------
DrawRectangleGradientEx(bounds, WHITE, WHITE, BLUE, BLUE);
DrawRectangleGradientEx(bounds, Fade(BLACK,0), BLACK, BLACK, Fade(BLACK,0));
DrawRectangleGradientEx((Rectangle){bounds.x + bounds.width + 10, bounds.y, 20, bounds.height/6}, (Color){255,0,0,255}, (Color){255,255,0,255}, (Color){255,255,0,255}, (Color){255,0,0,255}); // TEST
DrawRectangleGradientEx((Rectangle){bounds.x + bounds.width + 10, bounds.y + bounds.height/6, 20, bounds.height/6}, (Color){255,255,0,255}, (Color){0,255,0,255}, (Color){0,255,0,255}, (Color){255,255,0,255}); // TEST
DrawRectangleGradientEx((Rectangle){bounds.x + bounds.width + 10, bounds.y + 2*(bounds.height/6), 20, bounds.height/6}, (Color){0,255,0,255}, (Color){0,255,255,255}, (Color){0,255,255,255}, (Color){0,255,0,255}); // TEST
DrawRectangleGradientEx((Rectangle){bounds.x + bounds.width + 10, bounds.y + 3*(bounds.height/6), 20, bounds.height/6}, (Color){0,255,255,255}, (Color){0,0,255,255}, (Color){0,0,255,255}, (Color){0,255,255,255}); // TEST
DrawRectangleGradientEx((Rectangle){bounds.x + bounds.width + 10, bounds.y + 4*(bounds.height/6), 20, bounds.height/6}, (Color){0,0,255,255}, (Color){255,0,255,255}, (Color){255,0,255,255}, (Color){0,0,255,255}); // TEST
DrawRectangleGradientEx((Rectangle){bounds.x + bounds.width + 10, bounds.y + 5*(bounds.height/6), 20, bounds.height/6}, (Color){255,0,255,255}, (Color){255,0,0,255}, (Color){255,0,0,255}, (Color){255,0,255,255}); // TEST
// Draw checked background
for (int i = 0; i < 38; i++) DrawRectangle(bounds.x + 10*(i%19), bounds.x + bounds.width + 10 + 10*(i/19), bounds.width/20, bounds.width/20, (i%2) ? GRAY : LIGHTGRAY);
DrawRectangleGradientEx((Rectangle){bounds.x, bounds.x + bounds.width + 10, bounds.width, 20}, Fade(WHITE, 0), Fade(WHITE, 0), BLUE, BLUE);
DrawRectangle(bounds.x + bounds.width + 6, 120, 28, 5, WHITE);
DrawRectangleLines(bounds.x + bounds.width + 6, 120, 28, 5, BLACK);
DrawRectangle(196, bounds.y + bounds.height + 6, 5, 28, WHITE);
DrawRectangleLines(196, bounds.y + bounds.height + 6, 5, 28, BLACK);
DrawCircle(150, 150, 4, WHITE);
switch (state)
{
case NORMAL:
{
} break;
case FOCUSED:
{
} break;
case PRESSED:
{
} break;
default: break;
}
//------------------------------------------------------------------
return color;
}
// TODO: Panel system
RAYGUIDEF void GuiBeginPanel(Rectangle rec)
{