mirror of
https://github.com/KolibriOS/kolibrios.git
synced 2024-11-24 09:49:41 +03:00
font.h: global refactoring, simplify API
git-svn-id: svn://kolibrios.org@5987 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
8900a2a9ba
commit
377ac5168b
@ -116,14 +116,7 @@ void main()
|
||||
WB1.DrawBuf.zoom = 1;
|
||||
WB1.list.SetFont(8, 14, 10111000b);
|
||||
WB1.list.no_selection = true;
|
||||
//font init
|
||||
font.bg_color = 0xFFFFFF;
|
||||
font.load(DEFAULT_FONT);
|
||||
if (!font.data) {
|
||||
notify("'Error: Font is not loaded.' -E");
|
||||
ExitProcess();
|
||||
}
|
||||
//
|
||||
label.init(DEFAULT_FONT);
|
||||
SetEventMask(0xa7);
|
||||
BEGIN_LOOP_APPLICATION:
|
||||
WaitEventTimeout(2);
|
||||
@ -263,7 +256,7 @@ void SetElementSizes()
|
||||
|
||||
void Draw_Window()
|
||||
{
|
||||
int list__w;
|
||||
int list__w, list__h;
|
||||
DrawBar(0,0, Form.cwidth,TOOLBAR_H-2, panel_color);
|
||||
DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, 0xD7D0D3);
|
||||
DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, border_color);
|
||||
@ -283,19 +276,13 @@ void Draw_Window()
|
||||
|
||||
/*
|
||||
list__w = 200;
|
||||
font.buffer_size = 0;
|
||||
font.size.height = 200;
|
||||
font.color = 0x000000;
|
||||
font.size.text = 11;
|
||||
font.write_buf(10,10,list__w,font.size.height, "Hello World!");
|
||||
font.color = 0xFF00FF;
|
||||
font.size.text = 12;
|
||||
font.write_buf(10,23,list__w,font.size.height, "How are you?");
|
||||
font.color = 0x2E74BB;
|
||||
font.size.text = 15;
|
||||
font.write_buf(11,40,list__w,font.size.height, "Fine");
|
||||
font.apply_smooth();
|
||||
_PutImage(0,0,list__w,font.size.height,font.buffer);
|
||||
list__h = 200;
|
||||
label.raw_size = 0;
|
||||
label.write_buf(10,10, list__w, list__h, 0xFFFFFF, 0, 11, "Hello World!");
|
||||
label.write_buf(10,23, list__w, list__h, 0xFFFFFF, 0xFF00FF, 12, "How are you?");
|
||||
label.write_buf(11,40, list__w, list__h, 0xFFFFFF, 0x2E74BB, 15, "Fine");
|
||||
label.apply_smooth();
|
||||
label.show_buf(0,0);
|
||||
*/
|
||||
}
|
||||
|
||||
|
@ -702,7 +702,7 @@ void Line_ReDraw(dword bgcol, filenum){
|
||||
if (text_col==0xA6A6B7) text_col=0xFFFFFF;
|
||||
}
|
||||
if (file.selected) text_col=0xFF0000;
|
||||
if (font.size.text==9) || (!font.data)
|
||||
if (label.size.pt==9) || (!label.font)
|
||||
{
|
||||
if (Form.width>=480)
|
||||
{
|
||||
@ -717,9 +717,8 @@ void Line_ReDraw(dword bgcol, filenum){
|
||||
}
|
||||
else
|
||||
{
|
||||
font.bg_color = bgcol;
|
||||
font.smooth = smooth_font;
|
||||
font.write(files.x + 23, files.item_h - font.height / 2 + y, file_name_off);
|
||||
label.smooth = smooth_font;
|
||||
label.write(files.x + 23, files.item_h - label.height / 2 + y, bgcol, text_col, label.size.pt, file_name_off);
|
||||
}
|
||||
DrawBar(files.x+files.w-141,y,1,files.item_h,system.color.work); //gray line 1
|
||||
DrawBar(files.x+files.w-68,y,1,files.item_h,system.color.work); //gray line 2
|
||||
|
@ -58,8 +58,8 @@ void settings_dialog()
|
||||
else if (id==27) MOUSE_TIME++;
|
||||
else if (id==28) && (MOUSE_TIME>29) MOUSE_TIME--;
|
||||
//else if (id==29) smooth_font ^= true;
|
||||
else if (id==30) { font.size.text++; IF(!font.changeSIZE()) font.size.text--; BigFontsChange(); }
|
||||
else if (id==31) { font.size.text--; IF(!font.changeSIZE()) font.size.text++; BigFontsChange(); }
|
||||
else if (id==30) { label.size.pt++; IF(!label.changeSIZE()) label.size.pt--; BigFontsChange(); }
|
||||
else if (id==31) { label.size.pt--; IF(!label.changeSIZE()) label.size.pt++; BigFontsChange(); }
|
||||
EventRedrawWindow(Form.left,Form.top);
|
||||
DrawSettingsCheckBoxes();
|
||||
break;
|
||||
@ -95,7 +95,7 @@ void DrawSettingsCheckBoxes()
|
||||
//CheckBox2(10, 99, 29, smooth_FONT, smooth_font);
|
||||
MoreLessBox(10, 99, 18, 27, 28, #system.color, MOUSE_TIME, T_DOUBLE_CLICK);
|
||||
MoreLessBox(10, 125, 18, 25, 26, #system.color, files.item_h, LIST_LINE_HEIGHT);
|
||||
if (font.data) MoreLessBox(10, 152, 18, 30, 31, #system.color, font.size.text, FONT_SIZE_LABEL);
|
||||
if (label.font) MoreLessBox(10, 152, 18, 30, 31, #system.color, label.size.pt, FONT_SIZE_LABEL);
|
||||
}
|
||||
|
||||
|
||||
@ -107,7 +107,7 @@ void LoadIniSettings()
|
||||
ini_get_int stdcall (eolite_ini_path, #config_section, "ShowDeviceName", 1); show_dev_name = EAX;
|
||||
ini_get_int stdcall (eolite_ini_path, #config_section, "RealFileNamesCase", 0); real_files_names_case = EAX;
|
||||
ini_get_int stdcall (eolite_ini_path, #config_section, "InfoAfterCopy", 0); info_after_copy = EAX;
|
||||
ini_get_int stdcall (eolite_ini_path, #config_section, "FontSize", 9); font.size.text = EAX;
|
||||
ini_get_int stdcall (eolite_ini_path, #config_section, "FontSize", 9); label.size.pt = EAX;
|
||||
ini_get_int stdcall (eolite_ini_path, #config_section, "TwoPanels", 0); two_panels = EAX;
|
||||
//ini_get_int stdcall (eolite_ini_path, #config_section, "UseSmoothFont", true);smooth_font = EAX;
|
||||
ini_get_int stdcall (eolite_ini_path, #config_section, "LineHeight", 18); files.item_h = EAX;
|
||||
@ -118,8 +118,8 @@ void LoadIniSettings()
|
||||
ini_get_int stdcall (eolite_ini_path, #config_section, "WinH", 500); WinH = EAX;
|
||||
ini_get_str stdcall (eolite_ini_path, #config_section, "DefaultPath", #path,4096,"/rd/1/");
|
||||
|
||||
ini_get_str stdcall ("/sys/SETTINGS/SYSTEM.INI", "system", "font file",#temp,4096,"/sys/FONTS/Tahoma.kf");
|
||||
font.load(#temp);
|
||||
ini_get_str stdcall ("/sys/SETTINGS/SYSTEM.INI", "system", "font file",#temp,4096,DEFAULT_FONT);
|
||||
label.init(#temp);
|
||||
ini_get_str stdcall ("/sys/SETTINGS/SYSTEM.INI", "system", "font smoothing",#temp,4096,"on");
|
||||
if(!strcmp(#temp,"off"))smooth_font = false;
|
||||
else smooth_font = true;
|
||||
@ -132,7 +132,7 @@ void SaveIniSettings()
|
||||
ini_set_int stdcall (eolite_ini_path, #config_section, "ShowDeviceName", show_dev_name);
|
||||
ini_set_int stdcall (eolite_ini_path, #config_section, "RealFileNamesCase", real_files_names_case);
|
||||
ini_set_int stdcall (eolite_ini_path, #config_section, "InfoAfterCopy", info_after_copy);
|
||||
ini_set_int stdcall (eolite_ini_path, #config_section, "FontSize", font.size.text);
|
||||
ini_set_int stdcall (eolite_ini_path, #config_section, "FontSize", label.size.pt);
|
||||
ini_set_int stdcall (eolite_ini_path, #config_section, "TwoPanels", two_panels);
|
||||
//ini_set_int stdcall (eolite_ini_path, #config_section, "UseSmoothFont", smooth_font);
|
||||
ini_set_int stdcall (eolite_ini_path, #config_section, "LineHeight", files.item_h);
|
||||
@ -147,7 +147,7 @@ void SaveIniSettings()
|
||||
ini_set_int stdcall (fd_path_eolite_ini_path, #config_section, "ShowDeviceName", show_dev_name);
|
||||
ini_set_int stdcall (fd_path_eolite_ini_path, #config_section, "RealFileNamesCase", real_files_names_case);
|
||||
ini_set_int stdcall (fd_path_eolite_ini_path, #config_section, "InfoAfterCopy", info_after_copy);
|
||||
ini_set_int stdcall (fd_path_eolite_ini_path, #config_section, "FontSize", font.size.text);
|
||||
ini_set_int stdcall (fd_path_eolite_ini_path, #config_section, "FontSize", label.size.pt);
|
||||
ini_set_int stdcall (fd_path_eolite_ini_path, #config_section, "TwoPanels", two_panels);
|
||||
//ini_set_int stdcall (fd_path_eolite_ini_path, #config_section, "UseSmoothFont", smooth_font);
|
||||
ini_set_int stdcall (fd_path_eolite_ini_path, #config_section, "LineHeight", files.item_h);
|
||||
@ -187,7 +187,7 @@ void SetAppColors()
|
||||
|
||||
void BigFontsChange()
|
||||
{
|
||||
files.item_h = font.size.text + 4;
|
||||
files.item_h = label.size.pt + 4;
|
||||
if (files.item_h<18) files.item_h = 18;
|
||||
files_active.item_h = files_inactive.item_h = files.item_h;
|
||||
}
|
||||
|
@ -8,12 +8,10 @@
|
||||
void main()
|
||||
{
|
||||
proc_info Form;
|
||||
word i, y, btn;
|
||||
int i, y, btn;
|
||||
char line[256], title[4196];
|
||||
font.color = 0;
|
||||
font.bg_color = 0xFFFFFF;
|
||||
if (!param) strcpy(#param, DEFAULT_FONT);
|
||||
font.load(#param);
|
||||
label.init(#param);
|
||||
strcpy(#title, "Font preview: ");
|
||||
strcat(#title, #param);
|
||||
loop()
|
||||
@ -23,32 +21,32 @@ void main()
|
||||
case evButton:
|
||||
btn = GetButtonID();
|
||||
if (btn==1) ExitProcess();
|
||||
if (btn==2) font.bold ^=1;
|
||||
if (btn==3) font.italic ^=1;
|
||||
if (btn==4) font.smooth ^=1;
|
||||
if (btn==2) label.bold ^=1;
|
||||
if (btn==3) label.italic ^=1;
|
||||
if (btn==4) label.smooth ^=1;
|
||||
goto _DRAW_WINDOW_CONTENT;
|
||||
case evReDraw:
|
||||
DefineAndDrawWindow(215,100,500,320,0x74,0xFFFFFF,#title);
|
||||
GetProcessInfo(#Form, SelfInfo);
|
||||
if (Form.status_window>2) break;
|
||||
_DRAW_WINDOW_CONTENT:
|
||||
DrawBar(0, 0, Form.cwidth, PANELH, 0xCCCccc);
|
||||
CheckBox2(10, 8, 2, "Bold", font.bold);
|
||||
CheckBox2(70, 8, 3, "Italic", font.italic);
|
||||
CheckBox2(140, 8, 4, "Smooth", font.smooth);
|
||||
font.buffer_size = free(font.buffer);
|
||||
if (!font.data)
|
||||
CheckBox2(10, 8, 2, "Bold", label.bold);
|
||||
CheckBox2(70, 8, 3, "Italic", label.italic);
|
||||
CheckBox2(140, 8, 4, "Smooth", label.smooth);
|
||||
label.raw_size = free(label.raw);
|
||||
if (!label.font)
|
||||
{
|
||||
DrawBar(0, PANELH, Form.cwidth, Form.cheight - PANELH, 0xFFFfff);
|
||||
WriteText(10, 50, 0x82, 0xFF00FF, "Font is not loaded.");
|
||||
}
|
||||
else for (i=10, y=5; i<22; i++, y+=font.height;) //not flexible, need to calculate font count and max line length
|
||||
else for (i=10, y=5; i<22; i++, y+=label.height;) //not flexible, need to calculate font count and max line length
|
||||
{
|
||||
font.size.text = i;
|
||||
sprintf(#line,"<EFBFBD> §¬¥à èà¨äâ /size font %d ¯¨ªá¥«¥©.",i);
|
||||
font.write_buf(10,y,Form.cwidth,Form.cheight-PANELH, #line);
|
||||
label.write_buf(10,y,Form.cwidth,Form.cheight-PANELH, 0xFFFFFF, 0, i, #line);
|
||||
}
|
||||
if (font.smooth) font.apply_smooth();
|
||||
font.show_buf(0, PANELH);
|
||||
if (label.smooth) label.apply_smooth();
|
||||
label.show_buf(0, PANELH);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef INCLUDE_FONT_H
|
||||
#define INCLUDE_FONT_H
|
||||
#ifndef INCLUDE_LABEL_H
|
||||
#define INCLUDE_LABEL_H
|
||||
|
||||
#ifndef INCLUDE_MATH_H
|
||||
#include "../lib/math.h"
|
||||
@ -11,76 +11,70 @@
|
||||
|
||||
#define DEFAULT_FONT "/sys/fonts/Tahoma.kf"
|
||||
|
||||
:struct __OFFSET_FONT
|
||||
{
|
||||
signed x,y;
|
||||
};
|
||||
:struct __SIZE
|
||||
{
|
||||
dword width,height;
|
||||
__OFFSET_FONT offset;
|
||||
signed offset_x, offset_y;
|
||||
float offset_i,w_italic;
|
||||
byte text;
|
||||
byte points;
|
||||
byte TMP_WEIGHT;
|
||||
};
|
||||
:struct FONT
|
||||
:struct LABEL
|
||||
{
|
||||
__SIZE size;
|
||||
int left,top,width,height;
|
||||
int width,height;
|
||||
byte bold,italic,smooth;
|
||||
dword bg_color;
|
||||
dword color;
|
||||
dword file_size;
|
||||
dword buffer;
|
||||
dword buffer_size;
|
||||
dword font,font_begin;
|
||||
word block;
|
||||
dword data;
|
||||
dword begin;
|
||||
byte load(...);
|
||||
byte init();
|
||||
byte changeSIZE();
|
||||
byte symbol(signed x,y;byte s;dword c);
|
||||
byte symbol_size(byte s);
|
||||
dword getsize(dword text1);
|
||||
void apply_smooth();
|
||||
int write_center(dword x,y,w,h;dword txt);
|
||||
int write(int x,y;dword text1);
|
||||
void write_buf(int x,y,w,h, text1);
|
||||
void show_buf();
|
||||
};
|
||||
FONT font = 0;
|
||||
byte symbol();
|
||||
byte symbol_size();
|
||||
dword getsize();
|
||||
|
||||
:byte FONT::changeSIZE()
|
||||
dword raw;
|
||||
dword raw_size;
|
||||
void apply_smooth();
|
||||
int write_center();
|
||||
int write();
|
||||
void write_buf();
|
||||
void show_buf();
|
||||
} label;
|
||||
|
||||
:byte LABEL::changeSIZE()
|
||||
{
|
||||
dword file_size;
|
||||
dword TMP_DATA;
|
||||
dword ofs;
|
||||
IF(size.text<9) size.text = 8;
|
||||
TMP_DATA = data = begin;
|
||||
TMP_DATA +=size.text-8*4;
|
||||
IF(size.pt<9) size.pt = 8;
|
||||
TMP_DATA = font = font_begin;
|
||||
TMP_DATA +=size.pt-8*4;
|
||||
ofs = DSDWORD[TMP_DATA];
|
||||
IF(ofs==-1)return false;
|
||||
data += ofs + 156;
|
||||
TMP_DATA = data;
|
||||
font += ofs + 156;
|
||||
TMP_DATA = font;
|
||||
file_size = DSDWORD[TMP_DATA];
|
||||
TMP_DATA = data + file_size;
|
||||
TMP_DATA = font + file_size;
|
||||
height = DSBYTE[TMP_DATA - 1];
|
||||
width = DSBYTE[TMP_DATA - 2];
|
||||
block = math.ceil(height*width/32);
|
||||
return true;
|
||||
}
|
||||
:dword FONT::getsize(dword text1)
|
||||
:dword LABEL::getsize(dword text1)
|
||||
{
|
||||
size.height = size.width = 0;
|
||||
size.offset.x = size.offset.y = -1;
|
||||
IF(size.text)IF(!changeSIZE())return 0;
|
||||
size.offset_x = size.offset_y = -1;
|
||||
IF(size.pt)IF(!changeSIZE())return 0;
|
||||
WHILE(DSBYTE[text1])
|
||||
{
|
||||
symbol_size(DSBYTE[text1]);
|
||||
text1++;
|
||||
}
|
||||
$neg size.offset.y
|
||||
$neg size.offset.x
|
||||
size.height += size.offset.y; size.height++;
|
||||
size.width += size.offset.x; size.width++;
|
||||
$neg size.offset_y
|
||||
$neg size.offset_x
|
||||
size.height += size.offset_y; size.height++;
|
||||
size.width += size.offset_x; size.width++;
|
||||
IF(italic)
|
||||
{
|
||||
size.w_italic = size.height/3;
|
||||
@ -90,14 +84,14 @@ FONT font = 0;
|
||||
}
|
||||
return size.width;
|
||||
}
|
||||
:byte FONT::symbol_size(byte s)
|
||||
:byte LABEL::symbol_size(byte s)
|
||||
{
|
||||
dword xi,yi;
|
||||
dword tmp,_;
|
||||
dword iii = 0;
|
||||
byte rw=0;
|
||||
byte X;
|
||||
size.TMP_WEIGHT = math.ceil(size.text/17);
|
||||
size.TMP_WEIGHT = math.ceil(size.pt/17);
|
||||
IF(s==32)
|
||||
{
|
||||
size.width += width/4;
|
||||
@ -110,8 +104,8 @@ FONT font = 0;
|
||||
IF(bold) size.width+=size.TMP_WEIGHT;
|
||||
return;
|
||||
}
|
||||
s = AnsiToCp866(s);
|
||||
tmp = 4*block*s + data;
|
||||
s = Cp866ToAnsi(s);
|
||||
tmp = 4*block*s + font;
|
||||
for(yi=0; yi<height; yi++)
|
||||
{
|
||||
for(xi=0; xi<width; xi++)
|
||||
@ -126,8 +120,8 @@ FONT font = 0;
|
||||
{
|
||||
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(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;
|
||||
}
|
||||
@ -137,9 +131,9 @@ FONT font = 0;
|
||||
size.width += rw;
|
||||
IF(bold) size.width+=size.TMP_WEIGHT;
|
||||
IF(s=='_') size.width--;
|
||||
IF(size.offset.x<0)size.offset.x = X;
|
||||
IF(size.offset_x<0)size.offset_x = X;
|
||||
}
|
||||
:byte FONT::symbol(signed x,y;byte s)
|
||||
:byte LABEL::symbol(signed x,y; byte s; dword image_raw)
|
||||
{
|
||||
dword xi,yi;
|
||||
dword iii = 0;
|
||||
@ -149,11 +143,12 @@ FONT font = 0;
|
||||
byte rw=0;
|
||||
IF(s==32)return width/4;
|
||||
IF(s==9)return width;
|
||||
s = AnsiToCp866(s);
|
||||
EBX = block*s << 2 + data;
|
||||
debugch(s);
|
||||
s = Cp866ToAnsi(s);
|
||||
EBX = block*s << 2 + font;
|
||||
for(yi=0; yi<height; yi++)
|
||||
{
|
||||
EDI = size.offset.y + yi + y * size.width * 3 + buffer;
|
||||
EDI = size.offset_y + yi + y * size.width * 3 + image_raw;
|
||||
for(xi=0; xi<width; xi++)
|
||||
{
|
||||
IF(iii%32) $shr ecx,1
|
||||
@ -178,7 +173,7 @@ FONT font = 0;
|
||||
return rw;
|
||||
}
|
||||
|
||||
byte AnsiToCp866(byte s) {
|
||||
byte Cp866ToAnsi(byte s) {
|
||||
IF(s>=128)&&(s<=175)s+=64;
|
||||
ELSE IF(s>=224)&&(s<=239)s+=16;
|
||||
ELSE IF(s==241)s=184; //yo
|
||||
@ -186,15 +181,42 @@ byte AnsiToCp866(byte s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
: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 ===========================
|
||||
=========================== ===========================
|
||||
=====================================================================================*/
|
||||
|
||||
|
||||
inline fastcall dword b24(EBX) { return DSDWORD[EBX] << 8; }
|
||||
:void FONT::apply_smooth()
|
||||
:void LABEL::apply_smooth()
|
||||
{
|
||||
dword i,line_w,to;
|
||||
line_w = font.size.width * 3;
|
||||
to = font.size.height - 1 * line_w + font.buffer - 3;
|
||||
for(i=font.buffer; i < to; i+=3)
|
||||
line_w = size.width * 3;
|
||||
to = size.height - 1 * line_w + raw - 3;
|
||||
for(i=raw; i < to; i+=3)
|
||||
{
|
||||
IF(i-font.buffer%line_w +3 == line_w) continue;
|
||||
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)
|
||||
{
|
||||
ShadowPixel(i+3, 2);
|
||||
@ -207,101 +229,90 @@ inline fastcall dword b24(EBX) { return DSDWORD[EBX] << 8; }
|
||||
}
|
||||
}
|
||||
}
|
||||
:byte FONT::load(dword path)
|
||||
{
|
||||
lib_init_fs();
|
||||
buffer_size = 0;
|
||||
smooth = true;
|
||||
IF(data)free(data);
|
||||
IF(!fs.read(path)) { debug("Error while loading font: "); debugln(path); return false; }
|
||||
begin = data = EAX;
|
||||
EBX = begin + ECX;
|
||||
height = DSBYTE[EBX-1];
|
||||
width = DSBYTE[EBX-2];
|
||||
block = math.ceil(height*width/32);
|
||||
return true;
|
||||
}
|
||||
|
||||
:int FONT::write_center(dword x,y,w,h;dword txt)
|
||||
:int LABEL::write_center(dword x,y,w,h; dword background, color1; byte fontSizePoints; dword txt)
|
||||
{
|
||||
size.pt = fontSizePoints;
|
||||
getsize(txt);
|
||||
return write(w-size.width/2+x,y,txt);
|
||||
return write(w-size.width/2+x,y, background, color1, fontSizePoints, txt);
|
||||
}
|
||||
|
||||
:int FONT::write(int x,y; dword text1)
|
||||
:int LABEL::write(int x,y; dword background, color1; byte fontSizePoints; dword text1)
|
||||
{
|
||||
signed len=0;
|
||||
IF(!text1)return false;
|
||||
IF(size.text)IF(!changeSIZE())return false;
|
||||
left = x;
|
||||
IF(size.pt)IF(!changeSIZE())return false;
|
||||
size.pt = fontSizePoints;
|
||||
getsize(text1);
|
||||
y -= size.offset.y;
|
||||
top = y;
|
||||
color = color1;
|
||||
y -= size.offset_y;
|
||||
EDX = size.width*size.height*3;
|
||||
IF(!buffer_size)
|
||||
IF(!raw_size)
|
||||
{
|
||||
buffer_size = EDX;
|
||||
buffer = malloc(buffer_size);
|
||||
raw_size = EDX;
|
||||
raw = malloc(raw_size);
|
||||
}
|
||||
ELSE IF(buffer_size<EDX)
|
||||
ELSE IF(raw_size<EDX)
|
||||
{
|
||||
buffer_size = EDX;
|
||||
buffer = realloc(buffer,buffer_size);
|
||||
raw_size = EDX;
|
||||
raw = realloc(raw,raw_size);
|
||||
}
|
||||
// Fill background color {
|
||||
EBX = bg_color;
|
||||
EAX = buffer_size+buffer;
|
||||
for (EDI=buffer; EDI<EAX; EDI+=3) ESDWORD[EDI] = EBX;
|
||||
EBX = background;
|
||||
EAX = raw_size+raw;
|
||||
for (EDI=raw; EDI<EAX; EDI+=3) ESDWORD[EDI] = EBX;
|
||||
// }
|
||||
len = size.offset.x;
|
||||
len = size.offset_x;
|
||||
WHILE(DSBYTE[text1])
|
||||
{
|
||||
IF(DSBYTE[text1]=='_') len--;
|
||||
len+=symbol(len,0,DSBYTE[text1]);
|
||||
IF(bold)len+=math.ceil(size.text/17);
|
||||
len+=symbol(len,0,DSBYTE[text1], raw);
|
||||
IF(bold)len+=math.ceil(size.pt/17);
|
||||
text1++;
|
||||
}
|
||||
IF (smooth) apply_smooth();
|
||||
show_buf(left,top);
|
||||
show_buf(x,y);
|
||||
return len;
|
||||
}
|
||||
|
||||
:void FONT::write_buf(int x,y,w,h; dword text1)
|
||||
:void LABEL::write_buf(int x,y,w,h; dword background, color1; byte fontSizePoints; dword text1)
|
||||
{
|
||||
dword new_buffer_size;
|
||||
dword new_raw_size;
|
||||
IF(!text1)return;
|
||||
IF(size.text)IF(!changeSIZE())return;
|
||||
IF(size.pt)IF(!changeSIZE())return;
|
||||
|
||||
size.pt = fontSizePoints;
|
||||
getsize(text1);
|
||||
y -= size.offset.y;
|
||||
y -= size.offset_y;
|
||||
color = color1;
|
||||
|
||||
size.width = w;
|
||||
size.height = h;
|
||||
|
||||
new_buffer_size = w*h*3;
|
||||
IF(buffer_size != w*h*3)
|
||||
new_raw_size = w*h*3;
|
||||
IF(raw_size != new_raw_size)
|
||||
{
|
||||
buffer_size = new_buffer_size;
|
||||
free(buffer);
|
||||
buffer = malloc(buffer_size);
|
||||
raw_size = new_raw_size;
|
||||
free(raw);
|
||||
raw = malloc(raw_size);
|
||||
// Fill background color
|
||||
EBX = bg_color;
|
||||
EAX = buffer_size+buffer;
|
||||
for (EDI=buffer; EDI<EAX; EDI+=3) ESDWORD[EDI] = EBX;
|
||||
EBX = background;
|
||||
EAX = raw_size+raw;
|
||||
for (EDI=raw; EDI<EAX; EDI+=3) ESDWORD[EDI] = EBX;
|
||||
}
|
||||
WHILE(DSBYTE[text1])
|
||||
{
|
||||
x+=symbol(x,y,DSBYTE[text1]);
|
||||
IF(bold)x+=math.ceil(size.text/17);
|
||||
x+=symbol(x,y,DSBYTE[text1], raw);
|
||||
IF(bold)x+=math.ceil(size.pt/17);
|
||||
text1++;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
:void FONT::show_buf(dword left1, top1){
|
||||
_PutImage(left1,top1,size.width,size.height,buffer);
|
||||
:void LABEL::show_buf(dword x, y){
|
||||
_PutImage(x, y, size.width, size.height, raw);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -58,8 +58,7 @@ void load_config()
|
||||
void main()
|
||||
{
|
||||
dword id, key;
|
||||
font.load("/sys/fonts/Tahoma.kf");
|
||||
font.smooth = true;
|
||||
label.init("/sys/fonts/Tahoma.kf");
|
||||
load_dll(libio, #libio_init,1);
|
||||
load_dll(libimg, #libimg_init,1);
|
||||
load_dll(libini, #lib_init,1);
|
||||
@ -146,15 +145,9 @@ byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name)
|
||||
icon_char_pos = strchr(key_value, ',');
|
||||
if (icon_char_pos) icon_id = atoi(icon_char_pos+1); else icon_id = default_icon;
|
||||
img_draw stdcall(skin.image, col*cell_w+tmp-10, row*cell_h+5 + list_pos, 32, 32, 0, icon_id*32);
|
||||
//WriteTextCenter(col*cell_w+7,row*cell_h+47 + list_pos,cell_w,0xDCDCDC,key_name);
|
||||
//WriteTextCenter(col*cell_w+6,row*cell_h+46 + list_pos,cell_w,0x000000,key_name);
|
||||
font.size = 12;
|
||||
font.color = 0xDCDCDC;
|
||||
font.bold = false;
|
||||
font.bg_color = LIST_BACKGROUND_COLOR;
|
||||
font.write_center(col*cell_w+7,row*cell_h+47 + list_pos,cell_w,0,key_name);
|
||||
font.color = 0;
|
||||
font.write_center(col*cell_w+6,row*cell_h+46 + list_pos,cell_w,0,key_name);
|
||||
label.bold = false;
|
||||
label.write_center(col*cell_w+7,row*cell_h+47 + list_pos, cell_w,0, LIST_BACKGROUND_COLOR, 0xDCDCDC, 12, key_name);
|
||||
label.write_center(col*cell_w+6,row*cell_h+46 + list_pos, cell_w,0, LIST_BACKGROUND_COLOR, 0x000000, 12, key_name);
|
||||
current_item_id++;
|
||||
col++;
|
||||
return true;
|
||||
@ -184,10 +177,8 @@ byte process_sections(dword sec_name, f_name)
|
||||
old_row = row;
|
||||
DrawBar(0, row * cell_h + list_pos, Form.cwidth , 29, LIST_BACKGROUND_COLOR);
|
||||
//WriteTextB(10, row * cell_h + 9 + list_pos, 0x90, 0x000000, sec_name);
|
||||
font.size=15;
|
||||
font.bold=false;
|
||||
font.bg_color = LIST_BACKGROUND_COLOR;
|
||||
text_len = font.write(10, row * cell_h + 10 + list_pos,sec_name);
|
||||
label.bold=false;
|
||||
text_len = label.write(10, row * cell_h + 10 + list_pos, LIST_BACKGROUND_COLOR, 0, 15, sec_name);
|
||||
DrawBar(text_len+20, row * cell_h + list_pos + 20, Form.cwidth-text_len-20, 1, 0xDCDCDC);
|
||||
DrawBar(text_len+20, row * cell_h + list_pos + 21, Form.cwidth-text_len-20, 1, 0xFCFCFC);
|
||||
list_pos += 29;
|
||||
@ -201,10 +192,8 @@ void draw_top_bar()
|
||||
int top_position = 26;
|
||||
DrawBar(0,0,Form.cwidth, top_position-1, system.color.work);
|
||||
DrawBar(0,top_position-1, Form.cwidth, 1, system.color.work_graph);
|
||||
font.size = 17;
|
||||
font.bold = false;
|
||||
font.bg_color = system.color.work;
|
||||
font.write(Form.cwidth-font.getsize(#window_title)/2,0,#window_title);
|
||||
label.bold = false;
|
||||
label.write_center(0,0, Form.cwidth, top_position, system.color.work, system.color.work_text, 17, #window_title);
|
||||
list_top = top_position;
|
||||
list_pos = list_top;
|
||||
row = -1;
|
||||
|
@ -5,7 +5,7 @@ int encoding;
|
||||
void LoadIniSettings()
|
||||
{
|
||||
strcpy(#ini_path, "/sys/settings/treader.ini");
|
||||
ini_get_int stdcall (#ini_path, #config_section, "FontSize", 14); font.size.text = EAX;
|
||||
ini_get_int stdcall (#ini_path, #config_section, "FontSize", 14); label.size.pt = EAX;
|
||||
ini_get_int stdcall (#ini_path, #config_section, "Encoding", CH_CP866); encoding = EAX;
|
||||
ini_get_int stdcall (#ini_path, #config_section, "WinX", 150); Form.left = EAX;
|
||||
ini_get_int stdcall (#ini_path, #config_section, "WinY", 50); Form.top = EAX;
|
||||
@ -15,7 +15,7 @@ void LoadIniSettings()
|
||||
|
||||
void SaveIniSettings()
|
||||
{
|
||||
ini_set_int stdcall (#ini_path, #config_section, "FontSize", font.size.text);
|
||||
ini_set_int stdcall (#ini_path, #config_section, "FontSize", label.size.pt);
|
||||
ini_set_int stdcall (#ini_path, #config_section, "Encoding", encoding);
|
||||
ini_set_int stdcall (#ini_path, #config_section, "WinX", Form.left);
|
||||
ini_set_int stdcall (#ini_path, #config_section, "WinY", Form.top);
|
||||
|
@ -10,10 +10,10 @@ void PreparePage()
|
||||
dword stroka=0;
|
||||
int i, srch_pos;
|
||||
|
||||
font.changeSIZE();
|
||||
label.changeSIZE();
|
||||
list.w = Form.cwidth-scroll.size_x-1;
|
||||
//get font chars width, need to increase performance
|
||||
for (i=0; i<256; i++) char_width[i] = font.symbol_size(i);
|
||||
for (i=0; i<256; i++) char_width[i] = label.symbol_size(i);
|
||||
//get font buffer height
|
||||
for (bufoff=io.buffer_data; ESBYTE[bufoff]; bufoff++)
|
||||
{
|
||||
@ -34,11 +34,11 @@ void PreparePage()
|
||||
}
|
||||
//draw text in buffer
|
||||
list.count = stroka+2;
|
||||
list.SetSizes(0, TOOLBAR_H, list.w, Form.cheight-TOOLBAR_H, font.size.text+1);
|
||||
list.SetSizes(0, TOOLBAR_H, list.w, Form.cheight-TOOLBAR_H, label.size.pt+1);
|
||||
if (list.count < list.visible) list.count = list.visible;
|
||||
|
||||
font.size.height = list.count+1*list.item_h;
|
||||
font.buffer_size = 0;
|
||||
label.size.height = list.count+1*list.item_h;
|
||||
label.raw_size = 0;
|
||||
|
||||
line_length = 30;
|
||||
line_start = io.buffer_data;
|
||||
@ -58,13 +58,13 @@ void PreparePage()
|
||||
}
|
||||
i = bufoff-line_start;
|
||||
strlcpy(#line, line_start, i);
|
||||
font.write_buf(8,stroka_y,list.w,font.size.height, #line);
|
||||
label.write_buf(8,stroka_y,list.w,label.size.height, 0xFFFFFF, 0, label.size.pt, #line);
|
||||
stroka_y += list.item_h;
|
||||
line_start = bufoff;
|
||||
line_length = 30;
|
||||
}
|
||||
}
|
||||
font.write_buf(8,stroka_y,list.w,font.size.height, line_start);
|
||||
font.apply_smooth();
|
||||
label.write_buf(8,stroka_y,list.w,label.size.height, 0xFFFFFF, 0, label.size.pt, line_start);
|
||||
label.apply_smooth();
|
||||
DrawPage();
|
||||
}
|
||||
|
@ -15,11 +15,10 @@
|
||||
#define TOOLBAR_ICON_WIDTH 26
|
||||
#define TOOLBAR_ICON_HEIGHT 24
|
||||
|
||||
#define DEFAULT_FONT "/sys/fonts/Tahoma.kf"
|
||||
#define DEFAULT_EDITOR "/sys/tinypad"
|
||||
|
||||
#define INTRO_TEXT "This is a plain Text Reader.\nTry to open some text file."
|
||||
#define VERSION "Text Reader v1.04"
|
||||
#define VERSION "Text Reader v1.05"
|
||||
#define ABOUT "Idea: Leency, punk_joker
|
||||
Code: Leency, Veliant, KolibriOS Team
|
||||
|
||||
@ -71,24 +70,11 @@ void InitDlls()
|
||||
|
||||
void main()
|
||||
{
|
||||
InitDlls();
|
||||
|
||||
InitDlls();
|
||||
OpenDialog_init stdcall (#o_dialog);
|
||||
|
||||
font.color = 0;
|
||||
font.bg_color = 0xFFFFFF;
|
||||
|
||||
font.load(DEFAULT_FONT);
|
||||
|
||||
if (!font.data) {
|
||||
io.run("/sys/@notify","'Error: Font is not loaded.' -E");
|
||||
ExitProcess();
|
||||
}
|
||||
|
||||
label.init(DEFAULT_FONT);
|
||||
Libimg_LoadImage(#skin, abspath("toolbar.png"));
|
||||
|
||||
LoadIniSettings();
|
||||
|
||||
OpenFile(#param);
|
||||
list.no_selection = true;
|
||||
SetEventMask(10000000000000000000000001100111b);
|
||||
@ -215,18 +201,18 @@ void EventOpenFile()
|
||||
|
||||
void EventMagnifyPlus()
|
||||
{
|
||||
font.size.text++;
|
||||
if(!font.changeSIZE())
|
||||
font.size.text--;
|
||||
label.size.pt++;
|
||||
if(!label.changeSIZE())
|
||||
label.size.pt--;
|
||||
else
|
||||
PreparePage();
|
||||
}
|
||||
|
||||
void EventMagnifyMinus()
|
||||
{
|
||||
font.size.text--;
|
||||
if(!font.changeSIZE())
|
||||
font.size.text++;
|
||||
label.size.pt--;
|
||||
if(!label.changeSIZE())
|
||||
label.size.pt++;
|
||||
else
|
||||
PreparePage();
|
||||
}
|
||||
@ -303,6 +289,6 @@ void draw_window()
|
||||
|
||||
void DrawPage()
|
||||
{
|
||||
_PutImage(list.x,list.y,list.w,list.h,list.first*list.item_h*list.w*3 + font.buffer);
|
||||
_PutImage(list.x,list.y,list.w,list.h,list.first*list.item_h*list.w*3 + label.raw);
|
||||
DrawScroller();
|
||||
}
|
Loading…
Reference in New Issue
Block a user