source: branches/reyalp-flt/core/gui_palette.c @ 1536

Revision 1536, 6.4 KB checked in by philmoz, 17 months ago (diff)

Updates to module system:

  • Use hash value of symbol name to find addresses exported from CHDK when loading a module (instead of the array index). This removes the current constraints on making changes to the exported list of symbols.
  • Moved the 'Games' sub menu to a module. New games can be added as modules without any changes to the core CHDK (unless new exported symbols are needed).
  • Changed all the game modules to use 'simple_game.c' for consistency.
  • Property svn:eol-style set to native
RevLine 
[243]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
[1467]12
13#include "module_load.h"
[1513]14
[1467]15void gui_module_menu_kbd_process();
[1513]16void gui_palette_kbd_process();
17void gui_palette_draw(int enforce_redraw);
[1467]18
[1474]19gui_handler GUI_MODE_PALETTE_MODULE =
[1513]20    /*GUI_MODE_PALETTE*/    { GUI_MODE_PALETTE, gui_palette_draw,     gui_palette_kbd_process,    gui_module_menu_kbd_process, 0, GUI_MODE_MAGICNUM };
[1467]21
[243]22//-------------------------------------------------------------------
23static color cl;
24static int palette_mode;
25static void (*palette_on_select)(color clr);
26static int gui_palette_redraw;
27
28//-------------------------------------------------------------------
29void gui_palette_init(int mode, color st_color, void (*on_select)(color clr)) {
[1467]30        draw_restore();
[243]31    cl = st_color;
32    palette_mode = mode;
33    palette_on_select = on_select;
34    gui_palette_redraw = 1;
[1513]35        gui_set_mode(&GUI_MODE_PALETTE_MODULE);
[243]36}
37
38//-------------------------------------------------------------------
39void gui_palette_kbd_process() {
[1234]40    switch (kbd_get_autoclicked_key())
41    {
42        case KEY_DOWN:
43            cl = (((cl+16)&0xf0)|(cl&0x0f));
[243]44            gui_palette_redraw = 1;
[1234]45            break;
46        case KEY_UP:
47            cl = (((cl-16)&0xf0)|(cl&0x0f));
[243]48            gui_palette_redraw = 1;
[1234]49            break;
50        case KEY_LEFT:
51            cl = ((cl&0xf0)|((cl-1)&0x0f));
[243]52            gui_palette_redraw = 1;
[1234]53            break;
54        case KEY_RIGHT:
55            cl = ((cl&0xf0)|((cl+1)&0x0f));
[243]56            gui_palette_redraw = 1;
[1234]57            break;
58        case KEY_SET:
59            if (palette_mode == PALETTE_MODE_SELECT)
60            {
61                if (palette_on_select)
62                    palette_on_select(cl);
[1467]63                gui_module_menu_kbd_process();
[1234]64            }
65            break;
[243]66    }
67}
68
69//-------------------------------------------------------------------
[1234]70#define CELL_SIZE           13
71#define BORDER_SIZE         8
72#define CELL_ZOOM           6
73#define DISP_LEFT           BORDER_SIZE
74#define DISP_RIGHT          (BORDER_SIZE + CELL_SIZE * 16)
75#define DISP_TOP            (FONT_HEIGHT + BORDER_SIZE)
76#define DISP_BOTTOM         (FONT_HEIGHT + BORDER_SIZE + CELL_SIZE * 16)
77
[1467]78void gui_palette_draw(int enforce_redraw) {
[1338]79    unsigned int x, y, xl, xr;
[243]80    char f=0;
81    color c;
82    static char buf[64];
83
[1514]84    xl = camera_screen.ts_button_border;
85    xr = camera_screen.width - camera_screen.ts_button_border;
[1338]86
[1234]87    if (gui_palette_redraw)
88    {
89        // Draw top text line - current color + instructions
[1338]90        draw_string(xr-29*FONT_WIDTH, 0, "    Use \x18\x19\x1b\x1a to change color ", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
[1234]91        sprintf(buf, " %s: 0x%02hX    ", lang_str(LANG_PALETTE_TEXT_COLOR), (unsigned char)cl);
[1338]92        draw_string(xl, 0, buf, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
[243]93
[1234]94        // Draw Palette color boxes
95        c = COLOR_BLACK;
96        for (y=DISP_TOP; y<DISP_BOTTOM; y+=CELL_SIZE)
97        {
[1534]98            for (x=DISP_LEFT; x<DISP_RIGHT; x+=CELL_SIZE, c+=MAKE_COLOR(1,0))
[1234]99            {
[1338]100                draw_filled_rect(xl+x, y, xl+x+CELL_SIZE, y+CELL_SIZE, c);
[243]101            }
[1234]102        }
103
104        // Draw gray borders
[1514]105        draw_rect_thick(xl, DISP_TOP-BORDER_SIZE, xr-1, camera_screen.height-1, COLOR_GREY, BORDER_SIZE); // outer border
[1338]106        draw_filled_rect(xl+DISP_RIGHT+1, DISP_TOP, xl+DISP_RIGHT+BORDER_SIZE, DISP_BOTTOM, MAKE_COLOR(COLOR_GREY, COLOR_GREY)); //middle
[1234]107
[1338]108        // Co-ordinate of selected color
[1234]109        y = DISP_TOP + ((cl>>4)&0x0F) * CELL_SIZE;
110        x = DISP_LEFT + (cl&0x0F) * CELL_SIZE;
111
112        // Highlight selected color
[1338]113        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);
[1234]114
115        // Fill 'sample' area with selected color
[1338]116        draw_filled_rect(xl+DISP_RIGHT+BORDER_SIZE+1, DISP_TOP, xr-BORDER_SIZE-1, DISP_BOTTOM, MAKE_COLOR(cl, COLOR_WHITE));
[1234]117
118        gui_palette_redraw = 0;
[243]119    }
120}
121
[1467]122extern int module_idx;
123void gui_module_menu_kbd_process() {
124        gui_default_kbd_process_menu_btn();
125        module_async_unload(module_idx);
126}
127
128// =========  MODULE INIT =================
129#include "module_load.h"
130int module_idx=-1;
131
132/***************** BEGIN OF AUXILARY PART *********************
133  ATTENTION: DO NOT REMOVE OR CHANGE SIGNATURES IN THIS SECTION
134 **************************************************************/
135
136void* 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//---------------------------------------------------------
[1536]148int _module_loader( unsigned int* chdk_export_list )
[1467]149{
[1536]150  if ( chdk_export_list[0] != EXPORTLIST_MAGIC_NUMBER )
[1467]151     return 1;
[1516]152  if ( !API_VERSION_MATCH_REQUIREMENT( gui_version.common_api, 1, 0 ) )
153          return 1;
[1467]154
155  return 0;
156}
157
158
159
160//---------------------------------------------------------
161// PURPOSE: Finalize module operations (close allocs, etc)
162// RETURN VALUE: 0-ok, 1-fail
163//---------------------------------------------------------
164int _module_unloader()
165{
[1474]166  //sanity clean to prevent accidentaly assign/restore guimode to unloaded module
167  GUI_MODE_PALETTE_MODULE.magicnum = 0;
[1467]168
169  return 0;
170}
171
172
173//---------------------------------------------------------
174// PURPOSE: Default action for simple modules (direct run)
175// NOTE: Please comment this function if no default action and this library module
176//---------------------------------------------------------
177int _module_run(int moduleidx, int argn, int* arguments)
178{
179  module_idx=moduleidx;
180
[1489]181  if ( argn!=0 && argn!=3) {
[1467]182        module_async_unload(moduleidx);
183    return 1;
184  }
185
[1489]186  if ( argn==3 )
[1534]187    gui_palette_init( arguments[0], (color)arguments[1], (void*)arguments[2]);
[1489]188  else
189        gui_palette_init( PALETTE_MODE_DEFAULT, 0x00, NULL );
[1467]190
191  return 0;
192}
193
[1483]194/******************** Module Information structure ******************/
[1467]195
[1483]196struct ModuleInfo _module_info = {      MODULEINFO_V1_MAGICNUM,
197                                                                        sizeof(struct ModuleInfo),
198
199                                                                        ANY_CHDK_BRANCH, 0,                     // Requirements of CHDK version
200                                                                        ANY_PLATFORM_ALLOWED,           // Specify platform dependency
[1535]201                                                                        0,                                                      // flag
[1483]202                                                                        (int32_t)"Palette",                                     // Module name
203                                                                        1, 0,                                           // Module version
204                                                                        0
205                                                                 };
206
[1467]207/*************** END OF AUXILARY PART *******************/
Note: See TracBrowser for help on using the repository browser.