Subversion Repositories Kolibri OS

Rev

Rev 6479 | Rev 6524 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6470 siemargl 1
/*
6479 siemargl 2
    KolibriGUI demobox
3
    -Scrollbar
4
    -Progressbar
5
    -StaticText
6
    -StaticNum
6470 siemargl 7
 
8
    Free for all
9
 
10
    Initially written by Siemargl, 2016
11
 
12
 
13
    ToDo
14
*/
15
 
16
#include 
17
#include 
18
#include 
6479 siemargl 19
#include "kos32sys.h"
6470 siemargl 20
#include "kolibri_gui.h"
21
 
22
// codes copied from \programs\cmm\lib\keyboard.h, but they're decimal
23
//ASCII KEYS
24
#define ASCII_KEY_BS    8
25
#define ASCII_KEY_TAB   9
26
#define ASCII_KEY_ENTER 13
27
#define ASCII_KEY_ESC   27
28
#define ASCII_KEY_DEL   182
29
#define ASCII_KEY_INS   185
30
#define ASCII_KEY_SPACE 32
31
 
32
#define ASCII_KEY_LEFT  176
33
#define ASCII_KEY_RIGHT 179
34
#define ASCII_KEY_DOWN  177
35
#define ASCII_KEY_UP    178
36
#define ASCII_KEY_HOME  180
37
#define ASCII_KEY_END   181
38
#define ASCII_KEY_PGDN  183
39
#define ASCII_KEY_PGUP  184
40
 
41
//SCAN CODE KEYS
42
#define SCAN_CODE_BS    14
43
#define SCAN_CODE_TAB   15
44
#define SCAN_CODE_ENTER 28
45
#define SCAN_CODE_ESC   1
46
#define SCAN_CODE_DEL   83
47
#define SCAN_CODE_INS   82
48
#define SCAN_CODE_SPACE 57
49
 
50
#define SCAN_CODE_LEFT  75
51
#define SCAN_CODE_RIGHT 77
52
#define SCAN_CODE_DOWN  80
53
#define SCAN_CODE_UP    72
54
#define SCAN_CODE_HOME  71
55
#define SCAN_CODE_END   79
56
#define SCAN_CODE_PGDN  81
57
#define SCAN_CODE_PGUP  73
58
 
59
#define KEY_LSHIFT     00000000001b
60
#define KEY_RSHIFT     00000000010b
61
#define KEY_LCTRL      00000000100b
62
#define KEY_RCTRL      00000001000b
63
#define KEY_LALT       00000010000b
64
#define KEY_RALT       00000100000b
65
#define KEY_CAPSLOCK   00001000000b
66
#define KEY_NUMLOCK    00010000000b
67
#define KEY_SCROLLLOCK 00100000000b
68
#define KEY_LWIN       01000000000b
69
#define KEY_RWIN       10000000000b
70
 
71
 
72
int main()
73
{
74
    /* Load all libraries, initialize global tables like system color table and
75
    operations table. kolibri_gui_init() will EXIT with mcall -1 if it fails
76
    to do it's job. This is all you need to call and all libraries and GUI
77
    elements can be used after a successful call to this function
78
    */
79
    kolibri_gui_init();
80
    int gui_event = KOLIBRI_EVENT_REDRAW;
81
    uint32_t pressed_button = 0;
82
//    uint32_t mouse_button;
83
//    pos_t   mouse_pos;
84
    oskey_t keypress;
85
 
86
    int value = 40; // showed value
87
    int valuechange = 0;
88
 
89
    // creating GUI using library functions
6516 siemargl 90
    kolibri_window *main_window = kolibri_new_window(50, 40, 400, 400, "Scrollbar and progressbar showcase");
91
    statictext *txt = kolibri_new_statictext_def(X_Y(10, 20), "StaticText default 6x9. Use Arrows or PgUp/PgDn");
92
    statictext *txt2 = kolibri_new_statictext(X_Y(10, 30), "StaticText 8x16 x2:", CP866, 1, kolibri_color_table.color_work_text, 0);
93
    staticnum *num = kolibri_new_staticnum_def(X_Y(10 + (strlen("StaticText 8x16 x2:") + 2) * 8 * 2, 30), 3, value);
94
    scrollbar *sbh = kolibri_new_scrollbar(X_Y(30, 300), X_Y(370, 5), 15, 100, 10, value, kolibri_color_table.color_work_area, kolibri_color_table.color_work_button, 0);
95
    scrollbar *sbv = kolibri_new_scrollbar(X_Y(370, 15), X_Y(40, 300), 15, 100, 10, value, kolibri_color_table.color_work_area, kolibri_color_table.color_work_button, 0);
96
    progressbar *pg = kolibri_new_progressbar(0, 100, value, 10, 70, 200, 20);
6470 siemargl 97
 
98
    kolibri_window_add_element(main_window, KOLIBRI_STATICTEXT, txt);
99
    kolibri_window_add_element(main_window, KOLIBRI_STATICTEXT, txt2);
100
    kolibri_window_add_element(main_window, KOLIBRI_STATICNUM, num);
101
    kolibri_window_add_element(main_window, KOLIBRI_SCROLL_BAR_H, sbh);
102
    kolibri_window_add_element(main_window, KOLIBRI_SCROLL_BAR_V, sbv);
103
    kolibri_window_add_element(main_window, KOLIBRI_PROGRESS_BAR, pg);
104
 
105
    do  /* Start of main activity loop */
106
    {
107
        switch(gui_event)
108
        {
109
        case KOLIBRI_EVENT_REDRAW:
110
            sbh->all_redraw = sbv->all_redraw = 1; // resetted
111
            kolibri_handle_event_redraw(main_window);
112
            valuechange = 0;
113
            break;
114
        case KOLIBRI_EVENT_NONE:
115
			break;
116
        case KOLIBRI_EVENT_KEY:
117
            keypress = get_key();
118
            // add logic to find focused active widget
119
            // we have only one reaction
120
            switch (keypress.ctrl_key)
121
            {
122
              case SCAN_CODE_UP:  case SCAN_CODE_RIGHT:
123
                  if(value < 100)
124
                    {
125
                        value++; valuechange = 1;
126
                        progressbar_progress(pg); // +1 and redraw self
127
                    }
128
                break;
129
              case SCAN_CODE_PGUP:
130
                  if(value < 100)
131
                    {
132
                        value += 10; valuechange = 1;
133
                        if (value > 100) value = 100;
134
                    }
135
                break;
136
              case SCAN_CODE_DOWN:  case SCAN_CODE_LEFT:
137
                  if(value > 0)
138
                    {
139
                        value--; valuechange = 1;
140
                    }
141
                break;
142
              case SCAN_CODE_PGDN:
143
                  if(value > 0)
144
                    {
145
                        value -= 10; valuechange = 1;
146
                        if (value < 0) value = 0;
147
                    }
148
                break;
149
            }
150
            kolibri_handle_event_key(main_window); // ???????
151
			break;
152
        case KOLIBRI_EVENT_BUTTON:
153
            pressed_button = get_os_button();
154
            switch (pressed_button)
155
            {
156
              case BTN_QUIT:
157
                return 0;
158
                break;
159
            }
160
            break;
161
        case KOLIBRI_EVENT_MOUSE:
162
//            mouse_pos = get_mouse_pos(POS_WINDOW); // window relative
163
//            mouse_button = get_mouse_eventstate();
164
            // add logic to find widget under mouse
165
            kolibri_handle_event_mouse(main_window);
166
            if (sbh->position != value)  // scrollbars was changed
167
            {
168
                value = sbh->position;
169
                valuechange = 1;
170
            }else
171
            if (sbv->position != value)  // scrollbars was changed
172
            {
173
                value = sbv->position;
174
                valuechange = 1;
175
            }
176
/*            debug_board_printf("mouse ev (%d,%d)%x\n", mouse_pos.x, mouse_pos.y, mouse_button);
177
            if (mouse_button & (1<<24)) // double click
178
            {
179
            }
180
            // ignore
181
*/
182
            break;
183
        }
184
        if(valuechange)
185
        {
186
            debug_board_printf("value change (%d)\n", value);
187
            num->number = value;
188
            sbh->position = value;
189
            sbv->position = value;
190
            pg->value = value;
191
            gui_event = KOLIBRI_EVENT_REDRAW;
192
            continue;
193
        }
194
 
195
        gui_event = wait_for_event(10); // 100 = 1 sec
196
    } while(1) ; /* End of main activity loop */
197
 
198
  return 0;
199
}
200
/*
201
void __attribute__ ((noinline)) debug_board_write_str(const char* str){
202
  while(*str)
203
    debug_board_write_byte(*str++);
204
}
205
 
206
void __attribute__ ((noinline)) debug_board_printf(const char *format,...)
207
{
208
        va_list ap;
209
        char log_board[300];
210
 
211
        va_start (ap, format);
212
        tiny_vsnprintf(log_board, sizeof log_board, format, ap);
213
        va_end(ap);
214
        debug_board_write_str(log_board);
215
 
216
}
217
*/