| 1 | #include "stdlib.h" |
|---|
| 2 | #include "platform.h" |
|---|
| 3 | #include "core.h" |
|---|
| 4 | #include "keyboard.h" |
|---|
| 5 | #include "conf.h" |
|---|
| 6 | #include "lang.h" |
|---|
| 7 | #include "gui.h" |
|---|
| 8 | #include "gui_draw.h" |
|---|
| 9 | #include "gui_lang.h" |
|---|
| 10 | #include "gui_palette.h" |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | #include "module_load.h" |
|---|
| 14 | void gui_module_menu_kbd_process(); |
|---|
| 15 | |
|---|
| 16 | gui_handler GUI_MODE_PALETTE_MODULE = |
|---|
| 17 | /*GUI_MODE_PALETTE*/ { gui_palette_draw, gui_palette_kbd_process, gui_module_menu_kbd_process, 0, GUI_MODE_MAGICNUM }; |
|---|
| 18 | |
|---|
| 19 | //------------------------------------------------------------------- |
|---|
| 20 | static color cl; |
|---|
| 21 | static int palette_mode; |
|---|
| 22 | static void (*palette_on_select)(color clr); |
|---|
| 23 | static int gui_palette_redraw; |
|---|
| 24 | |
|---|
| 25 | //------------------------------------------------------------------- |
|---|
| 26 | void gui_palette_init(int mode, color st_color, void (*on_select)(color clr)) { |
|---|
| 27 | draw_restore(); |
|---|
| 28 | cl = st_color; |
|---|
| 29 | palette_mode = mode; |
|---|
| 30 | palette_on_select = on_select; |
|---|
| 31 | gui_palette_redraw = 1; |
|---|
| 32 | gui_set_mode((unsigned int)&GUI_MODE_PALETTE_MODULE); |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | //------------------------------------------------------------------- |
|---|
| 36 | void gui_palette_kbd_process() { |
|---|
| 37 | switch (kbd_get_autoclicked_key()) |
|---|
| 38 | { |
|---|
| 39 | case KEY_DOWN: |
|---|
| 40 | cl = (((cl+16)&0xf0)|(cl&0x0f)); |
|---|
| 41 | gui_palette_redraw = 1; |
|---|
| 42 | break; |
|---|
| 43 | case KEY_UP: |
|---|
| 44 | cl = (((cl-16)&0xf0)|(cl&0x0f)); |
|---|
| 45 | gui_palette_redraw = 1; |
|---|
| 46 | break; |
|---|
| 47 | case KEY_LEFT: |
|---|
| 48 | cl = ((cl&0xf0)|((cl-1)&0x0f)); |
|---|
| 49 | gui_palette_redraw = 1; |
|---|
| 50 | break; |
|---|
| 51 | case KEY_RIGHT: |
|---|
| 52 | cl = ((cl&0xf0)|((cl+1)&0x0f)); |
|---|
| 53 | gui_palette_redraw = 1; |
|---|
| 54 | break; |
|---|
| 55 | case KEY_SET: |
|---|
| 56 | if (palette_mode == PALETTE_MODE_SELECT) |
|---|
| 57 | { |
|---|
| 58 | if (palette_on_select) |
|---|
| 59 | palette_on_select(cl); |
|---|
| 60 | gui_module_menu_kbd_process(); |
|---|
| 61 | } |
|---|
| 62 | break; |
|---|
| 63 | } |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | //------------------------------------------------------------------- |
|---|
| 67 | #define CELL_SIZE 13 |
|---|
| 68 | #define BORDER_SIZE 8 |
|---|
| 69 | #define CELL_ZOOM 6 |
|---|
| 70 | #define DISP_LEFT BORDER_SIZE |
|---|
| 71 | #define DISP_RIGHT (BORDER_SIZE + CELL_SIZE * 16) |
|---|
| 72 | #define DISP_TOP (FONT_HEIGHT + BORDER_SIZE) |
|---|
| 73 | #define DISP_BOTTOM (FONT_HEIGHT + BORDER_SIZE + CELL_SIZE * 16) |
|---|
| 74 | |
|---|
| 75 | void gui_palette_draw(int enforce_redraw) { |
|---|
| 76 | unsigned int x, y, xl, xr; |
|---|
| 77 | char f=0; |
|---|
| 78 | color c; |
|---|
| 79 | static char buf[64]; |
|---|
| 80 | |
|---|
| 81 | xl = CAM_TS_BUTTON_BORDER; |
|---|
| 82 | xr = screen_width - CAM_TS_BUTTON_BORDER; |
|---|
| 83 | |
|---|
| 84 | if (gui_palette_redraw) |
|---|
| 85 | { |
|---|
| 86 | // Draw top text line - current color + instructions |
|---|
| 87 | draw_string(xr-29*FONT_WIDTH, 0, " Use \x18\x19\x1b\x1a to change color ", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE)); |
|---|
| 88 | sprintf(buf, " %s: 0x%02hX ", lang_str(LANG_PALETTE_TEXT_COLOR), (unsigned char)cl); |
|---|
| 89 | draw_string(xl, 0, buf, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE)); |
|---|
| 90 | |
|---|
| 91 | // Draw Palette color boxes |
|---|
| 92 | c = COLOR_BLACK; |
|---|
| 93 | for (y=DISP_TOP; y<DISP_BOTTOM; y+=CELL_SIZE) |
|---|
| 94 | { |
|---|
| 95 | for (x=DISP_LEFT; x<DISP_RIGHT; x+=CELL_SIZE, c+=0x0100) |
|---|
| 96 | { |
|---|
| 97 | draw_filled_rect(xl+x, y, xl+x+CELL_SIZE, y+CELL_SIZE, c); |
|---|
| 98 | } |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | // Draw gray borders |
|---|
| 102 | draw_rect_thick(xl, DISP_TOP-BORDER_SIZE, xr-1, screen_height-1, COLOR_GREY, BORDER_SIZE); // outer border |
|---|
| 103 | draw_filled_rect(xl+DISP_RIGHT+1, DISP_TOP, xl+DISP_RIGHT+BORDER_SIZE, DISP_BOTTOM, MAKE_COLOR(COLOR_GREY, COLOR_GREY)); //middle |
|---|
| 104 | |
|---|
| 105 | // Co-ordinate of selected color |
|---|
| 106 | y = DISP_TOP + ((cl>>4)&0x0F) * CELL_SIZE; |
|---|
| 107 | x = DISP_LEFT + (cl&0x0F) * CELL_SIZE; |
|---|
| 108 | |
|---|
| 109 | // Highlight selected color |
|---|
| 110 | draw_filled_rect_thick(xl+x-CELL_ZOOM, y-CELL_ZOOM, xl+x+CELL_SIZE+CELL_ZOOM, y+CELL_SIZE+CELL_ZOOM, MAKE_COLOR(cl, COLOR_RED), 2); |
|---|
| 111 | |
|---|
| 112 | // Fill 'sample' area with selected color |
|---|
| 113 | draw_filled_rect(xl+DISP_RIGHT+BORDER_SIZE+1, DISP_TOP, xr-BORDER_SIZE-1, DISP_BOTTOM, MAKE_COLOR(cl, COLOR_WHITE)); |
|---|
| 114 | |
|---|
| 115 | gui_palette_redraw = 0; |
|---|
| 116 | } |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | extern int module_idx; |
|---|
| 120 | void gui_module_menu_kbd_process() { |
|---|
| 121 | gui_default_kbd_process_menu_btn(); |
|---|
| 122 | module_async_unload(module_idx); |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | // ========= MODULE INIT ================= |
|---|
| 126 | #include "module_load.h" |
|---|
| 127 | int module_idx=-1; |
|---|
| 128 | |
|---|
| 129 | /***************** BEGIN OF AUXILARY PART ********************* |
|---|
| 130 | ATTENTION: DO NOT REMOVE OR CHANGE SIGNATURES IN THIS SECTION |
|---|
| 131 | **************************************************************/ |
|---|
| 132 | |
|---|
| 133 | int _chdk_required_ver = 1; // minimal required chdk build. 0-no limitation |
|---|
| 134 | int _chdk_required_platfid = 0; // platform-specific module. 0-no limitation |
|---|
| 135 | |
|---|
| 136 | void* MODULE_EXPORT_LIST[] = { |
|---|
| 137 | /* 0 */ (void*)EXPORTLIST_MAGIC_NUMBER, |
|---|
| 138 | /* 1 */ (void*)0 |
|---|
| 139 | }; |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | //--------------------------------------------------------- |
|---|
| 143 | // PURPOSE: Bind module symbols with chdk. |
|---|
| 144 | // Required function |
|---|
| 145 | // PARAMETERS: pointer to chdk list of export |
|---|
| 146 | // RETURN VALUE: 1 error, 0 ok |
|---|
| 147 | //--------------------------------------------------------- |
|---|
| 148 | int _module_loader( void** chdk_export_list ) |
|---|
| 149 | { |
|---|
| 150 | if ( (unsigned int)chdk_export_list[0] != EXPORTLIST_MAGIC_NUMBER ) |
|---|
| 151 | return 1; |
|---|
| 152 | |
|---|
| 153 | // Try to bind to generic gui mode alias |
|---|
| 154 | if (!gui_bind_mode( GUI_MODE_PALETTE, &GUI_MODE_PALETTE_MODULE)) |
|---|
| 155 | return 1; |
|---|
| 156 | |
|---|
| 157 | return 0; |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | //--------------------------------------------------------- |
|---|
| 163 | // PURPOSE: Finalize module operations (close allocs, etc) |
|---|
| 164 | // RETURN VALUE: 0-ok, 1-fail |
|---|
| 165 | //--------------------------------------------------------- |
|---|
| 166 | int _module_unloader() |
|---|
| 167 | { |
|---|
| 168 | //sanity clean to prevent accidentaly assign/restore guimode to unloaded module |
|---|
| 169 | GUI_MODE_PALETTE_MODULE.magicnum = 0; |
|---|
| 170 | |
|---|
| 171 | // unbind generic alias |
|---|
| 172 | gui_bind_mode( GUI_MODE_PALETTE, 0); |
|---|
| 173 | |
|---|
| 174 | return 0; |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | //--------------------------------------------------------- |
|---|
| 179 | // PURPOSE: Default action for simple modules (direct run) |
|---|
| 180 | // NOTE: Please comment this function if no default action and this library module |
|---|
| 181 | //--------------------------------------------------------- |
|---|
| 182 | int _module_run(int moduleidx, int argn, int* arguments) |
|---|
| 183 | { |
|---|
| 184 | module_idx=moduleidx; |
|---|
| 185 | |
|---|
| 186 | if ( argn!=3) { |
|---|
| 187 | module_async_unload(moduleidx); |
|---|
| 188 | return 1; |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | gui_palette_init( arguments[0], (color)arguments[1], (void*)arguments[2]); |
|---|
| 192 | |
|---|
| 193 | return 0; |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | |
|---|
| 197 | /*************** END OF AUXILARY PART *******************/ |
|---|