2015-09-02 15:15:32 +02:00
# define MEMSIZE 0x2EE80
2015-08-27 10:33:51 +02:00
2016-12-21 16:40:39 +01:00
# include "../lib/kfont.h"
2015-08-27 10:33:51 +02:00
# include "../lib/gui.h"
2018-04-11 20:32:00 +02:00
# define PANELH 28
# define WIN_W 490
# define WIN_H 315
2016-02-20 14:06:19 +01:00
proc_info Form ;
enum {
PHRASE_TAB = 20 , CHARS_TAB
} ;
2018-04-11 20:32:00 +02:00
_tabs tabs = { 0 , 0 , WIN_W , WIN_H , PHRASE_TAB } ;
2018-04-16 00:44:36 +02:00
block preview = { 0 , PANELH , WIN_W , WIN_H - PANELH } ;
2018-04-19 22:12:07 +02:00
checkbox bold = { " Bold " , false } ;
checkbox smooth = { " Smooth " , true } ;
2015-09-02 15:15:32 +02:00
2015-08-27 10:33:51 +02:00
void main ( )
{
2016-02-20 14:06:19 +01:00
int btn ;
char title [ 4196 ] ;
2015-12-17 20:15:49 +01:00
if ( ! param ) strcpy ( # param , DEFAULT_FONT ) ;
2016-12-21 20:50:13 +01:00
kfont . init ( # param ) ;
2015-11-06 15:49:37 +01:00
strcpy ( # title , " Font preview: " ) ;
2015-08-27 10:33:51 +02:00
strcat ( # title , # param ) ;
2016-02-20 14:06:19 +01:00
loop ( ) switch ( WaitEvent ( ) )
2015-08-27 10:33:51 +02:00
{
case evButton :
btn = GetButtonID ( ) ;
if ( btn = = 1 ) ExitProcess ( ) ;
2018-04-19 22:12:07 +02:00
if ( bold . click ( btn ) ) kfont . bold = bold . checked ;
if ( smooth . click ( btn ) ) kfont . smooth = smooth . checked ;
2016-02-20 14:06:19 +01:00
if ( btn = = PHRASE_TAB ) | | ( btn = = CHARS_TAB ) tabs . click ( btn ) ;
2015-09-02 15:15:32 +02:00
goto _DRAW_WINDOW_CONTENT ;
2015-08-27 10:33:51 +02:00
case evReDraw :
2016-02-11 14:46:53 +01:00
system . color . get ( ) ;
2018-04-11 20:32:00 +02:00
DefineAndDrawWindow ( 215 , 100 , WIN_W + 9 , WIN_H + skin_height + 5 , 0x74 , 0xFFFFFF , # title , 0 ) ;
2015-09-02 15:15:32 +02:00
GetProcessInfo ( # Form , SelfInfo ) ;
2015-12-18 22:10:45 +01:00
if ( Form . status_window > 2 ) break ;
2015-09-02 15:15:32 +02:00
_DRAW_WINDOW_CONTENT :
2018-04-11 20:32:00 +02:00
2016-02-20 14:06:19 +01:00
DrawBar ( 0 , 0 , Form . cwidth , PANELH - 1 , system . color . work ) ;
2018-04-11 20:32:00 +02:00
DrawBar ( 0 , PANELH - 1 , Form . cwidth , 1 , system . color . work_graph ) ;
2018-04-19 22:12:07 +02:00
bold . draw ( 10 , 8 ) ;
smooth . draw ( 83 , 8 ) ;
2018-04-11 20:32:00 +02:00
tabs . draw_button ( Form . cwidth - 130 , PHRASE_TAB , " Phrase " ) ;
tabs . draw_button ( Form . cwidth - 60 , CHARS_TAB , " Chars " ) ;
2016-12-21 20:50:13 +01:00
if ( ! kfont . font )
2015-08-27 10:33:51 +02:00
{
2018-04-11 20:32:00 +02:00
DrawBar ( preview . x , preview . y , preview . w , preview . h , 0xFFFfff ) ;
2015-12-17 20:15:49 +01:00
WriteText ( 10 , 50 , 0x82 , 0xFF00FF , " Font is not loaded. " ) ;
2016-02-20 14:06:19 +01:00
break ;
2015-09-02 15:15:32 +02:00
}
2016-02-20 14:06:19 +01:00
if ( tabs . active_tab = = PHRASE_TAB ) DrawPreviewPhrase ( ) ;
if ( tabs . active_tab = = CHARS_TAB ) DrawPreviewChars ( ) ;
}
}
void DrawPreviewPhrase ( )
{
dword i , y ;
char line [ 256 ] ;
2016-12-21 20:50:13 +01:00
kfont . raw_size = free ( kfont . raw ) ;
for ( i = 10 , y = 5 ; i < 22 ; i + + , y + = kfont . height ; ) //not flexible, need to calculate font count and max line length
2016-02-20 14:06:19 +01:00
{
sprintf ( # line , " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> /size font %d <20> <> <EFBFBD> ᥫ<EFBFBD> <E1A5AB> ." , i ) ;
2016-12-21 20:50:13 +01:00
kfont . WriteIntoBuffer ( 10 , y , Form . cwidth , Form . cheight - PANELH , 0xFFFFFF , 0 , i , # line ) ;
2016-02-20 14:06:19 +01:00
}
2016-12-21 20:50:13 +01:00
if ( kfont . smooth ) kfont . ApplySmooth ( ) ;
2018-04-11 20:32:00 +02:00
kfont . ShowBuffer ( preview . x , preview . y ) ;
2016-02-20 14:06:19 +01:00
}
void DrawPreviewChars ( )
{
dword i , x = 20 , y = 0 ;
char line [ 2 ] ;
line [ 1 ] = NULL ;
2016-12-21 20:50:13 +01:00
kfont . raw_size = free ( kfont . raw ) ;
2016-02-20 14:06:19 +01:00
for ( i = 0 ; i < 255 ; i + + ) //not flexible, need to calculate font count and max line length
{
line [ 0 ] = i ;
2016-12-21 20:50:13 +01:00
kfont . WriteIntoBuffer ( x , y , Form . cwidth , Form . cheight - PANELH , 0xFFFFFF , 0 , 16 , # line ) ;
x + = kfont . height + 2 ;
2018-04-11 20:32:00 +02:00
if ( x > = preview . w - 30 ) {
2016-02-20 14:06:19 +01:00
x = 20 ;
2016-12-21 20:50:13 +01:00
y + = kfont . height + 2 ;
2016-02-20 14:06:19 +01:00
}
2015-08-27 10:33:51 +02:00
}
2016-12-21 20:50:13 +01:00
if ( kfont . smooth ) kfont . ApplySmooth ( ) ;
2018-04-11 20:32:00 +02:00
kfont . ShowBuffer ( preview . x , preview . y ) ;
2015-08-27 10:33:51 +02:00
}