Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
6589 siemargl 1
 
2
    KolibriGUI demobox
3
    -Editor (multiline edit)
4
    -TreeView
5
    -MsgBox Dialog
6
7
 
8
9
 
10
11
 
12
 
13
*/
14
15
 
16
#include 
17
#include 
18
#include 
19
#include "kos32sys.h"
20
#include "kolibri_gui.h"
21
#include "kolibri_libimg.h"
22
#include "kolibri_msgbox.h"
23
24
 
6601 siemargl 25
char fname[4096];
26
6589 siemargl 27
 
28
char*   load_image_file(char* fname); // see below
6601 siemargl 29
6589 siemargl 30
 
31
{
32
    /* Load all libraries, initialize global tables like system color table and
33
    operations table. kolibri_gui_init() will EXIT with mcall -1 if it fails
34
    to do it's job. This is all you need to call and all libraries and GUI
35
    elements can be used after a successful call to this function
36
    */
37
    kolibri_gui_init();
38
//    kolibri_proclib_init();  // opensave && color dialogs
6601 siemargl 39
    kolibri_libimg_init();  // png handling
6589 siemargl 40
41
 
42
    uint32_t pressed_button = 0;
43
//    uint32_t mouse_button;
44
//    pos_t   mouse_pos;
45
    oskey_t keypress;
46
47
 
48
    strcpy(run_path, argv[0]);
6601 siemargl 49
    char *pc = strrchr(run_path, '/');  // this fails if has params with '/' within. use argv[0] instead
50
    if (pc) pc[1] = 0;
6589 siemargl 51
//    debug_board_write_str(temp_path);
52
53
 
54
    kolibri_window *main_window = kolibri_new_window(50, 40, 490, 500, "Editor, TreeView and MsgBox demo");
6601 siemargl 55
6589 siemargl 56
 
57
    editor *ed_lock;
58
59
 
6601 siemargl 60
    ed_lock = ed;
6589 siemargl 61
62
 
6601 siemargl 63
    treelist_data_init(tl);
64
6589 siemargl 65
 
6601 siemargl 66
    strcpy(fname, run_path);
67
    strcat(fname, "tl_sys_16.png");
68
    tl->data_img_sys = load_image_file(fname);
69
6589 siemargl 70
 
6601 siemargl 71
    strcpy(fname, run_path);
72
    strcat(fname, "tl_nod_16.png");
73
    tl->data_img = load_image_file(fname);
74
6589 siemargl 75
 
6601 siemargl 76
    treelist_cursor_next(tl);
77
6589 siemargl 78
 
6601 siemargl 79
    treelist_cursor_next(tl);
80
81
 
82
    treelist_cursor_next(tl);
83
84
 
85
    gui_add_treelist(main_window, tl);
86
87
 
6589 siemargl 88
89
 
90
    {
91
        switch(gui_event)
92
        {
93
        case KOLIBRI_EVENT_REDRAW:
94
            if (box->retval == 1 || box->retval == 2) goto clearing;  // msgbox closes
6601 siemargl 95
6589 siemargl 96
 
97
            break;
98
        case KOLIBRI_EVENT_NONE:
99
			break;
100
        case KOLIBRI_EVENT_KEY:
101
            if (ed_lock == ed)
102
                editor_key(ed);
103
            else
104
                kolibri_handle_event_key(main_window);
105
			break;
106
        case KOLIBRI_EVENT_BUTTON:
107
            pressed_button = get_os_button();
108
            switch (pressed_button)
109
            {
110
              case BTN_QUIT:
111
                  if (box->retval == 3 || box->retval == 0) // not started or cancelled, analyze when redraw after closing msgbox
112
                    kolibri_start_msgbox(box, NULL);
6601 siemargl 113
                break;
6589 siemargl 114
            }
115
            break;
116
        case KOLIBRI_EVENT_MOUSE:
117
            kolibri_handle_event_mouse(main_window);
118
            break;
119
        }
120
121
 
122
    } while(1) ; /* End of main activity loop */
123
6601 siemargl 124
 
125
    editor_delete(ed);
126
    treelist_data_clear(tl);
127
6589 siemargl 128
 
129
}
130
6601 siemargl 131
 
132
 
133
{
134
    FILE *f = fopen(fname, "rb");
135
    if (!f) {
136
        debug_board_printf("Can't open file: %s", fname);
137
        exit(1);
138
    }
139
    if (fseek(f, 0, SEEK_END)) {
140
        debug_board_printf("Can't SEEK_END file: %s", fname);
141
        exit(1);
142
    }
143
    int filesize = ftell(f);
144
    rewind(f);
145
    char* fdata = malloc(filesize);
146
    if(!fdata) {
147
        debug_board_printf("No memory for file %s", fname);
148
        exit(1);
149
    }
150
    *read_sz = fread(fdata, 1, filesize, f);
151
    if (ferror(f)) {
152
        debug_board_printf("Error reading file %s", fname);
153
        exit(1);
154
    }
155
    fclose(f);
156
157
 
158
}
159
160
 
161
{
162
    int32_t     read_bytes = -1, w, h;
163
    char    *image_data = 0, *image_data_rgb = 0, *filedata = 0;
164
165
 
166
    // определяем вид изображения и переводим его во временный буфер image_data
167
    image_data = (*img_decode)(filedata, read_bytes, 0);
168
    w = *(int*)(image_data +4);
169
    h = *(int*)(image_data +8);
170
    image_data_rgb = malloc(w * h * 3);
171
    // преобразуем изображение к формату rgb
172
    (*img_to_rgb2)(image_data, image_data_rgb);
173
    // удаляем временный буфер image_data
174
    (*img_destroy)(image_data);
175
    free(filedata);
176
177
 
178
}
179