From 9a24f3f7fb95a2a82fe03c51bff635e2bacd2a84 Mon Sep 17 00:00:00 2001 From: maxcodehack Date: Fri, 13 Nov 2020 17:47:07 +0000 Subject: [PATCH] Tcc: Add libimg example, update other examples git-svn-id: svn://kolibrios.org@8187 a494cfbc-eb01-0410-851d-a64ba20cac60 --- .../ktcc/trunk/samples/clayer/kolibrios.jpg | Bin 0 -> 6873 bytes .../ktcc/trunk/samples/clayer/libimg.c | 86 ++++++++++++++++++ .../ktcc/trunk/samples/clayer/msgbox.c | 4 +- .../ktcc/trunk/samples/clayer/rasterworks.c | 84 +++++++++-------- 4 files changed, 135 insertions(+), 39 deletions(-) create mode 100755 programs/develop/ktcc/trunk/samples/clayer/kolibrios.jpg create mode 100755 programs/develop/ktcc/trunk/samples/clayer/libimg.c 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 0000000000000000000000000000000000000000..9f58f0931b25a24c2a4017267fb1af0a90c40b05 GIT binary patch literal 6873 zcmbVQcT`hRlYca+(yN37DGJi0BUMDIB28LoB25IOMmh*e?@|;{dY2+X2qkn75m7)0 zJ&=SV)r10>11rQ5nTFg0~ubIZVg#Lb4D2qG{|uUO`dmhO*XeZ5>@beFL-m<`$M#)=(#B7gx7O?vMQgU{3>sf4Ah zPe^>3nU$UM>UC~jNoiSmMP*fW&4;FDcnhMnt-Y^*VDRJ6r{T{N-zTR~(=)Sk7%XmO zb#48}#wKBJ|KRZGnE31WUtDAW#Xn(@`hOz(AGlaZxX4Lvp``wci;O(*FK`x0s>{+B zST#+k9evpZWTI%;Z)FrW_Rzd0vSgp9Ul)Vy)hv!QffLXy>GJzLGkH)B(VX4Kld-D6nl zAap(@_~5Og33B{UMe*ew`uHnLd`SK^xg1s>LhHgEC&8$UXL{82Cbo#E6BC7ZLUZbf zCwY}e6+ygz^y_;J`4P34HmdMGEaQS)R-){znj~_x7C|VB>8*bqXlO*Kz zCQy5N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5bXxDvwEH2{Ri*O5?kA2uv?nSETdJ zx)jN+o%o|oWb|y^3S^f6%jPgaqCcjA@g(vk6U~qx3Jsco@2#Tgk%8+b6Y#t70RP z8py%E_4oG5c|V!7Y&mcXK~jTrsSOg%`@~3V=bSY?K}nP)T@?L?di|71Nj-?DeUPfm zz3;{!n!6iwz8;~)l7h3!GCmb&M{Ux`uew)0ZrTW(qsmjLK(kF_^5)Ri>K^$H63%)_ ziWVl90fcE%Cc1-nDPEmBb%vKu6J}FQz3U}T{Z=mS{amMd-7}Rb2L_rGu~G+*0`ZQP z#!i$}%G8*9t*v7!>V`FXXgf7bM$F0KaBx_aBDa|Ke0x9mSW2p=Y-dx z0Q5*q#B?R|r85nM|I(Z96!-r1K2N#xx2n}8B~;Yx4?;-!6*oAGS)}9{qnZeAg7oCs nQ%Vv9oF +#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; }