root/modules/gui_palette.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. gui_palette_init
  2. gui_palette_kbd_process
  3. palette_test
  4. palette_draw
  5. gui_palette_draw
  6. gui_module_menu_kbd_process
  7. _module_can_unload
  8. _module_exit_alt

   1 #include "camera_info.h"
   2 #include "stdlib.h"
   3 #include "keyboard.h"
   4 #include "conf.h"
   5 #include "lang.h"
   6 #include "gui.h"
   7 #include "gui_draw.h"
   8 #include "gui_lang.h"
   9 
  10 #include "gui_palette.h"
  11 #include "module_def.h"
  12 
  13 #include "viewport.h"
  14 
  15 void gui_module_menu_kbd_process();
  16 int gui_palette_kbd_process();
  17 void gui_palette_draw();
  18 
  19 gui_handler GUI_MODE_PALETTE_MODULE = 
  20 /*GUI_MODE_PALETTE*/    { GUI_MODE_PALETTE, gui_palette_draw, gui_palette_kbd_process, gui_module_menu_kbd_process, 0, 0 };
  21 
  22 //-------------------------------------------------------------------
  23 static int running = 0;
  24 static chdkColor cl;
  25 static int palette_mode;
  26 static void (*palette_on_select)(chdkColor clr);
  27 static int gui_palette_redraw;
  28 static int test_page;
  29 
  30 //-------------------------------------------------------------------
  31 void gui_palette_init(int mode, chdkColor st_color, void (*on_select)(chdkColor clr))
  32 {
  33     running = 1;
  34     cl = st_color;
  35     palette_mode = mode;
  36     palette_on_select = on_select;
  37     gui_palette_redraw = 1;
  38     test_page = 0;
  39     gui_set_mode(&GUI_MODE_PALETTE_MODULE);
  40 }
  41 
  42 //-------------------------------------------------------------------
  43 int gui_palette_kbd_process()
  44 {
  45     switch (kbd_get_autoclicked_key())
  46     {
  47         case KEY_DOWN:
  48             if (palette_mode != PALETTE_MODE_TEST)
  49             {
  50                 if (cl.type)
  51                 {
  52                     cl.type = 0;
  53                     if (cl.col > 15)
  54                         cl.col = 15;
  55                 }
  56                 else
  57                 {
  58                     if ((cl.col & 0xF0) == 0xF0)
  59                     {
  60                         cl.type = 1;
  61                         cl.col &= 0x0F;
  62                     }
  63                     else
  64                     {
  65                         cl.col = (((cl.col+16)&0xf0)|(cl.col&0x0f));
  66                     }
  67                 }
  68                 gui_palette_redraw = 1;
  69             }
  70             break;
  71         case KEY_UP:
  72             if (palette_mode != PALETTE_MODE_TEST)
  73             {
  74                 if (cl.type)
  75                 {
  76                     cl.type = 0;
  77                     if (cl.col > 15)
  78                         cl.col = 15;
  79                     cl.col |= 0xF0;
  80                 }
  81                 else
  82                 {
  83                     if ((cl.col & 0xF0) == 0x00)
  84                     {
  85                         cl.type = 1;
  86                     }
  87                     else
  88                     {
  89                         cl.col = (((cl.col-16)&0xf0)|(cl.col&0x0f));
  90                     }
  91                 }
  92                 gui_palette_redraw = 1;
  93             }
  94             break;
  95         case KEY_LEFT:
  96             if (palette_mode != PALETTE_MODE_TEST)
  97             {
  98                 if (cl.type)
  99                 {
 100                     if (cl.col-- == 0) cl.col = IDX_COLOR_MAX;
 101                 }
 102                 else
 103                 {
 104                     cl.col = ((cl.col&0xf0)|((cl.col-1)&0x0f));
 105                 }
 106             }
 107             else
 108             {
 109                 if (--test_page < 0) test_page = 2;
 110             }
 111             gui_palette_redraw = 1;
 112             break;
 113         case KEY_RIGHT:
 114             if (palette_mode != PALETTE_MODE_TEST)
 115             {
 116                 if (cl.type)
 117                 {
 118                     if (cl.col++ == IDX_COLOR_MAX) cl.col = 0;
 119                 }
 120                 else
 121                 {
 122                     cl.col = ((cl.col&0xf0)|((cl.col+1)&0x0f));
 123                 }
 124             }
 125             else
 126             {
 127                 if (++test_page > 2) test_page = 0;
 128             }
 129             gui_palette_redraw = 1;
 130             break;
 131         case KEY_SET:
 132             if (palette_mode == PALETTE_MODE_SELECT)
 133             {
 134                 if (palette_on_select) 
 135                     palette_on_select(cl);
 136                 gui_module_menu_kbd_process();
 137             }
 138             break;
 139     }
 140     return 0;
 141 }
 142 
 143 //-------------------------------------------------------------------
 144 static void palette_test()
 145 {
 146     unsigned int x, y, xl, xr, w, h;
 147     color c;
 148 
 149     xl = camera_screen.disp_left;
 150     xr = camera_screen.disp_right;
 151 
 152     if (gui_palette_redraw)
 153     {
 154         // Draw top text line - current color + instructions
 155         draw_rectangle(xl, 0, xr, camera_screen.height-1, MAKE_COLOR(COLOR_BLACK, COLOR_BLACK), RECT_BORDER0|DRAW_FILLED);
 156         draw_string(xr-22*FONT_WIDTH, 0, "Use \x1b\x1a to change page", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 157 
 158         color cols[3][20] = {
 159                 {
 160                         COLOR_WHITE         ,COLOR_RED           ,COLOR_RED_DK        ,COLOR_RED_LT        ,
 161                         COLOR_GREEN         ,COLOR_BLUE          ,COLOR_BLUE_LT       ,COLOR_YELLOW        ,
 162                         COLOR_GREY          ,COLOR_GREY_DK       ,COLOR_GREY_LT       ,COLOR_TRANSPARENT
 163                 },
 164                 {
 165                         COLOR_RED       ,COLOR_GREEN     ,
 166                         COLOR_BLUE      ,COLOR_CYAN      ,
 167                         COLOR_MAGENTA   ,COLOR_YELLOW
 168                 },
 169                 {
 170                         3   ,6  ,9  ,12 ,15,
 171                         4   ,7  ,10 ,13 ,16,
 172                         5   ,8  ,11 ,14 ,17,
 173                         1   ,1  ,1  ,18 ,1
 174                 }
 175         };
 176 
 177         char *nams[3][20] = {
 178                 {
 179                         "white", "red", "dark red", "light red",
 180                         "green", "blue", "light blue", "yellow",
 181                         "grey", "dark grey", "light grey", "transparent"
 182                 },
 183                 {
 184                         "red", "green", "blue", "cyan", "magenta", "yellow",
 185                 },
 186                 {
 187                         "red", "green", "blue", "grey", "yellow",
 188                         "dk red", "dk green", "dk blue", "dk grey", "dk yellow",
 189                         "lt red", "lt green", "lt blue", "lt grey", "lt yellow",
 190                         "", "", "", "trns grey", ""
 191                 }
 192         };
 193 
 194         if (test_page == 0)
 195         {
 196             draw_string(xl, 0, "System Colors", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 197             c = 0;
 198             w = camera_screen.disp_width / 4;
 199             h = (camera_screen.height - (2 * FONT_HEIGHT)) / 3;
 200             for (y=0; y<3; y++)
 201             {
 202                 for (x=0; x<4; x++, c++)
 203                 {
 204                     draw_rectangle(xl+(x*w), (2*FONT_HEIGHT)+(y*h), xl+(x*w)+w-1, (2*FONT_HEIGHT)+(y*h)+h-FONT_HEIGHT-6, MAKE_COLOR(cols[test_page][c],cols[test_page][c]), RECT_BORDER0|DRAW_FILLED);
 205                     draw_string(xl+(x*w),(2*FONT_HEIGHT)+(y*h)+h-FONT_HEIGHT-3, nams[test_page][c], MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 206                 }
 207             }
 208         }
 209         else if (test_page == 1)
 210         {
 211             draw_string(xl, 0, "Histogram Colors", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 212             c = 0;
 213             w = camera_screen.disp_width / 2;
 214             h = (camera_screen.height - (2 * FONT_HEIGHT)) / 3;
 215             for (y=0; y<3; y++)
 216             {
 217                 for (x=0; x<2; x++, c++)
 218                 {
 219                     draw_rectangle(xl+(x*w), (2*FONT_HEIGHT)+(y*h), xl+(x*w)+w-1, (2*FONT_HEIGHT)+(y*h)+h-FONT_HEIGHT-6, MAKE_COLOR(cols[test_page][c],cols[test_page][c]), RECT_BORDER0|DRAW_FILLED);
 220                     draw_string(xl+(x*w),(2*FONT_HEIGHT)+(y*h)+h-FONT_HEIGHT-3, nams[test_page][c], MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 221                 }
 222             }
 223         }
 224         else if (test_page == 2)
 225         {
 226             draw_string(xl, 0, "Script/Icon Colors", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 227             c = 0;
 228             w = camera_screen.disp_width / 5;
 229             h = (camera_screen.height - (2 * FONT_HEIGHT)) / 4;
 230             for (y=0; y<4; y++)
 231             {
 232                 for (x=0; x<5; x++, c++)
 233                 {
 234                     draw_rectangle(xl+(x*w), (2*FONT_HEIGHT)+(y*h), xl+(x*w)+w-1, (2*FONT_HEIGHT)+(y*h)+h-FONT_HEIGHT-6,
 235                             MAKE_COLOR(get_script_color(cols[test_page][c]+256),get_script_color(cols[test_page][c]+256)), RECT_BORDER0|DRAW_FILLED);
 236                     draw_string(xl+(x*w),(2*FONT_HEIGHT)+(y*h)+h-FONT_HEIGHT-3, nams[test_page][c], MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 237                 }
 238             }
 239         }
 240 
 241         gui_palette_redraw = 0;
 242     }
 243 }
 244 
 245 //-------------------------------------------------------------------
 246 // sizes computed at runtime
 247 #define CELL_SIZE           cellsize
 248 #define BORDER_SIZE         6
 249 #define CELL_ZOOM           BORDER_SIZE
 250 #define DISP_TOP_CHDK       (FONT_HEIGHT + BORDER_SIZE)
 251 #define DISP_TOP            disptop
 252 #define DISP_LEFT           BORDER_SIZE
 253 #define DISP_RIGHT          dispright
 254 #define DISP_BOTTOM         dispbottom
 255 
 256 static void palette_draw()
 257 {
 258     unsigned int x, y, xl, xr;
 259     color c;
 260     static char buf[64];
 261     static int cellsize = 0, disptop, dispright, dispbottom;
 262 
 263     if (!cellsize)
 264     {
 265         // calculate these only once
 266         cellsize = (camera_screen.height - FONT_HEIGHT - 3 * BORDER_SIZE -1 ) / 17;
 267         disptop = camera_screen.height + DISP_TOP_CHDK - cellsize * 16 - FONT_HEIGHT - 2 * BORDER_SIZE - 1;
 268         dispright = DISP_LEFT + cellsize * 16;
 269         dispbottom = DISP_TOP + cellsize * 16;
 270     }
 271 
 272     xl = camera_screen.disp_left;
 273     xr = camera_screen.disp_right;
 274     int *pal = (int*)vid_get_bitmap_active_palette();
 275 
 276     if (gui_palette_redraw)
 277     {
 278         // Draw top text line - current color + instructions
 279         draw_rectangle(xl, 0, xr, FONT_HEIGHT-1, MAKE_COLOR(COLOR_BLACK, COLOR_BLACK), RECT_BORDER0|DRAW_FILLED);
 280         draw_string(xr-29*FONT_WIDTH, 0, "    Use \x18\x19\x1b\x1a to change color ", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 281         if ( pal )
 282             sprintf(buf, " %s: 0x%02hX 0x%08X", lang_str(LANG_PALETTE_TEXT_COLOR), cl.col, pal[chdkColorToCanonColor(cl)]);
 283         else
 284             sprintf(buf, " %s: 0x%02hX", lang_str(LANG_PALETTE_TEXT_COLOR), cl.col );
 285         draw_string(xl, 0, buf, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 286 
 287         // Draw gray borders
 288         draw_rectangle(xl, DISP_TOP_CHDK-BORDER_SIZE, xr, camera_screen.height-1, MAKE_COLOR(COLOR_GREY, COLOR_GREY), RECT_BORDER6); // outer border
 289         draw_rectangle(xl+BORDER_SIZE, DISP_TOP_CHDK+CELL_SIZE+1, xr-BORDER_SIZE, DISP_TOP-1, MAKE_COLOR(COLOR_GREY, COLOR_GREY), RECT_BORDER0|DRAW_FILLED); //horiz divider
 290         draw_rectangle(xl+DISP_RIGHT+1, DISP_TOP, xl+DISP_RIGHT+BORDER_SIZE, DISP_BOTTOM, MAKE_COLOR(COLOR_GREY, COLOR_GREY), RECT_BORDER0|DRAW_FILLED); //vert divider
 291         draw_rectangle(xl+DISP_RIGHT+BORDER_SIZE+1, DISP_TOP, xr-BORDER_SIZE, DISP_TOP+3*CELL_SIZE-1, MAKE_COLOR(COLOR_GREY, COLOR_GREY), RECT_BORDER0|DRAW_FILLED); //above sample
 292 
 293         // Draw CHDK Palette color boxes
 294         c = 0;
 295         for (x=DISP_LEFT; x<DISP_LEFT+CELL_SIZE*(IDX_COLOR_MAX+1); x+=CELL_SIZE, c++)
 296         {
 297             draw_rectangle(xl+x, DISP_TOP_CHDK, xl+x+CELL_SIZE, DISP_TOP_CHDK+CELL_SIZE, MAKE_COLOR(chdk_colors[c],COLOR_BLACK), RECT_BORDER1|DRAW_FILLED);
 298         }
 299         draw_rectangle(xl+DISP_LEFT+CELL_SIZE*(IDX_COLOR_MAX+1)+1, DISP_TOP_CHDK, xr-BORDER_SIZE, DISP_TOP_CHDK+CELL_SIZE, MAKE_COLOR(COLOR_GREY, COLOR_GREY), RECT_BORDER0|DRAW_FILLED);
 300         draw_string(xl+DISP_LEFT+CELL_SIZE*(IDX_COLOR_MAX+1)+1, DISP_TOP_CHDK, " <-- CHDK", MAKE_COLOR(COLOR_GREY,COLOR_WHITE));
 301 
 302         // Draw Canon Palette color boxes
 303         c = 0;
 304         for (y=DISP_TOP; y<DISP_BOTTOM; y+=CELL_SIZE)
 305         {
 306             for (x=DISP_LEFT; x<DISP_RIGHT; x+=CELL_SIZE, c++)
 307             {
 308                 draw_rectangle(xl+x, y, xl+x+CELL_SIZE, y+CELL_SIZE, MAKE_COLOR(c,COLOR_BLACK), RECT_BORDER1|DRAW_FILLED);
 309             }
 310         }
 311         draw_string(xl+DISP_RIGHT+BORDER_SIZE, DISP_TOP+10, "<-- Canon", MAKE_COLOR(COLOR_GREY,COLOR_WHITE));
 312 
 313         // Co-ordinate of selected color
 314         if (cl.type)
 315         {
 316             y = DISP_TOP_CHDK;
 317             x = DISP_LEFT + cl.col * CELL_SIZE;
 318         }
 319         else
 320         {
 321             y = DISP_TOP + ((cl.col>>4)&0x0F) * CELL_SIZE;
 322             x = DISP_LEFT + (cl.col&0x0F) * CELL_SIZE;
 323         }
 324 
 325         // Highlight selected color
 326         draw_rectangle(xl+x-CELL_ZOOM, y-CELL_ZOOM, xl+x+CELL_SIZE+CELL_ZOOM, y+CELL_SIZE+CELL_ZOOM, MAKE_COLOR(chdkColorToCanonColor(cl), COLOR_RED), RECT_BORDER2|DRAW_FILLED);
 327 
 328         // Fill 'sample' area with selected color
 329         draw_rectangle(xl+DISP_RIGHT+BORDER_SIZE+1, DISP_TOP+CELL_SIZE*3, xr-BORDER_SIZE, DISP_BOTTOM, MAKE_COLOR(chdkColorToCanonColor(cl), COLOR_WHITE), RECT_BORDER1|DRAW_FILLED);
 330 
 331         gui_palette_redraw = 0;
 332     }
 333 }
 334 
 335 //-------------------------------------------------------------------
 336 
 337 void gui_palette_draw()
 338 {
 339     if (palette_mode == PALETTE_MODE_TEST)
 340         palette_test();
 341     else
 342         palette_draw();
 343 }
 344 
 345 void gui_module_menu_kbd_process()
 346 {
 347     running = 0;
 348     gui_default_kbd_process_menu_btn();
 349 }
 350 
 351 // =========  MODULE INIT =================
 352 
 353 /***************** BEGIN OF AUXILARY PART *********************
 354 ATTENTION: DO NOT REMOVE OR CHANGE SIGNATURES IN THIS SECTION
 355 **************************************************************/
 356 
 357 int _module_can_unload()
 358 {
 359     return running == 0;
 360 }
 361 
 362 int _module_exit_alt()
 363 {
 364     running = 0;
 365     return 0;
 366 }
 367 
 368 /******************** Module Information structure ******************/
 369 
 370 libpalette_sym _libpalette =
 371 {
 372     {
 373          0, 0, _module_can_unload, _module_exit_alt, 0
 374     },
 375 
 376     gui_palette_init
 377 };
 378 
 379 ModuleInfo _module_info =
 380 {
 381     MODULEINFO_V1_MAGICNUM,
 382     sizeof(ModuleInfo),
 383     GUI_PALETTE_VERSION,                // Module version
 384 
 385     ANY_CHDK_BRANCH, 0, OPT_ARCHITECTURE,                       // Requirements of CHDK version
 386     ANY_PLATFORM_ALLOWED,               // Specify platform dependency
 387 
 388     (int32_t)"Palette",
 389     MTYPE_EXTENSION,
 390 
 391     &_libpalette.base,
 392 
 393     ANY_VERSION,                // CONF version
 394     CAM_SCREEN_VERSION,         // CAM SCREEN version
 395     ANY_VERSION,                // CAM SENSOR version
 396     ANY_VERSION,                // CAM INFO version
 397 };
 398 
 399 /*************** END OF AUXILARY PART *******************/

/* [<][>][^][v][top][bottom][index][help] */