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
|
|
|
|
|
2015-11-26 11:53:50 +01:00
|
|
|
#ifndef INCLUDE_FS_H
|
2015-11-06 15:49:37 +01:00
|
|
|
#include "../lib/obj/fs.h"
|
2015-08-17 02:16:17 +02:00
|
|
|
#endif
|
|
|
|
|
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-08-21 13:03:08 +02:00
|
|
|
float offset_i,w_italic;
|
2015-12-18 22:13:19 +01:00
|
|
|
byte pt;
|
2015-08-20 18:37:49 +02:00
|
|
|
byte TMP_WEIGHT;
|
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;
|
2015-12-17 20:15:49 +01:00
|
|
|
byte bold,italic,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;
|
2015-12-18 22:10:45 +01:00
|
|
|
byte init();
|
2015-12-18 16:21:19 +01:00
|
|
|
byte changeSIZE();
|
2015-12-18 22:10:45 +01:00
|
|
|
byte symbol();
|
|
|
|
byte symbol_size();
|
|
|
|
dword getsize();
|
|
|
|
|
|
|
|
dword raw;
|
|
|
|
dword raw_size;
|
2015-12-18 16:21:19 +01:00
|
|
|
void apply_smooth();
|
2015-12-18 22:10:45 +01:00
|
|
|
int write_center();
|
|
|
|
int write();
|
|
|
|
void write_buf();
|
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
|
|
|
|
2015-12-18 22:10:45 +01:00
|
|
|
:byte 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 TMP_DATA;
|
|
|
|
dword ofs;
|
2015-12-18 22:10:45 +01:00
|
|
|
IF(size.pt<9) size.pt = 8;
|
|
|
|
TMP_DATA = font = font_begin;
|
|
|
|
TMP_DATA +=size.pt-8*4;
|
2015-08-20 18:37:49 +02:00
|
|
|
ofs = DSDWORD[TMP_DATA];
|
|
|
|
IF(ofs==-1)return false;
|
2015-12-18 22:10:45 +01:00
|
|
|
font += ofs + 156;
|
|
|
|
TMP_DATA = font;
|
2015-08-20 18:37:49 +02:00
|
|
|
file_size = DSDWORD[TMP_DATA];
|
2015-12-18 22:10:45 +01:00
|
|
|
TMP_DATA = font + file_size;
|
2015-09-01 15:55:35 +02:00
|
|
|
height = DSBYTE[TMP_DATA - 1];
|
|
|
|
width = DSBYTE[TMP_DATA - 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;
|
|
|
|
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-21 13:03:08 +02:00
|
|
|
IF(italic)
|
|
|
|
{
|
2015-08-21 13:13:10 +02:00
|
|
|
size.w_italic = size.height/3;
|
|
|
|
size.offset_i = size.w_italic/size.height;
|
|
|
|
size.width += size.w_italic;
|
|
|
|
size.w_italic = -size.w_italic;
|
2015-08-21 13:03:08 +02:00
|
|
|
}
|
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;
|
2015-12-18 22:10:45 +01:00
|
|
|
size.TMP_WEIGHT = math.ceil(size.pt/17);
|
2015-12-17 20:15:49 +01:00
|
|
|
IF(s==32)
|
2015-08-20 17:04:18 +02:00
|
|
|
{
|
|
|
|
size.width += width/4;
|
2015-12-17 20:15:49 +01:00
|
|
|
IF(bold) size.width+=size.TMP_WEIGHT;
|
2015-08-20 17:04:18 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
IF(s==9)
|
|
|
|
{
|
|
|
|
size.width += width;
|
2015-12-17 20:15:49 +01:00
|
|
|
IF(bold) size.width+=size.TMP_WEIGHT;
|
2015-08-20 17:04:18 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-12-18 22:10:45 +01:00
|
|
|
s = Cp866ToAnsi(s);
|
|
|
|
tmp = 4*block*s + font;
|
2015-12-17 20:15:49 +01:00
|
|
|
for(yi=0; yi<height; yi++)
|
|
|
|
{
|
|
|
|
for(xi=0; xi<width; xi++)
|
|
|
|
{
|
|
|
|
IF(iii%32) _ >>= 1;
|
2015-09-02 15:15:32 +02:00
|
|
|
ELSE
|
|
|
|
{
|
2015-12-17 20:15:49 +01:00
|
|
|
tmp += 4;
|
|
|
|
_ = DSDWORD[tmp];
|
|
|
|
}
|
|
|
|
IF(_&1)
|
2015-09-02 15:15:32 +02:00
|
|
|
{
|
|
|
|
IF(xi>rw)rw=xi;
|
|
|
|
IF(size.height<yi)size.height = yi;
|
2015-12-18 22:10:45 +01:00
|
|
|
IF(size.offset_y<0)size.offset_y = yi;
|
|
|
|
ELSE IF(yi<size.offset_y)size.offset_y = yi;
|
2015-09-02 15:15:32 +02:00
|
|
|
IF(!X) X = xi;
|
|
|
|
ELSE IF(X>xi)X = xi;
|
|
|
|
}
|
2015-12-17 20:15:49 +01:00
|
|
|
iii++;
|
|
|
|
}
|
|
|
|
}
|
2015-08-20 17:04:18 +02:00
|
|
|
size.width += rw;
|
2015-12-17 20:15:49 +01:00
|
|
|
IF(bold) size.width+=size.TMP_WEIGHT;
|
2015-08-20 17:04:18 +02:00
|
|
|
IF(s=='_') size.width--;
|
2015-12-18 22:10:45 +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
|
|
|
float ital = -size.w_italic;
|
|
|
|
dword ___x;
|
|
|
|
byte rw=0;
|
|
|
|
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++)
|
|
|
|
{
|
|
|
|
IF(iii%32) $shr ecx,1
|
|
|
|
ELSE
|
|
|
|
{
|
|
|
|
EBX += 4;
|
|
|
|
ECX = DSDWORD[EBX];
|
|
|
|
}
|
|
|
|
IF(ECX&true)
|
|
|
|
{
|
|
|
|
IF(xi>rw)rw=xi;
|
|
|
|
___x = x+xi;
|
|
|
|
IF(italic)___x+=math.ceil(ital);
|
2015-12-18 16:21:19 +01:00
|
|
|
offs = ___x*3 + EDI;
|
|
|
|
DSDWORD[offs] = DSDWORD[offs] & 0xFF000000 | color;
|
|
|
|
IF(bold) DSDWORD[offs+3] = DSDWORD[offs+3] & 0xFF000000 | color;
|
2015-12-17 20:15:49 +01:00
|
|
|
}
|
|
|
|
iii++;
|
|
|
|
}
|
|
|
|
if (italic) ital-=size.offset_i;
|
|
|
|
}
|
|
|
|
return rw;
|
|
|
|
}
|
|
|
|
|
2015-12-18 22:10:45 +01:00
|
|
|
byte Cp866ToAnsi(byte s) {
|
2015-12-17 20:15:49 +01:00
|
|
|
IF(s>=128)&&(s<=175)s+=64;
|
|
|
|
ELSE IF(s>=224)&&(s<=239)s+=16;
|
|
|
|
ELSE IF(s==241)s=184; //yo
|
|
|
|
ELSE IF(s==240)s=168; //YO
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2015-12-18 22:10:45 +01:00
|
|
|
:byte LABEL::init(dword font_path)
|
|
|
|
{
|
|
|
|
lib_init_fs();
|
|
|
|
IF(font)free(font);
|
|
|
|
IF(!fs.read(font_path)) {
|
|
|
|
debug("Error while loading font: ");
|
|
|
|
debugln(font_path);
|
|
|
|
//io.run("/sys/@notify","'Error: Font is not loaded.' -E");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
font_begin = font = EAX;
|
|
|
|
EBX = font_begin + ECX;
|
|
|
|
height = DSBYTE[EBX-1];
|
|
|
|
width = DSBYTE[EBX-2];
|
|
|
|
block = math.ceil(height*width/32);
|
|
|
|
smooth = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*=====================================================================================
|
|
|
|
=========================== ===========================
|
|
|
|
=========================== RAW ===========================
|
|
|
|
=========================== ===========================
|
|
|
|
=====================================================================================*/
|
|
|
|
|
|
|
|
|
2015-12-17 20:15:49 +01:00
|
|
|
inline fastcall dword b24(EBX) { return DSDWORD[EBX] << 8; }
|
2015-12-18 22:10:45 +01:00
|
|
|
:void LABEL::apply_smooth()
|
2015-12-17 20:15:49 +01:00
|
|
|
{
|
|
|
|
dword i,line_w,to;
|
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;
|
|
|
|
if(b24(i)==0x000000) && (b24(i+3)!=0x000000) && (b24(i+line_w)!=0x000000) && (b24(i+3+line_w)==0x000000)
|
|
|
|
{
|
|
|
|
ShadowImage(i+3, 1, 1, 2);
|
|
|
|
ShadowImage(i+line_w, 1, 1, 2);
|
2015-12-17 20:15:49 +01:00
|
|
|
}
|
2015-12-21 20:04:39 +01:00
|
|
|
else if(b24(i)!=0x000000) && (b24(i+3)==0x000000) && (b24(i+line_w)==0x000000) && (b24(i+3+line_w)!=0x000000)
|
2015-12-17 20:15:49 +01:00
|
|
|
{
|
2015-12-21 20:04:39 +01:00
|
|
|
ShadowImage(i, 1, 1, 2);
|
|
|
|
ShadowImage(i+3+line_w, 1, 1, 2);
|
2015-12-17 20:15:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-21 20:04:39 +01:00
|
|
|
:int LABEL::write_center(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);
|
2015-12-21 20:04:39 +01:00
|
|
|
return write(w-size.width/2+x,y, _background, _color, fontSizePoints, txt);
|
2015-12-18 16:21:19 +01:00
|
|
|
}
|
|
|
|
|
2015-12-21 20:04:39 +01:00
|
|
|
:int LABEL::write(int x,y; dword _background, _color; byte fontSizePoints; dword text1)
|
2015-08-18 12:43:23 +02:00
|
|
|
{
|
|
|
|
signed len=0;
|
2015-08-20 18:37:49 +02:00
|
|
|
IF(!text1)return false;
|
2015-12-18 22:10:45 +01:00
|
|
|
IF(size.pt)IF(!changeSIZE())return false;
|
|
|
|
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;
|
2015-12-18 22:10:45 +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
|
|
|
}
|
2015-12-18 22:10:45 +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-08-20 17:04:18 +02:00
|
|
|
IF(DSBYTE[text1]=='_') len--;
|
2015-12-18 22:10:45 +01:00
|
|
|
len+=symbol(len,0,DSBYTE[text1], raw);
|
|
|
|
IF(bold)len+=math.ceil(size.pt/17);
|
2015-08-17 02:16:17 +02:00
|
|
|
text1++;
|
|
|
|
}
|
2015-12-18 16:21:19 +01:00
|
|
|
IF (smooth) apply_smooth();
|
2015-12-18 22:10:45 +01:00
|
|
|
show_buf(x,y);
|
2015-08-17 02:16:17 +02:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2015-12-21 20:04:39 +01:00
|
|
|
:void LABEL::write_buf(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;
|
2015-09-01 15:11:07 +02:00
|
|
|
IF(!text1)return;
|
2015-12-18 22:10:45 +01:00
|
|
|
IF(size.pt)IF(!changeSIZE())return;
|
|
|
|
|
|
|
|
size.pt = fontSizePoints;
|
2015-09-01 15:11:07 +02:00
|
|
|
getsize(text1);
|
2015-12-18 22:10:45 +01:00
|
|
|
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;
|
|
|
|
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);
|
|
|
|
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
|