forked from KolibriOS/kolibrios
buf2d examples clean code
git-svn-id: svn://kolibrios.org@9675 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
2edd1b82f9
commit
fdc6bbf450
@ -82,6 +82,18 @@ namespace Kolibri // All kolibri functions, types and data are nested in the (
|
||||
else return 0;
|
||||
}
|
||||
|
||||
unsigned long int FileCreate(FileInfoBlock* file_data, void *mem, int size)
|
||||
{
|
||||
file_data->Function = 2; //SSF_CREATE_FILE
|
||||
file_data->Position = 0;
|
||||
file_data->Flags = 0;
|
||||
file_data->Count = size;
|
||||
file_data->Buffer = (char*)mem;
|
||||
|
||||
if(!_FileAccess(file_data)) return file_data->Function;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
// Inline functions.
|
||||
|
||||
inline unsigned long int FileGetLength(FileInfoBlock* file_data)
|
||||
|
90
programs/bcc32/include/l_buf2d.h
Normal file
90
programs/bcc32/include/l_buf2d.h
Normal file
@ -0,0 +1,90 @@
|
||||
#ifndef __L_BUF2D_H_INCLUDED_
|
||||
#define __L_BUF2D_H_INCLUDED_
|
||||
//
|
||||
// buf2d.obj
|
||||
//
|
||||
|
||||
struct buf_2d_header
|
||||
{
|
||||
void* img_data;
|
||||
short int left, top;
|
||||
long size_x, size_y;
|
||||
unsigned long color; //color
|
||||
unsigned char bit_pp; //bit in pixel
|
||||
};
|
||||
|
||||
const long BUF2D_OPT_CROP_TOP = 1;
|
||||
const long BUF2D_OPT_CROP_LEFT = 2;
|
||||
const long BUF2D_OPT_CROP_BOTTOM = 4;
|
||||
const long BUF2D_OPT_CROP_RIGHT = 8;
|
||||
const long BUF2D_BIT_OPT_CROP_TOP = 0;
|
||||
const long BUF2D_BIT_OPT_CROP_LEFT = 1;
|
||||
const long BUF2D_BIT_OPT_CROP_BOTTOM = 2;
|
||||
const long BUF2D_BIT_OPT_CROP_RIGHT = 3;
|
||||
|
||||
//
|
||||
// buf2d - import table
|
||||
//
|
||||
void (__stdcall* import_buf2d)() = (void (__stdcall*)())&"lib_init";
|
||||
void (__stdcall* buf2d_create)(buf_2d_header* buf) = (void (__stdcall*)(buf_2d_header*))&"buf2d_create";
|
||||
void (__stdcall* buf2d_create_f_img)(buf_2d_header* buf, void* img_data) = (void (__stdcall*)(buf_2d_header*, void*))&"buf2d_create_f_img";
|
||||
void (__stdcall* buf2d_clear)(buf_2d_header* buf, long color) = (void (__stdcall*)(buf_2d_header*, long))&"buf2d_clear";
|
||||
void (__stdcall* buf2d_draw)(buf_2d_header* buf) = (void (__stdcall*)(buf_2d_header*))&"buf2d_draw";
|
||||
void (__stdcall* buf2d_delete)(buf_2d_header* buf) = (void (__stdcall*)(buf_2d_header*))&"buf2d_delete";
|
||||
void (__stdcall* buf2d_resize)(buf_2d_header* buf, long n_w, long n_h, long opt) = (void (__stdcall*)(buf_2d_header*, long, long, long))&"buf2d_resize";
|
||||
void (__stdcall* buf2d_rotate)(buf_2d_header* buf, long angle) = (void (__stdcall*)(buf_2d_header*, long))&"buf2d_rotate";
|
||||
void (__stdcall* buf2d_line)(buf_2d_header* buf, long x1, long y1, long x2, long y2, long color) = (void (__stdcall*)(buf_2d_header*, long, long, long, long, long))&"buf2d_line";
|
||||
void (__stdcall* buf2d_line_sm)(buf_2d_header* buf, long x1, long y1, long x2, long y2, long color) = (void (__stdcall*)(buf_2d_header*, long, long, long, long, long))&"buf2d_line_sm";
|
||||
void (__stdcall* buf2d_rect_by_size)(buf_2d_header* buf, long x1, long y1, long w, long h, long color) = (void (__stdcall*)(buf_2d_header*, long, long, long, long, long))&"buf2d_rect_by_size";
|
||||
void (__stdcall* buf2d_filled_rect_by_size)(buf_2d_header* buf, long x1, long y1, long w, long h, long color) = (void (__stdcall*)(buf_2d_header*, long, long, long, long, long))&"buf2d_filled_rect_by_size";
|
||||
void (__stdcall* buf2d_circle)(buf_2d_header* buf, long x, long y, long r, long color) = (void (__stdcall*)(buf_2d_header*, long, long, long, long))&"buf2d_circle";
|
||||
void (__stdcall* buf2d_img_hdiv2)(buf_2d_header* buf) = (void (__stdcall*)(buf_2d_header*))&"buf2d_img_hdiv2";
|
||||
void (__stdcall* buf2d_img_wdiv2)(buf_2d_header* buf) = (void (__stdcall*)(buf_2d_header*))&"buf2d_img_wdiv2";
|
||||
void (__stdcall* buf2d_conv_24_to_8)(buf_2d_header* buf24, long opt_rgb) = (void (__stdcall*)(buf_2d_header*, long))&"buf2d_conv_24_to_8";
|
||||
void (__stdcall* buf2d_conv_24_to_32)(buf_2d_header* buf24, buf_2d_header* buf8) = (void (__stdcall*)(buf_2d_header*, buf_2d_header*))&"buf2d_conv_24_to_32";
|
||||
void (__stdcall* buf2d_bit_blt)(buf_2d_header* buf0, long x, long y, buf_2d_header* buf1) = (void (__stdcall*)(buf_2d_header*, long, long, buf_2d_header*))&"buf2d_bit_blt";
|
||||
void (__stdcall* buf2d_bit_blt_transp)(buf_2d_header* buf0, long x, long y, buf_2d_header* buf32) = (void (__stdcall*)(buf_2d_header*, long, long, buf_2d_header*))&"buf2d_bit_blt_transp";
|
||||
void (__stdcall* buf2d_bit_blt_alpha)(buf_2d_header* buf0, long x, long y, buf_2d_header* buf8) = (void (__stdcall*)(buf_2d_header*, long, long, buf_2d_header*))&"buf2d_bit_blt_alpha";
|
||||
void (__stdcall* buf2d_curve_bezier)(buf_2d_header* buf, long p1, long p2, long p3, long color) = (void (__stdcall*)(buf_2d_header*, long, long, long, long))&"buf2d_curve_bezier";
|
||||
void (__stdcall* buf2d_convert_text_matrix)(buf_2d_header* buf) = (void (__stdcall*)(buf_2d_header*))&"buf2d_convert_text_matrix";
|
||||
void (__stdcall* buf2d_draw_text)(buf_2d_header* buf, buf_2d_header* buf_txt, char* txt, long x, long y, long color) = (void (__stdcall*)(buf_2d_header*, buf_2d_header*, char*, long, long, long))&"buf2d_draw_text";
|
||||
void (__stdcall* buf2d_crop_color)(buf_2d_header* buf, long color, long opt) = (void (__stdcall*)(buf_2d_header*, long, long))&"buf2d_crop_color";
|
||||
void (__stdcall* buf2d_offset_h)(buf_2d_header* buf, long dy) = (void (__stdcall*)(buf_2d_header*, long))&"buf2d_offset_h";
|
||||
void (__stdcall* buf2d_flood_fill)(buf_2d_header* buf, long x, long y, long opt, long color1, long color2) = (void (__stdcall*)(buf_2d_header*, long, long, long, long, long))&"buf2d_flood_fill";
|
||||
void (__stdcall* buf2d_set_pixel)(buf_2d_header* buf, long x, long y, long color) = (void (__stdcall*)(buf_2d_header*, long, long, long))&"buf2d_set_pixel";
|
||||
long (__stdcall* buf2d_get_pixel)(buf_2d_header* buf, long x, long y) = (long (__stdcall*)(buf_2d_header*, long, long))&"buf2d_get_pixel";
|
||||
void (__stdcall* buf2d_flip_h)(buf_2d_header* buf) = (void (__stdcall*)(buf_2d_header*))&"buf2d_flip_h";
|
||||
void (__stdcall* buf2d_flip_v)(buf_2d_header* buf) = (void (__stdcall*)(buf_2d_header*))&"buf2d_flip_v";
|
||||
void (__stdcall* buf2d_filter_dither)(buf_2d_header* buf, long opt) = (void (__stdcall*)(buf_2d_header*, long))&"buf2d_filter_dither";
|
||||
|
||||
/*
|
||||
void (__stdcall* buf2d_vox_brush_create)(buf_2d_header* buf, long* opt) = (void (__stdcall*)(buf_2d_header*, long*))&"buf2d_vox_brush_create";
|
||||
"buf2d_vox_brush_delete
|
||||
"buf2d_vox_obj_get_img_w_3g
|
||||
"buf2d_vox_obj_get_img_h_3g
|
||||
"buf2d_vox_obj_draw_1g
|
||||
"buf2d_vox_obj_draw_3g
|
||||
"buf2d_vox_obj_draw_3g_scaled
|
||||
"buf2d_vox_obj_draw_pl
|
||||
"buf2d_vox_obj_draw_pl_scaled
|
||||
"buf2d_vox_obj_draw_3g_shadows
|
||||
*/
|
||||
asm{
|
||||
dd 0,0
|
||||
}
|
||||
|
||||
|
||||
bool buf2d_create_ex(buf_2d_header* buf, long l, long t, long w, long h, unsigned long c=0xffffff, unsigned char bit_pp=24)
|
||||
{
|
||||
buf->left=l;
|
||||
buf->top=t;
|
||||
buf->size_x=w;
|
||||
buf->size_y=h;
|
||||
buf->color=c;
|
||||
if(bit_pp!=8 && bit_pp!=24 && bit_pp!=32) return false;
|
||||
buf->bit_pp=bit_pp;
|
||||
buf2d_create(buf);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
@ -17,7 +17,7 @@ start:
|
||||
cmp eax,-1
|
||||
jz button.exit
|
||||
|
||||
mcall 40,0x27
|
||||
mcall SF_SET_EVENTS_MASK, 0x27
|
||||
stdcall [buf2d_create], buf_0 ;ᮧ¤ ¥¬ ¡ãä¥à
|
||||
stdcall [buf2d_line], buf_0, 110, 20, 125, 90, 0xffff00 ;à¨á㥬 «¨¨î
|
||||
stdcall [buf2d_line], buf_0, 60, 120, 110, 20, 0xd000 ;à¨á㥬 «¨¨î
|
||||
@ -31,7 +31,7 @@ red_win:
|
||||
|
||||
align 4
|
||||
still:
|
||||
mcall 10
|
||||
mcall SF_WAIT_EVENT
|
||||
cmp al,1 ;¨§¬¥¨«®áì ¯®«®¦¥¨¥ ®ª
|
||||
jz red_win
|
||||
cmp al,2
|
||||
@ -43,21 +43,21 @@ still:
|
||||
align 4
|
||||
draw_window:
|
||||
pushad
|
||||
mcall 12,1
|
||||
mcall SF_REDRAW, SSF_BEGIN_DRAW
|
||||
|
||||
;mov edx,0x32000000
|
||||
mov edx,0x33000000
|
||||
mcall 0,(50 shl 16)+330,(30 shl 16)+275,,,caption
|
||||
mcall SF_CREATE_WINDOW, (50 shl 16)+330,(30 shl 16)+275,,,caption
|
||||
|
||||
stdcall [buf2d_draw], buf_0
|
||||
|
||||
mcall 12,2
|
||||
mcall SF_REDRAW, SSF_END_DRAW
|
||||
popad
|
||||
ret
|
||||
|
||||
align 4
|
||||
key:
|
||||
mcall 2
|
||||
mcall SF_GET_KEY
|
||||
|
||||
cmp ah,27 ;Esc
|
||||
je button.exit
|
||||
@ -66,12 +66,12 @@ key:
|
||||
|
||||
align 4
|
||||
button:
|
||||
mcall 17 ;¯®«ãç¨âì ª®¤ ¦ ⮩ ª®¯ª¨
|
||||
mcall SF_GET_BUTTON
|
||||
cmp ah,1
|
||||
jne still
|
||||
.exit:
|
||||
stdcall [buf2d_delete],buf_0 ;㤠«ï¥¬ ¡ãä¥à
|
||||
mcall -1 ;¢ë室 ¨§ ¯à®£à ¬¬ë
|
||||
mcall SF_TERMINATE_PROCESS
|
||||
|
||||
caption db 'Test buf2d library, [Esc] - exit',0
|
||||
|
||||
@ -134,9 +134,6 @@ lib0_name db 'buf2d.obj',0
|
||||
i_end: ;ª®¥æ ª®¤
|
||||
rb 1024
|
||||
stacktop:
|
||||
cur_dir_path:
|
||||
rb 4096
|
||||
library_path:
|
||||
rb 4096
|
||||
cur_dir_path rb 4096
|
||||
library_path rb 4096
|
||||
mem:
|
||||
|
||||
|
@ -17,7 +17,7 @@ start:
|
||||
cmp eax,-1
|
||||
jz button.exit
|
||||
|
||||
mcall 40,0x27
|
||||
mcall SF_SET_EVENTS_MASK, 0x27
|
||||
stdcall [buf2d_create], buf_0 ;ᮧ¤ ¥¬ ¡ãä¥à
|
||||
stdcall [buf2d_line], buf_0, 110, 20, 125, 90, 0xffff00 ;à¨á㥬 «¨¨î
|
||||
stdcall [buf2d_line], buf_0, 60, 120, 110, 20, 0xd000 ;à¨á㥬 «¨¨î
|
||||
@ -31,10 +31,8 @@ start:
|
||||
|
||||
;¥á«¨ ¡ë ¨á¯®«ì§®¢ « áì äãªæ¨ï buf2d_create, ⮣¤ ¡¨âë ¨§®¡à ¦¥¨ï
|
||||
;¯à¨è«®áì ¡ë ª®¯¨à®¢ âì á«¥¤ã騬¨ áâப ¬¨:
|
||||
;xor ecx,ecx
|
||||
;xor eax,eax
|
||||
;mov cx,word[buf_1.size_x]
|
||||
;mov ax,word[buf_1.size_y]
|
||||
;movzx ecx,word[buf_1.size_x]
|
||||
;movzx eax,word[buf_1.size_y]
|
||||
;imul ecx,eax
|
||||
;imul ecx,3 ;ecx - ª®««¨ç¥á⢮ ¡ ©â ¢ ¬ «¥ìª®¬ ¡ãä¥à¥
|
||||
;stdcall mem_copy, dword[buf_0],dword[buf_1],ecx
|
||||
@ -52,7 +50,7 @@ red_win:
|
||||
|
||||
align 4
|
||||
still:
|
||||
mcall 10
|
||||
mcall SF_WAIT_EVENT
|
||||
cmp al,1 ;¨§¬. ¯®«®¦¥¨¥ ®ª
|
||||
jz red_win
|
||||
cmp al,2
|
||||
@ -64,21 +62,21 @@ still:
|
||||
align 4
|
||||
draw_window:
|
||||
pushad
|
||||
mcall 12,1
|
||||
mcall SF_REDRAW, SSF_BEGIN_DRAW
|
||||
|
||||
;mov edx,0x32000000
|
||||
mov edx,0x33000000
|
||||
mcall 0,(50 shl 16)+330,(30 shl 16)+275,,,caption
|
||||
mcall SF_CREATE_WINDOW, (50 shl 16)+330,(30 shl 16)+275,,,caption
|
||||
|
||||
stdcall [buf2d_draw], buf_0
|
||||
|
||||
mcall 12,2
|
||||
mcall SF_REDRAW, SSF_END_DRAW
|
||||
popad
|
||||
ret
|
||||
|
||||
align 4
|
||||
key:
|
||||
mcall 2
|
||||
mcall SF_GET_KEY
|
||||
|
||||
cmp ah,27 ;Esc
|
||||
je button.exit
|
||||
@ -87,13 +85,13 @@ key:
|
||||
|
||||
align 4
|
||||
button:
|
||||
mcall 17 ;¯®«ãç¨âì ª®¤ ¦ ⮩ ª®¯ª¨
|
||||
mcall SF_GET_BUTTON
|
||||
cmp ah,1
|
||||
jne still
|
||||
.exit:
|
||||
stdcall [buf2d_delete],buf_0 ;㤠«ï¥¬ ¡ãä¥à
|
||||
stdcall [buf2d_delete],buf_1 ;㤠«ï¥¬ ¡ãä¥à
|
||||
mcall -1 ;¢ë室 ¨§ ¯à®£à ¬¬ë
|
||||
mcall SF_TERMINATE_PROCESS
|
||||
|
||||
caption db 'Test buf2d library, [Esc] - exit',0
|
||||
|
||||
@ -166,9 +164,6 @@ lib0_name db 'buf2d.obj',0
|
||||
i_end: ;ª®¥æ ª®¤
|
||||
rb 1024
|
||||
stacktop:
|
||||
cur_dir_path:
|
||||
rb 4096
|
||||
library_path:
|
||||
rb 4096
|
||||
cur_dir_path rb 4096
|
||||
library_path rb 4096
|
||||
mem:
|
||||
|
||||
|
@ -20,8 +20,8 @@ start:
|
||||
cmp eax,-1
|
||||
jz button.exit
|
||||
|
||||
mcall 40,0x27
|
||||
mcall 48,3,sc,sizeof.system_colors ;получаем системные цвета
|
||||
mcall SF_SET_EVENTS_MASK, 0x27
|
||||
mcall SF_STYLE_SETTINGS, SSF_GET_COLORS,sc,sizeof.system_colors ;ïîëó÷àåì ñèñòåìíûå öâåòà
|
||||
stdcall [buf2d_create], buf_0 ;ñîçäàåì áóôåð
|
||||
|
||||
align 4
|
||||
@ -30,55 +30,55 @@ red_win:
|
||||
|
||||
align 4
|
||||
still:
|
||||
mcall 10
|
||||
cmp al,0x1 ;изм. положение окна
|
||||
mcall SF_WAIT_EVENT
|
||||
cmp al,1 ;èçì. ïîëîæåíèå îêíà
|
||||
jz red_win
|
||||
cmp al,0x2
|
||||
cmp al,2
|
||||
jz key
|
||||
cmp al,0x3
|
||||
cmp al,3
|
||||
jz button
|
||||
cmp al,0x6
|
||||
cmp al,6
|
||||
jz mouse
|
||||
jmp still
|
||||
|
||||
align 4
|
||||
draw_window:
|
||||
pushad
|
||||
mcall 12,1
|
||||
mcall SF_REDRAW, SSF_BEGIN_DRAW
|
||||
|
||||
mov edx,[sc.work]
|
||||
or edx,0x33000000
|
||||
mcall 0,(50 shl 16)+500,(30 shl 16)+370,,,caption
|
||||
mcall SF_CREATE_WINDOW, (50 shl 16)+500,(30 shl 16)+370,,,caption
|
||||
|
||||
stdcall [buf2d_draw], buf_0
|
||||
|
||||
mcall 12,2
|
||||
mcall SF_REDRAW, SSF_END_DRAW
|
||||
popad
|
||||
ret
|
||||
|
||||
align 4
|
||||
key:
|
||||
mcall 2
|
||||
mcall SF_GET_KEY
|
||||
; cmp ah,27 ;Esc
|
||||
; je button.exit
|
||||
jmp still
|
||||
|
||||
align 4
|
||||
button:
|
||||
mcall 17 ;получить код нажатой кнопки
|
||||
mcall SF_GET_BUTTON
|
||||
cmp ah,1
|
||||
jne still
|
||||
.exit:
|
||||
stdcall [buf2d_delete],buf_0 ;óäàëÿåì áóôåð
|
||||
mcall -1 ;выход из программы
|
||||
mcall SF_TERMINATE_PROCESS
|
||||
|
||||
align 4
|
||||
mouse:
|
||||
;îáðàáàòûâàåì îêíî ðåäàêòîðà
|
||||
mcall 37,2 ;get mouse buttons
|
||||
mcall SF_MOUSE_GET, SSF_BUTTON ;get mouse buttons
|
||||
cmp al,1
|
||||
jne @f
|
||||
mcall 37,1 ;get mouse coords
|
||||
mcall SF_MOUSE_GET, SSF_WINDOW_POSITION ;get mouse coords
|
||||
mov ebx,eax
|
||||
shr ebx,16 ;â eax êîîðäèíàòà ìèøè ïî îñè 'x'
|
||||
and eax,0xffff ;â eax êîîðäèíàòà ìèøè ïî îñè 'y'
|
||||
@ -173,9 +173,6 @@ lib0_name db 'buf2d.obj',0
|
||||
i_end: ;êîíåö êîäà
|
||||
rb 2*4096
|
||||
stacktop:
|
||||
cur_dir_path:
|
||||
rb 4096
|
||||
library_path:
|
||||
rb 4096
|
||||
cur_dir_path rb 4096
|
||||
library_path rb 4096
|
||||
mem:
|
||||
|
||||
|
@ -62,17 +62,17 @@ start:
|
||||
cmp eax,-1
|
||||
jz button.exit
|
||||
|
||||
mcall SF_SET_EVENTS_MASK,0x27
|
||||
mcall SF_SET_EVENTS_MASK, 0x27
|
||||
stdcall [buf2d_create], buf_0 ;ᮧ¤ ¥¬ ¡ãä¥à
|
||||
stdcall [buf2d_create], buf_z
|
||||
stdcall [buf2d_vox_brush_create], buf_vox, vox_6_7_z ;ᮧ¤ ¥¬ ¢®ªá¥«ìãî ª¨áâì
|
||||
|
||||
stdcall mem.Alloc,max_open_file_size
|
||||
mov dword[open_file_vox],eax
|
||||
mov [open_file_vox],eax
|
||||
|
||||
copy_path f_name,[32],file_name,0
|
||||
|
||||
mov eax,70 ;70-ï äãªæ¨ï à ¡®â á ä ©« ¬¨
|
||||
mov eax,SF_FILE
|
||||
mov [run_file_70.Function], 0
|
||||
mov [run_file_70.Position], 0
|
||||
mov [run_file_70.Flags], 0
|
||||
@ -113,14 +113,14 @@ still:
|
||||
align 4
|
||||
draw_window:
|
||||
pushad
|
||||
mcall SF_REDRAW,SSF_BEGIN_DRAW
|
||||
mcall SF_REDRAW, SSF_BEGIN_DRAW
|
||||
|
||||
mov edx,0x33000000
|
||||
mcall SF_CREATE_WINDOW,(50 shl 16)+410,(30 shl 16)+480,,,caption
|
||||
mcall SF_CREATE_WINDOW, (50 shl 16)+410,(30 shl 16)+480,,,caption
|
||||
|
||||
stdcall [buf2d_draw], buf_0
|
||||
|
||||
mcall SF_REDRAW,SSF_END_DRAW
|
||||
mcall SF_REDRAW, SSF_END_DRAW
|
||||
popad
|
||||
ret
|
||||
|
||||
@ -230,13 +230,11 @@ name_buf2d db 'buf2d.obj',0
|
||||
|
||||
align 16
|
||||
i_end: ;ª®¥æ ª®¤
|
||||
file_name:
|
||||
rb 4096
|
||||
cur_dir_path:
|
||||
rb 4096
|
||||
library_path:
|
||||
rb 4096
|
||||
file_name rb 4096
|
||||
cur_dir_path rb 4096
|
||||
library_path rb 4096
|
||||
rb 1024
|
||||
stacktop:
|
||||
mem:
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user