Rev 6795 | Rev 7738 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6795 | Rev 6803 | ||
---|---|---|---|
Line 4... | Line 4... | ||
4 | 4 | ||
5 | #ifndef INCLUDE_KOLIBRI_H |
5 | #ifndef INCLUDE_KOLIBRI_H |
6 | #include "../lib/kolibri.h" |
6 | #include "../lib/kolibri.h" |
Line 7... | Line 7... | ||
7 | #endif |
7 | #endif |
Line 8... | Line 8... | ||
8 | 8 | ||
9 | unsigned buf_data; |
9 | dword buf_data; |
10 | - | ||
Line 11... | Line 10... | ||
11 | 10 | ||
12 | struct DrawBufer { |
11 | |
13 | unsigned bufx, bufy, bufw, bufh; |
12 | struct DrawBufer { |
14 | byte zoom; |
- | |
15 | 13 | dword bufx, bufy, bufw, bufh; |
|
16 | bool Init(); |
14 | |
17 | void Show(); |
15 | bool Init(); |
18 | void Fill(); |
16 | void Show(); |
19 | void Skew(); |
17 | void Fill(); |
Line 20... | Line 18... | ||
20 | void DrawBar(); |
18 | void DrawBar(); |
21 | void PutPixel(); |
19 | void PutPixel(); |
22 | void AlignCenter(); |
20 | void AlignCenter(); |
Line 23... | Line 21... | ||
23 | void AlignRight(); |
21 | void AlignRight(); |
24 | }; |
22 | }; |
Line 25... | Line 23... | ||
25 | 23 | ||
26 | char draw_buf_not_enaught_ram[] = |
24 | char draw_buf_not_enaught_ram[] = |
27 | "'DrawBufer needs more memory than currenly available. |
25 | "'DrawBufer needs more memory than currenly available. |
28 | Application could be unstable. |
26 | Application could be unstable. |
29 | - | ||
30 | Requested size: %i Kb |
27 | |
31 | Free RAM: %i Kb' -E"; |
28 | Requested size: %i Mb |
32 | 29 | Free RAM: %i Mb' -E"; |
|
33 | bool DrawBufer::Init(int i_bufx, i_bufy, i_bufw, i_bufh) |
30 | |
34 | { |
31 | bool DrawBufer::Init(dword i_bufx, i_bufy, i_bufw, i_bufh) |
35 | dword alloc_size, free_ram_size; |
32 | { |
36 | char error_str[256]; |
33 | dword alloc_size, free_ram_size; |
37 | if (!zoom) zoom = 1; |
34 | char error_str[256]; |
38 | bufx = i_bufx; |
35 | bufx = i_bufx; |
39 | bufy = i_bufy; |
36 | bufy = i_bufy; |
40 | bufw = i_bufw * zoom; |
37 | bufw = i_bufw; |
41 | bufh = i_bufh * zoom; |
38 | bufh = i_bufh; |
42 | free(buf_data); |
39 | free(buf_data); |
43 | free_ram_size = GetFreeRAM() * 1024; |
40 | free_ram_size = GetFreeRAM() * 1024; |
44 | alloc_size = bufw * bufh * 4 + 8; |
41 | alloc_size = bufw * bufh * 4 + 8; |
45 | if (alloc_size >= free_ram_size) { |
42 | if (alloc_size >= free_ram_size) { |
46 | sprintf(#error_str, #draw_buf_not_enaught_ram, alloc_size/1024, free_ram_size/1024); |
43 | sprintf(#error_str, #draw_buf_not_enaught_ram, alloc_size/1048576, free_ram_size/1048576); |
47 | notify(#error_str); |
44 | notify(#error_str); |
Line 48... | Line 45... | ||
48 | } |
45 | } |
49 | buf_data = malloc(alloc_size); |
46 | buf_data = malloc(alloc_size); |
50 | //debugval("buf_data",buf_data); |
47 | //debugval("buf_data",buf_data); |
51 | if (!buf_data) return false; |
48 | if (!buf_data) return false; |
52 | ESDWORD[buf_data] = bufw; |
49 | ESDWORD[buf_data] = bufw; |
53 | ESDWORD[buf_data+4] = bufh; |
50 | ESDWORD[buf_data+4] = bufh; |
Line 54... | Line 51... | ||
54 | return true; |
51 | return true; |
55 | } |
52 | } |
56 | 53 | ||
57 | void DrawBufer::Fill(unsigned fill_color) |
54 | void DrawBufer::Fill(dword fill_color) |
58 | { |
55 | { |
59 | unsigned i; |
56 | dword i; |
- | 57 | dword max_i = bufw * bufh * 4 + buf_data + 8; |
|
60 | unsigned max_i = bufw * bufh * 4 + buf_data + 8; |
58 | for (i=buf_data+8; i |
61 | for (i=buf_data+8; i |
59 | } |
62 | } |
- | |
63 | - | ||
64 | void DrawBufer::DrawBar(unsigned x, y, w, h, color) |
- | |
65 | { |
- | |
66 | int i, j; |
- | |
67 | for (j=0; j |
60 | |
Line 68... | Line -... | ||
68 | { |
- | |
69 | for (i = y+j*bufw+x<<2+8+buf_data; i |
61 | void DrawBufer::DrawBar(dword x, y, w, h, color) |
70 | } |
62 | { |
71 | } |
- | |
72 | - | ||
73 | void DrawBufer::PutPixel(unsigned x, y, color) |
- | |
74 | { |
63 | dword i, j; |
75 | int pos = y*bufw+x*4+8+buf_data; |
64 | for (j=0; j |
76 | ESDWORD[pos] = color; |
- | |
77 | } |
65 | { |
Line 78... | Line 66... | ||
78 | 66 | for (i = y+j*bufw+x<<2+8+buf_data; i |
|
79 | char shift[]={8,8,4,4}; |
67 | ESDWORD[i] = color; |
80 | void DrawBufer::Skew(unsigned x, y, w, h) |
68 | } |
81 | { |
69 | } |
82 | int i, j; |
70 | } |
83 | for (j=0; j<=3; j++) |
71 | |
84 | { |
72 | void DrawBufer::PutPixel(dword x, y, color) |
85 | for (i = y+j*bufw+x+w+h*4; i>y+j*bufw+x+h-12*4 ; i-=4) |
73 | { |
86 | ESDWORD[buf_data+i+8] = ESDWORD[-shift[j]+buf_data+i+8]; |
74 | dword pos = y*bufw+x*4+8+buf_data; |
87 | } |
75 | ESDWORD[pos] = color; |
88 | } |
76 | } |
89 | 77 | ||
Line 90... | Line 78... | ||
90 | void DrawBufer::AlignRight(unsigned x,y,w,h, content_width) |
78 | void DrawBufer::AlignRight(dword x,y,w,h, content_width) |
91 | { |
79 | { |
92 | int i, j, l; |
80 | dword i, j, l; |
93 | int content_left = w - content_width / 2; |
81 | dword content_left = w - content_width / 2; |
94 | for (j=0; j |
82 | for (j=0; j |
95 | { |
83 | { |
96 | for (i=j*w+w-x*4, l=j*w+content_width+x*4; (i>=j*w+content_left*4) && (l>=j*w*4); i-=4, l-=4) |
84 | for (i=j*w+w-x*4, l=j*w+content_width+x*4; (i>=j*w+content_left*4) && (l>=j*w*4); i-=4, l-=4) |
97 | { |
85 | { |
98 | ESDWORD[buf_data+8+i] >< ESDWORD[buf_data+8+l]; |
86 | ESDWORD[buf_data+8+i] >< ESDWORD[buf_data+8+l]; |
99 | } |
87 | } |
100 | } |
88 | } |
101 | } |
89 | } |
Line 102... | Line 90... | ||
102 | 90 | ||
103 | void DrawBufer::AlignCenter(unsigned x,y,w,h, content_width) |
91 | void DrawBufer::AlignCenter(dword x,y,w,h, content_width) |
104 | { |
92 | { |
105 | int i, j, l; |
93 | dword i, j, l; |
106 | int content_left = w - content_width / 2; |
94 | dword content_left = w - content_width / 2; |
Line 107... | Line 95... | ||
107 | for (j=0; j |
95 | for (j=0; j |
108 | { |
96 | { |
109 | for (i=j*w+content_width+content_left*4, l=j*w+content_width+x*4; (i>=j*w+content_left*4) && (l>=j*w*4); i-=4, l-=4) |
97 | for (i=j*w+content_width+content_left*4, l=j*w+content_width+x*4; (i>=j*w+content_left*4) && (l>=j*w*4); i-=4, l-=4) |
110 | { |
98 | { |