]> git.mcshandy.xyz Git - picker/commitdiff
Added a palette system
authorRandy McShandy <randy@mcshandy.xyz>
Sun, 8 Oct 2023 00:56:51 +0000 (19:56 -0500)
committerRandy McShandy <randy@mcshandy.xyz>
Sun, 8 Oct 2023 00:56:51 +0000 (19:56 -0500)
project.vim
source/config.h
source/rendering.c
source/structs.h
tasks.md

index 8ec80d4dacaa19fa425dc61eb21f7427daf0410b..f9e639161d798fdeddec1229647136200833bb4d 100644 (file)
@@ -14,14 +14,10 @@ augroup remember_folds
 augroup END
 
 " start up a faux-IDE view
-command! Ide call s:ide()
-function! s:ide()
-       execute("sp")
-       execute("\<C-w\>J")
-       execute("resize 10")
-       execute("term")
-       execute("NERDTreeToggle")
-endfunction
+execute("sp")
+execute("resize 10")
+execute("term")
+execute("NERDTreeToggle")
 
 let $src=prj_base.'/source'
 let $bin=prj_base.'/bin'
index 1c5113586da1fbd0a1c11e19897c2854705ecec3..f15e5e20c1bf5571233ae1885c47af6a40bc7540 100644 (file)
@@ -21,8 +21,8 @@ Window_Layout config_layout = {
 // satisfying rel.[xy]*2 == .[wh] centers axis in parent container
        .hsl_square.rel                                         =       (SDL_FRect){.x = 0.05, .y = 0.05, .w = 0.50, .h = 0.50},
        .hue_slider.rel                                         =       (SDL_FRect){.x = 0.70, .y = 0.05, .w = 0.08, .h = 0.50},
-       .final_sample.rel                                       =       (SDL_FRect){.x = 0.05, .y = 0.65, .w = 0.20, .h = 0.20},
-       .info_container.rel                             =       (SDL_FRect){.x = 0.05, .y = 0.65, .w = 0.90, .h = 0.30},
+       .final_sample.rel                                       =       (SDL_FRect){.x = 0.05, .y = 0.60, .w = 0.20, .h = 0.20},
+       .info_container.rel                             =       (SDL_FRect){.x = 0.05, .y = 0.60, .w = 0.90, .h = 0.40},
        .info_boxes.rel                                         =       (SDL_FRect){.x = 0.25, .y = 0.00, .w = 0.75, .h = 1.00},
        .rgb_info.rel                                                   =       (SDL_FRect){.x = 0.00, .y = 0.00, .w = 1.00, .h = 0.50},
        .red_component.body.rel         =       (SDL_FRect){.x = 0.00, .y = 0.00, .w = 0.30, .h = 1.00},
@@ -31,7 +31,8 @@ Window_Layout config_layout = {
        .hsl_info.rel                                                   =       (SDL_FRect){.x = 0.50, .y = 0.00, .w = 1.00, .h = 0.50},
        .hue_component.body.rel         =       (SDL_FRect){.x = 0.00, .y = 0.00, .w = 0.30, .h = 1.00},
        .sat_component.body.rel         =       (SDL_FRect){.x = 0.00, .y = 0.40, .w = 0.30, .h = 1.00},
-       .lum_component.body.rel         =       (SDL_FRect){.x = 0.00, .y = 0.80, .w = 0.30, .h = 1.00}
+       .lum_component.body.rel         =       (SDL_FRect){.x = 0.00, .y = 0.80, .w = 0.30, .h = 1.00},
+       .palette.rel                                                    = (SDL_FRect){.x = 0.00, .y = 0.60, .w = 1.00, .h = 0.30}
 };
 
 #endif //__PICKER_CONFIG__
index 691786b71943207a6cf39c200a14dae79509bdad..498762d82df89668924b0e089afa3209950aa94f 100644 (file)
@@ -15,6 +15,7 @@ SDL_Color green = {0, 255, 0, 255};
 SDL_Color blue = {0, 0, 255, 255};
 SDL_Color black = {0, 0, 0, 255};
 SDL_Color white = {255, 255, 255, 255};
+HSL_Color hsl_white = {0, 0, 100};
 SDL_Color magenta = {255, 0, 255, 255};
 
 sdl_group mgr;
@@ -35,6 +36,7 @@ int32_t refresh_layout(Runtime_Info* runtime)
        render_container(&runtime->layout.window, &runtime->layout.info_container);
        render_container(&runtime->layout.window, &runtime->layout.final_sample);
        render_container(&runtime->layout.info_container.real, &runtime->layout.info_boxes);
+       render_container(&runtime->layout.info_container.real, &runtime->layout.palette);
        render_container(&runtime->layout.info_boxes.real, &runtime->layout.rgb_info);
        render_container(&runtime->layout.rgb_info.real, &runtime->layout.red_component.body);
        render_container(&runtime->layout.rgb_info.real, &runtime->layout.green_component.body);
@@ -86,6 +88,11 @@ int32_t init_renderer(Runtime_Info* runtime)
        init_text_container(&runtime->layout.sat_component, 64);
        init_text_container(&runtime->layout.lum_component, 64);
 
+       for (int p = 0; p < PALETTE_SIZE; p++)
+       {
+               runtime->layout.palette_color[p] = hsl_white;
+       }
+
        refresh_layout(runtime);
 
        return 0;
@@ -152,8 +159,27 @@ int32_t mouse_click_in_container(Runtime_Info* runtime, SDL_FRect* container)
        return 0;
 }
 
-// Rename this eventually
-// It's actually HSL
+int32_t render_palette(Runtime_Info* runtime, SDL_FRect* container)
+{
+       for (int p = 0; p < PALETTE_SIZE; p++)
+       {
+               SDL_Color item_color = hsl_to_rgb(runtime->layout.palette_color[p]);
+               SDL_FRect item = {
+                       .x = container->x + (p * ((float)container->w / (float)PALETTE_SIZE)), .y = container->y,
+                       .w = ((float)container->w / PALETTE_SIZE) * 0.90, .h = container->h};
+
+               SDL_SetRenderDrawColor(mgr.rend, unroll_sdl_color(item_color));
+               if (p == runtime->active_palette)
+               {
+                       SDL_SetRenderDrawColor(mgr.rend, unroll_sdl_color(item_color));
+                       item.h *= 1.2;
+               }
+               SDL_RenderFillRectF(mgr.rend, &item);
+       }
+
+       return 0;
+}
+
 int32_t render_hsl_square(Runtime_Info* runtime, SDL_FRect* container)
 {
        NULL_CHECK(runtime);
@@ -354,6 +380,7 @@ int32_t render_layout(Runtime_Info* runtime, Window_Layout* layout)
        render_vertical_hue_spectrum(runtime, &layout->hue_slider.real);
        render_hsl_square(runtime, &layout->hsl_square.real);
        render_info_boxes(runtime, &layout->info_boxes.real);
+       render_palette(runtime, &layout->palette.real);
 
        return 0;
 }
@@ -422,6 +449,7 @@ int32_t check_inputs(Runtime_Info* runtime)
                }
                if (mgr.event.type == SDL_KEYUP)
                {
+                       int p = runtime->active_palette;
                        switch(mgr.event.key.keysym.sym)
                        {
                                case SDLK_q:
@@ -431,7 +459,36 @@ int32_t check_inputs(Runtime_Info* runtime)
                                case SDLK_LSHIFT:
                                        move_speed = 1;
                                        break;
+
+                               case SDLK_0:
+                               case SDLK_1:
+                               case SDLK_2:
+                               case SDLK_3:
+                               case SDLK_4:
+                               case SDLK_5:
+                               case SDLK_6:
+                               case SDLK_7:
+                               case SDLK_8:
+                               case SDLK_9:
+                               {
+                                       int new_palette = mgr.event.key.keysym.sym - 48 - 1;
+                                       if (new_palette < 0)
+                                               new_palette = PALETTE_SIZE-1;
+
+                                       if (new_palette <= PALETTE_SIZE)
+                                       {
+                                               runtime->active_palette = new_palette;
+                                               runtime->active_hsl = runtime->layout.palette_color[new_palette];
+                                               runtime->active_rgb = hsl_to_rgb(runtime->active_hsl);
+                                       }
+                               } break;
+
+                               case SDLK_RETURN:
+                               case SDLK_KP_ENTER:
+                                       runtime->layout.palette_color[p] = runtime->active_hsl;
+                                       break;
                        }
+
                }
 
        }
index 1cbf73d682b3b2215ce6f469f42256b6cab61ee4..92053ecc9496b535c3bcd1fa26f8887e7809b716 100644 (file)
@@ -6,6 +6,8 @@
 #define Relative_Rect SDL_FRect
 #include <stdint.h>
 
+#define PALETTE_SIZE 10
+
 // A placeable rect, with relative components to its parent,
 // and its finalized real placement rectangle
 typedef struct
@@ -54,20 +56,23 @@ typedef struct
 {
        // Tabbing these to visually indicate layout
        SDL_FRect window;
-               Layout_Rect hsl_square; // big clicky draggy square
-               Layout_Rect hue_slider; // HSV slider bar
-               Layout_Rect info_container;
-                       Layout_Rect final_sample; // small square showing full selected color
-                       Layout_Rect info_boxes;
-                               Layout_Rect rgb_info;
-                                       Text_Container red_component;
-                                       Text_Container green_component;
-                                       Text_Container blue_component;
-                               Layout_Rect hsl_info;
-                                       Text_Container hue_component;
-                                       Text_Container sat_component;
-                                       Text_Container lum_component;
-
+       Layout_Rect hsl_square; // big clicky draggy square
+       Layout_Rect hue_slider; // HSV slider bar
+       Layout_Rect info_container;
+               Layout_Rect palette;
+               Layout_Rect final_sample; // small square showing full selected color
+               Layout_Rect info_boxes;
+                       Layout_Rect rgb_info;
+                               Text_Container red_component;
+                               Text_Container green_component;
+                               Text_Container blue_component;
+                       Layout_Rect hsl_info;
+                               Text_Container hue_component;
+                               Text_Container sat_component;
+                               Text_Container lum_component;
+
+       Layout_Rect palette_item[PALETTE_SIZE];
+       HSL_Color               palette_color[PALETTE_SIZE];
 } Window_Layout;
 
 typedef struct
@@ -85,6 +90,8 @@ typedef struct
        SDL_Point mouse_click_pos;
        int mouse_click;
 
+       int active_palette;
+
 } Runtime_Info;
 
 #endif // STRUCTS__
index 507fd003c6a9fae3678518061579044c4075d43a..babe5ccdd56faf91867485dee39b8fdcfd906208 100644 (file)
--- a/tasks.md
+++ b/tasks.md
@@ -1,17 +1,21 @@
 ## To Do
 
-- Mode-based keybinds
 - UI library
     > Move UI stuff into a standalone library some day, because it's kinda cool
+- Color export
+    > Send active color somewhere like the clipboard. X usually uses xclip, so it'll need pipes.
 
 ## Doing
 
 
 ## Done
 
-- Color export
 - Config header
 - Cleanup
     * [x] Text rendering
     * [x] Layout rendering
     * [x] Old gameframe cruft needs to go
+- Mouse support
+    > Add some simple mouse support for hue spectrum and S/L box
+- Palette
+    > Add a palette for saving and recalling colors