Subversion Repositories Kolibri OS

Rev

Rev 6728 | Rev 6803 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5598 pavelyakov 1
#ifndef INCLUDE_DRAW_BUF_H
2
#define INCLUDE_DRAW_BUF_H
5676 pavelyakov 3
#print "[include ]\n"
4486 leency 4
 
5598 pavelyakov 5
#ifndef INCLUDE_KOLIBRI_H
6
#include "../lib/kolibri.h"
7
#endif
8
 
6672 leency 9
unsigned buf_data;
4475 leency 10
 
5519 leency 11
 
4475 leency 12
struct DrawBufer {
6672 leency 13
	unsigned bufx, bufy, bufw, bufh;
5678 leency 14
	byte zoom;
4475 leency 15
 
6698 leency 16
	bool Init();
4666 leency 17
	void Show();
4475 leency 18
	void Fill();
19
	void Skew();
20
	void DrawBar();
4666 leency 21
	void PutPixel();
4475 leency 22
	void AlignCenter();
23
	void AlignRight();
24
};
25
 
6795 leency 26
char draw_buf_not_enaught_ram[] =
27
"'DrawBufer needs more memory than currenly available.
28
Application could be unstable.
29
 
30
Requested size: %i Kb
31
Free RAM: %i Kb' -E";
32
 
6698 leency 33
bool DrawBufer::Init(int i_bufx, i_bufy, i_bufw, i_bufh)
4475 leency 34
{
6724 leency 35
	dword alloc_size, free_ram_size;
36
	char error_str[256];
6672 leency 37
	if (!zoom) zoom = 1;
4475 leency 38
	bufx = i_bufx;
39
	bufy = i_bufy;
5678 leency 40
	bufw = i_bufw * zoom;
41
	bufh = i_bufh * zoom;
4475 leency 42
	free(buf_data);
6795 leency 43
	free_ram_size = GetFreeRAM() * 1024;
6724 leency 44
	alloc_size = bufw * bufh * 4 + 8;
45
	if (alloc_size >= free_ram_size) {
6795 leency 46
		sprintf(#error_str, #draw_buf_not_enaught_ram, alloc_size/1024, free_ram_size/1024);
6724 leency 47
		notify(#error_str);
48
	}
49
	buf_data = malloc(alloc_size);
6698 leency 50
	//debugval("buf_data",buf_data);
51
	if (!buf_data) return false;
4475 leency 52
	ESDWORD[buf_data] = bufw;
4666 leency 53
	ESDWORD[buf_data+4] = bufh;
6698 leency 54
	return true;
4666 leency 55
}
56
 
6672 leency 57
void DrawBufer::Fill(unsigned fill_color)
4475 leency 58
{
6672 leency 59
	unsigned i;
60
	unsigned max_i = bufw * bufh * 4 + buf_data + 8;
4486 leency 61
	for (i=buf_data+8; i
4475 leency 62
}
63
 
6672 leency 64
void DrawBufer::DrawBar(unsigned x, y, w, h, color)
4475 leency 65
{
66
	int i, j;
67
	for (j=0; j
68
	{
6795 leency 69
		for (i = y+j*bufw+x<<2+8+buf_data; i
4475 leency 70
	}
71
}
72
 
6672 leency 73
void DrawBufer::PutPixel(unsigned x, y, color)
4666 leency 74
{
75
	int pos = y*bufw+x*4+8+buf_data;
76
	ESDWORD[pos] = color;
77
}
78
 
4475 leency 79
char shift[]={8,8,4,4};
6672 leency 80
void DrawBufer::Skew(unsigned x, y, w, h)
4475 leency 81
{
82
	int i, j;
83
	for (j=0; j<=3; j++)
84
	{
85
		for (i = y+j*bufw+x+w+h*4; i>y+j*bufw+x+h-12*4 ; i-=4)
86
								ESDWORD[buf_data+i+8] = ESDWORD[-shift[j]+buf_data+i+8];
87
	}
88
}
89
 
6672 leency 90
void DrawBufer::AlignRight(unsigned x,y,w,h, content_width)
4475 leency 91
{
92
	int i, j, l;
93
	int content_left = w - content_width / 2;
94
	for (j=0; j
95
	{
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)
97
		{
98
			ESDWORD[buf_data+8+i] >< ESDWORD[buf_data+8+l];
99
		}
100
	}
101
}
102
 
6672 leency 103
void DrawBufer::AlignCenter(unsigned x,y,w,h, content_width)
4475 leency 104
{
105
	int i, j, l;
106
	int content_left = w - content_width / 2;
107
	for (j=0; j
108
	{
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)
110
		{
111
			ESDWORD[buf_data+8+i] >< ESDWORD[buf_data+8+l];
112
		}
113
	}
114
}
115
 
5678 leency 116
/*
5519 leency 117
void DrawBufer::Zoom2x()
118
{
119
	int i, s;
6672 leency 120
	unsigned point_x, max_i, zline_w, s_inc;
4475 leency 121
 
5519 leency 122
	point_x = 0;
123
	max_i = bufw * bufh * 4 + buf_data+8;
5678 leency 124
	s_inc = zoom * 4;
5519 leency 125
	zline_w = zbufw * 4;
126
 
127
	for (i=buf_data+8, s=zbuf_data+8; i
128
		ESDWORD[s] = ESDWORD[i];
129
		ESDWORD[s+4] = ESDWORD[i];
130
		ESDWORD[s+zline_w] = ESDWORD[i];
131
		ESDWORD[s+zline_w+4] = ESDWORD[i];
5678 leency 132
		if (zoom==3)
5519 leency 133
		{
134
			ESDWORD[s+8] = ESDWORD[i];
135
			ESDWORD[zline_w+s+8] = ESDWORD[i];
136
			ESDWORD[zline_w*2+s] = ESDWORD[i];
137
			ESDWORD[zline_w*2+s+4] = ESDWORD[i];
138
			ESDWORD[zline_w*2+s+8] = ESDWORD[i];
139
		}
140
 
141
		point_x++;
142
		if (point_x >= bufw)
143
		{
5678 leency 144
			s += zoom - 1 * zline_w;
5519 leency 145
			point_x = 0;
146
		}
147
	}
148
}
5678 leency 149
*/
5519 leency 150
 
151
 
152
void DrawBufer::Show()
153
{
5678 leency 154
	PutPaletteImage(buf_data+8, bufw, bufh, bufx, bufy, 32, 0);
5519 leency 155
}
5598 pavelyakov 156
 
157
#endif