Subversion Repositories Kolibri OS

Rev

Rev 6612 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6612 Rev 8581
Line 18... Line 18...
18
#include "kos32sys.h"
18
#include "kos32sys.h"
19
#include "kolibri_gui.h"
19
#include "kolibri_gui.h"
Line 20... Line 20...
20
 
20
 
21
#define SCAN_CODE_ALTM  50
21
#define SCAN_CODE_ALTM  50
22
#define SCAN_CODE_ALTE  18
22
#define SCAN_CODE_ALTE  18
23
inline
23
 
24
uint32_t get_os_keyb_modifiers()
24
static inline uint32_t get_os_keyb_modifiers()
25
{
25
{
26
    register uint32_t val;
26
    register uint32_t val;
27
    __asm__ __volatile__(
27
    __asm__ __volatile__(
28
    "int $0x40"
28
    "int $0x40"
Line 41... Line 41...
41
#define KEY_NUMLOCK    0x80
41
#define KEY_NUMLOCK    0x80
42
#define KEY_SCROLLLOCK 0x100
42
#define KEY_SCROLLLOCK 0x100
43
#define KEY_LWIN       0x200
43
#define KEY_LWIN       0x200
44
#define KEY_RWIN       0x400
44
#define KEY_RWIN       0x400
Line 45... Line -...
45
 
-
 
46
inline
45
 
47
void set_os_keyb_mode(int mode)
46
static inline void set_os_keyb_mode(int mode)
48
// 0 - ASCII, 1 - SCAN
47
// 0 - ASCII, 1 - SCAN
49
{
48
{
50
    __asm__ __volatile__(
49
    __asm__ __volatile__(
51
    "int $0x40"
50
    "int $0x40"
52
    ::"a"(66), "b"(1), "c"(mode));
51
    ::"a"(66), "b"(1), "c"(mode));
Line 53... Line 52...
53
};
52
};
54
 
53
 
55
int main()
54
int main()
56
{
55
{
57
    /* Load all libraries, initialize global tables like system color table and
56
    /* Load all libraries, initialize global tables like system color table and
58
    operations table. kolibri_gui_init() will EXIT with mcall -1 if it fails
57
    operations table. kolibri_gui_init() will EXIT with mcall -1 if it fails
59
    to do it's job. This is all you need to call and all libraries and GUI
58
    to do it's job. This is all you need to call and all libraries and GUI
60
    elements can be used after a successful call to this function
59
    elements can be used after a successful call to this function
61
    */
60
    */
62
    kolibri_gui_init();
61
    kolibri_gui_init();
63
    int gui_event = KOLIBRI_EVENT_REDRAW;
62
    int gui_event = KOLIBRI_EVENT_REDRAW;
64
    uint32_t pressed_button = 0;
63
    uint32_t pressed_button = 0;
65
//    uint32_t mouse_button;
64
//    uint32_t mouse_button;
Line 66... Line 65...
66
//    pos_t   mouse_pos;
65
//    pos_t   mouse_pos;
67
    oskey_t keypress;
66
    oskey_t keypress;
68
 
67
 
Line 69... Line 68...
69
 
68
 
70
    // creating GUI using library functions
69
    // creating GUI using library functions
Line 71... Line 70...
71
    kolibri_window *main_window = kolibri_new_window(50, 40, 400, 160, "OptionBox and Menu demo");
70
    kolibri_window *main_window = kolibri_new_window(50, 40, 400, 160, "OptionBox and Menu demo");
72
    //check_box *checkbox = kolibri_new_check_box(20, 45, 12, 12, "Append BOARDMSG to entered message.");
71
    //check_box *checkbox = kolibri_new_check_box(20, 45, 12, 12, "Append BOARDMSG to entered message.");
73
 
72
 
74
    option_box opts1[3];
73
    option_box opts1[3];
Line 75... Line 74...
75
    option_box *option1sel = opts1; // intially selected RED
74
    option_box *option1sel = opts1; // intially selected RED
76
 
75
 
77
    option_box *op1_1 = gui_optionbox(opts1, X_Y(20, 50), "G1 Item RED", &option1sel);
76
    option_box *op1_1 = gui_optionbox(opts1, X_Y(20, 50), "G1 Item RED", &option1sel);
78
    option_box *op1_2 = gui_optionbox(opts1+1, X_Y(20, 70), "G1 Item GREEN", &option1sel);
77
    option_box *op1_2 = gui_optionbox(opts1+1, X_Y(20, 70), "G1 Item GREEN", &option1sel);
79
    option_box *op1_3 = gui_optionbox(opts1+2, X_Y(20, 90), "G1 Item BLUE", &option1sel);
78
    option_box *op1_3 = gui_optionbox(opts1+2, X_Y(20, 90), "G1 Item BLUE", &option1sel);
80
    option_box* option_group1[] = {op1_1, op1_2, op1_3, NULL};
79
    option_box* option_group1[] = {op1_1, op1_2, op1_3, NULL};
Line 81... Line 80...
81
 
80
 
82
    option_box opts2[3];
81
    option_box opts2[3];
Line 83... Line 82...
83
    option_box *option2sel = opts2 + 1; // intially selected #2
82
    option_box *option2sel = opts2 + 1; // intially selected #2
84
    option_box *op2_1 = gui_optionbox(&opts2[0], X_Y(140, 50), "G2 Item 1st", &option2sel);
83
    option_box *op2_1 = gui_optionbox(&opts2[0], X_Y(140, 50), "G2 Item 1st", &option2sel);
85
    option_box *op2_2 = gui_optionbox(&opts2[1], X_Y(140, 70), "G2 Item 2nd", &option2sel);
84
    option_box *op2_2 = gui_optionbox(&opts2[1], X_Y(140, 70), "G2 Item 2nd", &option2sel);
86
    option_box *op2_3 = gui_optionbox(&opts2[2], X_Y(140, 90), "G2 Item 3rd", &option2sel);
85
    option_box *op2_3 = gui_optionbox(&opts2[2], X_Y(140, 90), "G2 Item 3rd", &option2sel);
Line 87... Line 86...
87
    option_box* option_group2[] = {op2_1, op2_2, op2_3, NULL};
86
    option_box* option_group2[] = {op2_1, op2_2, op2_3, NULL};
88
 
87
 
Line 89... Line 88...
89
    frame *fr1 = kolibri_new_frame_def(X_Y(12, 110), X_Y(40, 70), "Option 1");
88
    frame *fr1 = kolibri_new_frame_def(X_Y(12, 110), X_Y(40, 70), "Option 1");
90
    frame *fr2 = kolibri_new_frame_def(X_Y(132, 100), X_Y(40, 70), "Option 2");
89
    frame *fr2 = kolibri_new_frame_def(X_Y(132, 100), X_Y(40, 70), "Option 2");
91
 
90
 
Line 92... Line 91...
92
    gui_add_optiongroup(main_window, option_group1);  // new syntax
91
    gui_add_optiongroup(main_window, option_group1);  // new syntax
93
    gui_add_optiongroup(main_window, option_group2);
92
    gui_add_optiongroup(main_window, option_group2);
94
    gui_add_frame(main_window, fr1);
93
    gui_add_frame(main_window, fr1);
Line 95... Line 94...
95
    gui_add_frame(main_window, fr2);
94
    gui_add_frame(main_window, fr2);
96
 
95
 
97
    int option_index1 = 0;  // index of selected option
96
    int option_index1 = 0;  // index of selected option
98
    int option_index2 = 0;
97
    int option_index2 = 0;
Line 99... Line 98...
99
 
98
 
Line 100... Line 99...
100
    char *menu1stru[] = {"Menu1", "Set RED", "Set GREEN", "Set BLUE", NULL};
99
    char *menu1stru[] = {"Menu1", "Set RED", "Set GREEN", "Set BLUE", NULL};
101
    menubar* menu1 = kolibri_new_menubar_def(X_Y(10, 40), X_Y(5, 15), 80, 100, menu1stru);
100
    menubar* menu1 = kolibri_new_menubar_def(X_Y(10, 40), X_Y(5, 15), 80, 100, menu1stru);
102
    gui_add_menubar(main_window, menu1);
101
    gui_add_menubar(main_window, menu1);
103
 
102
 
104
    char *menu2stru[] = {"mEnu2", "Set Option 1", "Set Option 2", "Set Option 3", NULL};
103
    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(5, 15), 80, 100, menu2stru);
104
    menubar* menu2 = kolibri_new_menubar_def(X_Y(50, 40), X_Y(5, 15), 80, 100, menu2stru);
Line 136... Line 135...
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());
135
            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());
137
            kolibri_handle_event_key(main_window, keypress);
136
            kolibri_handle_event_key(main_window, keypress);
Line 138... Line 137...
138
 
137
 
139
            if(keypress.code == SCAN_CODE_ALTM && get_os_keyb_modifiers() & (KEY_LALT | KEY_RALT))
138
            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 (  . but Alt+F1 worked in opendial.asm:463
139
                (*menu_bar_activate)(menu1); // wont work, immediately redraw command closes menu (  . but Alt+F1 worked in opendial.asm:463
141
 
140
 
142
			break;
141
			break;
143
        case KOLIBRI_EVENT_BUTTON:
142
        case KOLIBRI_EVENT_BUTTON:
144
            pressed_button = get_os_button();
143
            pressed_button = get_os_button();
145
            switch (pressed_button)
144
            switch (pressed_button)
146
            {
145
            {
147
              case BTN_QUIT:
146
              case BTN_QUIT:
148
                return 0;
147
                return 0;
149
                break;
148
                break;
150
            }
149
            }
151
            break;
150
            break;
152
        case KOLIBRI_EVENT_MOUSE:
151
        case KOLIBRI_EVENT_MOUSE:
153
//            mouse_pos = get_mouse_pos(POS_WINDOW); // window relative
152
//            mouse_pos = get_mouse_pos(POS_WINDOW); // window relative
154
//            mouse_button = get_mouse_eventstate();
153
//            mouse_button = get_mouse_eventstate();
155
            kolibri_handle_event_mouse(main_window);
154
            kolibri_handle_event_mouse(main_window);
Line 165... Line 164...
165
            }
164
            }
166
            if(menu3->click && menu3->cursor_out)
165
            if(menu3->click && menu3->cursor_out)
167
            {
166
            {
168
                return 0; // quit
167
                return 0; // quit
169
            }
168
            }
170
 
169
 
171
            break;
170
            break;
172
        }
171
        }
Line 173... Line 172...
173
 
172
 
174
        gui_event = get_os_event();
173
        gui_event = get_os_event();
175
    } while(1) ; /* End of main activity loop */
174
    } while(1) ; /* End of main activity loop */
176
 
175
 
177
  return 0;
176
  return 0;