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, xt, w, h;
 147     color c, co;
 148     static char buf[64];
 149 
 150     xl = camera_screen.disp_left;
 151     xr = camera_screen.disp_right;
 152 
 153     if (gui_palette_redraw)
 154     {
 155         // Draw top text line - current color + instructions
 156         draw_rectangle(xl, 0, xr, camera_screen.height-1, MAKE_COLOR(COLOR_BLACK, COLOR_BLACK), RECT_BORDER0|DRAW_FILLED);
 157         draw_string(xr-22*FONT_WIDTH, 0, "Use \x1b\x1a to change page", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 158 
 159         color cols[3][20] = {
 160                 {
 161                         COLOR_WHITE         ,COLOR_RED           ,COLOR_RED_DK        ,COLOR_RED_LT        ,
 162                         COLOR_GREEN         ,COLOR_BLUE          ,COLOR_BLUE_LT       ,COLOR_YELLOW        ,
 163                         COLOR_GREY          ,COLOR_GREY_DK       ,COLOR_GREY_LT       ,COLOR_TRANSPARENT
 164                 },
 165                 {
 166                         COLOR_RED       ,COLOR_GREEN     ,
 167                         COLOR_BLUE      ,COLOR_CYAN      ,
 168                         COLOR_MAGENTA   ,COLOR_YELLOW
 169                 },
 170                 {
 171                         3   ,6  ,9  ,12 ,15,
 172                         4   ,7  ,10 ,13 ,16,
 173                         5   ,8  ,11 ,14 ,17,
 174                         1   ,1  ,1  ,18 ,1
 175                 }
 176         };
 177 
 178         char *nams[3][20] = {
 179                 {
 180                         "white", "red", "dark red", "light red",
 181                         "green", "blue", "light blue", "yellow",
 182                         "grey", "dark grey", "light grey", "transparent"
 183                 },
 184                 {
 185                         "red", "green", "blue", "cyan", "magenta", "yellow",
 186                 },
 187                 {
 188                         "red", "green", "blue", "grey", "yellow",
 189                         "dk red", "dk green", "dk blue", "dk grey", "dk yellow",
 190                         "lt red", "lt green", "lt blue", "lt grey", "lt yellow",
 191                         "", "", "", "trns grey", ""
 192                 }
 193         };
 194 
 195         if (test_page == 0)
 196         {
 197             draw_string(xl, 0, "System Colors", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 198             c = 0;
 199             w = camera_screen.disp_width / 4;
 200             h = (camera_screen.height - (2 * FONT_HEIGHT)) / 3;
 201             for (y=0; y<3; y++)
 202             {
 203                 for (x=0; x<4; x++, c++)
 204                 {
 205                     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);
 206                     draw_string(xl+(x*w),(2*FONT_HEIGHT)+(y*h)+h-FONT_HEIGHT-3, nams[test_page][c], MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 207                 }
 208             }
 209         }
 210         else if (test_page == 1)
 211         {
 212             draw_string(xl, 0, "Histogram Colors", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 213             c = 0;
 214             w = camera_screen.disp_width / 2;
 215             h = (camera_screen.height - (2 * FONT_HEIGHT)) / 3;
 216             for (y=0; y<3; y++)
 217             {
 218                 for (x=0; x<2; x++, c++)
 219                 {
 220                     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);
 221                     draw_string(xl+(x*w),(2*FONT_HEIGHT)+(y*h)+h-FONT_HEIGHT-3, nams[test_page][c], MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 222                 }
 223             }
 224         }
 225         else if (test_page == 2)
 226         {
 227             draw_string(xl, 0, "Script/Icon Colors", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 228             c = 0;
 229             w = camera_screen.disp_width / 5;
 230             h = (camera_screen.height - (2 * FONT_HEIGHT)) / 4;
 231             for (y=0; y<4; y++)
 232             {
 233                 for (x=0; x<5; x++, c++)
 234                 {
 235                     draw_rectangle(xl+(x*w), (2*FONT_HEIGHT)+(y*h), xl+(x*w)+w-1, (2*FONT_HEIGHT)+(y*h)+h-FONT_HEIGHT-6,
 236                             MAKE_COLOR(get_script_color(cols[test_page][c]+256),get_script_color(cols[test_page][c]+256)), RECT_BORDER0|DRAW_FILLED);
 237                     draw_string(xl+(x*w),(2*FONT_HEIGHT)+(y*h)+h-FONT_HEIGHT-3, nams[test_page][c], MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 238                 }
 239             }
 240         }
 241 
 242         gui_palette_redraw = 0;
 243     }
 244 }
 245 
 246 //-------------------------------------------------------------------
 247 // sizes computed at runtime
 248 #define CELL_SIZE           cellsize
 249 #define BORDER_SIZE         6
 250 #define CELL_ZOOM           BORDER_SIZE
 251 #define DISP_TOP_CHDK       (FONT_HEIGHT + BORDER_SIZE)
 252 #define DISP_TOP            disptop
 253 #define DISP_LEFT           BORDER_SIZE
 254 #define DISP_RIGHT          dispright
 255 #define DISP_BOTTOM         dispbottom
 256 
 257 static void palette_draw()
 258 {
 259     unsigned int x, y, xl, xr;
 260     color c;
 261     static char buf[64];
 262     static int cellsize = 0, disptop, dispright, dispbottom;
 263 
 264     if (!cellsize)
 265     {
 266         // calculate these only once
 267         cellsize = (camera_screen.height - FONT_HEIGHT - 3 * BORDER_SIZE -1 ) / 17;
 268         disptop = camera_screen.height + DISP_TOP_CHDK - cellsize * 16 - FONT_HEIGHT - 2 * BORDER_SIZE - 1;
 269         dispright = DISP_LEFT + cellsize * 16;
 270         dispbottom = DISP_TOP + cellsize * 16;
 271     }
 272 
 273     xl = camera_screen.disp_left;
 274     xr = camera_screen.disp_right;
 275     int *pal = (int*)vid_get_bitmap_active_palette();
 276 
 277     if (gui_palette_redraw)
 278     {
 279         // Draw top text line - current color + instructions
 280         draw_rectangle(xl, 0, xr, FONT_HEIGHT-1, MAKE_COLOR(COLOR_BLACK, COLOR_BLACK), RECT_BORDER0|DRAW_FILLED);
 281         draw_string(xr-29*FONT_WIDTH, 0, "    Use \x18\x19\x1b\x1a to change color ", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 282         if ( pal )
 283             sprintf(buf, " %s: 0x%02hX 0x%08X", lang_str(LANG_PALETTE_TEXT_COLOR), cl.col, pal[chdkColorToCanonColor(cl)]);
 284         else
 285             sprintf(buf, " %s: 0x%02hX", lang_str(LANG_PALETTE_TEXT_COLOR), cl.col );
 286         draw_string(xl, 0, buf, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 287 
 288         // Draw gray borders
 289         draw_rectangle(xl, DISP_TOP_CHDK-BORDER_SIZE, xr, camera_screen.height-1, MAKE_COLOR(COLOR_GREY, COLOR_GREY), RECT_BORDER6); // outer border
 290         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
 291         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
 292         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
 293 
 294         // Draw CHDK Palette color boxes
 295         c = 0;
 296         for (x=DISP_LEFT; x<DISP_LEFT+CELL_SIZE*(IDX_COLOR_MAX+1); x+=CELL_SIZE, c++)
 297         {
 298             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);
 299         }
 300         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);
 301         draw_string(xl+DISP_LEFT+CELL_SIZE*(IDX_COLOR_MAX+1)+1, DISP_TOP_CHDK, " <-- CHDK", MAKE_COLOR(COLOR_GREY,COLOR_WHITE));
 302 
 303         // Draw Canon Palette color boxes
 304         c = 0;
 305         for (y=DISP_TOP; y<DISP_BOTTOM; y+=CELL_SIZE)
 306         {
 307             for (x=DISP_LEFT; x<DISP_RIGHT; x+=CELL_SIZE, c++)
 308             {
 309                 draw_rectangle(xl+x, y, xl+x+CELL_SIZE, y+CELL_SIZE, MAKE_COLOR(c,COLOR_BLACK), RECT_BORDER1|DRAW_FILLED);
 310             }
 311         }
 312         draw_string(xl+DISP_RIGHT+BORDER_SIZE, DISP_TOP+10, "<-- Canon", MAKE_COLOR(COLOR_GREY,COLOR_WHITE));
 313 
 314         // Co-ordinate of selected color
 315         if (cl.type)
 316         {
 317             y = DISP_TOP_CHDK;
 318             x = DISP_LEFT + cl.col * CELL_SIZE;
 319         }
 320         else
 321         {
 322             y = DISP_TOP + ((cl.col>>4)&0x0F) * CELL_SIZE;
 323             x = DISP_LEFT + (cl.col&0x0F) * CELL_SIZE;
 324         }
 325 
 326         // Highlight selected color
 327         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);
 328 
 329         // Fill 'sample' area with selected color
 330         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);
 331 
 332         gui_palette_redraw = 0;
 333     }
 334 }
 335 
 336 //-------------------------------------------------------------------
 337 
 338 void gui_palette_draw()
 339 {
 340     if (palette_mode == PALETTE_MODE_TEST)
 341         palette_test();
 342     else
 343         palette_draw();
 344 }
 345 
 346 void gui_module_menu_kbd_process()
 347 {
 348     running = 0;
 349     gui_default_kbd_process_menu_btn();
 350 }
 351 
 352 // =========  MODULE INIT =================
 353 
 354 /***************** BEGIN OF AUXILARY PART *********************
 355 ATTENTION: DO NOT REMOVE OR CHANGE SIGNATURES IN THIS SECTION
 356 **************************************************************/
 357 
 358 int _module_can_unload()
 359 {
 360     return running == 0;
 361 }
 362 
 363 int _module_exit_alt()
 364 {
 365     running = 0;
 366     return 0;
 367 }
 368 
 369 /******************** Module Information structure ******************/
 370 
 371 libpalette_sym _libpalette =
 372 {
 373     {
 374          0, 0, _module_can_unload, _module_exit_alt, 0
 375     },
 376 
 377     gui_palette_init
 378 };
 379 
 380 ModuleInfo _module_info =
 381 {
 382     MODULEINFO_V1_MAGICNUM,
 383     sizeof(ModuleInfo),
 384     GUI_PALETTE_VERSION,                // Module version
 385 
 386     ANY_CHDK_BRANCH, 0, OPT_ARCHITECTURE,                       // Requirements of CHDK version
 387     ANY_PLATFORM_ALLOWED,               // Specify platform dependency
 388 
 389     (int32_t)"Palette",
 390     MTYPE_EXTENSION,
 391 
 392     &_libpalette.base,
 393 
 394     ANY_VERSION,                // CONF version
 395     CAM_SCREEN_VERSION,         // CAM SCREEN version
 396     ANY_VERSION,                // CAM SENSOR version
 397     ANY_VERSION,                // CAM INFO version
 398 };
 399 
 400 /*************** END OF AUXILARY PART *******************/

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