Subversion Repositories Kolibri OS

Rev

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