WebView 1.82: dynamic realloc finally, working anchors again!
git-svn-id: svn://kolibrios.org@7738 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
@@ -11,14 +11,17 @@ dword buf_data;
|
||||
|
||||
struct DrawBufer {
|
||||
dword bufx, bufy, bufw, bufh;
|
||||
dword fill_color;
|
||||
|
||||
bool Init();
|
||||
void Show();
|
||||
void Fill();
|
||||
void DrawBar();
|
||||
void WriteText();
|
||||
void PutPixel();
|
||||
void AlignCenter();
|
||||
void AlignRight();
|
||||
void IncreaseBufSize();
|
||||
};
|
||||
|
||||
char draw_buf_not_enaught_ram[] =
|
||||
@@ -30,20 +33,12 @@ Free RAM: %i Mb' -E";
|
||||
|
||||
bool DrawBufer::Init(dword i_bufx, i_bufy, i_bufw, i_bufh)
|
||||
{
|
||||
dword alloc_size, free_ram_size;
|
||||
char error_str[256];
|
||||
bufx = i_bufx;
|
||||
bufy = i_bufy;
|
||||
bufw = i_bufw;
|
||||
bufh = i_bufh;
|
||||
free(buf_data);
|
||||
free_ram_size = GetFreeRAM() * 1024;
|
||||
alloc_size = bufw * bufh * 4 + 8;
|
||||
if (alloc_size >= free_ram_size) {
|
||||
sprintf(#error_str, #draw_buf_not_enaught_ram, alloc_size/1048576, free_ram_size/1048576);
|
||||
notify(#error_str);
|
||||
}
|
||||
buf_data = malloc(alloc_size);
|
||||
buf_data = free(buf_data);
|
||||
IncreaseBufSize();
|
||||
//debugval("buf_data",buf_data);
|
||||
if (!buf_data) return false;
|
||||
ESDWORD[buf_data] = bufw;
|
||||
@@ -51,24 +46,36 @@ bool DrawBufer::Init(dword i_bufx, i_bufy, i_bufw, i_bufh)
|
||||
return true;
|
||||
}
|
||||
|
||||
void DrawBufer::Fill(dword fill_color)
|
||||
void DrawBufer::Fill(dword start_pointer, i_fill_color)
|
||||
{
|
||||
dword i;
|
||||
dword max_i = bufw * bufh * 4 + buf_data + 8;
|
||||
for (i=buf_data+8; i<max_i; i+=4) ESDWORD[i] = fill_color;
|
||||
fill_color = i_fill_color;
|
||||
for (i=buf_data+start_pointer+8; i<max_i; i+=4) ESDWORD[i] = fill_color;
|
||||
}
|
||||
|
||||
void DrawBufer::DrawBar(dword x, y, w, h, color)
|
||||
{
|
||||
dword i, j;
|
||||
for (j=0; j<h; j++)
|
||||
{
|
||||
if (y + h >= bufh) IncreaseBufSize();
|
||||
for (j=0; j<h; j++) {
|
||||
for (i = y+j*bufw+x<<2+8+buf_data; i<y+j*bufw+x+w<<2+8+buf_data; i+=4) {
|
||||
ESDWORD[i] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DrawBuf_WriteText(dword x, y, byte fontType, dword color, str_offset)
|
||||
{
|
||||
EDI = buf_data;
|
||||
WriteText(x, y, fontType, color, str_offset);
|
||||
}
|
||||
void DrawBufer::WriteText(dword x, y, byte fontType, dword color, str_offset)
|
||||
{
|
||||
if (y + 30 >= bufh) IncreaseBufSize();
|
||||
DrawBuf_WriteText(x, y, fontType, color, str_offset);
|
||||
}
|
||||
|
||||
void DrawBufer::PutPixel(dword x, y, color)
|
||||
{
|
||||
dword pos = y*bufw+x*4+8+buf_data;
|
||||
@@ -142,4 +149,35 @@ void DrawBufer::Show()
|
||||
PutPaletteImage(buf_data+8, bufw, bufh, bufx, bufy, 32, 0);
|
||||
}
|
||||
|
||||
void DrawBufer::IncreaseBufSize()
|
||||
{
|
||||
static dword alloc_counter;
|
||||
static dword bufh_initial;
|
||||
dword alloc_size;
|
||||
dword free_ram_size;
|
||||
char error_str[256];
|
||||
|
||||
if (!buf_data) {
|
||||
alloc_counter = 1;
|
||||
bufh_initial = bufh;
|
||||
alloc_size = bufw * bufh * 4 + 8;
|
||||
buf_data = malloc(alloc_size);
|
||||
}
|
||||
else {
|
||||
alloc_counter++;
|
||||
bufh = bufh_initial * alloc_counter;
|
||||
alloc_size = bufw * bufh * 4 + 8;
|
||||
buf_data = realloc(buf_data, alloc_size);
|
||||
Fill(alloc_counter - 1 * bufw * bufh_initial * 4 + 8, fill_color);
|
||||
}
|
||||
|
||||
free_ram_size = GetFreeRAM() * 1024;
|
||||
if (alloc_size >= free_ram_size) {
|
||||
sprintf(#error_str, #draw_buf_not_enaught_ram, alloc_size/1048576, free_ram_size/1048576);
|
||||
notify(#error_str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user