From 30ab10e50a9d2b288bd5ca1a6083ab1d6e7215e0 Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Sat, 20 Feb 2016 16:15:35 +0000 Subject: [PATCH] cmm: add rgb example git-svn-id: svn://kolibrios.org@6266 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/cmm/examples/Tupfile.lua | 1 + programs/cmm/examples/compile_en.bat | 19 ++-- programs/cmm/examples/rgb.c | 136 +++++++++++++++++++++++++++ programs/cmm/lib/patterns/rgb.h | 2 +- 4 files changed, 146 insertions(+), 12 deletions(-) create mode 100644 programs/cmm/examples/rgb.c diff --git a/programs/cmm/examples/Tupfile.lua b/programs/cmm/examples/Tupfile.lua index 3f28e56d65..dd9ff3d2d1 100644 --- a/programs/cmm/examples/Tupfile.lua +++ b/programs/cmm/examples/Tupfile.lua @@ -6,3 +6,4 @@ end tup.rule("window.c", "c-- /D=AUTOBUILD /D=$(C_LANG) %f" .. tup.getconfig("KPACK_CMD"), "window.com") tup.rule("collections.c", "c-- /D=AUTOBUILD /D=$(C_LANG) %f" .. tup.getconfig("KPACK_CMD"), "collections.com") tup.rule("menu.c", "c-- /D=AUTOBUILD /D=$(C_LANG) %f" .. tup.getconfig("KPACK_CMD"), "menu.com") +tup.rule("rgb.c", "c-- /D=AUTOBUILD /D=$(C_LANG) %f" .. tup.getconfig("KPACK_CMD"), "rgb.com") diff --git a/programs/cmm/examples/compile_en.bat b/programs/cmm/examples/compile_en.bat index 2f1a4bd111..cba7f6bc96 100644 --- a/programs/cmm/examples/compile_en.bat +++ b/programs/cmm/examples/compile_en.bat @@ -1,17 +1,14 @@ -c-- window.c -c-- collections.c -c-- menu.c +@del *.kex -@echo off -@del _window -@del _collections -@del _menu +@c-- window.c +@c-- collections.c +@c-- menu.c +@c-- rgb.c -@rename window.com _window -@rename collections.com _collections -@rename menu.com _menu +@rename *.com *.kex +@mkdir bin +@move *.kex bin\ @del warning.txt -@echo on @pause \ No newline at end of file diff --git a/programs/cmm/examples/rgb.c b/programs/cmm/examples/rgb.c new file mode 100644 index 0000000000..8f2179a4b4 --- /dev/null +++ b/programs/cmm/examples/rgb.c @@ -0,0 +1,136 @@ +//Generated with Lev's C-- pack for HiAsm, www.hiasm.com + +#define MEMSIZE 4096*400 + +#include "../lib/kolibri.h" +#include "../lib/gui.h" + +/*======================================================== += = += DATA = += = +========================================================*/ + +_rgb image[256*256]; + +#define fw 256+167 +#define fh 290 + +enum { + DRAW1_BTN=10, + DRAW2_BTN, + SETBG_BTN +}; + +/*======================================================== += = += MAIN CYCLE = += = +========================================================*/ + +void main() +byte id; +{ + loop() switch(WaitEvent()) + { + case evButton: + id=GetButtonID(); + if (id==1) ExitProcess(); + if (id==DRAW1_BTN) EventDraw1(); + if (id==DRAW2_BTN) EventDraw2(); + if (id==SETBG_BTN) EventSetBackground(#image,256,256); + break; + case evKey: + if (GetKey()==27) ExitProcess(); + break; + case evReDraw: + system.color.get(); + DefineAndDrawWindow(screen.width-fw/2,screen.height-fh/2,fw,fh+skin_height,0x33,0xE0DFE3,"Rainbow (rgb test)"); + _PutImage(0,0,256,256,#image); + DrawCaptButton(280,20, 110,30,DRAW1_BTN,system.color.work_button,system.color.work_button_text,"Draw 1"); + DrawCaptButton(280,60, 110,30,DRAW2_BTN,system.color.work_button,system.color.work_button_text,"Draw 2"); + DrawCaptButton(280,100,110,30,SETBG_BTN,system.color.work_button,system.color.work_button_text,"Background"); + } +} + +/*======================================================== += = += Background system functions = += = +========================================================*/ + +inline fastcall void BG_PaintMode( ECX) +{ + $mov eax, 15 + $mov ebx, 4 + $int 0x40 +} + +inline fastcall void BG_SetImageSize( ECX, EDX) +{ + $mov eax, 15 + $mov ebx, 1 + $int 0x40 +} + +inline fastcall void BG_PutPixels( ECX, EDX, ESI) +{ + $mov eax, 15 + $mov ebx, 5 + $int 0x40 +} + +inline fastcall void BG_Redraw() +{ + $mov eax, 15 + $mov ebx, 3 + $int 0x40 +} + +/*======================================================== += = += EVENTS = += = +========================================================*/ + +void EventDraw1() +{ +int i1; +int i4; +int pos; + for(i4 = 0; i4 < 256; i4++) { + for(i1 = 0; i1 < 256; i1++) { + pos = i1 * 256 + i4; + image[pos].b = i1; + image[pos].r = 0; + image[pos].g = 0; + } + } + _PutImage(0,0,256,256,#image); +} + +void EventDraw2() +{ +int i1; +int i4; +int t2; + for(i4 = 0; i4 < 256; i4++) { + for(i1 = 0; i1 < 256; i1++) { + t2 = i1 * 256 + i4; + image[t2].r = i4; + image[t2].g = i1; + image[t2].b = 0; + } + } + _PutImage(0,0,256,256,#image); +} + +void EventSetBackground(dword img_pointer, w,h) +{ + BG_PaintMode(2); //1-tile,2-stratch + BG_SetImageSize(w,h); + BG_PutPixels(img_pointer, 0, 3*w*h); + BG_Redraw(); +} + +stop: diff --git a/programs/cmm/lib/patterns/rgb.h b/programs/cmm/lib/patterns/rgb.h index 69dc64f65d..957b590993 100644 --- a/programs/cmm/lib/patterns/rgb.h +++ b/programs/cmm/lib/patterns/rgb.h @@ -4,7 +4,7 @@ struct _rgb { - byte r,g,b; + byte b,g,r; void DwordToRgb(); dword RgbToDword(); } rgb;