2015-07-22 21:32:54 +03:00
|
|
|
#ifndef INCLUDE_DRAW_BUF_H
|
|
|
|
#define INCLUDE_DRAW_BUF_H
|
2015-08-04 18:48:36 +03:00
|
|
|
#print "[include <draw_buf.h>]\n"
|
2015-07-22 21:32:54 +03:00
|
|
|
|
|
|
|
#ifndef INCLUDE_KOLIBRI_H
|
|
|
|
#include "../lib/kolibri.h"
|
|
|
|
#endif
|
2014-01-19 21:12:45 +04:00
|
|
|
|
2016-11-04 13:43:03 +03:00
|
|
|
unsigned buf_data;
|
2015-03-16 17:20:32 +03:00
|
|
|
|
2014-01-18 15:46:58 +04:00
|
|
|
|
|
|
|
struct DrawBufer {
|
2016-11-04 13:43:03 +03:00
|
|
|
unsigned bufx, bufy, bufw, bufh;
|
2015-08-05 01:21:08 +03:00
|
|
|
byte zoom;
|
2014-01-18 15:46:58 +04:00
|
|
|
|
2016-11-10 20:48:36 +03:00
|
|
|
bool Init();
|
2014-03-21 04:21:09 +04:00
|
|
|
void Show();
|
2014-01-18 15:46:58 +04:00
|
|
|
void Fill();
|
|
|
|
void Skew();
|
|
|
|
void DrawBar();
|
2014-03-21 04:21:09 +04:00
|
|
|
void PutPixel();
|
2014-01-18 15:46:58 +04:00
|
|
|
void AlignCenter();
|
|
|
|
void AlignRight();
|
|
|
|
};
|
|
|
|
|
2016-11-10 20:48:36 +03:00
|
|
|
bool DrawBufer::Init(int i_bufx, i_bufy, i_bufw, i_bufh)
|
2014-01-18 15:46:58 +04:00
|
|
|
{
|
2016-11-18 00:23:36 +03:00
|
|
|
dword alloc_size, free_ram_size;
|
|
|
|
char error_str[256];
|
2016-11-04 13:43:03 +03:00
|
|
|
if (!zoom) zoom = 1;
|
2014-01-18 15:46:58 +04:00
|
|
|
bufx = i_bufx;
|
|
|
|
bufy = i_bufy;
|
2015-08-05 01:21:08 +03:00
|
|
|
bufw = i_bufw * zoom;
|
|
|
|
bufh = i_bufh * zoom;
|
2014-01-18 15:46:58 +04:00
|
|
|
free(buf_data);
|
2016-11-18 00:23:36 +03:00
|
|
|
$mov eax, 18
|
|
|
|
$mov ebx, 16
|
|
|
|
$int 0x40
|
|
|
|
free_ram_size = EAX * 1024;
|
|
|
|
alloc_size = bufw * bufh * 4 + 8;
|
|
|
|
if (alloc_size >= free_ram_size) {
|
|
|
|
sprintf(#error_str,
|
|
|
|
"'DrawBufer needs more memory than currenly available.
|
|
|
|
Application could be unstable.
|
|
|
|
|
2016-11-19 16:46:22 +03:00
|
|
|
Requested size: %i Kb
|
2016-11-18 00:23:36 +03:00
|
|
|
Free RAM: %i Kb' -E", alloc_size/1024, free_ram_size/1024);
|
|
|
|
notify(#error_str);
|
|
|
|
}
|
|
|
|
buf_data = malloc(alloc_size);
|
2016-11-10 20:48:36 +03:00
|
|
|
//debugval("buf_data",buf_data);
|
|
|
|
if (!buf_data) return false;
|
2014-01-18 15:46:58 +04:00
|
|
|
ESDWORD[buf_data] = bufw;
|
2014-03-21 04:21:09 +04:00
|
|
|
ESDWORD[buf_data+4] = bufh;
|
2016-11-10 20:48:36 +03:00
|
|
|
return true;
|
2014-01-18 15:46:58 +04:00
|
|
|
}
|
|
|
|
|
2016-11-04 13:43:03 +03:00
|
|
|
void DrawBufer::Fill(unsigned fill_color)
|
2014-01-18 15:46:58 +04:00
|
|
|
{
|
2016-11-04 13:43:03 +03:00
|
|
|
unsigned i;
|
|
|
|
unsigned max_i = bufw * bufh * 4 + buf_data + 8;
|
2014-01-19 21:12:45 +04:00
|
|
|
for (i=buf_data+8; i<max_i; i+=4) ESDWORD[i] = fill_color;
|
2014-01-18 15:46:58 +04:00
|
|
|
}
|
|
|
|
|
2016-11-04 13:43:03 +03:00
|
|
|
void DrawBufer::DrawBar(unsigned x, y, w, h, color)
|
2014-01-18 15:46:58 +04:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
for (j=0; j<h; j++)
|
|
|
|
{
|
2014-01-19 21:12:45 +04:00
|
|
|
for (i = y+j*bufw+x*4+8+buf_data; i<y+j*bufw+x+w*4+8+buf_data; i+=4) ESDWORD[i] = color;
|
2014-01-18 15:46:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-04 13:43:03 +03:00
|
|
|
void DrawBufer::PutPixel(unsigned x, y, color)
|
2014-03-21 04:21:09 +04:00
|
|
|
{
|
|
|
|
int pos = y*bufw+x*4+8+buf_data;
|
|
|
|
ESDWORD[pos] = color;
|
|
|
|
}
|
|
|
|
|
2014-01-18 15:46:58 +04:00
|
|
|
char shift[]={8,8,4,4};
|
2016-11-04 13:43:03 +03:00
|
|
|
void DrawBufer::Skew(unsigned x, y, w, h)
|
2014-01-18 15:46:58 +04:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
for (j=0; j<=3; j++)
|
|
|
|
{
|
|
|
|
for (i = y+j*bufw+x+w+h*4; i>y+j*bufw+x+h-12*4 ; i-=4)
|
|
|
|
ESDWORD[buf_data+i+8] = ESDWORD[-shift[j]+buf_data+i+8];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-04 13:43:03 +03:00
|
|
|
void DrawBufer::AlignRight(unsigned x,y,w,h, content_width)
|
2014-01-18 15:46:58 +04:00
|
|
|
{
|
|
|
|
int i, j, l;
|
|
|
|
int content_left = w - content_width / 2;
|
|
|
|
for (j=0; j<h; j++)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
ESDWORD[buf_data+8+i] >< ESDWORD[buf_data+8+l];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-04 13:43:03 +03:00
|
|
|
void DrawBufer::AlignCenter(unsigned x,y,w,h, content_width)
|
2014-01-18 15:46:58 +04:00
|
|
|
{
|
|
|
|
int i, j, l;
|
|
|
|
int content_left = w - content_width / 2;
|
|
|
|
for (j=0; j<h; j++)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
ESDWORD[buf_data+8+i] >< ESDWORD[buf_data+8+l];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-05 01:21:08 +03:00
|
|
|
/*
|
2015-03-16 17:20:32 +03:00
|
|
|
void DrawBufer::Zoom2x()
|
|
|
|
{
|
|
|
|
int i, s;
|
2016-11-04 13:43:03 +03:00
|
|
|
unsigned point_x, max_i, zline_w, s_inc;
|
2015-03-16 17:20:32 +03:00
|
|
|
|
|
|
|
point_x = 0;
|
|
|
|
max_i = bufw * bufh * 4 + buf_data+8;
|
2015-08-05 01:21:08 +03:00
|
|
|
s_inc = zoom * 4;
|
2015-03-16 17:20:32 +03:00
|
|
|
zline_w = zbufw * 4;
|
|
|
|
|
|
|
|
for (i=buf_data+8, s=zbuf_data+8; i<max_i; i+=4, s+= s_inc) {
|
|
|
|
ESDWORD[s] = ESDWORD[i];
|
|
|
|
ESDWORD[s+4] = ESDWORD[i];
|
|
|
|
ESDWORD[s+zline_w] = ESDWORD[i];
|
|
|
|
ESDWORD[s+zline_w+4] = ESDWORD[i];
|
2015-08-05 01:21:08 +03:00
|
|
|
if (zoom==3)
|
2015-03-16 17:20:32 +03:00
|
|
|
{
|
|
|
|
ESDWORD[s+8] = ESDWORD[i];
|
|
|
|
ESDWORD[zline_w+s+8] = ESDWORD[i];
|
|
|
|
ESDWORD[zline_w*2+s] = ESDWORD[i];
|
|
|
|
ESDWORD[zline_w*2+s+4] = ESDWORD[i];
|
|
|
|
ESDWORD[zline_w*2+s+8] = ESDWORD[i];
|
|
|
|
}
|
2014-01-18 15:46:58 +04:00
|
|
|
|
2015-03-16 17:20:32 +03:00
|
|
|
point_x++;
|
|
|
|
if (point_x >= bufw)
|
|
|
|
{
|
2015-08-05 01:21:08 +03:00
|
|
|
s += zoom - 1 * zline_w;
|
2015-03-16 17:20:32 +03:00
|
|
|
point_x = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-05 01:21:08 +03:00
|
|
|
*/
|
2015-03-16 17:20:32 +03:00
|
|
|
|
|
|
|
|
|
|
|
void DrawBufer::Show()
|
|
|
|
{
|
2015-08-05 01:21:08 +03:00
|
|
|
PutPaletteImage(buf_data+8, bufw, bufh, bufx, bufy, 32, 0);
|
2015-03-16 17:20:32 +03:00
|
|
|
}
|
2015-07-22 21:32:54 +03:00
|
|
|
|
|
|
|
#endif
|