diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugins/rockpaint.c | 225 |
1 files changed, 73 insertions, 152 deletions
diff --git a/apps/plugins/rockpaint.c b/apps/plugins/rockpaint.c index 07351ffb44..4e4791c659 100644 --- a/apps/plugins/rockpaint.c +++ b/apps/plugins/rockpaint.c | |||
@@ -407,6 +407,14 @@ static fb_data save_buffer[ ROWS*COLS ]; | |||
407 | extern fb_data rockpaint[]; | 407 | extern fb_data rockpaint[]; |
408 | extern fb_data rockpaint_hsvrgb[]; | 408 | extern fb_data rockpaint_hsvrgb[]; |
409 | 409 | ||
410 | struct incdec_ctx { | ||
411 | int max; | ||
412 | int step[2]; | ||
413 | bool wrap; | ||
414 | }; | ||
415 | struct incdec_ctx incdec_x = { COLS, { 1, 4}, true }; | ||
416 | struct incdec_ctx incdec_y = { ROWS, { 1, 4}, true }; | ||
417 | |||
410 | /* Maximum string size allowed for the text tool */ | 418 | /* Maximum string size allowed for the text tool */ |
411 | #define MAX_TEXT 256 | 419 | #define MAX_TEXT 256 |
412 | 420 | ||
@@ -451,6 +459,27 @@ static buf *buffer; | |||
451 | /* Current filename */ | 459 | /* Current filename */ |
452 | static char filename[MAX_PATH]; | 460 | static char filename[MAX_PATH]; |
453 | 461 | ||
462 | static bool incdec_value(int *pval, struct incdec_ctx *ctx, bool inc, bool bigstep) | ||
463 | { | ||
464 | bool of = true; | ||
465 | int step = ctx->step[bigstep?1:0]; | ||
466 | step = inc?step: -step; | ||
467 | *pval += step; | ||
468 | if (ctx->wrap) | ||
469 | { | ||
470 | if (*pval < 0) *pval += ctx->max; | ||
471 | else if (*pval >= ctx->max) *pval -= ctx->max; | ||
472 | else of = false; | ||
473 | } | ||
474 | else | ||
475 | { | ||
476 | if (*pval < 0) *pval = 0; | ||
477 | else if (*pval > ctx->max) *pval = ctx->max; | ||
478 | else of = false; | ||
479 | } | ||
480 | return of; | ||
481 | } | ||
482 | |||
454 | /* Font preview buffer */ | 483 | /* Font preview buffer */ |
455 | //#define FONT_PREVIEW_WIDTH ((LCD_WIDTH-30)/8) | 484 | //#define FONT_PREVIEW_WIDTH ((LCD_WIDTH-30)/8) |
456 | //#define FONT_PREVIEW_HEIGHT 1000 | 485 | //#define FONT_PREVIEW_HEIGHT 1000 |
@@ -982,6 +1011,12 @@ static unsigned int color_chooser( unsigned int color ) | |||
982 | int hue, saturation, value; | 1011 | int hue, saturation, value; |
983 | int r, g, b; /* temp variables */ | 1012 | int r, g, b; /* temp variables */ |
984 | int i, top, left; | 1013 | int i, top, left; |
1014 | int button; | ||
1015 | int *pval; | ||
1016 | static struct incdec_ctx ctxs[] = { | ||
1017 | { 3600, { 10, 100}, true }, /* hue */ | ||
1018 | { 0xff, { 1, 8}, false }, /* the others */ | ||
1019 | }; | ||
985 | 1020 | ||
986 | enum BaseColor { Hue = 0, Saturation = 1, Value = 2, | 1021 | enum BaseColor { Hue = 0, Saturation = 1, Value = 2, |
987 | Red = 3, Green = 4, Blue = 5 }; | 1022 | Red = 3, Green = 4, Blue = 5 }; |
@@ -1058,123 +1093,49 @@ static unsigned int color_chooser( unsigned int color ) | |||
1058 | 1093 | ||
1059 | rb->lcd_update(); | 1094 | rb->lcd_update(); |
1060 | 1095 | ||
1061 | switch( rb->button_get(true) ) | 1096 | switch( button = rb->button_get(true) ) |
1062 | { | 1097 | { |
1063 | case ROCKPAINT_UP: | 1098 | case ROCKPAINT_UP: |
1064 | current = ( current + 5 )%6; | 1099 | current = ( current + 5 )%6; |
1065 | break; | 1100 | break; |
1066 | 1101 | ||
1067 | case ROCKPAINT_DOWN: | 1102 | case ROCKPAINT_DOWN: |
1068 | current = (current + 1 )%6; | 1103 | current = ( current + 1 )%6; |
1069 | break; | 1104 | break; |
1070 | 1105 | ||
1071 | case ROCKPAINT_LEFT: | 1106 | case ROCKPAINT_LEFT: |
1072 | has_changed = true; | ||
1073 | switch( current ) | ||
1074 | { | ||
1075 | case Hue: | ||
1076 | hue = ( hue + 3600 - 10 )%3600; | ||
1077 | break; | ||
1078 | case Saturation: | ||
1079 | if( saturation ) saturation--; | ||
1080 | break; | ||
1081 | case Value: | ||
1082 | if( value ) value--; | ||
1083 | break; | ||
1084 | case Red: | ||
1085 | if( red ) red--; | ||
1086 | break; | ||
1087 | case Green: | ||
1088 | if( green ) green--; | ||
1089 | break; | ||
1090 | case Blue: | ||
1091 | if( blue ) blue--; | ||
1092 | break; | ||
1093 | } | ||
1094 | break; | ||
1095 | |||
1096 | case ROCKPAINT_LEFT|BUTTON_REPEAT: | 1107 | case ROCKPAINT_LEFT|BUTTON_REPEAT: |
1097 | has_changed = true; | ||
1098 | switch( current ) | ||
1099 | { | ||
1100 | case Hue: | ||
1101 | hue = ( hue + 3600 - 100 )%3600; | ||
1102 | break; | ||
1103 | case Saturation: | ||
1104 | if( saturation >= 8 ) saturation-=8; | ||
1105 | else saturation = 0; | ||
1106 | break; | ||
1107 | case Value: | ||
1108 | if( value >= 8 ) value-=8; | ||
1109 | else value = 0; | ||
1110 | break; | ||
1111 | case Red: | ||
1112 | if( red >= 8 ) red-=8; | ||
1113 | else red = 0; | ||
1114 | break; | ||
1115 | case Green: | ||
1116 | if( green >= 8 ) green-=8; | ||
1117 | else green = 0; | ||
1118 | break; | ||
1119 | case Blue: | ||
1120 | if( blue >= 8 ) blue-=8; | ||
1121 | else blue = 0; | ||
1122 | break; | ||
1123 | } | ||
1124 | break; | ||
1125 | |||
1126 | case ROCKPAINT_RIGHT: | 1108 | case ROCKPAINT_RIGHT: |
1109 | case ROCKPAINT_RIGHT|BUTTON_REPEAT: | ||
1127 | has_changed = true; | 1110 | has_changed = true; |
1128 | switch( current ) | 1111 | switch( current ) |
1129 | { | 1112 | { |
1130 | case Hue: | 1113 | case Hue: |
1131 | hue = ( hue + 10 )%3600; | 1114 | pval = &hue; |
1132 | break; | 1115 | break; |
1133 | case Saturation: | 1116 | case Saturation: |
1134 | if( saturation < 0xff ) saturation++; | 1117 | pval = &saturation; |
1135 | break; | 1118 | break; |
1136 | case Value: | 1119 | case Value: |
1137 | if( value < 0xff ) value++; | 1120 | pval = &value; |
1138 | break; | 1121 | break; |
1139 | case Red: | 1122 | case Red: |
1140 | if( red < 0xff ) red++; | 1123 | pval = &red; |
1141 | break; | 1124 | break; |
1142 | case Green: | 1125 | case Green: |
1143 | if( green < 0xff ) green++; | 1126 | pval = &green; |
1144 | break; | 1127 | break; |
1145 | case Blue: | 1128 | case Blue: |
1146 | if( blue < 0xff ) blue++; | 1129 | pval = &blue; |
1130 | break; | ||
1131 | default: | ||
1132 | pval = NULL; | ||
1147 | break; | 1133 | break; |
1148 | } | 1134 | } |
1149 | break; | 1135 | if (pval) |
1150 | |||
1151 | case ROCKPAINT_RIGHT|BUTTON_REPEAT: | ||
1152 | has_changed = true; | ||
1153 | switch( current ) | ||
1154 | { | 1136 | { |
1155 | case Hue: | 1137 | incdec_value(pval, &ctxs[(current != Hue? 1: 0)], |
1156 | hue = ( hue + 100 )%3600; | 1138 | (button&ROCKPAINT_RIGHT), (button&BUTTON_REPEAT)); |
1157 | break; | ||
1158 | case Saturation: | ||
1159 | if( saturation < 0xff - 8 ) saturation+=8; | ||
1160 | else saturation = 0xff; | ||
1161 | break; | ||
1162 | case Value: | ||
1163 | if( value < 0xff - 8 ) value+=8; | ||
1164 | else value = 0xff; | ||
1165 | break; | ||
1166 | case Red: | ||
1167 | if( red < 0xff - 8 ) red+=8; | ||
1168 | else red = 0xff; | ||
1169 | break; | ||
1170 | case Green: | ||
1171 | if( green < 0xff - 8 ) green+=8; | ||
1172 | else green = 0xff; | ||
1173 | break; | ||
1174 | case Blue: | ||
1175 | if( blue < 0xff - 8 ) blue+=8; | ||
1176 | else blue = 0xff; | ||
1177 | break; | ||
1178 | } | 1139 | } |
1179 | break; | 1140 | break; |
1180 | 1141 | ||
@@ -1549,26 +1510,18 @@ static void draw_text( int x, int y ) | |||
1549 | { | 1510 | { |
1550 | case ROCKPAINT_LEFT: | 1511 | case ROCKPAINT_LEFT: |
1551 | case ROCKPAINT_LEFT | BUTTON_REPEAT: | 1512 | case ROCKPAINT_LEFT | BUTTON_REPEAT: |
1552 | x-=bspeed * ( button & BUTTON_REPEAT ? 4 : 1 ); | ||
1553 | if (x<0) x=COLS-1; | ||
1554 | break; | ||
1555 | |||
1556 | case ROCKPAINT_RIGHT: | 1513 | case ROCKPAINT_RIGHT: |
1557 | case ROCKPAINT_RIGHT | BUTTON_REPEAT: | 1514 | case ROCKPAINT_RIGHT | BUTTON_REPEAT: |
1558 | x+=bspeed * ( button & BUTTON_REPEAT ? 4 : 1 ); | 1515 | incdec_value(&x, &incdec_x, |
1559 | if (x>=COLS) x=0; | 1516 | (button&ROCKPAINT_RIGHT), (button&BUTTON_REPEAT)); |
1560 | break; | 1517 | break; |
1561 | 1518 | ||
1562 | case ROCKPAINT_UP: | 1519 | case ROCKPAINT_UP: |
1563 | case ROCKPAINT_UP | BUTTON_REPEAT: | 1520 | case ROCKPAINT_UP | BUTTON_REPEAT: |
1564 | y-=bspeed * ( button & BUTTON_REPEAT ? 4 : 1 ); | ||
1565 | if (y<0) y=ROWS-1; | ||
1566 | break; | ||
1567 | |||
1568 | case ROCKPAINT_DOWN: | 1521 | case ROCKPAINT_DOWN: |
1569 | case ROCKPAINT_DOWN | BUTTON_REPEAT: | 1522 | case ROCKPAINT_DOWN | BUTTON_REPEAT: |
1570 | y+=bspeed * ( button & BUTTON_REPEAT ? 4 : 1 ); | 1523 | incdec_value(&y, &incdec_y, |
1571 | if (y>=ROWS-1) y=0; | 1524 | (button&ROCKPAINT_DOWN), (button&BUTTON_REPEAT)); |
1572 | break; | 1525 | break; |
1573 | 1526 | ||
1574 | case ROCKPAINT_DRAW: | 1527 | case ROCKPAINT_DRAW: |
@@ -2426,38 +2379,24 @@ static void toolbar( void ) | |||
2426 | 2379 | ||
2427 | case ROCKPAINT_LEFT: | 2380 | case ROCKPAINT_LEFT: |
2428 | case ROCKPAINT_LEFT | BUTTON_REPEAT: | 2381 | case ROCKPAINT_LEFT | BUTTON_REPEAT: |
2429 | inv_cursor(false); | ||
2430 | x-=bspeed * ( button & BUTTON_REPEAT ? 4 : 1 ); | ||
2431 | if (x<0) x=COLS-1; | ||
2432 | inv_cursor(true); | ||
2433 | break; | ||
2434 | |||
2435 | case ROCKPAINT_RIGHT: | 2382 | case ROCKPAINT_RIGHT: |
2436 | case ROCKPAINT_RIGHT | BUTTON_REPEAT: | 2383 | case ROCKPAINT_RIGHT | BUTTON_REPEAT: |
2437 | inv_cursor(false); | 2384 | inv_cursor(false); |
2438 | x+=bspeed * ( button & BUTTON_REPEAT ? 4 : 1 ); | 2385 | incdec_value(&x, &incdec_x, |
2439 | if (x>=COLS) x=0; | 2386 | (button&ROCKPAINT_RIGHT), (button&BUTTON_REPEAT)); |
2440 | inv_cursor(true); | 2387 | inv_cursor(true); |
2441 | break; | 2388 | break; |
2442 | 2389 | ||
2443 | case ROCKPAINT_UP: | 2390 | case ROCKPAINT_UP: |
2444 | case ROCKPAINT_UP | BUTTON_REPEAT: | 2391 | case ROCKPAINT_UP | BUTTON_REPEAT: |
2445 | inv_cursor(false); | ||
2446 | y-=bspeed * ( button & BUTTON_REPEAT ? 4 : 1 ); | ||
2447 | if (y<LCD_HEIGHT-TB_HEIGHT) | ||
2448 | { | ||
2449 | return; | ||
2450 | } | ||
2451 | inv_cursor(true); | ||
2452 | break; | ||
2453 | |||
2454 | case ROCKPAINT_DOWN: | 2392 | case ROCKPAINT_DOWN: |
2455 | case ROCKPAINT_DOWN | BUTTON_REPEAT: | 2393 | case ROCKPAINT_DOWN | BUTTON_REPEAT: |
2456 | inv_cursor(false); | 2394 | inv_cursor(false); |
2457 | y+=bspeed * ( button & BUTTON_REPEAT ? 4 : 1 ); | 2395 | if (incdec_value(&y, &incdec_y, |
2458 | if (y>=LCD_HEIGHT) | 2396 | (button&ROCKPAINT_DOWN), (button&BUTTON_REPEAT)) |
2397 | || y < LCD_HEIGHT-TB_HEIGHT) | ||
2459 | { | 2398 | { |
2460 | y = 0; | 2399 | /* went out of region. exit toolbar. */ |
2461 | return; | 2400 | return; |
2462 | } | 2401 | } |
2463 | inv_cursor(true); | 2402 | inv_cursor(true); |
@@ -2569,8 +2508,13 @@ static void goto_menu(void) | |||
2569 | for(multi = 0; multi<3; multi++) | 2508 | for(multi = 0; multi<3; multi++) |
2570 | if(bspeed == times_list[multi]) break; | 2509 | if(bspeed == times_list[multi]) break; |
2571 | rb->set_option( "Brush Speed", &multi, INT, times_options, 3, NULL ); | 2510 | rb->set_option( "Brush Speed", &multi, INT, times_options, 3, NULL ); |
2572 | if( multi >= 0 ) | 2511 | if( multi >= 0 ) { |
2573 | bspeed = times_list[multi]; | 2512 | bspeed = times_list[multi]; |
2513 | incdec_x.step[0] = bspeed; | ||
2514 | incdec_x.step[1] = bspeed * 4; | ||
2515 | incdec_y.step[0] = bspeed; | ||
2516 | incdec_y.step[1] = bspeed * 4; | ||
2517 | } | ||
2574 | break; | 2518 | break; |
2575 | 2519 | ||
2576 | case MAIN_MENU_COLOR: | 2520 | case MAIN_MENU_COLOR: |
@@ -2617,7 +2561,7 @@ static void reset_tool( void ) | |||
2617 | static bool rockpaint_loop( void ) | 2561 | static bool rockpaint_loop( void ) |
2618 | { | 2562 | { |
2619 | int button=0,i,j; | 2563 | int button=0,i,j; |
2620 | int accelaration; | 2564 | bool bigstep; |
2621 | 2565 | ||
2622 | x = 10; | 2566 | x = 10; |
2623 | toolbar(); | 2567 | toolbar(); |
@@ -2627,19 +2571,7 @@ static bool rockpaint_loop( void ) | |||
2627 | 2571 | ||
2628 | while (!quit) { | 2572 | while (!quit) { |
2629 | button = rb->button_get(true); | 2573 | button = rb->button_get(true); |
2630 | 2574 | bigstep = (button & BUTTON_REPEAT) && !(tool == Brush && prev_x != -1); | |
2631 | if( tool == Brush && prev_x != -1 ) | ||
2632 | { | ||
2633 | accelaration = 1; | ||
2634 | } | ||
2635 | else if( button & BUTTON_REPEAT ) | ||
2636 | { | ||
2637 | accelaration = 4; | ||
2638 | } | ||
2639 | else | ||
2640 | { | ||
2641 | accelaration = 1; | ||
2642 | } | ||
2643 | 2575 | ||
2644 | switch(button) | 2576 | switch(button) |
2645 | { | 2577 | { |
@@ -2846,33 +2778,22 @@ static bool rockpaint_loop( void ) | |||
2846 | 2778 | ||
2847 | case ROCKPAINT_LEFT: | 2779 | case ROCKPAINT_LEFT: |
2848 | case ROCKPAINT_LEFT | BUTTON_REPEAT: | 2780 | case ROCKPAINT_LEFT | BUTTON_REPEAT: |
2849 | inv_cursor(false); | ||
2850 | x-=bspeed * accelaration; | ||
2851 | if (x<0) x=COLS-1; | ||
2852 | inv_cursor(true); | ||
2853 | break; | ||
2854 | |||
2855 | case ROCKPAINT_RIGHT: | 2781 | case ROCKPAINT_RIGHT: |
2856 | case ROCKPAINT_RIGHT | BUTTON_REPEAT: | 2782 | case ROCKPAINT_RIGHT | BUTTON_REPEAT: |
2857 | inv_cursor(false); | 2783 | inv_cursor(false); |
2858 | x+=bspeed * accelaration; | 2784 | incdec_value(&x, &incdec_x, |
2859 | if (x>=COLS) x=0; | 2785 | (button&ROCKPAINT_RIGHT), bigstep); |
2860 | inv_cursor(true); | 2786 | inv_cursor(true); |
2861 | break; | 2787 | break; |
2862 | 2788 | ||
2863 | case ROCKPAINT_UP: | 2789 | case ROCKPAINT_UP: |
2864 | case ROCKPAINT_UP | BUTTON_REPEAT: | 2790 | case ROCKPAINT_UP | BUTTON_REPEAT: |
2865 | inv_cursor(false); | ||
2866 | y-=bspeed * accelaration; | ||
2867 | if (y<0) y=ROWS-1; | ||
2868 | inv_cursor(true); | ||
2869 | break; | ||
2870 | |||
2871 | case ROCKPAINT_DOWN: | 2791 | case ROCKPAINT_DOWN: |
2872 | case ROCKPAINT_DOWN | BUTTON_REPEAT: | 2792 | case ROCKPAINT_DOWN | BUTTON_REPEAT: |
2873 | inv_cursor(false); | 2793 | inv_cursor(false); |
2874 | y+=bspeed * accelaration; | 2794 | if (incdec_value(&y, &incdec_y, |
2875 | if (y>=ROWS) | 2795 | (button&ROCKPAINT_DOWN), bigstep) |
2796 | && (button&ROCKPAINT_DOWN)) | ||
2876 | { | 2797 | { |
2877 | toolbar(); | 2798 | toolbar(); |
2878 | restore_screen(); | 2799 | restore_screen(); |