Subversion Repositories Kolibri OS

Rev

Rev 6482 | Rev 6516 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6482 Rev 6489
Line 16... Line 16...
16
#include 
16
#include 
17
#include 
17
#include 
18
#include "kos32sys.h"
18
#include "kos32sys.h"
19
#include "kolibri_gui.h"
19
#include "kolibri_gui.h"
Line -... Line 20...
-
 
20
 
-
 
21
#define SCAN_CODE_ALTM  50
-
 
22
#define SCAN_CODE_ALTE  18
-
 
23
inline
-
 
24
uint32_t get_os_keyb_modifiers()
-
 
25
{
-
 
26
    register uint32_t val;
-
 
27
    __asm__ __volatile__(
-
 
28
    "int $0x40"
-
 
29
    :"=a"(val)
-
 
30
    :"a"(66), "b"(3));
-
 
31
    return val;
-
 
32
};
-
 
33
 
-
 
34
#define KEY_LSHIFT     0x1
-
 
35
#define KEY_RSHIFT     0x2
-
 
36
#define KEY_LCTRL      0x4
-
 
37
#define KEY_RCTRL      0x8
-
 
38
#define KEY_LALT       0x10
-
 
39
#define KEY_RALT       0x20
-
 
40
#define KEY_CAPSLOCK   0x40
-
 
41
#define KEY_NUMLOCK    0x80
-
 
42
#define KEY_SCROLLLOCK 0x100
-
 
43
#define KEY_LWIN       0x200
-
 
44
#define KEY_RWIN       0x400
-
 
45
 
-
 
46
inline
-
 
47
void set_os_keyb_mode(int mode)
-
 
48
// 0 - ASCII, 1 - SCAN
-
 
49
{
-
 
50
    __asm__ __volatile__(
-
 
51
    "int $0x40"
-
 
52
    ::"a"(66), "b"(1), "c"(mode));
Line 20... Line 53...
20
 
53
};
21
 
54
 
22
int main()
55
int main()
23
{
56
{
Line 62... Line 95...
62
    gui_add_frame(main_window, fr2);
95
    gui_add_frame(main_window, fr2);
Line 63... Line 96...
63
 
96
 
64
    int option_index1 = 0;  // index of selected option
97
    int option_index1 = 0;  // index of selected option
Line 65... Line -...
65
    int option_index2 = 0;
-
 
66
 
-
 
67
    static char *menu1t = "Menu1";
98
    int option_index2 = 0;
68
    static char *menu11t = "Set RED";
-
 
69
    static char *menu12t = "Set GREEN";
-
 
70
    static char *menu13t = "Set BLUE";
99
 
71
    static char *menu14t = "";
100
    char *menu1stru[] = {"Menu1", "Set RED", "Set GREEN", "Set BLUE", NULL};
Line 72... Line -...
72
    menubar* menu1 = kolibri_new_menubar_def(X_Y(20, 40), X_Y(25, 15), 80, 100, menu1t, menu11t);
-
 
73
    gui_add_menubar(main_window, menu1);
-
 
74
 
-
 
75
    static char *menu2t = "Menu2";
101
    menubar* menu1 = kolibri_new_menubar_def(X_Y(10, 40), X_Y(25, 15), 80, 100, menu1stru);
76
    static char *menu21t = "Set Option 1";
-
 
77
    static char *menu22t = "Set Option 2";
102
    gui_add_menubar(main_window, menu1);
78
    static char *menu23t = "Set Option 3";
103
 
Line -... Line 104...
-
 
104
    char *menu2stru[] = {"mEnu2", "Set Option 1", "Set Option 2", "Set Option 3", NULL};
-
 
105
    menubar* menu2 = kolibri_new_menubar_def(X_Y(50, 40), X_Y(25, 15), 80, 100, menu2stru);
-
 
106
    gui_add_menubar(main_window, menu2);
-
 
107
 
-
 
108
    char *menu3stru[] = {"Quit", NULL};
-
 
109
    menubar* menu3 = kolibri_new_menubar_def(X_Y(90, 40), X_Y(25, 15), 0, 0, menu3stru);
Line -... Line 110...
-
 
110
    menu3->type = 1;  // no subitems
Line 79... Line 111...
79
    static char *menu24t = "";
111
    gui_add_menubar(main_window, menu3);
80
    menubar* menu2 = kolibri_new_menubar_def(X_Y(60, 40), X_Y(25, 15), 80, 100, menu2t, menu21t);
112
 
81
    gui_add_menubar(main_window, menu2);
113
 
Line 98... Line 130...
98
            kolibri_handle_event_redraw(main_window);
130
            kolibri_handle_event_redraw(main_window);
99
            break;
131
            break;
100
        case KOLIBRI_EVENT_NONE:
132
        case KOLIBRI_EVENT_NONE:
101
			break;
133
			break;
102
        case KOLIBRI_EVENT_KEY:
134
        case KOLIBRI_EVENT_KEY:
-
 
135
            keypress = get_key();
-
 
136
            debug_board_printf("Key pressed state(%d) code(%d) ctrl_key(%d)  modifiers(%#x)\n", keypress.state, keypress.code, keypress.ctrl_key, get_os_keyb_modifiers());
103
            kolibri_handle_event_key(main_window); // ???????
137
            kolibri_handle_event_key(main_window); // ???????
-
 
138
 
-
 
139
            if(keypress.code == SCAN_CODE_ALTM && get_os_keyb_modifiers() & (KEY_LALT | KEY_RALT))
-
 
140
                (*menu_bar_activate)(menu1); // wont work, immediately redraw command closes menu (
-
 
141
 
104
			break;
142
			break;
105
        case KOLIBRI_EVENT_BUTTON:
143
        case KOLIBRI_EVENT_BUTTON:
106
            pressed_button = get_os_button();
144
            pressed_button = get_os_button();
107
            switch (pressed_button)
145
            switch (pressed_button)
108
            {
146
            {
Line 113... Line 151...
113
            break;
151
            break;
114
        case KOLIBRI_EVENT_MOUSE:
152
        case KOLIBRI_EVENT_MOUSE:
115
//            mouse_pos = get_mouse_pos(POS_WINDOW); // window relative
153
//            mouse_pos = get_mouse_pos(POS_WINDOW); // window relative
116
//            mouse_button = get_mouse_eventstate();
154
//            mouse_button = get_mouse_eventstate();
117
            kolibri_handle_event_mouse(main_window);
155
            kolibri_handle_event_mouse(main_window);
-
 
156
            if(menu1->click && menu1->cursor_out)
-
 
157
            {
-
 
158
                option1sel = opts1 + menu1->cursor_out - 1; // check bounds ?
-
 
159
                (*option_box_draw)(option_group1);
-
 
160
            }
-
 
161
            if(menu2->click && menu2->cursor_out)
-
 
162
            {
-
 
163
                option2sel = opts2 + menu2->cursor_out - 1; // check bounds ?
-
 
164
                (*option_box_draw)(option_group2);
-
 
165
            }
-
 
166
            if(menu3->click && menu3->cursor_out)
-
 
167
            {
-
 
168
                return 0; // quit
-
 
169
            }
-
 
170
 
118
            break;
171
            break;
119
        }
172
        }
Line 120... Line 173...
120
 
173
 
121
        gui_event = get_os_event();
174
        gui_event = get_os_event();