2015-12-18 22:10:45 +01:00
|
|
|
#ifndef INCLUDE_LABEL_H
|
|
|
|
#define INCLUDE_LABEL_H
|
2015-08-17 02:16:17 +02:00
|
|
|
|
|
|
|
#ifndef INCLUDE_MATH_H
|
|
|
|
#include "../lib/math.h"
|
|
|
|
#endif
|
|
|
|
|
2016-12-04 20:30:30 +01:00
|
|
|
#ifndef INCLUDE_IO_H
|
|
|
|
#include "../lib/io.h"
|
2015-08-17 02:16:17 +02:00
|
|
|
#endif
|
|
|
|
|
2016-01-01 17:51:53 +01:00
|
|
|
#include "../lib/patterns/rgb.h"
|
|
|
|
|
|
|
|
|
2015-12-17 20:15:49 +01:00
|
|
|
#define DEFAULT_FONT "/sys/fonts/Tahoma.kf"
|
|
|
|
|
2015-08-20 17:04:18 +02:00
|
|
|
:struct __SIZE
|
|
|
|
{
|
2015-09-07 15:07:29 +02:00
|
|
|
dword width,height;
|
2015-12-18 22:10:45 +01:00
|
|
|
signed offset_x, offset_y;
|
2015-12-18 22:13:19 +01:00
|
|
|
byte pt;
|
2015-08-20 17:04:18 +02:00
|
|
|
};
|
2015-12-18 22:10:45 +01:00
|
|
|
:struct LABEL
|
2015-08-17 02:16:17 +02:00
|
|
|
{
|
2015-08-20 17:04:18 +02:00
|
|
|
__SIZE size;
|
2015-12-18 22:10:45 +01:00
|
|
|
int width,height;
|
2016-12-21 11:56:06 +01:00
|
|
|
byte bold,smooth;
|
2015-12-21 20:04:39 +01:00
|
|
|
dword color, background;
|
2015-12-18 22:10:45 +01:00
|
|
|
dword font,font_begin;
|
2015-08-17 02:16:17 +02:00
|
|
|
word block;
|
2016-12-21 11:56:06 +01:00
|
|
|
dword raw;
|
|
|
|
dword raw_size;
|
|
|
|
|
2015-12-18 22:10:45 +01:00
|
|
|
byte init();
|
2016-12-21 11:56:06 +01:00
|
|
|
bool changeSIZE();
|
2015-12-18 22:10:45 +01:00
|
|
|
byte symbol();
|
|
|
|
byte symbol_size();
|
|
|
|
dword getsize();
|
|
|
|
|
2016-12-21 11:56:06 +01:00
|
|
|
void ApplySmooth();
|
|
|
|
int WriteIntoWindow();
|
|
|
|
int WriteIntoWindowCenter();
|
|
|
|
void WriteIntoBuffer();
|
2015-12-18 16:21:19 +01:00
|
|
|
void show_buf();
|
2015-12-18 22:10:45 +01:00
|
|
|
} label;
|
2015-12-17 20:15:49 +01:00
|
|
|
|
2016-12-21 11:56:06 +01:00
|
|
|
:bool LABEL::changeSIZE()
|
2015-08-17 18:21:51 +02:00
|
|
|
{
|
2015-12-18 22:10:45 +01:00
|
|
|
dword file_size;
|
2015-08-17 18:21:51 +02:00
|
|
|
dword ofs;
|
2016-12-21 11:56:06 +01:00
|
|
|
if(size.pt<9) size.pt = 8;
|
|
|
|
font = font_begin;
|
|
|
|
ofs = DSDWORD[calc(size.pt-8<<2+font_begin)];
|
|
|
|
if(ofs==-1)return false;
|
2015-12-18 22:10:45 +01:00
|
|
|
font += ofs + 156;
|
2016-12-21 11:56:06 +01:00
|
|
|
file_size = DSDWORD[calc(font)];
|
|
|
|
height = DSBYTE[calc(font+file_size) - 1];
|
|
|
|
width = DSBYTE[calc(font+file_size) - 2];
|
2015-08-20 18:37:49 +02:00
|
|
|
block = math.ceil(height*width/32);
|
|
|
|
return true;
|
2015-08-17 18:21:51 +02:00
|
|
|
}
|
2015-12-18 22:10:45 +01:00
|
|
|
:dword LABEL::getsize(dword text1)
|
2015-08-17 02:16:17 +02:00
|
|
|
{
|
2015-08-20 17:04:18 +02:00
|
|
|
size.height = size.width = 0;
|
2015-12-18 22:10:45 +01:00
|
|
|
size.offset_x = size.offset_y = -1;
|
2016-12-21 11:56:06 +01:00
|
|
|
if(size.pt)if(!changeSIZE())return 0;
|
2015-08-18 12:43:23 +02:00
|
|
|
WHILE(DSBYTE[text1])
|
|
|
|
{
|
2015-08-20 17:04:18 +02:00
|
|
|
symbol_size(DSBYTE[text1]);
|
2015-08-18 12:43:23 +02:00
|
|
|
text1++;
|
|
|
|
}
|
2015-12-18 22:10:45 +01:00
|
|
|
$neg size.offset_y
|
|
|
|
$neg size.offset_x
|
2015-12-21 17:37:24 +01:00
|
|
|
size.height += size.offset_y+1;
|
|
|
|
size.width += size.offset_x+1;
|
2015-08-20 17:04:18 +02:00
|
|
|
return size.width;
|
2015-08-18 12:43:23 +02:00
|
|
|
}
|
2015-12-18 22:10:45 +01:00
|
|
|
:byte LABEL::symbol_size(byte s)
|
2015-08-18 12:43:23 +02:00
|
|
|
{
|
2015-12-17 20:15:49 +01:00
|
|
|
dword xi,yi;
|
|
|
|
dword tmp,_;
|
2015-12-18 16:21:19 +01:00
|
|
|
dword iii = 0;
|
2015-12-17 20:15:49 +01:00
|
|
|
byte rw=0;
|
2015-08-20 17:04:18 +02:00
|
|
|
byte X;
|
2016-12-21 11:56:06 +01:00
|
|
|
if(bold) size.width+=math.ceil(size.pt/17);
|
|
|
|
if(s==32)
|
2015-08-20 17:04:18 +02:00
|
|
|
{
|
|
|
|
size.width += width/4;
|
|
|
|
return;
|
|
|
|
}
|
2016-12-21 11:56:06 +01:00
|
|
|
if(s==9)
|
2015-08-20 17:04:18 +02:00
|
|
|
{
|
|
|
|
size.width += width;
|
|
|
|
return;
|
|
|
|
}
|
2015-12-18 22:10:45 +01:00
|
|
|
s = Cp866ToAnsi(s);
|
2016-12-21 11:56:06 +01:00
|
|
|
tmp = block*s << 2 + font;
|
2015-12-17 20:15:49 +01:00
|
|
|
for(yi=0; yi<height; yi++)
|
|
|
|
{
|
|
|
|
for(xi=0; xi<width; xi++)
|
|
|
|
{
|
2016-12-21 11:56:06 +01:00
|
|
|
if(iii%32) _ >>= 1;
|
|
|
|
else
|
2015-09-02 15:15:32 +02:00
|
|
|
{
|
2015-12-17 20:15:49 +01:00
|
|
|
tmp += 4;
|
|
|
|
_ = DSDWORD[tmp];
|
|
|
|
}
|
2016-12-21 11:56:06 +01:00
|
|
|
if(_&1)
|
2015-09-02 15:15:32 +02:00
|
|
|
{
|
2016-12-21 11:56:06 +01:00
|
|
|
if(xi>rw)rw=xi;
|
|
|
|
if(size.height<yi)size.height = yi;
|
|
|
|
if(size.offset_y<0)size.offset_y = yi;
|
|
|
|
else if(yi<size.offset_y)size.offset_y = yi;
|
|
|
|
if(!X) X = xi;
|
|
|
|
else if(X>xi)X = xi;
|
2015-09-02 15:15:32 +02:00
|
|
|
}
|
2015-12-17 20:15:49 +01:00
|
|
|
iii++;
|
|
|
|
}
|
|
|
|
}
|
2015-08-20 17:04:18 +02:00
|
|
|
size.width += rw;
|
2016-12-21 11:56:06 +01:00
|
|
|
if(size.offset_x<0)size.offset_x = X;
|
2015-08-18 12:43:23 +02:00
|
|
|
}
|
2015-12-18 22:10:45 +01:00
|
|
|
:byte LABEL::symbol(signed x,y; byte s; dword image_raw)
|
2015-12-17 20:15:49 +01:00
|
|
|
{
|
|
|
|
dword xi,yi;
|
2015-12-18 16:21:19 +01:00
|
|
|
dword iii = 0;
|
|
|
|
dword offs;
|
2015-12-17 20:15:49 +01:00
|
|
|
byte rw=0;
|
2016-12-21 11:56:06 +01:00
|
|
|
if(s==32)return width/4;
|
|
|
|
if(s==9)return width;
|
2015-12-18 22:10:45 +01:00
|
|
|
s = Cp866ToAnsi(s);
|
|
|
|
EBX = block*s << 2 + font;
|
2015-12-17 20:15:49 +01:00
|
|
|
for(yi=0; yi<height; yi++)
|
|
|
|
{
|
2015-12-18 22:10:45 +01:00
|
|
|
EDI = size.offset_y + yi + y * size.width * 3 + image_raw;
|
2015-12-17 20:15:49 +01:00
|
|
|
for(xi=0; xi<width; xi++)
|
|
|
|
{
|
2016-12-21 11:56:06 +01:00
|
|
|
if(iii%32) $shr ecx,1
|
|
|
|
else
|
2015-12-17 20:15:49 +01:00
|
|
|
{
|
|
|
|
EBX += 4;
|
|
|
|
ECX = DSDWORD[EBX];
|
|
|
|
}
|
2016-12-21 11:56:06 +01:00
|
|
|
if(ECX&true)
|
2015-12-17 20:15:49 +01:00
|
|
|
{
|
2016-12-21 11:56:06 +01:00
|
|
|
if(xi>rw)rw=xi;
|
|
|
|
offs = x + xi *3 + EDI;
|
2015-12-18 16:21:19 +01:00
|
|
|
DSDWORD[offs] = DSDWORD[offs] & 0xFF000000 | color;
|
2016-12-21 11:56:06 +01:00
|
|
|
if(bold) DSDWORD[offs+3] = DSDWORD[offs+3] & 0xFF000000 | color;
|
2015-12-17 20:15:49 +01:00
|
|
|
}
|
|
|
|
iii++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rw;
|
|
|
|
}
|
|
|
|
|
2016-12-21 11:56:06 +01:00
|
|
|
inline fastcall Cp866ToAnsi(AL) {
|
|
|
|
if (AL>=128)&&(AL<=175) return AL+64;
|
|
|
|
if (AL>=224)&&(AL<=239) return AL+16;
|
|
|
|
if (AL==241) return 184; //e ruAL with dotAL (yo)
|
|
|
|
if (AL==240) return 168; //E ruAL with dotAL (yo)
|
|
|
|
if (AL==242) return 'E'; //E ukr (ye)
|
|
|
|
if (AL==243) return 186; //e ukr (ye)
|
|
|
|
if (AL==244) return 'I'; //I ukr (yi)
|
|
|
|
if (AL==245) return 191; //i ukr (yi)
|
|
|
|
return AL;
|
2015-12-17 20:15:49 +01:00
|
|
|
}
|
|
|
|
|
2015-12-18 22:10:45 +01:00
|
|
|
:byte LABEL::init(dword font_path)
|
|
|
|
{
|
2016-12-04 20:30:30 +01:00
|
|
|
IO label_io;
|
2016-12-21 11:56:06 +01:00
|
|
|
if(font)free(font);
|
2016-12-04 20:30:30 +01:00
|
|
|
label_io.read(font_path);
|
2016-12-21 11:56:06 +01:00
|
|
|
if(!EAX) {
|
2016-12-04 20:33:48 +01:00
|
|
|
debugln(font_path);
|
2016-12-05 20:20:57 +01:00
|
|
|
label_io.run("/sys/@notify", "'Error: KFONT is not loaded.' -E");
|
2015-12-18 22:10:45 +01:00
|
|
|
return false;
|
|
|
|
}
|
2016-12-21 11:56:06 +01:00
|
|
|
font_begin = label_io.buffer_data;
|
|
|
|
size.pt = 9;
|
|
|
|
changeSIZE();
|
2015-12-18 22:10:45 +01:00
|
|
|
smooth = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*=====================================================================================
|
|
|
|
=========================== ===========================
|
|
|
|
=========================== RAW ===========================
|
|
|
|
=========================== ===========================
|
|
|
|
=====================================================================================*/
|
|
|
|
|
|
|
|
|
2016-01-10 23:33:10 +01:00
|
|
|
inline fastcall dword b24(EAX) { return DSDWORD[EAX] & 0x00FFFFFF; }
|
2016-12-21 11:56:06 +01:00
|
|
|
:void LABEL::ApplySmooth()
|
2015-12-17 20:15:49 +01:00
|
|
|
{
|
2016-01-10 23:33:10 +01:00
|
|
|
dword i,line_w,to,dark_background;
|
2015-12-18 22:10:45 +01:00
|
|
|
line_w = size.width * 3;
|
|
|
|
to = size.height - 1 * line_w + raw - 3;
|
|
|
|
for(i=raw; i < to; i+=3)
|
2015-12-18 16:21:19 +01:00
|
|
|
{
|
2015-12-21 20:04:39 +01:00
|
|
|
if(i-raw%line_w +3 == line_w) continue;
|
2016-01-01 17:51:53 +01:00
|
|
|
// pixels position, where b - black, w - write
|
|
|
|
// bw
|
|
|
|
// wb
|
2016-01-10 23:33:10 +01:00
|
|
|
if(b24(i)!=background) && (b24(i+3)==background) && (b24(i+line_w)==background) && (b24(i+3+line_w)!=background)
|
2015-12-21 20:04:39 +01:00
|
|
|
{
|
2016-02-13 20:59:07 +01:00
|
|
|
dark_background = MixColors(background,b24(i),210);
|
2016-01-10 23:33:10 +01:00
|
|
|
DSDWORD[i+3] = DSDWORD[i+3] & 0xFF000000 | dark_background;
|
|
|
|
DSDWORD[i+line_w] = DSDWORD[i+line_w] & 0xFF000000 | dark_background;
|
2015-12-17 20:15:49 +01:00
|
|
|
}
|
2016-01-01 17:51:53 +01:00
|
|
|
// wb
|
|
|
|
// bw
|
2016-01-10 23:33:10 +01:00
|
|
|
else if(b24(i)==background) && (b24(i+3)!=background) && (b24(i+line_w)!=background) && (b24(i+3+line_w)==background)
|
2015-12-17 20:15:49 +01:00
|
|
|
{
|
2016-02-13 20:59:07 +01:00
|
|
|
dark_background = MixColors(background,b24(i+3),210);
|
2016-01-10 23:33:10 +01:00
|
|
|
DSDWORD[i] = DSDWORD[i] & 0xFF000000 | dark_background;
|
|
|
|
DSDWORD[i+3+line_w] = DSDWORD[i+3+line_w] & 0xFF000000 | dark_background;
|
2015-12-17 20:15:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 11:56:06 +01:00
|
|
|
:int LABEL::WriteIntoWindowCenter(dword x,y,w,h; dword _background, _color; byte fontSizePoints; dword txt)
|
2015-12-18 16:21:19 +01:00
|
|
|
{
|
2015-12-18 22:10:45 +01:00
|
|
|
size.pt = fontSizePoints;
|
2015-12-18 16:21:19 +01:00
|
|
|
getsize(txt);
|
2016-12-21 11:56:06 +01:00
|
|
|
return WriteIntoWindow(w-size.width/2+x,y, _background, _color, fontSizePoints, txt);
|
2015-12-18 16:21:19 +01:00
|
|
|
}
|
|
|
|
|
2016-12-21 11:56:06 +01:00
|
|
|
:int LABEL::WriteIntoWindow(int x,y; dword _background, _color; byte fontSizePoints; dword text1)
|
2015-08-18 12:43:23 +02:00
|
|
|
{
|
|
|
|
signed len=0;
|
2016-12-21 11:56:06 +01:00
|
|
|
if(!text1)return false;
|
|
|
|
if(size.pt)if(!changeSIZE())return false;
|
2015-12-18 22:10:45 +01:00
|
|
|
size.pt = fontSizePoints;
|
2015-08-20 17:04:18 +02:00
|
|
|
getsize(text1);
|
2015-12-21 20:04:39 +01:00
|
|
|
color = _color;
|
|
|
|
background = _background;
|
2015-12-18 22:10:45 +01:00
|
|
|
y -= size.offset_y;
|
2015-08-20 18:37:49 +02:00
|
|
|
EDX = size.width*size.height*3;
|
2016-12-21 11:56:06 +01:00
|
|
|
if(!raw_size)
|
2015-08-19 13:14:15 +02:00
|
|
|
{
|
2015-12-18 22:10:45 +01:00
|
|
|
raw_size = EDX;
|
|
|
|
raw = malloc(raw_size);
|
2015-08-19 13:14:15 +02:00
|
|
|
}
|
2016-12-21 11:56:06 +01:00
|
|
|
else if(raw_size<EDX)
|
2015-08-19 13:14:15 +02:00
|
|
|
{
|
2015-12-18 22:10:45 +01:00
|
|
|
raw_size = EDX;
|
|
|
|
raw = realloc(raw,raw_size);
|
2015-08-19 13:14:15 +02:00
|
|
|
}
|
2015-12-18 16:21:19 +01:00
|
|
|
// Fill background color {
|
2015-12-18 22:10:45 +01:00
|
|
|
EBX = background;
|
|
|
|
EAX = raw_size+raw;
|
|
|
|
for (EDI=raw; EDI<EAX; EDI+=3) ESDWORD[EDI] = EBX;
|
2015-12-18 16:21:19 +01:00
|
|
|
// }
|
2015-12-18 22:10:45 +01:00
|
|
|
len = size.offset_x;
|
2015-08-17 02:16:17 +02:00
|
|
|
WHILE(DSBYTE[text1])
|
|
|
|
{
|
2015-12-18 22:10:45 +01:00
|
|
|
len+=symbol(len,0,DSBYTE[text1], raw);
|
2016-12-21 11:56:06 +01:00
|
|
|
if(bold)len+=math.ceil(size.pt/17);
|
2015-08-17 02:16:17 +02:00
|
|
|
text1++;
|
|
|
|
}
|
2016-12-21 11:56:06 +01:00
|
|
|
IF (smooth) ApplySmooth();
|
2015-12-18 22:10:45 +01:00
|
|
|
show_buf(x,y);
|
2015-08-17 02:16:17 +02:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2016-12-21 11:56:06 +01:00
|
|
|
:void LABEL::WriteIntoBuffer(int x,y,w,h; dword _background, _color; byte fontSizePoints; dword text1)
|
2015-09-01 15:11:07 +02:00
|
|
|
{
|
2015-12-18 22:10:45 +01:00
|
|
|
dword new_raw_size;
|
2016-12-21 11:56:06 +01:00
|
|
|
if(!text1)return;
|
|
|
|
if(size.pt)if(!changeSIZE())return;
|
2015-12-18 22:10:45 +01:00
|
|
|
|
2016-01-01 17:51:53 +01:00
|
|
|
if (size.pt != fontSizePoints) {
|
|
|
|
size.pt = fontSizePoints;
|
|
|
|
getsize(text1);
|
|
|
|
y -= size.offset_y;
|
|
|
|
}
|
2015-12-21 20:04:39 +01:00
|
|
|
color = _color;
|
|
|
|
background = _background;
|
2015-12-17 20:15:49 +01:00
|
|
|
|
2015-09-01 15:11:07 +02:00
|
|
|
size.width = w;
|
2015-09-01 15:55:35 +02:00
|
|
|
size.height = h;
|
2015-09-02 15:15:32 +02:00
|
|
|
|
2015-12-18 22:10:45 +01:00
|
|
|
new_raw_size = w*h*3;
|
2016-12-21 11:56:06 +01:00
|
|
|
if(raw_size != new_raw_size)
|
2015-09-01 15:11:07 +02:00
|
|
|
{
|
2015-12-18 22:10:45 +01:00
|
|
|
raw_size = new_raw_size;
|
|
|
|
free(raw);
|
|
|
|
raw = malloc(raw_size);
|
2015-12-18 16:21:19 +01:00
|
|
|
// Fill background color
|
2015-12-18 22:10:45 +01:00
|
|
|
EBX = background;
|
|
|
|
EAX = raw_size+raw;
|
|
|
|
for (EDI=raw; EDI<EAX; EDI+=3) ESDWORD[EDI] = EBX;
|
2015-09-01 15:11:07 +02:00
|
|
|
}
|
|
|
|
WHILE(DSBYTE[text1])
|
|
|
|
{
|
2015-12-18 22:10:45 +01:00
|
|
|
x+=symbol(x,y,DSBYTE[text1], raw);
|
2016-12-21 11:56:06 +01:00
|
|
|
if(bold)x+=math.ceil(size.pt/17);
|
2015-09-01 15:11:07 +02:00
|
|
|
text1++;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-18 22:10:45 +01:00
|
|
|
:void LABEL::show_buf(dword x, y){
|
|
|
|
_PutImage(x, y, size.width, size.height, raw);
|
2015-12-18 16:21:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-08-17 02:16:17 +02:00
|
|
|
#endif
|