Subversion Repositories Kolibri OS

Rev

Rev 9766 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
9766 turbocat 1
#include 
8687 turbocat 2
#include 
3
#include 
4
#include 
5
#include 
6
 
7
ksys_colors_table_t sys_color_table;
8
 
9
char statusbar[255];
9094 turbocat 10
ksys_thread_t proc_info;
8687 turbocat 11
char text_line[255];
12
 
9766 turbocat 13
enum BUTTONS {
8687 turbocat 14
    BTN_QUIT = 1,
15
    BTN_POP = 10,
16
    BTN_UNLOCK = 11
17
};
18
 
19
#define FONT_W 8
20
#define FONT_H 14
21
#define LINES 10
22
 
23
void draw_window()
24
{
9766 turbocat 25
    int win_hight, win_width, i, pos_y = _ksys_get_skin_height() + 36; // 60 == 24+36
8687 turbocat 26
 
27
    // start redraw
28
    _ksys_start_draw();
9766 turbocat 29
    // define&draw window
8687 turbocat 30
    _ksys_create_window(10, 40, 600, 400, "My window", sys_color_table.work_area, 0x13);
9094 turbocat 31
    _ksys_thread_info(&proc_info, -1);
8687 turbocat 32
 
9766 turbocat 33
        win_width
34
        = proc_info.winx_size;
8687 turbocat 35
    win_hight = proc_info.winy_size;
9766 turbocat 36
 
8687 turbocat 37
    _ksys_define_button(10, 30, 70, 20, BTN_POP, sys_color_table.work_button);
9766 turbocat 38
    _ksys_draw_text("BUTTON1", 15, 34, 0, 0x90000000 | sys_color_table.work_button_text); // 0x80000000 asciiz
8687 turbocat 39
    _ksys_define_button(100, 30, 80, 20, BTN_UNLOCK, sys_color_table.work_button);
40
    _ksys_draw_text("BUTTTON2", 110, 34, 0, 0x90000000 | sys_color_table.work_button_text);
41
 
42
    // display statusbar
9766 turbocat 43
    _ksys_draw_bar(6, win_hight - 17, win_width - 11, 12, 0x80000000 | sys_color_table.work_area); // 0x80000000 gradient
8687 turbocat 44
    _ksys_draw_text(statusbar, 10, win_hight - 15, 0, 0x80000000 | sys_color_table.work_text);
45
 
46
    // display strings
9766 turbocat 47
    for (i = LINES; i > 0; i--) {
48
        snprintf(text_line, sizeof text_line, "Line[%d]<>", i);
8687 turbocat 49
 
50
        text_line[(win_width - 10 - 5) / FONT_W + 1] = '\0'; // clip text size, seems to big lines crashing OS, and form len by window size
51
        _ksys_draw_text(text_line, 5, pos_y, 0, 0x90000000 | sys_color_table.work_text);
52
        pos_y += FONT_H;
53
 
9766 turbocat 54
        if (pos_y + 29 > win_hight)
55
            break; // 12 font + 12 statusbar + 5 border
8687 turbocat 56
    }
57
    // end redraw
58
    _ksys_end_draw();
59
}
9766 turbocat 60
 
8687 turbocat 61
int main()
62
{
63
    int gui_event;
64
    uint32_t pressed_button = 0, mouse_button;
65
    ksys_pos_t mouse_pos;
66
    strcpy(statusbar, "Program running...Double click on TEXT for details");
67
 
8718 turbocat 68
    _ksys_get_system_colors(&sys_color_table);
8687 turbocat 69
    _ksys_set_event_mask(0xC0000027); // mouse events only when focused window and mouse inside
70
 
9766 turbocat 71
    do {
72
        gui_event = _ksys_get_event();
73
        switch (gui_event) {
8687 turbocat 74
        case KSYS_EVENT_NONE:
9766 turbocat 75
            break;
8687 turbocat 76
        case KSYS_EVENT_REDRAW:
77
            draw_window();
9766 turbocat 78
            break;
8687 turbocat 79
        case KSYS_EVENT_KEY:
9766 turbocat 80
            break;
8687 turbocat 81
        case KSYS_EVENT_BUTTON:
82
            pressed_button = _ksys_get_button();
9766 turbocat 83
            switch (pressed_button) {
84
            case BTN_POP:
8687 turbocat 85
                strcpy(statusbar, "POP pressed....");
86
                draw_window();
87
                break;
9766 turbocat 88
            case BTN_UNLOCK:
8687 turbocat 89
                strcpy(statusbar, "UNLOCK pressed....");
90
                draw_window();
91
                break;
9766 turbocat 92
            case BTN_QUIT:
8687 turbocat 93
                return 0;
94
                break;
95
            }
96
            break;
97
        case KSYS_EVENT_MOUSE:
98
            mouse_pos = _ksys_get_mouse_pos(KSYS_MOUSE_WINDOW_POS); // window relative
99
            mouse_button = _ksys_get_mouse_eventstate();
100
            debug_printf("mouse ev (%d,%d)%x\n", mouse_pos.x, mouse_pos.y, mouse_button);
9766 turbocat 101
            if (mouse_button & (1 << 24)) // double click
8687 turbocat 102
            {
103
                int n = (mouse_pos.y - 60) / FONT_H;
9766 turbocat 104
                if (n < 0 || n >= LINES)
105
                    break;
8687 turbocat 106
                debug_printf("click on str(%d), clip slot(%d)\n", n, LINES - n - 1);
107
                sprintf(statusbar, "click on str(%d), clip slot(%d)\n", n, LINES - n - 1);
108
                draw_window();
109
            }
110
            break;
111
        }
9766 turbocat 112
    } while (1); /* End of main activity loop */
8687 turbocat 113
 
9766 turbocat 114
    return 0;
8687 turbocat 115
}