source: trunk/core/gui_mpopup.c @ 547

Revision 547, 5.8 KB checked in by EWAVR, 5 years ago (diff)

+ G7: added jogdial support in menu, file browser and text reader

  • G7, A650: fixed "sporadic RAW images" bug
  • increased maximum 'badpixel' file size
  • fixed ND filter control for IXUS960 (maybe)
  • Property svn:eol-style set to native
Line 
1#include "stdlib.h"
2#include "keyboard.h"
3#include "platform.h"
4#include "core.h"
5#include "lang.h"
6#include "gui.h"
7#include "gui_draw.h"
8#include "gui_lang.h"
9#include "gui_mpopup.h"
10
11
12//-------------------------------------------------------------------
13static enum Gui_Mode            gui_mpopup_mode_old;
14static char                     mpopup_to_draw;
15
16static struct {
17        unsigned int            flag;
18        int                     text;
19} actions[] = {
20        { MPOPUP_CUT,           LANG_POPUP_CUT    },
21        { MPOPUP_COPY,          LANG_POPUP_COPY   },
22        { MPOPUP_PASTE,         LANG_POPUP_PASTE  },
23        { MPOPUP_DELETE,        LANG_POPUP_DELETE },
24        { MPOPUP_SELINV,        LANG_POPUP_SELINV },
25        { MPOPUP_RAW_ADD,       LANG_POPUP_RAW_SUM},
26        { MPOPUP_RAW_AVERAGE,   LANG_POPUP_RAW_AVERAGE },
27        { MPOPUP_RAW_DEVELOP,   (int)"Raw Develop"  },
28        { MPOPUP_PURGE,         LANG_POPUP_PURGE  },
29        { MPOPUP_SUBTRACT,      LANG_POPUP_SUB_FROM_MARKED  },
30};
31
32#define ACTIONSNUM              (sizeof(actions)/sizeof(actions[0]))
33#define MAX_ACTIONS             10
34static int                      mpopup_actions[MAX_ACTIONS], mpopup_actions_num, mpopup_actions_active;
35static coord                    mpopup_actions_x, mpopup_actions_y;
36static unsigned int             mpopup_actions_w;
37static void (*mpopup_on_select)(unsigned int btn);
38
39//-------------------------------------------------------------------
40void gui_mpopup_init(const unsigned int flags, void (*on_select)(unsigned int actn)) {
41    int i;
42
43    mpopup_actions_num = 0;
44    for (i=0; i<ACTIONSNUM && mpopup_actions_num<MAX_ACTIONS; ++i) {
45        if (flags & MPOPUP_MASK & actions[i].flag)
46            mpopup_actions[mpopup_actions_num++] = i;
47    }
48    if (mpopup_actions_num == 0)
49        on_select(MPOPUP_CANCEL);
50
51    mpopup_actions_active = 0;
52
53    gui_mpopup_mode_old = gui_get_mode();
54    mpopup_to_draw = 1;
55    mpopup_on_select = on_select;
56    gui_set_mode(GUI_MODE_MPOPUP);
57}
58
59//-------------------------------------------------------------------
60unsigned int gui_mpopup_result() {
61    return actions[mpopup_actions[mpopup_actions_active]].flag;
62}
63
64//-------------------------------------------------------------------
65static void gui_mpopup_draw_actions() {
66    int i;
67    coord y = mpopup_actions_y;
68    color cl;
69
70    for (i=0; i<mpopup_actions_num; ++i) {
71        cl = MAKE_COLOR((mpopup_actions_active==i)?COLOR_RED:COLOR_GREY, (mpopup_actions_active==i)?COLOR_RED:COLOR_GREY);
72        draw_filled_rect(mpopup_actions_x, y, mpopup_actions_x+mpopup_actions_w*FONT_WIDTH, y+FONT_HEIGHT-1, cl);
73        cl = MAKE_COLOR((mpopup_actions_active==i)?COLOR_RED:COLOR_GREY, COLOR_WHITE);
74        draw_string(mpopup_actions_x+FONT_WIDTH, y, lang_str(actions[mpopup_actions[i]].text), cl);
75        y+=FONT_HEIGHT;
76    }
77}
78
79//-------------------------------------------------------------------
80void gui_mpopup_draw() {
81    if (mpopup_to_draw) {
82        int i;
83        coord x=0, y=0;
84        unsigned int w, h;
85
86        w = 0;
87        for (i=0; i<mpopup_actions_num; ++i) {
88            h=strlen(lang_str(actions[mpopup_actions[i]].text));
89            if (h > w) w=h;
90        }
91        w+=2;
92        h = mpopup_actions_num;
93   
94        x = 10*FONT_WIDTH;
95        y = 5*FONT_HEIGHT;
96        draw_rect(x-3, y-3, x+w*FONT_WIDTH+5, y+h*FONT_HEIGHT+4, COLOR_BLACK); //shadow
97        draw_rect(x-2, y-2, x+w*FONT_WIDTH+6, y+h*FONT_HEIGHT+5, COLOR_BLACK); //shadow
98        draw_rect(x-1, y-1, x+w*FONT_WIDTH+7, y+h*FONT_HEIGHT+6, COLOR_BLACK); //shadow
99        draw_filled_rect(x-4, y-4, x+w*FONT_WIDTH+4, y+h*FONT_HEIGHT+3, MAKE_COLOR(COLOR_GREY, COLOR_WHITE)); // main box
100        draw_rect(x-2, y-2, x+w*FONT_WIDTH+2, y+h*FONT_HEIGHT+1, COLOR_WHITE); //border
101        draw_rect(x-3, y-3, x+w*FONT_WIDTH+3, y+h*FONT_HEIGHT+2, COLOR_WHITE); //border
102   
103        mpopup_actions_x = x;
104        mpopup_actions_y = y;
105        mpopup_actions_w = w;
106
107        gui_mpopup_draw_actions();
108        mpopup_to_draw = 0;
109    }
110}
111
112//-------------------------------------------------------------------
113void gui_mpopup_kbd_process() {
114    switch (kbd_get_clicked_key() | get_jogdial_direction()) {
115    case JOGDIAL_LEFT:
116    case KEY_UP:
117        if (mpopup_actions_active > 0) --mpopup_actions_active;
118        else mpopup_actions_active = mpopup_actions_num-1;
119        gui_mpopup_draw_actions();
120        break;
121    case JOGDIAL_RIGHT:
122    case KEY_DOWN:
123        if (mpopup_actions_active < mpopup_actions_num-1) ++mpopup_actions_active;
124        else mpopup_actions_active = 0;
125        gui_mpopup_draw_actions();
126        break;
127    case KEY_LEFT:
128        kbd_reset_autoclicked_key();
129        gui_set_mode(gui_mpopup_mode_old);
130        if (mpopup_on_select)
131            mpopup_on_select(MPOPUP_CANCEL);
132        break;
133    case KEY_SET:
134        kbd_reset_autoclicked_key();
135        gui_set_mode(gui_mpopup_mode_old);
136        if (mpopup_on_select)
137            mpopup_on_select(actions[mpopup_actions[mpopup_actions_active]].flag);
138        break;
139    }
140}
141
142//-------------------------------------------------------------------
143void gui_browser_progress_show(char* msg, const unsigned int perc) {
144    coord x=60, y=100;
145    unsigned int w=240, h=40, len;
146
147    draw_rect(x+1, y+1, x+w+1, y+h+1, COLOR_BLACK); //shadow
148    draw_rect(x+2, y+2, x+w+2, y+h+2, COLOR_BLACK); //shadow
149    draw_rect(x+3, y+3, x+w+3, y+h+3, COLOR_BLACK); //shadow
150    draw_filled_rect(x, y, x+w, y+h, MAKE_COLOR(COLOR_GREY, COLOR_WHITE)); // main box
151    len = strlen(msg);
152    draw_string(x+((w-len*FONT_WIDTH)>>1), y+2, msg, MAKE_COLOR(COLOR_GREY, COLOR_WHITE)); //title text
153    draw_filled_rect(x+10, y+4+FONT_HEIGHT, x+w-10, y+h-10, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE)); // progress rect
154    draw_filled_rect(x+11, y+5+FONT_HEIGHT, x+11+(w-22)*perc/100, y+h-11, MAKE_COLOR(COLOR_RED, COLOR_RED)); // progress bar
155}
Note: See TracBrowser for help on using the repository browser.