Commits:
-
3cc67019
by Alexei Podtelezhnikov at 2023-01-27T23:14:54-05:00
* graph/win32/grwin32.c (key_translators): Sort virtual-key codes.
-
ab74662d
by Alexei Podtelezhnikov at 2023-01-27T23:30:25-05:00
* src/ftstring.c (event_render_mode_change): Remove report.
-
4028f9ac
by Alexei Podtelezhnikov at 2023-01-27T23:38:26-05:00
[ftstring] New feature: simple string editor.
It only handles printable ASCII characters and backspace to erase them.
* src/ftstring.c (Process_Event): Use Enter key to initiate this mode.
(Process_TTY): Intercept and handle relevant keys while editing.
(Render_TTY): Special rendering mode while editing.
(main, event_help): Updated.
2 changed files:
Changes:
graph/win32/grwin32.c
... |
... |
@@ -70,14 +70,14 @@ |
70
|
70
|
static
|
71
|
71
|
Translator key_translators[] =
|
72
|
72
|
{
|
|
73
|
+ { VK_PRIOR, grKeyPageUp },
|
|
74
|
+ { VK_NEXT, grKeyPageDown },
|
|
75
|
+ { VK_END, grKeyEnd },
|
73
|
76
|
{ VK_HOME, grKeyHome },
|
74
|
77
|
{ VK_LEFT, grKeyLeft },
|
75
|
78
|
{ VK_UP, grKeyUp },
|
76
|
79
|
{ VK_RIGHT, grKeyRight },
|
77
|
80
|
{ VK_DOWN, grKeyDown },
|
78
|
|
- { VK_PRIOR, grKeyPageUp },
|
79
|
|
- { VK_NEXT, grKeyPageDown },
|
80
|
|
- { VK_END, grKeyEnd },
|
81
|
81
|
{ VK_F1, grKeyF1 },
|
82
|
82
|
{ VK_F2, grKeyF2 },
|
83
|
83
|
{ VK_F3, grKeyF3 },
|
src/ftstring.c
... |
... |
@@ -81,7 +81,8 @@ |
81
|
81
|
RENDER_MODE_TEXT,
|
82
|
82
|
RENDER_MODE_WATERFALL,
|
83
|
83
|
RENDER_MODE_KERNCMP,
|
84
|
|
- N_RENDER_MODES
|
|
84
|
+ N_RENDER_MODES,
|
|
85
|
+ RENDER_FLAG_TTY = 8
|
85
|
86
|
};
|
86
|
87
|
|
87
|
88
|
static struct status_
|
... |
... |
@@ -258,8 +259,7 @@ |
258
|
259
|
|
259
|
260
|
grWriteln( buf );
|
260
|
261
|
grLn();
|
261
|
|
- grWriteln( "This program is used to display a string of text using" );
|
262
|
|
- grWriteln( "the new convenience API of the FreeType 2 library." );
|
|
262
|
+ grWriteln( "This program is used to display a text string." );
|
263
|
263
|
grLn();
|
264
|
264
|
grWriteln( "Use the following keys :" );
|
265
|
265
|
grLn();
|
... |
... |
@@ -269,6 +269,7 @@ |
269
|
269
|
grWriteln( " f : toggle forced auto-hinting" );
|
270
|
270
|
grWriteln( " h : toggle outline hinting" );
|
271
|
271
|
grWriteln( " H : change hinting engine" );
|
|
272
|
+ grWriteln( " V : toggle vertical rendering" );
|
272
|
273
|
grLn();
|
273
|
274
|
grWriteln( " 1-4 : select rendering mode" );
|
274
|
275
|
grWriteln( " l : cycle through anti-aliasing modes" );
|
... |
... |
@@ -276,7 +277,7 @@ |
276
|
277
|
grWriteln( " t : cycle through kerning degrees" );
|
277
|
278
|
grWriteln( " Space : cycle through color" );
|
278
|
279
|
grWriteln( " Tab : cycle through sample strings" );
|
279
|
|
- grWriteln( " V : toggle vertical rendering" );
|
|
280
|
+ grWriteln( " Enter : toggle simple string editor" );
|
280
|
281
|
grLn();
|
281
|
282
|
grWriteln( " g, v : adjust gamma by 0.1" );
|
282
|
283
|
grLn();
|
... |
... |
@@ -464,17 +465,36 @@ |
464
|
465
|
if ( status.render_mode < 0 )
|
465
|
466
|
status.render_mode += N_RENDER_MODES;
|
466
|
467
|
}
|
|
468
|
+ }
|
467
|
469
|
|
468
|
|
- switch ( status.render_mode )
|
469
|
|
- {
|
470
|
|
- case RENDER_MODE_KERNCMP:
|
471
|
|
- status.header = "Kerning comparison";
|
472
|
|
- break;
|
473
|
470
|
|
474
|
|
- default:
|
475
|
|
- status.header = NULL;
|
476
|
|
- break;
|
|
471
|
+ static int
|
|
472
|
+ Process_TTY( grKey key )
|
|
473
|
+ {
|
|
474
|
+ static char buffer[32] = "Edit this text";
|
|
475
|
+ static int cursor = 14;
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+ if ( key == grKeyReturn )
|
|
479
|
+ status.render_mode ^= RENDER_FLAG_TTY;
|
|
480
|
+ else if ( key == grKeyBackSpace )
|
|
481
|
+ {
|
|
482
|
+ if ( cursor )
|
|
483
|
+ buffer[--cursor] = '\0';
|
|
484
|
+ }
|
|
485
|
+ else if ( 31 < key && key < 127 )
|
|
486
|
+ {
|
|
487
|
+ if ( cursor < 31)
|
|
488
|
+ buffer[cursor++] = key;
|
477
|
489
|
}
|
|
490
|
+ else if ( key != grKeyTab )
|
|
491
|
+ return 0;
|
|
492
|
+
|
|
493
|
+ snprintf( status.header_buffer, sizeof ( status.header_buffer ),
|
|
494
|
+ "TTY mode [%s%*c]", buffer, cursor - 32, '_' );
|
|
495
|
+
|
|
496
|
+ FTDemo_String_Set( handle, buffer );
|
|
497
|
+ return 1;
|
478
|
498
|
}
|
479
|
499
|
|
480
|
500
|
|
... |
... |
@@ -497,6 +517,10 @@ |
497
|
517
|
return ret;
|
498
|
518
|
}
|
499
|
519
|
|
|
520
|
+ if ( status.render_mode & RENDER_FLAG_TTY &&
|
|
521
|
+ Process_TTY( event.key ) )
|
|
522
|
+ goto String;
|
|
523
|
+
|
500
|
524
|
if ( event.key >= '1' && event.key < '1' + N_RENDER_MODES )
|
501
|
525
|
{
|
502
|
526
|
status.render_mode = (int)( event.key - '1' );
|
... |
... |
@@ -512,6 +536,10 @@ |
512
|
536
|
ret = 1;
|
513
|
537
|
goto Exit;
|
514
|
538
|
|
|
539
|
+ case grKeyReturn:
|
|
540
|
+ Process_TTY( event.key );
|
|
541
|
+ goto String;
|
|
542
|
+
|
515
|
543
|
case grKeyF1:
|
516
|
544
|
case grKEY( '?' ):
|
517
|
545
|
event_help();
|
... |
... |
@@ -778,6 +806,29 @@ |
778
|
806
|
}
|
779
|
807
|
|
780
|
808
|
|
|
809
|
+ static void
|
|
810
|
+ Render_TTY( void )
|
|
811
|
+ {
|
|
812
|
+ FT_Size size;
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+ /* check the sizing error */
|
|
816
|
+ error = FTDemo_Get_Size( handle, &size );
|
|
817
|
+ if ( error )
|
|
818
|
+ return;
|
|
819
|
+
|
|
820
|
+ FTDemo_String_Draw( handle, display,
|
|
821
|
+ &status.sc,
|
|
822
|
+ FT_MulFix( display->bitmap->width, status.sc.center),
|
|
823
|
+ display->bitmap->rows / 2 );
|
|
824
|
+
|
|
825
|
+ /* this was prepared in Process_TTY */
|
|
826
|
+ status.header = status.header_buffer;
|
|
827
|
+
|
|
828
|
+ return;
|
|
829
|
+ }
|
|
830
|
+
|
|
831
|
+
|
781
|
832
|
static void
|
782
|
833
|
Render_String( void )
|
783
|
834
|
{
|
... |
... |
@@ -1018,6 +1069,10 @@ |
1018
|
1069
|
case RENDER_MODE_KERNCMP:
|
1019
|
1070
|
Render_KernCmp();
|
1020
|
1071
|
break;
|
|
1072
|
+
|
|
1073
|
+ default:
|
|
1074
|
+ Render_TTY();
|
|
1075
|
+ break;
|
1021
|
1076
|
}
|
1022
|
1077
|
|
1023
|
1078
|
write_header( error );
|
|