Subversion Repositories Kolibri OS

Rev

Rev 6615 | Rev 8581 | 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
 
6612 siemargl 31
// 0 - ASCII, 1 - SCAN
32
{
33
    __asm__ __volatile__(
34
    "int $0x40"
35
    ::"a"(66), "b"(1), "c"(mode));
36
};
37
38
 
39
 
6589 siemargl 40
{
41
    /* Load all libraries, initialize global tables like system color table and
42
    operations table. kolibri_gui_init() will EXIT with mcall -1 if it fails
43
    to do it's job. This is all you need to call and all libraries and GUI
44
    elements can be used after a successful call to this function
45
    */
46
    kolibri_gui_init();
47
    set_os_keyb_mode(1); // scan code mode needed for editor
6612 siemargl 48
//    kolibri_proclib_init();  // opensave && color dialogs
6601 siemargl 49
    kolibri_libimg_init();  // png handling
6589 siemargl 50
51
 
52
    uint32_t pressed_button = 0;
53
//    uint32_t mouse_button;
54
//    pos_t   mouse_pos;
55
//    oskey_t keypress;
6612 siemargl 56
6589 siemargl 57
 
58
    strcpy(run_path, argv[0]);
6601 siemargl 59
    char *pc = strrchr(run_path, '/');  // this fails if has params with '/' within. use argv[0] instead
60
    if (pc) pc[1] = 0;
6589 siemargl 61
//    debug_board_write_str(temp_path);
62
63
 
64
    kolibri_window *main_window = kolibri_new_window(50, 40, 490, 500, "Editor, TreeView and MsgBox demo");
6601 siemargl 65
6589 siemargl 66
 
67
    void *ed_lock;
6612 siemargl 68
6589 siemargl 69
 
6612 siemargl 70
    ed_lock = ed;
71
6615 siemargl 72
 
6612 siemargl 73
    //int res, len;
6615 siemargl 74
    //res = editor_openfile(ed, "/rd/1/boardlog.txt", &len);
75
    //debug_board_printf("loaded sample file err=%d, len=%d\n", res, len);
76
77
 
6612 siemargl 78
    char *sampletext = "*123*=========ADDED SAMPLE TEXT=========*789*\n";
6615 siemargl 79
    (*ted_text_add)(ed, sampletext, strlen(sampletext), 0);
6612 siemargl 80
81
 
82
    treelist *tl = kolibri_new_treelist(X_Y(0, 200), X_Y(200, 200), 16, X_Y(16, 16), 100, 50, 0, 0, /*TL_KEY_NO_EDIT |*/ TL_DRAW_PAR_LINE, &ed_lock, 0x8080ff, 0x0000ff, 0xffffff);
6690 siemargl 83
    (*tl_data_init)(tl);
6615 siemargl 84
6589 siemargl 85
 
6601 siemargl 86
    strcpy(fname, run_path);
87
    strcat(fname, "tl_sys_16.png");
88
    tl->data_img_sys = load_image_file(fname);
89
6589 siemargl 90
 
6601 siemargl 91
    strcpy(fname, run_path);
92
    strcat(fname, "tl_nod_16.png");
93
    tl->data_img = load_image_file(fname);
94
6589 siemargl 95
 
6601 siemargl 96
    (*tl_cur_next)(tl);
6615 siemargl 97
    treelist_node_add(tl, "node1.1", 1, 0, 1);
6612 siemargl 98
    (*tl_cur_next)(tl);
6615 siemargl 99
    treelist_node_add(tl, "node1.1.1", 0, 0, 2);
6612 siemargl 100
    (*tl_cur_next)(tl);
6615 siemargl 101
    treelist_node_add(tl, "node1.2", 1, 0, 1);
6612 siemargl 102
    (*tl_cur_next)(tl);
6615 siemargl 103
6589 siemargl 104
 
6612 siemargl 105
    (*tl_cur_next)(tl);
6615 siemargl 106
    treelist_node_add(tl, "node2.1", 1, 0, 1);
6612 siemargl 107
    (*tl_cur_next)(tl);
6615 siemargl 108
6601 siemargl 109
 
110
    (*tl_cur_next)(tl);
6615 siemargl 111
6601 siemargl 112
 
6615 siemargl 113
    gui_add_treelist(main_window, tl);
6601 siemargl 114
115
 
6690 siemargl 116
    treelist *tl2 = kolibri_new_treelist(X_Y(220, 200), X_Y(200, 200), 0, X_Y(16, 16), 100, 50, 0, 0, TL_LISTBOX_MODE, &ed_lock, 0x8080ff, 0x0000ff, 0xffffff);
117
    (*tl_data_init)(tl2);
6615 siemargl 118
    // tl->col_zag |= 0x10000000; // 0x10 in txt color must give font 9x16, but this not work, only 6x8 font (
6690 siemargl 119
6612 siemargl 120
 
121
    //tl2->data_img = tl->data_img; - no icons will be drawed
6690 siemargl 122
6612 siemargl 123
 
124
    (*tl_cur_next)(tl2);
6615 siemargl 125
6612 siemargl 126
 
127
    (*tl_cur_next)(tl2);
6615 siemargl 128
6612 siemargl 129
 
130
    (*tl_cur_next)(tl2);
6615 siemargl 131
6612 siemargl 132
 
6615 siemargl 133
    gui_add_treelist(main_window, tl2);
6612 siemargl 134
135
 
6589 siemargl 136
137
 
6612 siemargl 138
    do  /* Start of main activity loop */
6589 siemargl 139
    {
140
        switch(gui_event)
141
        {
142
        case KOLIBRI_EVENT_REDRAW:
143
            if (box->retval == 1 || box->retval == 2) goto clearing;  // msgbox closes
6601 siemargl 144
6589 siemargl 145
 
146
            break;
147
        case KOLIBRI_EVENT_NONE:
148
			break;
149
        case KOLIBRI_EVENT_KEY:
150
            key = get_key();
6612 siemargl 151
            if (ed_lock == ed)
6589 siemargl 152
                editor_key(ed, key);
6612 siemargl 153
            else if(ed_lock == tl)
154
            {
155
                treelist_key(tl, key);
156
            }
157
            else if(ed_lock == tl2)
158
            {
159
                treelist_key(tl2, key);
160
            }
161
            else
6589 siemargl 162
                kolibri_handle_event_key(main_window, key);
6612 siemargl 163
			break;
6589 siemargl 164
        case KOLIBRI_EVENT_BUTTON:
165
            pressed_button = get_os_button();
166
            switch (pressed_button)
167
            {
168
              case BTN_QUIT:
169
                  if (box->retval == 3 || box->retval == 0) // not started or cancelled, analyze when redraw after closing msgbox
170
                    kolibri_start_msgbox(box, NULL);
6601 siemargl 171
                break;
6589 siemargl 172
            }
173
            break;
174
        case KOLIBRI_EVENT_MOUSE:
175
            kolibri_handle_event_mouse(main_window);
176
            break;
177
        }
178
179
 
180
    } while(1) ; /* End of main activity loop */
181
6601 siemargl 182
 
183
trap(0x55); // for stop in debug
6615 siemargl 184
    //res = editor_savefile(ed, "/tmp0/1/editorlog.txt");
185
    pc = editor_get_text(ed);
186
    debug_board_printf("saved text \"%s\"\n", pc);
187
    free(pc);
188
189
 
190
 
191
 
6601 siemargl 192
    treelist_data_clear(tl);
193
6589 siemargl 194
 
195
}
196
6601 siemargl 197
 
198
 
199
{
200
    FILE *f = fopen(fname, "rb");
201
    if (!f) {
202
        debug_board_printf("Can't open file: %s", fname);
203
        exit(1);
204
    }
205
    if (fseek(f, 0, SEEK_END)) {
206
        debug_board_printf("Can't SEEK_END file: %s", fname);
207
        exit(1);
208
    }
209
    int filesize = ftell(f);
210
    rewind(f);
211
    char* fdata = malloc(filesize);
212
    if(!fdata) {
213
        debug_board_printf("No memory for file %s", fname);
214
        exit(1);
215
    }
216
    *read_sz = fread(fdata, 1, filesize, f);
217
    if (ferror(f)) {
218
        debug_board_printf("Error reading file %s", fname);
219
        exit(1);
220
    }
221
    fclose(f);
222
223
 
224
}
225
226
 
227
{
228
    int32_t     read_bytes = -1, w, h;
229
    char    *image_data = 0, *image_data_rgb = 0, *filedata = 0;
230
231
 
232
    // определяем вид изображения и переводим его во временный буфер image_data
233
    image_data = (*img_decode)(filedata, read_bytes, 0);
234
    w = *(int*)(image_data +4);
235
    h = *(int*)(image_data +8);
236
    image_data_rgb = malloc(w * h * 3);
237
    // преобразуем изображение к формату rgb
238
    (*img_to_rgb2)(image_data, image_data_rgb);
239
    // удаляем временный буфер image_data
240
    (*img_destroy)(image_data);
241
    free(filedata);
242
243
 
244
}
245