Subversion Repositories Kolibri OS

Rev

Rev 6482 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6479 siemargl 1
/*
2
    KolibriGUI demobox
3
    -OptionBox
4
    -MenuBar
5
    -Frame
6
 
7
    Free for all
8
 
9
    Initially written by Siemargl, 2016
10
 
11
 
12
    ToDo
13
*/
14
 
15
#include 
16
#include 
17
#include 
18
#include "kos32sys.h"
19
#include "kolibri_gui.h"
20
 
21
 
22
int main()
23
{
24
    /* Load all libraries, initialize global tables like system color table and
25
    operations table. kolibri_gui_init() will EXIT with mcall -1 if it fails
26
    to do it's job. This is all you need to call and all libraries and GUI
27
    elements can be used after a successful call to this function
28
    */
29
    kolibri_gui_init();
30
    int gui_event = KOLIBRI_EVENT_REDRAW;
31
    uint32_t pressed_button = 0;
32
//    uint32_t mouse_button;
33
//    pos_t   mouse_pos;
34
    oskey_t keypress;
35
 
36
 
37
    // creating GUI using library functions
38
    kolibri_window *main_window = kolibri_new_window(50, 50, 400, 160, "OptionBox and Menu demo");
39
    //check_box *checkbox = kolibri_new_check_box(20, 45, 12, 12, "Append BOARDMSG to entered message.");
40
 
41
    option_box opts1[3];
42
    option_box *option1sel = opts1; // intially selected RED
43
 
44
    option_box *op1_1 = gui_optionbox(opts1, X_Y(20, 60), "G1 Item RED", &option1sel);
45
    option_box *op1_2 = gui_optionbox(opts1+1, X_Y(20, 80), "G1 Item GREEN", &option1sel);
46
    option_box *op1_3 = gui_optionbox(opts1+2, X_Y(20, 100), "G1 Item BLUE", &option1sel);
47
    option_box* option_group1[] = {op1_1, op1_2, op1_3, NULL};
48
 
49
    option_box opts2[3];
50
    option_box *option2sel = opts2 + 1; // intially selected #2
51
    option_box *op2_1 = gui_optionbox(&opts2[0], X_Y(140, 60), "G2 Item 1st", &option2sel);
52
    option_box *op2_2 = gui_optionbox(&opts2[1], X_Y(140, 80), "G2 Item 2nd", &option2sel);
53
    option_box *op2_3 = gui_optionbox(&opts2[2], X_Y(140, 100), "G2 Item 3rd", &option2sel);
54
    option_box* option_group2[] = {op2_1, op2_2, op2_3, NULL};
55
 
56
    frame *fr1 = kolibri_new_frame_def(X_Y(12, 110), X_Y(50, 70), "Option 1");
57
    frame *fr2 = kolibri_new_frame_def(X_Y(132, 100), X_Y(50, 70), "Option 2");
58
 
59
    gui_add_optiongroup(main_window, option_group1);  // new syntax
60
    gui_add_optiongroup(main_window, option_group2);
61
    gui_add_frame(main_window, fr1);
62
    gui_add_frame(main_window, fr2);
63
 
64
    int option_index1 = 0;  // index of selected option
65
    int option_index2 = 0;
66
 
67
    do  /* Start of main activity loop */
68
    {
69
        if(option_index1 != option1sel - opts1)
70
            debug_board_printf("Option1 change to %d\n", option1sel - opts1);
71
        if(option_index2 != option2sel - opts2)
72
            debug_board_printf("Option2 change to %d\n", option2sel - opts2);
73
        option_index1 = option1sel - opts1;
74
        option_index2 = option2sel - opts2;
75
 
76
        switch(gui_event)
77
        {
78
        case KOLIBRI_EVENT_REDRAW:
79
            kolibri_handle_event_redraw(main_window);
80
            break;
81
        case KOLIBRI_EVENT_NONE:
82
			break;
83
        case KOLIBRI_EVENT_KEY:
84
            kolibri_handle_event_key(main_window); // ???????
85
			break;
86
        case KOLIBRI_EVENT_BUTTON:
87
            pressed_button = get_os_button();
88
            switch (pressed_button)
89
            {
90
              case BTN_QUIT:
91
                return 0;
92
                break;
93
            }
94
            break;
95
        case KOLIBRI_EVENT_MOUSE:
96
//            mouse_pos = get_mouse_pos(POS_WINDOW); // window relative
97
//            mouse_button = get_mouse_eventstate();
98
            kolibri_handle_event_mouse(main_window);
99
            break;
100
        }
101
 
102
        gui_event = get_os_event();
103
    } while(1) ; /* End of main activity loop */
104
 
105
  return 0;
106
}
107