2015-07-22 20:32:54 +02:00
|
|
|
#ifndef INCLUDE_DRAW_BUF_H
|
|
|
|
#define INCLUDE_DRAW_BUF_H
|
|
|
|
|
|
|
|
#ifndef INCLUDE_KOLIBRI_H
|
|
|
|
#include "../lib/kolibri.h"
|
|
|
|
#endif
|
2014-01-19 18:12:45 +01:00
|
|
|
|
2014-01-18 12:46:58 +01:00
|
|
|
dword buf_data;
|
2015-03-16 15:20:32 +01:00
|
|
|
dword zbuf_data;
|
|
|
|
|
2014-01-18 12:46:58 +01:00
|
|
|
|
|
|
|
struct DrawBufer {
|
2014-03-21 01:21:09 +01:00
|
|
|
int bufx, bufy, bufw, bufh;
|
2015-03-16 15:20:32 +01:00
|
|
|
int zbufx, zbufy, zbufw, zbufh;
|
|
|
|
byte zoomf;
|
2014-01-18 12:46:58 +01:00
|
|
|
|
|
|
|
void Init();
|
2014-03-21 01:21:09 +01:00
|
|
|
void Show();
|
2014-01-18 12:46:58 +01:00
|
|
|
void Fill();
|
|
|
|
void Skew();
|
|
|
|
void DrawBar();
|
2014-03-21 01:21:09 +01:00
|
|
|
void PutPixel();
|
2014-01-18 12:46:58 +01:00
|
|
|
void AlignCenter();
|
|
|
|
void AlignRight();
|
2015-03-16 15:20:32 +01:00
|
|
|
void Zoom2x();
|
2014-01-18 12:46:58 +01:00
|
|
|
};
|
|
|
|
|
2014-03-21 01:21:09 +01:00
|
|
|
void DrawBufer::Init(int i_bufx, i_bufy, i_bufw, i_bufh)
|
2014-01-18 12:46:58 +01:00
|
|
|
{
|
|
|
|
bufx = i_bufx;
|
|
|
|
bufy = i_bufy;
|
|
|
|
bufw = i_bufw;
|
|
|
|
bufh = i_bufh;
|
|
|
|
free(buf_data);
|
2015-03-16 15:20:32 +01:00
|
|
|
buf_data = malloc(bufw * bufh * 4 + 8);
|
2014-01-18 12:46:58 +01:00
|
|
|
ESDWORD[buf_data] = bufw;
|
2014-03-21 01:21:09 +01:00
|
|
|
ESDWORD[buf_data+4] = bufh;
|
|
|
|
|
2015-03-16 15:20:32 +01:00
|
|
|
if (zoomf != 1)
|
|
|
|
{
|
|
|
|
zbufx = bufx;
|
|
|
|
zbufy = bufy;
|
|
|
|
zbufw = bufw * zoomf;
|
|
|
|
zbufh = bufh * zoomf;
|
|
|
|
free(zbuf_data);
|
|
|
|
zbuf_data = malloc(zbufw * zbufh * 4 + 8);
|
|
|
|
ESDWORD[zbuf_data] = zbufw;
|
|
|
|
ESDWORD[zbuf_data+4] = zbufh;
|
|
|
|
}
|
2014-01-18 12:46:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DrawBufer::Fill(dword fill_color)
|
|
|
|
{
|
|
|
|
int i;
|
2014-03-21 01:21:09 +01:00
|
|
|
int max_i = bufw * bufh * 4 + buf_data + 8;
|
2014-01-19 18:12:45 +01:00
|
|
|
for (i=buf_data+8; i<max_i; i+=4) ESDWORD[i] = fill_color;
|
2014-01-18 12:46:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DrawBufer::DrawBar(dword x, y, w, h, color)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
for (j=0; j<h; j++)
|
|
|
|
{
|
2014-01-19 18:12:45 +01: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 12:46:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-21 01:21:09 +01:00
|
|
|
void DrawBufer::PutPixel(dword x, y, color)
|
|
|
|
{
|
|
|
|
int pos = y*bufw+x*4+8+buf_data;
|
|
|
|
ESDWORD[pos] = color;
|
|
|
|
}
|
|
|
|
|
2014-01-18 12:46:58 +01:00
|
|
|
char shift[]={8,8,4,4};
|
|
|
|
void DrawBufer::Skew(dword x, y, w, h)
|
|
|
|
{
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrawBufer::AlignRight(dword x,y,w,h, content_width)
|
|
|
|
{
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrawBufer::AlignCenter(dword x,y,w,h, content_width)
|
|
|
|
{
|
|
|
|
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-03-16 15:20:32 +01:00
|
|
|
void DrawBufer::Zoom2x()
|
|
|
|
{
|
|
|
|
int i, s;
|
|
|
|
dword point_x, max_i, zline_w, s_inc;
|
|
|
|
|
|
|
|
point_x = 0;
|
|
|
|
max_i = bufw * bufh * 4 + buf_data+8;
|
|
|
|
s_inc = zoomf * 4;
|
|
|
|
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];
|
|
|
|
if (zoomf==3)
|
|
|
|
{
|
|
|
|
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 12:46:58 +01:00
|
|
|
|
2015-03-16 15:20:32 +01:00
|
|
|
point_x++;
|
|
|
|
if (point_x >= bufw)
|
|
|
|
{
|
|
|
|
s += zoomf - 1 * zline_w;
|
|
|
|
point_x = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DrawBufer::Show()
|
|
|
|
{
|
|
|
|
if (zoomf == 1)
|
|
|
|
{
|
|
|
|
PutPaletteImage(buf_data+8, bufw, bufh, bufx, bufy, 32, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Zoom2x();
|
|
|
|
PutPaletteImage(zbuf_data+8, zbufw, zbufh, zbufx, zbufy, 32, 0);
|
|
|
|
}
|
|
|
|
}
|
2015-07-22 20:32:54 +02:00
|
|
|
|
|
|
|
#endif
|