CMM. list_box.h: handle incorect values

font.h: finally ability to write into a buffer
kolibri font viewer.c: write into a buffer

git-svn-id: svn://kolibrios.org@5784 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2015-09-02 13:15:32 +00:00
parent 8aee87f84f
commit 6f0e6671db
3 changed files with 60 additions and 66 deletions

View File

@ -1,10 +1,13 @@
#define MEMSIZE 0xEE80
#define MEMSIZE 0x2EE80
#include "../lib/font.h"
#include "../lib/gui.h"
#define PANELH 30
void main()
{
proc_info Form;
word i, y, btn;
char line[256], title[4196];
font.no_bg_copy = true;
@ -23,24 +26,30 @@ void main()
if (btn==1) ExitProcess();
if (btn==2) font.weight ^=1;
if (btn==3) font.italic ^=1;
if (btn==4) font.no_bg_copy ^=1;
if (btn==4) font.smooth ^=1;
goto _DRAW_WINDOW_CONTENT;
case evReDraw:
DefineAndDrawWindow(215,100,500,320,0x33,0xFFFFFF,#title);
DrawBar(0, 0, 500-9, 30, 0xCCCccc);
DefineAndDrawWindow(215,100,500,320,0x74,0xFFFFFF,#title);
GetProcessInfo(#Form, SelfInfo);
_DRAW_WINDOW_CONTENT:
DrawBar(0, 0, Form.cwidth, PANELH, 0xCCCccc);
CheckBox2(10, 8, 2, "Bold", font.weight);
CheckBox2(70, 8, 3, "Italic", font.italic);
CheckBox2(140, 8, 4, "Smooth", font.no_bg_copy);
CheckBox2(140, 8, 4, "Smooth", font.smooth);
font.buffer_size = free(font.buffer);
if (!font.data)
{
DrawBar(0, PANELH, Form.cwidth, Form.cheight - PANELH, 0xFFFfff);
WriteText(10, 50, 0x82, 0xFF00FF, "Font is not loaded.");
}
else for (i=10, y=40; i<22; i++, y+=font.height;)
}
else for (i=10, y=5; i<22; i++, y+=font.height;) //not flexible, need to calculate font count and max line length
{
font.size.text = i;
sprintf(#line,"<EFBFBD> §¬¥à èà¨äâ /size font %d ¯¨ªá¥«¥©.",i);
font.prepare(10,y,#line);
font.show(10, y);
font.prepare_buf(10,y,Form.cwidth,Form.cheight-PANELH, #line);
}
if (font.smooth) SmoothFont(font.buffer, font.size.width, font.size.height);
font.show(0, PANELH);
}
}
}

View File

@ -20,7 +20,7 @@
:struct FONT
{
__SIZE size;
byte r,g,b,weight,italic;
byte r,g,b,weight,italic, smooth;
byte width,height;
byte encoding;
dword color;
@ -30,9 +30,8 @@
word block;
dword data;
dword begin;
dword size_file;
byte load(...);
byte symbol(word x;byte s;dword c);
byte symbol(word x,y;byte s;dword c);
byte symbol_size(byte s);
dword prepare(word x,y;dword text1);
void prepare_buf(word x,y,w,h;dword text1);
@ -103,10 +102,8 @@ FONT font = 0;
}
$neg size.offset_y
$neg size.offset_x
size.height++;
size.height += size.offset_y;
size.width += size.offset_x;
size.width++;
size.height += size.offset_y; size.height++;
size.width += size.offset_x; size.width++;
IF(italic)
{
size.w_italic = size.height/3;
@ -142,33 +139,29 @@ FONT font = 0;
ELSE IF(s==241)s=184; //yo
ELSE IF(s==240)s=168; //YO
}
yi = 0;
iii = 0;
tmp = 4*block*s + data;
while(yi<height)
for(yi=0; yi<height; yi++)
{
xi = 0;
WHILE(xi<width)
{
IF(iii%32) _ >>= 1;
ELSE
{
tmp += 4;
_ = DSDWORD[tmp];
}
IF(_&1)
{
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;
}
xi++;
iii++;
for(xi=0; xi<width; xi++)
{
IF(iii%32) _ >>= 1;
ELSE
{
tmp += 4;
_ = DSDWORD[tmp];
}
yi++;
IF(_&1)
{
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;
}
iii++;
}
}
size.width += rw;
IF(weight) size.width+=size.TMP_WEIGHT;
@ -218,7 +211,7 @@ FONT font = 0;
WHILE(DSBYTE[text1])
{
IF(DSBYTE[text1]=='_') len--;
len+=symbol(len,DSBYTE[text1]);
len+=symbol(len,0,DSBYTE[text1]);
IF(weight)len+=math.ceil(size.text/17);
text1++;
}
@ -250,7 +243,7 @@ inline fastcall dword b24(EBX) { return DSDWORD[EBX] << 8; }
}
}
}
:byte FONT::symbol(signed x;byte s)
:byte FONT::symbol(signed x,y;byte s)
{
dword xi,yi;
dword tmp,_;
@ -269,15 +262,12 @@ inline fastcall dword b24(EBX) { return DSDWORD[EBX] << 8; }
ELSE IF(s==241)s=184; //yo
ELSE IF(s==240)s=168; //YO
}
yi = 0;
iii = 0;
tmp = 4*block*s;
tmp +=data;
while(yi<height)
tmp = 4*block*s + data;
for(yi=0; yi<height; yi++)
{
xi = 0;
TMP = size.offset_y+yi;
while(xi<width)
TMP = size.offset_y+yi+y;
for(xi=0; xi<width; xi++)
{
IF(iii%32) _ >>= 1;
ELSE
@ -291,17 +281,13 @@ inline fastcall dword b24(EBX) { return DSDWORD[EBX] << 8; }
___x = x+xi;
IF(italic)___x+=math.ceil(ital);
PixelRGB(___x,TMP);
_TMP_WEIGHT = size.TMP_WEIGHT;
WHILE(_TMP_WEIGHT)
for(_TMP_WEIGHT=size.TMP_WEIGHT; _TMP_WEIGHT; _TMP_WEIGHT--)
{
IF(weight) PixelRGB(___x+_TMP_WEIGHT,TMP);
_TMP_WEIGHT--;
}
}
xi++;
iii++;
}
yi++;
IF(italic) ital-=size.offset_i;
}
return rw;
@ -312,8 +298,7 @@ inline fastcall dword b24(EBX) { return DSDWORD[EBX] << 8; }
IF(data)free(data);
if (!io.readKPACK(path)) { debug("Error while loading font: "); debugln(path); return false; }
begin = data = io.buffer_data;
size_file = io.FILES_SIZE;
EBX = begin + size_file;
EBX = begin + io.FILES_SIZE;
height = DSBYTE[EBX - 1];
width = DSBYTE[EBX - 2];
block = math.ceil(height*width/32);
@ -322,7 +307,6 @@ inline fastcall dword b24(EBX) { return DSDWORD[EBX] << 8; }
:void FONT::prepare_buf(word x,y,w,h; dword text1)
{
signed len=0;
dword c;
c = color;
IF(!text1)return;
@ -333,14 +317,16 @@ inline fastcall dword b24(EBX) { return DSDWORD[EBX] << 8; }
size.width = w;
size.height = h;
EDX = size.width*size.height*3;
IF(!buffer_size)
if(buffer_size!=EDX)
{
buffer_size = EDX;
buffer = malloc(buffer_size);
EBX = bg_color;
EDI = buffer;
EAX = buffer_size+EDI;
buffer_size = EDX;
free(buffer);
buffer = malloc(buffer_size);
EBX = font.bg_color;
EDI = font.buffer;
EAX = font.buffer_size+font.buffer;
WHILE (EDI<EAX)
{
ESDWORD[EDI] = EBX;
@ -349,12 +335,11 @@ inline fastcall dword b24(EBX) { return DSDWORD[EBX] << 8; }
}
WHILE(DSBYTE[text1])
{
x+=symbol(x,DSBYTE[text1]);
x+=symbol(x,y,DSBYTE[text1]);
IF(weight)x+=math.ceil(size.text/17);
text1++;
}
return;
}
#endif

View File

@ -59,7 +59,7 @@ void llist::SetSizes(int xx, yy, ww, hh, line_hh)
text_y = line_h - font_h / 2;
visible = h / line_h;
wheel_size = 3;
//if (visible > count) visible=count;
CheckDoesValuesOkey();
}
void llist::SetFont(dword font_ww, font_hh, font_tt)
@ -214,8 +214,8 @@ int llist::KeyPgDown()
void llist::CheckDoesValuesOkey()
{
if (first < 0) first = 0;
if (visible + first > count) first = count - visible;
if (first < 0) first = 0;
if (current >= count) current = count - 1;
if (current < 0) current = 0;
}