diff --git a/programs/develop/ktcc/trunk/samples/clayer/kolibrios.jpg b/programs/develop/ktcc/trunk/samples/clayer/kolibrios.jpg new file mode 100755 index 0000000000..9f58f0931b Binary files /dev/null and b/programs/develop/ktcc/trunk/samples/clayer/kolibrios.jpg differ diff --git a/programs/develop/ktcc/trunk/samples/clayer/libimg.c b/programs/develop/ktcc/trunk/samples/clayer/libimg.c new file mode 100755 index 0000000000..df5cf05f28 --- /dev/null +++ b/programs/develop/ktcc/trunk/samples/clayer/libimg.c @@ -0,0 +1,86 @@ +#include +#include +#include +#include +#include +#include + +struct kolibri_system_colors sys_color_table; + +char path[4096]; +char* picture; +int x_size = 200, y_size = 150; + +char* load_file_inmem(char* fname, int32_t* read_sz) +{ + FILE *f = fopen(fname, "rb"); + if (!f) { + printf("Can't open file: %s\n", fname); + } + if (fseek(f, 0, SEEK_END)) { + printf("Can't SEEK_END file: %s\n", fname); + } + int filesize = ftell(f); + rewind(f); + char* fdata = malloc(filesize); + if(!fdata) { + printf("No memory for file %s\n", fname); + } + *read_sz = fread(fdata, 1, filesize, f); + if (ferror(f)) { + printf("Error reading file %s\n", fname); + } + fclose(f); + + return fdata; +} + +void draw_window() +{ + BeginDraw(); + DrawWindow(10, 40, x_size + 50, y_size + 50, "Libimg", sys_color_table.work_area, 0x34); + + // Draw Picture + draw_bitmap(picture, 10, 10, x_size, y_size); + + EndDraw(); +} + +int main() +{ + if (kolibri_libimg_init() == -1) + { + printf("Error loading lib_img.obj\n"); + } + + // Load Image + const int icon_rgb_size = x_size * y_size; + char *image_data, + *filedata; + + strcpy(path, "kolibrios.jpg"); // Filename + int32_t read_bytes; + filedata = load_file_inmem(path, &read_bytes); + picture = malloc(icon_rgb_size * 3); + image_data = img_decode(filedata, read_bytes, 0); + img_to_rgb2(image_data, picture); + img_destroy(image_data); + free(filedata); + // End Load Image + + get_system_colors(&sys_color_table); + set_event_mask(0xC0000027); + + while (1) { + switch(get_os_event()) + { + case KOLIBRI_EVENT_REDRAW: + draw_window(); + break; + case KOLIBRI_EVENT_BUTTON: + if (get_os_button() == 1) exit(0); + break; + } + } + return 0; +} diff --git a/programs/develop/ktcc/trunk/samples/clayer/msgbox.c b/programs/develop/ktcc/trunk/samples/clayer/msgbox.c index 3042ec19cf..7ccd9369eb 100644 --- a/programs/develop/ktcc/trunk/samples/clayer/msgbox.c +++ b/programs/develop/ktcc/trunk/samples/clayer/msgbox.c @@ -2,7 +2,7 @@ int main() { - msgbox *msg1=NULL; - msg1 = kolibri_new_msgbox("MsgBoxTest", "Hello world!", 0, "ok"); + msgbox *msg1 = NULL; + msg1 = kolibri_new_msgbox("Title", "Text in window", 0, "Ok"); kolibri_start_msgbox(msg1, NULL); } diff --git a/programs/develop/ktcc/trunk/samples/clayer/rasterworks.c b/programs/develop/ktcc/trunk/samples/clayer/rasterworks.c index 44b6d91724..145cf47fcd 100644 --- a/programs/develop/ktcc/trunk/samples/clayer/rasterworks.c +++ b/programs/develop/ktcc/trunk/samples/clayer/rasterworks.c @@ -1,45 +1,55 @@ #include +#include #include -#include #include #include +// Sizes +int x_size = 768, y_size = 256; + +// Out example string +char* string = "Пример/Example"; + int main() { - unsigned int event; - int ln_str = countUTF8Z("Example", -1); - void *buffi = malloc(768*256*3 * sizeof(char)); - *((int*)buffi) = 768; - *((int*)buffi+1) = 256; - memset((char*)buffi+8, (char)-1, 768*256*3); - drawText(buffi, 0, 0, "Example", ln_str, 0xFF000000, 0x30C18); - drawText(buffi, 0, 32, "Example", ln_str, 0xFF000000, 0x1030C18); - drawText(buffi, 0, 64, "Example", ln_str, 0xFF000000, 0x2030C18); - drawText(buffi, 0, 96, "Example", ln_str, 0xFF000000, 0x4030C18); - drawText(buffi, 0, 128, "Example", ln_str, 0xFF000000, 0x8030C18); - drawText(buffi, 0, 160, "Example", ln_str, 0xFF000000, 0x0F031428); - for (;;){ - event = get_os_event(); - switch (event) - { - case 1: - begin_draw(); - sys_create_window(50, 50, 800, 300, "rasterworks example" ,0x34f0f0f0, 0x14); - draw_bitmap(buffi+8, 5, 25, 768, 256); - end_draw(); - break; - - case 2: - get_key(); - break; - - case 3: - if (1==get_os_button()) - { - exit(0); - } - break; - }; - } - exit(0); + // Count length + int ln_str = countUTF8Z(string, -1); + + // Create image buffer + void *buffi = malloc(x_size * y_size * 3 * sizeof(char) + 8); + + // Set sizes + *((int*)buffi) = x_size; + *((int*)buffi+1) = y_size; + + // Fill color + memset((char*)buffi + 8, 0xFF, x_size * y_size * 3); + + // Draw text on buffer + drawText(buffi, 5, 0, string, ln_str, 0xFF000000, 0x30C18); + drawText(buffi, 5, 32, string, ln_str, 0xFF000000, 0x1030C18); + drawText(buffi, 5, 64, string, ln_str, 0xFF000000, 0x2030C18); + drawText(buffi, 5, 96, string, ln_str, 0xFF000000, 0x4030C18); + drawText(buffi, 5, 128, string, ln_str, 0xFF000000, 0x8030C18); + drawText(buffi, 5, 160, string, ln_str, 0xFF000000, 0x0F031428); + + while (1) + { + switch (get_os_event()) + { + case 1: + BeginDraw(); + DrawWindow(50, 50, 800, 300, "Rasterworks Example", 0x999999, 0x34); + DrawBitmap(buffi + 8, 10, 10, 768, 256); + EndDraw(); + break; + case 2: + get_key(); + break; + case 3: + if (get_os_button() == 1) exit(0); + break; + }; + } + return 0; }