-
Notifications
You must be signed in to change notification settings - Fork 52
/
editor.c
1738 lines (1581 loc) · 77.5 KB
/
editor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//--------------------------------------------------------------
// File name: editor.c
//--------------------------------------------------------------
#include "launchelf.h"
enum {
COL_NORM_BG = GS_SETREG_RGBA(160, 160, 160, 0),
COL_NORM_TEXT = GS_SETREG_RGBA(0, 0, 0, 0),
COL_MARK_BG = GS_SETREG_RGBA(0, 40, 160, 0),
COL_MARK_TEXT = GS_SETREG_RGBA(160, 160, 160, 0),
COL_CUR_INSERT = GS_SETREG_RGBA(0, 160, 0, 0),
COL_CUR_OVERWR = GS_SETREG_RGBA(160, 0, 0, 0),
COL_LINE_END = GS_SETREG_RGBA(160, 80, 0, 0),
COL_TAB = GS_SETREG_RGBA(0, 0, 160, 0),
COL_TEXT_END = GS_SETREG_RGBA(0, 160, 160, 0),
COL_dummy
};
enum {
NEW,
OPEN,
CLOSE,
SAVE,
SAVE_AS,
WINDOWS,
EXIT,
NUM_MENU
}; // Menu Fonction.
enum {
MARK_START,
MARK_ON,
MARK_COPY,
MARK_CUT,
MARK_IN,
MARK_OUT,
MARK_TMP,
MARK_SIZE,
MARK_PRINT,
MARK_COLOR,
NUM_MARK
}; // Marking Fonction/State.
enum {
CREATED,
OPENED,
SAVED,
NUM_STATE
}; // Windowing State.
#define OTHER 1 // CR/LF Return Text Mode, 'All Normal System'.
#define UNIX 2 // CR Return Text Mode, Unix.
#define MAC 3 // LF Return Text Mode, Mac.
#define TMP 10 // Temp Buffer For Add / Remove Char.
#define EDIT 11 // Edit Buffer For Copy / Cut / Paste.
static char *TextBuffer[12]; // Text Buffers, 10 Windows Max + 1 TMP + 1 EDIT. See above.
static int Window[10][NUM_STATE], // Windowing System, 10 Windows Max.
TextMode[10], // Text Mode, UNIX, MAC, OTHER.
TextSize[10], // Text Size, 10 Windows Max.
Editor_nRowsWidth[MAX_ENTRY], // Current Window, Char Number For Each Rows. (MAX_ENTRY???)
Mark[NUM_MARK], // Marking System,(Mark, Copy, Cut, Paste, Delete),Work From 1 Window To An Other.
Active_Window, // Activated Windows Number.
Num_Window, // Opened Windows Count.
Editor_Cur, // Text Cursor.
Tmp_Cur, // Temp Cursor For Rules Calculations.
Editor_nChar, // Current Window, Total Char Number.
Editor_nRowsNum, // Current Window, Total Rows Number.
Editor_nCharRows, // Current Window, Char Number Per Rows Height.
Editor_nRowsTop, // Current Window, Rows Number Above Top Screen For Rules Calculations.
Rows_Num, // Rows Number Feeting In Screen Height.
Rows_Width, // Char Number Feeting In Screen Width.
Top_Width, // Char Number In Rows Above Top Screen.
Top_Height, // Current Window Rows Number Above Top Screen.
Editor_Insert, // Setting Insert On/Off.
Editor_RetMode, // Setting Insert On/Off.
Editor_Home, // Goto Line Home.
Editor_End, // Goto Line End
Editor_PushRows, // Push 1 Row Height Up(+1) Or Down(-1), Use For Page Up/Down Too.
Editor_TextEnd, // Set To 1 When '\0' Char Is Found Tell Text End.
KeyBoard_Cur, // Virtual KeyBoard Cursor.
KeyBoard_Active, // Virtual KeyBoard Activated Or Not.
del1, del2, del3, del4, // Deleted Chars Different Cases.
ins1, ins2, ins3, ins4, ins5, // Added Chars Different Cases.
t; // Text Cursor Timer.
static char Path[10][MAX_PATH]; // File Path For Each Opened Windows. 10 Max.
static const int WFONTS = 20, // Virtual KeyBoard Width.
HFONTS = 5; // Virtual KeyBoard Height.
static char *KEY = " 01ABCDEFGHIJKLM:; "
" 23NOPQRSTUVWXYZ., "
" 45abcdefghijklm() "
" 67nopqrstuvwxyz[] "
" 89+-=!#\\/?$%&@_^' "; // Virtual KeyBoard Matrix.
// Function Prototypes
static int MenuEditor(void);
static void Virt_KeyBoard_Entry(void);
static int KeyBoard_Entry(void);
static void Editor_Rules(void);
static int Windows_Selector(void);
static void Init(void);
static int New(int Win);
static int OpenFile(int Win);
static int Open(int Win, const char *path);
static void Close(int Win);
static void Save(int Win);
static void Save_As(int Win);
//--------------------------------------------------------------
static int MenuEditor(void)
{
u64 color;
char enable[NUM_MENU], tmp[64];
int x, y, i, Menu_Sel;
int event, post_event = 0;
int menu_len = strlen(LNG(New)) > strlen(LNG(Open)) ?
strlen(LNG(New)) :
strlen(LNG(Open));
menu_len = strlen(LNG(Close)) > menu_len ? strlen(LNG(Close)) : menu_len;
menu_len = strlen(LNG(Save)) > menu_len ? strlen(LNG(Save)) : menu_len;
menu_len = strlen(LNG(Save_As)) > menu_len ? strlen(LNG(Save_As)) : menu_len;
menu_len = strlen(LNG(Windows)) > menu_len ? strlen(LNG(Windows)) : menu_len;
menu_len = strlen(LNG(Exit)) > menu_len ? strlen(LNG(Exit)) : menu_len;
int menu_ch_w = menu_len + 1; // Total characters in longest menu string.
int menu_ch_h = NUM_MENU; // Total number of menu lines.
int mSprite_Y1 = 64; // Top edge of sprite.
int mSprite_X2 = SCREEN_WIDTH - 35; // Right edge of sprite.
int mSprite_X1 = mSprite_X2 - (menu_ch_w + 3) * FONT_WIDTH; // Left edge of sprite
int mSprite_Y2 = mSprite_Y1 + (menu_ch_h + 1) * FONT_HEIGHT; // Bottom edge of sprite
memset(enable, TRUE, NUM_MENU);
if (!Window[Active_Window][OPENED]) {
enable[CLOSE] = FALSE;
enable[SAVE] = FALSE;
enable[SAVE_AS] = FALSE;
}
if (Window[Active_Window][CREATED]) {
enable[SAVE] = FALSE;
}
if (!Num_Window)
enable[WINDOWS] = FALSE;
for (Menu_Sel = 0; Menu_Sel < NUM_MENU; Menu_Sel++)
if (enable[Menu_Sel] == TRUE)
break;
event = 1; // event = initial entry.
while (1) {
// Pad response section.
waitPadReady(0, 0);
if (readpad()) {
if (new_pad & PAD_UP && Menu_Sel < NUM_MENU) {
event |= 2; // event |= valid pad command.
do {
Menu_Sel--;
if (Menu_Sel < 0)
Menu_Sel = NUM_MENU - 1;
} while (!enable[Menu_Sel]);
} else if (new_pad & PAD_DOWN && Menu_Sel < NUM_MENU) {
event |= 2; // event |= valid pad command.
do {
Menu_Sel++;
if (Menu_Sel == NUM_MENU)
Menu_Sel = 0;
} while (!enable[Menu_Sel]);
} else if ((new_pad & PAD_TRIANGLE) || (!swapKeys && new_pad & PAD_CROSS) || (swapKeys && new_pad & PAD_CIRCLE)) {
return -1;
} else if ((swapKeys && new_pad & PAD_CROSS) || (!swapKeys && new_pad & PAD_CIRCLE)) {
break;
}
}
if (event || post_event) { // NB: We need to update two frame buffers per event.
// Display section.
drawPopSprite(setting->color[COLOR_BACKGR],
mSprite_X1, mSprite_Y1,
mSprite_X2, mSprite_Y2);
drawFrame(mSprite_X1, mSprite_Y1, mSprite_X2, mSprite_Y2, setting->color[COLOR_FRAME]);
for (i = 0, y = mSprite_Y1 + FONT_HEIGHT / 2; i < NUM_MENU; i++) {
if (i == NEW)
strcpy(tmp, LNG(New));
else if (i == OPEN)
strcpy(tmp, LNG(Open));
else if (i == CLOSE)
strcpy(tmp, LNG(Close));
else if (i == SAVE)
strcpy(tmp, LNG(Save));
else if (i == SAVE_AS)
strcpy(tmp, LNG(Save_As));
else if (i == WINDOWS)
strcpy(tmp, LNG(Windows));
else if (i == EXIT)
strcpy(tmp, LNG(Exit));
if (enable[i])
color = setting->color[COLOR_TEXT];
else
color = setting->color[COLOR_FRAME];
printXY(tmp, mSprite_X1 + 2 * FONT_WIDTH, y, color, TRUE, 0);
y += FONT_HEIGHT;
}
if (Menu_Sel < NUM_MENU)
drawChar(LEFT_CUR, mSprite_X1 + FONT_WIDTH, mSprite_Y1 + (FONT_HEIGHT / 2 + Menu_Sel * FONT_HEIGHT), setting->color[COLOR_TEXT]);
// Tooltip section.
x = SCREEN_MARGIN;
y = Menu_tooltip_y;
drawSprite(setting->color[COLOR_BACKGR],
0, y - 1,
SCREEN_WIDTH, y + 16);
if (swapKeys)
sprintf(tmp, "\xFF"
"1:%s \xFF"
"0:%s \xFF"
"3:%s",
LNG(OK), LNG(Cancel), LNG(Back));
else
sprintf(tmp, "\xFF"
"0:%s \xFF"
"1:%s \xFF"
"3:%s",
LNG(OK), LNG(Cancel), LNG(Back));
printXY(tmp, x, y, setting->color[COLOR_SELECT], TRUE, 0);
} // ends if(event||post_event).
drawScr();
post_event = event;
event = 0;
} // ends while.
return Menu_Sel;
} // ends menu.
//--------------------------------------------------------------
static void Virt_KeyBoard_Entry(void)
{
int i, Operation;
Operation = 0;
if (new_pad & PAD_UP) { // Virtual KeyBoard move up.
if (!KeyBoard_Cur)
KeyBoard_Cur = WFONTS * (HFONTS - 1);
else if (KeyBoard_Cur == WFONTS - 1)
KeyBoard_Cur = WFONTS * HFONTS - 1;
else if (KeyBoard_Cur > 0) {
if ((KeyBoard_Cur -= WFONTS) < 0)
KeyBoard_Cur = 0;
}
// ends Virtual KeyBoard move up.
} else if (new_pad & PAD_DOWN) { // Virtual KeyBoard move down.
if (KeyBoard_Cur == WFONTS * HFONTS - 1)
KeyBoard_Cur = WFONTS - 1;
else if (KeyBoard_Cur == WFONTS * (HFONTS - 1))
KeyBoard_Cur = 0;
else if (KeyBoard_Cur < WFONTS * HFONTS - 1) {
if ((KeyBoard_Cur += WFONTS) > WFONTS * HFONTS - 1)
KeyBoard_Cur = WFONTS * HFONTS - 1;
}
// ends Virtual KeyBoard move down.
} else if (new_pad & PAD_LEFT) { // Virtual KeyBoard move left.
if (!KeyBoard_Cur)
KeyBoard_Cur = WFONTS * HFONTS - 1;
else
KeyBoard_Cur--;
// ends Virtual KeyBoard move left.
} else if (new_pad & PAD_RIGHT) { // Virtual KeyBoard move right.
if (KeyBoard_Cur == WFONTS * HFONTS - 1)
KeyBoard_Cur = 0;
else
KeyBoard_Cur++;
// ends Virtual KeyBoard move right.
} else if (new_pad & PAD_L2) { // Text move left.
if (Editor_Cur > 0)
Editor_Cur--;
} else if (new_pad & PAD_R2) { // Text move right.
if (Editor_Cur < Editor_nChar && TextBuffer[Active_Window][Editor_Cur] != '\0')
Editor_Cur++;
} else if (new_pad & PAD_SELECT) { // Virtual KeyBoard Exit.
Rows_Num += 6;
KeyBoard_Active = 0;
} else if ((!swapKeys && new_pad & PAD_CROSS) || (swapKeys && new_pad & PAD_CIRCLE)) { // Virtual KeyBoard Backspace
if (Editor_Cur > 0) {
if (TextMode[Active_Window] == OTHER && TextBuffer[Active_Window][Editor_Cur] == '\n' && TextBuffer[Active_Window][Editor_Cur - 1] == '\r') {
Editor_Cur += 1; // Backspace at LF of CRLF must work after LF instead
}
if (Mark[MARK_ON]) {
Mark[MARK_OUT] = Editor_Cur;
if (Mark[MARK_OUT] < Mark[MARK_IN]) {
Mark[MARK_TMP] = Mark[MARK_IN];
Mark[MARK_IN] = Mark[MARK_OUT];
Mark[MARK_OUT] = Mark[MARK_TMP];
} else if (Mark[MARK_IN] == Mark[MARK_OUT])
goto abort;
Mark[MARK_SIZE] = Mark[MARK_OUT] - Mark[MARK_IN];
del1 = -Mark[MARK_SIZE], del2 = 0, del3 = -Mark[MARK_SIZE], del4 = -Mark[MARK_SIZE];
Mark[MARK_ON] = 0;
} else if (TextMode[Active_Window] == OTHER && TextBuffer[Active_Window][Editor_Cur - 1] == '\n' && Editor_Cur > 1 && TextBuffer[Active_Window][Editor_Cur - 2] == '\r') {
del1 = -2, del2 = 0, del3 = -2, del4 = -2; // Backspace CRLF
} else {
del1 = -1, del2 = 0, del3 = -1, del4 = -1; // Backspace single char
}
Operation = -1;
}
// ends Virtual KeyBoard Backspace
} else if ((swapKeys && new_pad & PAD_CROSS) || (!swapKeys && new_pad & PAD_CIRCLE)) { // Virtual KeyBoard Select.
if (!KeyBoard_Cur) { // Virtual KeyBoard MARK.
Mark[MARK_ON] = !Mark[MARK_ON];
if (Mark[MARK_ON]) {
if (TextMode[Active_Window] == OTHER && TextBuffer[Active_Window][Editor_Cur] == '\n' && Editor_Cur > 0 && TextBuffer[Active_Window][Editor_Cur - 1] == '\r') {
Editor_Cur -= 1; // Marking at LF of CRLF must start at CR instead
}
if (Mark[MARK_COPY] || Mark[MARK_CUT])
free(TextBuffer[EDIT]);
Mark[MARK_ON] = 1, Mark[MARK_COPY] = 0, Mark[MARK_CUT] = 0,
Mark[MARK_IN] = 0, Mark[MARK_OUT] = 0, Mark[MARK_TMP] = 0,
Mark[MARK_SIZE] = 0, Mark[MARK_PRINT] = 0, Mark[MARK_COLOR] = 0;
Mark[MARK_IN] = Mark[MARK_OUT] = Editor_Cur;
}
Mark[MARK_START] = 1;
// ends Virtual KeyBoard MARK.
} else if (KeyBoard_Cur == WFONTS) { // Virtual KeyBoard COPY.
if (Mark[MARK_ON]) {
if (TextMode[Active_Window] == OTHER && TextBuffer[Active_Window][Editor_Cur] == '\n' && Editor_Cur > 0 && TextBuffer[Active_Window][Editor_Cur - 1] == '\r') {
Editor_Cur += 1; // Mark end at LF of CRLF must include LF as well
}
Mark[MARK_OUT] = Editor_Cur;
if (Mark[MARK_OUT] < Mark[MARK_IN]) {
Mark[MARK_TMP] = Mark[MARK_IN];
Mark[MARK_IN] = Mark[MARK_OUT];
Mark[MARK_OUT] = Mark[MARK_TMP];
} else if (Mark[MARK_IN] == Mark[MARK_OUT])
goto abort;
if (Mark[MARK_COPY] || Mark[MARK_CUT])
free(TextBuffer[EDIT]);
Mark[MARK_SIZE] = Mark[MARK_OUT] - Mark[MARK_IN];
TextBuffer[EDIT] = malloc(Mark[MARK_SIZE] + 256); // 256 To Avoid Crash 256???
for (i = 0; i < Mark[MARK_SIZE]; i++)
TextBuffer[EDIT][i] = TextBuffer[Active_Window][i + Mark[MARK_IN]];
Mark[MARK_COPY] = 1, Mark[MARK_CUT] = 0, Mark[MARK_ON] = 0;
}
// ends Virtual KeyBoard COPY.
} else if (KeyBoard_Cur == 2 * WFONTS) { // Virtual KeyBoard CUT.
if (Mark[MARK_ON]) {
if (TextMode[Active_Window] == OTHER && TextBuffer[Active_Window][Editor_Cur] == '\n' && Editor_Cur > 0 && TextBuffer[Active_Window][Editor_Cur - 1] == '\r') {
Editor_Cur += 1; // Mark end at LF of CRLF must include LF as well
}
Mark[MARK_OUT] = Editor_Cur;
if (Mark[MARK_OUT] < Mark[MARK_IN]) {
Mark[MARK_TMP] = Mark[MARK_IN];
Mark[MARK_IN] = Mark[MARK_OUT];
Mark[MARK_OUT] = Mark[MARK_TMP];
} else if (Mark[MARK_IN] == Mark[MARK_OUT])
goto abort;
if (Mark[MARK_COPY] || Mark[MARK_CUT])
free(TextBuffer[EDIT]);
Mark[MARK_SIZE] = Mark[MARK_OUT] - Mark[MARK_IN];
TextBuffer[EDIT] = malloc(Mark[MARK_SIZE] + 256); // 256 To Avoid Crash 256???
for (i = 0; i < Mark[MARK_SIZE]; i++)
TextBuffer[EDIT][i] = TextBuffer[Active_Window][i + Mark[MARK_IN]];
del1 = -Mark[MARK_SIZE], del2 = 0, del3 = -Mark[MARK_SIZE], del4 = -Mark[MARK_SIZE];
Mark[MARK_CUT] = 1, Mark[MARK_COPY] = 0, Mark[MARK_ON] = 0;
Operation = -1;
}
abort:
Mark[MARK_TMP] = 0; // just for compiler warning.
// ends Virtual KeyBoard CUT.
} else if (KeyBoard_Cur == 3 * WFONTS) { // Virtual KeyBoard PASTE.
if (Mark[MARK_COPY] || Mark[MARK_CUT]) {
if (TextMode[Active_Window] == OTHER && TextBuffer[Active_Window][Editor_Cur] == '\n') {
Editor_Cur -= 1;
Mark[MARK_SIZE] -= 1;
}
ins1 = Mark[MARK_SIZE], ins2 = Mark[MARK_SIZE], ins3 = Mark[MARK_SIZE], ins4 = 0, ins5 = Mark[MARK_SIZE];
Operation = 1;
}
// ends Virtual KeyBoard PASTE.
} else if (KeyBoard_Cur == 4 * WFONTS) { // Virtual KeyBoard HOME.
Editor_Home = 1;
} else if (KeyBoard_Cur == 1) { // Virtual KeyBoard LINE UP.
if (Editor_Cur > 0)
Editor_PushRows++;
} else if (KeyBoard_Cur == WFONTS + 1) { // Virtual KeyBoard LINE DOWN.
if (Editor_Cur < Editor_nChar)
Editor_PushRows--;
} else if (KeyBoard_Cur == 2 * WFONTS + 1) { // Virtual KeyBoard PAGE UP.
if (Editor_Cur > 0)
Editor_PushRows += 1 * (Rows_Num - 1);
} else if (KeyBoard_Cur == 3 * WFONTS + 1) { // Virtual KeyBoard PAGE DOWN.
if (Editor_Cur < Editor_nChar && TextBuffer[Active_Window][Editor_Cur] != '\0')
Editor_PushRows -= 1 * (Rows_Num - 1);
} else if (KeyBoard_Cur == 4 * WFONTS + 1) { // Virtual KeyBoard END.
Editor_End = 1;
} else if (KeyBoard_Cur == WFONTS - 1) { // Virtual KeyBoard INSERT.
Editor_Insert = !Editor_Insert;
} else if (KeyBoard_Cur == 2 * WFONTS - 1) { // Virtual KeyBoard Return Mode CR/LF, LF, CR.
if ((Editor_RetMode++) >= 4)
Editor_RetMode = OTHER;
} else if (KeyBoard_Cur == 5 * WFONTS - 1) { // Virtual KeyBoard RETURN.
if (TextMode[Active_Window] == OTHER && TextBuffer[Active_Window][Editor_Cur] == '\n' && Editor_Cur > 0 && TextBuffer[Active_Window][Editor_Cur - 1] == '\r') {
Editor_Cur -= 1; // Entry at LF of CRLF must work at CR instead
}
if (Editor_Insert || TextBuffer[Active_Window][Editor_Cur] == '\0')
if (Editor_RetMode == OTHER)
ins1 = 2, ins2 = 0, ins3 = 2, ins4 = 0, ins5 = 2; // Insert CRLF
else
ins1 = 1, ins2 = 0, ins3 = 1, ins4 = 0, ins5 = 1; // Insert LF/CR
else if (TextMode[Active_Window] == OTHER && TextBuffer[Active_Window][Editor_Cur] == '\r' && TextBuffer[Active_Window][Editor_Cur + 1] == '\n') { // OWrite Return at CRLF
if (Editor_RetMode == OTHER)
ins1 = 0, ins2 = 0, ins3 = 2, ins4 = 2, ins5 = 2; // OWrite CRLF at CRLF
else
ins1 = 0, ins2 = 0, ins3 = 1, ins4 = 2, ins5 = 1; // OWrite LF/CR at CRLF
} else { // OWrite return at normal char
if (Editor_RetMode == OTHER)
ins1 = 1, ins2 = 0, ins3 = 2, ins4 = 1, ins5 = 2; // OWrite CRLF at char
else
ins1 = 0, ins2 = 0, ins3 = 1, ins4 = 1, ins5 = 1; // OWrite LF/CR at char
}
Operation = 2;
// ends Virtual KeyBoard RETURN.
} else { // Virtual KeyBoard Any other char + Space + Tabulation.
if (TextMode[Active_Window] == OTHER && TextBuffer[Active_Window][Editor_Cur] == '\n' && Editor_Cur > 0 && TextBuffer[Active_Window][Editor_Cur - 1] == '\r') {
Editor_Cur -= 1; // Entry at LF of CRLF must work at CR instead
}
if (Editor_Insert || TextBuffer[Active_Window][Editor_Cur] == '\0') {
ins1 = 1, ins2 = 0, ins3 = 1, ins4 = 0, ins5 = 1; // Insert char normally
} else {
if (TextMode[Active_Window] == OTHER && TextBuffer[Active_Window][Editor_Cur] == '\r' && TextBuffer[Active_Window][Editor_Cur + 1] == '\n') { // OWrite char at CRLF
ins1 = 0, ins2 = 0, ins3 = 1, ins4 = 2, ins5 = 1; // OWrite at CR of CRLF
} else { // OWrite return at normal char
ins1 = 0, ins2 = 0, ins3 = 1, ins4 = 1, ins5 = 1; // OWrite normal char
}
}
if (KeyBoard_Cur == 3 * WFONTS - 1) // Tabulation.
Operation = 3;
else if (KeyBoard_Cur == 4 * WFONTS - 1) // Space.
Operation = 4;
else // Any other char.
Operation = 5;
}
// ends Virtual KeyBoard Select.
}
if (Operation > 0) { // Perform Add Char / Paste. Can Be Simplify???
TextBuffer[TMP] = malloc(TextSize[Active_Window] + ins1 + 256); // 256 To Avoid Crash 256???
strcpy(TextBuffer[TMP], TextBuffer[Active_Window]);
// memset(TextBuffer[Active_Window], 0, TextSize[Active_Window]+256); // 256 To Avoid Crash 256??? free(TextBuffer[Active_Window]);
TextBuffer[Active_Window] = malloc(TextSize[Active_Window] + ins1 + 256); // 256 To Avoid Crash 256???
strcpy(TextBuffer[Active_Window], TextBuffer[TMP]);
}
switch (Operation) {
case 0:
break;
case -1: // Perform Del Char / Cut. Can Be Simplify???
TextBuffer[TMP] = malloc(TextSize[Active_Window] + 256); // 256 To Avoid Crash 256???
strcpy(TextBuffer[TMP], TextBuffer[Active_Window]);
TextBuffer[Active_Window][Editor_Cur + del1] = '\0';
strcat(TextBuffer[Active_Window], TextBuffer[TMP] + (Editor_Cur + del2));
strcpy(TextBuffer[TMP], TextBuffer[Active_Window]);
// memset(TextBuffer[Active_Window], 0, TextSize[Active_Window]+256); // 256 To Avoid Crash 256???
free(TextBuffer[Active_Window]);
TextBuffer[Active_Window] = malloc(TextSize[Active_Window] + del3 + 256); // 256 To Avoid Crash 256???
strcpy(TextBuffer[Active_Window], TextBuffer[TMP]);
// memset(TextBuffer[TMP], 0, TextSize[Active_Window]+256); // 256 To Avoid Crash 256???
free(TextBuffer[TMP]);
Editor_Cur += del3, TextSize[Active_Window] += del4;
t = 0;
break;
case 1: // Paste.
for (i = 0; i < ins2; i++)
TextBuffer[Active_Window][i + Editor_Cur] = TextBuffer[EDIT][i];
goto common;
case 2: // Return.
if (Editor_RetMode == OTHER) {
TextBuffer[Active_Window][Editor_Cur + ins2] = '\r';
TextBuffer[Active_Window][Editor_Cur + ins2 + 1] = '\n';
} else if (Editor_RetMode == UNIX) {
TextBuffer[Active_Window][Editor_Cur + ins2] = '\r';
} else if (Editor_RetMode == MAC) {
TextBuffer[Active_Window][Editor_Cur + ins2] = '\n';
}
goto common;
case 3: // Tabulation.
TextBuffer[Active_Window][Editor_Cur + ins2] = '\t';
goto common;
case 4: // Space.
TextBuffer[Active_Window][Editor_Cur + ins2] = ' ';
goto common;
case 5: // Any Char.
TextBuffer[Active_Window][Editor_Cur + ins2] = KEY[KeyBoard_Cur];
goto common;
common:
TextBuffer[Active_Window][Editor_Cur + ins3] = '\0';
strcat(TextBuffer[Active_Window], TextBuffer[TMP] + (Editor_Cur + ins4));
// memset(TextBuffer[TMP], 0, TextSize[Active_Window]+256); // 256 To Avoid Crash 256???
free(TextBuffer[TMP]);
Editor_Cur += ins5, TextSize[Active_Window] += ins1;
t = 0;
break;
}
}
//------------------------------
// endfunc Virt_KeyBoard_Entry
//--------------------------------------------------------------
static int KeyBoard_Entry(void)
{
int i, ret = 0, Operation;
char KeyPress;
Operation = 0;
if (PS2KbdRead(&KeyPress)) { // KeyBoard Response Section.
ret = 1; // Equal To event |= pad command.
if (KeyPress == PS2KBD_ESCAPE_KEY) {
PS2KbdRead(&KeyPress);
if (KeyPress)
t = 0;
if (KeyPress == 0x29) { // Key Right.
if (Editor_Cur < Editor_nChar && TextBuffer[Active_Window][Editor_Cur] != '\0')
Editor_Cur++;
} else if (KeyPress == 0x2A) { // Key Left.
if (Editor_Cur > 0)
Editor_Cur--;
} else if (KeyPress == 0x2C) { // Key Up.
if (Editor_Cur > 0)
Editor_PushRows++;
} else if (KeyPress == 0x2B) { // Key Down.
if (Editor_Cur < Editor_nChar && TextBuffer[Active_Window][Editor_Cur] != '\0')
Editor_PushRows--;
} else if (KeyPress == 0x24) // Key Home.
Editor_Home = 1;
else if (KeyPress == 0x27) // Key End.
Editor_End = 1;
else if (KeyPress == 0x25) { // Key PgUp.
if (Editor_Cur > 0)
Editor_PushRows += 1 * (Rows_Num - 1);
} else if (KeyPress == 0x28) { // Key PgDn.
if (Editor_Cur < Editor_nChar && TextBuffer[Active_Window][Editor_Cur] != '\0')
Editor_PushRows -= 1 * (Rows_Num - 1);
} else if (KeyPress == 0x23) // Key Insert.
Editor_Insert = !Editor_Insert;
else if (KeyPress == 0x26) { // Key Delete.
if (Editor_Cur < Editor_nChar) {
if (TextMode[Active_Window] == OTHER && TextBuffer[Active_Window][Editor_Cur] == '\n' && Editor_Cur > 0 && TextBuffer[Active_Window][Editor_Cur - 1] == '\r') {
Editor_Cur -= 1; // Delete at LF of CRLF must work at CR instead
}
if (Mark[MARK_ON]) {
Mark[MARK_OUT] = Editor_Cur;
if (Mark[MARK_OUT] < Mark[MARK_IN]) {
Mark[MARK_TMP] = Mark[MARK_IN];
Mark[MARK_IN] = Mark[MARK_OUT];
Mark[MARK_OUT] = Mark[MARK_TMP];
} else if (Mark[MARK_IN] == Mark[MARK_OUT])
goto abort;
Mark[MARK_SIZE] = Mark[MARK_OUT] - Mark[MARK_IN];
del1 = -Mark[MARK_SIZE], del2 = 0, del3 = -Mark[MARK_SIZE], del4 = -Mark[MARK_SIZE];
Mark[MARK_ON] = 0;
} else if (TextMode[Active_Window] == OTHER && TextBuffer[Active_Window][Editor_Cur] == '\r' && TextBuffer[Active_Window][Editor_Cur + 1] == '\n') { // Delete at CRLF
del1 = 0, del2 = 2, del3 = 0, del4 = -2; // delete CRLF
} else if (TextMode[Active_Window] == OTHER && TextBuffer[Active_Window][Editor_Cur] == '\n') {
del1 = -1, del2 = 1, del3 = -1, del4 = -2;
} else {
del1 = 0, del2 = 1, del3 = 0, del4 = -1; // delete single char
}
Operation = -1;
}
} else if (KeyPress == 0x01) { // Key F1 MENU.
ret = 2;
} else if (KeyPress == 0x1B) { // Key Escape EXIT Editor.
ret = 3;
}
} else {
if (KeyPress == 0x12) { // Key Ctrl+r Return Mode CR/LF Or LF Or CR.
if ((Editor_RetMode++) >= 4)
Editor_RetMode = OTHER;
} else if (KeyPress == 0x02) { // Key Ctrl+b MARK.
Mark[MARK_ON] = !Mark[MARK_ON];
if (Mark[MARK_ON]) {
if (TextMode[Active_Window] == OTHER && TextBuffer[Active_Window][Editor_Cur] == '\n' && Editor_Cur > 0 && TextBuffer[Active_Window][Editor_Cur - 1] == '\r') {
Editor_Cur -= 1; // Marking at LF of CRLF must start at CR instead
}
if (Mark[MARK_COPY] || Mark[MARK_CUT])
free(TextBuffer[EDIT]);
Mark[MARK_ON] = 1, Mark[MARK_COPY] = 0, Mark[MARK_CUT] = 0,
Mark[MARK_IN] = 0, Mark[MARK_OUT] = 0, Mark[MARK_TMP] = 0,
Mark[MARK_SIZE] = 0, Mark[MARK_PRINT] = 0, Mark[MARK_COLOR] = 0;
Mark[MARK_IN] = Mark[MARK_OUT] = Editor_Cur;
}
Mark[MARK_START] = 1;
// ends Key Ctrl+b MARK.
} else if (KeyPress == 0x03) { // Key Ctrl+c COPY.
if (TextMode[Active_Window] == OTHER && TextBuffer[Active_Window][Editor_Cur] == '\n' && Editor_Cur > 0 && TextBuffer[Active_Window][Editor_Cur - 1] == '\r') {
Editor_Cur += 1; // Mark end at LF of CRLF must include LF as well
}
if (Mark[MARK_ON]) {
Mark[MARK_OUT] = Editor_Cur;
if (Mark[MARK_OUT] < Mark[MARK_IN]) {
Mark[MARK_TMP] = Mark[MARK_IN];
Mark[MARK_IN] = Mark[MARK_OUT];
Mark[MARK_OUT] = Mark[MARK_TMP];
} else if (Mark[MARK_IN] == Mark[MARK_OUT])
goto abort;
if (Mark[MARK_COPY] || Mark[MARK_CUT])
free(TextBuffer[EDIT]);
Mark[MARK_SIZE] = Mark[MARK_OUT] - Mark[MARK_IN];
TextBuffer[EDIT] = malloc(Mark[MARK_SIZE] + 256); // 256 To Avoid Crash 256???
for (i = 0; i < Mark[MARK_SIZE]; i++)
TextBuffer[EDIT][i] = TextBuffer[Active_Window][i + Mark[MARK_IN]];
Mark[MARK_COPY] = 1, Mark[MARK_CUT] = 0, Mark[MARK_ON] = 0, Mark[MARK_TMP] = 0;
}
// ends Key Ctrl+c COPY.
} else if (KeyPress == 0x18) { // Key Ctrl+x CUT.
if (Mark[MARK_ON]) {
if (TextMode[Active_Window] == OTHER && TextBuffer[Active_Window][Editor_Cur] == '\n' && Editor_Cur > 0 && TextBuffer[Active_Window][Editor_Cur - 1] == '\r') {
Editor_Cur += 1; // Mark end at LF of CRLF must include LF as well
}
Mark[MARK_OUT] = Editor_Cur;
if (Mark[MARK_OUT] < Mark[MARK_IN]) {
Mark[MARK_TMP] = Mark[MARK_IN];
Mark[MARK_IN] = Mark[MARK_OUT];
Mark[MARK_OUT] = Mark[MARK_TMP];
} else if (Mark[MARK_IN] == Mark[MARK_OUT])
goto abort;
if (Mark[MARK_COPY] || Mark[MARK_CUT])
free(TextBuffer[EDIT]);
Mark[MARK_SIZE] = Mark[MARK_OUT] - Mark[MARK_IN];
TextBuffer[EDIT] = malloc(Mark[MARK_SIZE] + 256); // 256 To Avoid Crash 256???
for (i = 0; i < Mark[MARK_SIZE]; i++)
TextBuffer[EDIT][i] = TextBuffer[Active_Window][i + Mark[MARK_IN]];
del1 = -Mark[MARK_SIZE], del2 = 0, del3 = -Mark[MARK_SIZE], del4 = -Mark[MARK_SIZE];
Mark[MARK_CUT] = 1, Mark[MARK_COPY] = 0, Mark[MARK_ON] = 0, Mark[MARK_TMP] = 0;
Operation = -2;
}
// ends Key Ctrl+x CUT.
} else if (KeyPress == 0x16) { // Key Ctrl+v PASTE.
if (Mark[MARK_COPY] || Mark[MARK_CUT]) {
if (TextMode[Active_Window] == OTHER && TextBuffer[Active_Window][Editor_Cur] == '\n') {
Editor_Cur -= 1;
Mark[MARK_SIZE] -= 1;
}
ins1 = Mark[MARK_SIZE], ins2 = Mark[MARK_SIZE], ins3 = Mark[MARK_SIZE], ins4 = 0, ins5 = Mark[MARK_SIZE];
Operation = 1;
}
// ends Key Ctrl+v PASTE.
} else if (KeyPress == 0x07) { // Key BackSpace.
if (Editor_Cur > 0) {
if (TextMode[Active_Window] == OTHER && TextBuffer[Active_Window][Editor_Cur] == '\n' && TextBuffer[Active_Window][Editor_Cur - 1] == '\r') {
Editor_Cur += 1; // Backspace at LF of CRLF must work after LF
}
if (Mark[MARK_ON]) {
Mark[MARK_OUT] = Editor_Cur;
if (Mark[MARK_OUT] < Mark[MARK_IN]) {
Mark[MARK_TMP] = Mark[MARK_IN];
Mark[MARK_IN] = Mark[MARK_OUT];
Mark[MARK_OUT] = Mark[MARK_TMP];
} else if (Mark[MARK_IN] == Mark[MARK_OUT])
goto abort;
Mark[MARK_SIZE] = Mark[MARK_OUT] - Mark[MARK_IN];
del1 = -Mark[MARK_SIZE], del2 = 0, del3 = -Mark[MARK_SIZE], del4 = -Mark[MARK_SIZE];
Mark[MARK_ON] = 0;
} else if (TextMode[Active_Window] == OTHER && TextBuffer[Active_Window][Editor_Cur - 1] == '\n' && Editor_Cur > 1 && TextBuffer[Active_Window][Editor_Cur - 2] == '\r') {
del1 = -2, del2 = 0, del3 = -2, del4 = -2; // Backspace CRLF
} else {
del1 = -1, del2 = 0, del3 = -1, del4 = -1; // Backspace single char
}
Operation = -3;
}
// ends Key BackSpace.
} else if (KeyPress == 0x0A) { // Key Return.
if (TextMode[Active_Window] == OTHER && TextBuffer[Active_Window][Editor_Cur] == '\n' && Editor_Cur > 0 && TextBuffer[Active_Window][Editor_Cur - 1] == '\r') {
Editor_Cur -= 1; // Entry at LF of CRLF must work at CR instead
}
if (Editor_Insert || TextBuffer[Active_Window][Editor_Cur] == '\0')
if (Editor_RetMode == OTHER)
ins1 = 2, ins2 = 0, ins3 = 2, ins4 = 0, ins5 = 2; // Insert CRLF
else
ins1 = 1, ins2 = 0, ins3 = 1, ins4 = 0, ins5 = 1; // Insert LF/CR
else if (TextMode[Active_Window] == OTHER && TextBuffer[Active_Window][Editor_Cur] == '\r' && TextBuffer[Active_Window][Editor_Cur + 1] == '\n') { // OWrite Return at CRLF
if (Editor_RetMode == OTHER)
ins1 = 0, ins2 = 0, ins3 = 2, ins4 = 2, ins5 = 2; // OWrite CRLF at CRLF
else
ins1 = 0, ins2 = 0, ins3 = 1, ins4 = 2, ins5 = 1; // OWrite LF/CR at CRLF
} else { // OWrite return at normal char
if (Editor_RetMode == OTHER)
ins1 = 1, ins2 = 0, ins3 = 2, ins4 = 1, ins5 = 2; // OWrite CRLF at char
else
ins1 = 0, ins2 = 0, ins3 = 1, ins4 = 1, ins5 = 1; // OWrite LF/CR at char
}
Operation = 2;
// ends Key Return.
} else { // All Other Keys.
if (TextMode[Active_Window] == OTHER && TextBuffer[Active_Window][Editor_Cur] == '\n' && Editor_Cur > 0 && TextBuffer[Active_Window][Editor_Cur - 1] == '\r') {
Editor_Cur -= 1; // Entry at LF of CRLF must work at CR instead
}
if (Editor_Insert || TextBuffer[Active_Window][Editor_Cur] == '\0') {
ins1 = 1, ins2 = 0, ins3 = 1, ins4 = 0, ins5 = 1; // Insert char normally
} else {
if (TextMode[Active_Window] == OTHER && TextBuffer[Active_Window][Editor_Cur] == '\r' && TextBuffer[Active_Window][Editor_Cur + 1] == '\n') { // OWrite char at CRLF
ins1 = 0, ins2 = 0, ins3 = 1, ins4 = 2, ins5 = 1; // OWrite at CR of CRLF
} else { // OWrite return at normal char
ins1 = 0, ins2 = 0, ins3 = 1, ins4 = 1, ins5 = 1; // OWrite normal char
}
}
Operation = 3;
}
}
if (Operation > 0) { // Perform Add Char / Paste. Can Be Simplify???
TextBuffer[TMP] = malloc(TextSize[Active_Window] + ins1 + 256); // 256 To Avoid Crash 256???
strcpy(TextBuffer[TMP], TextBuffer[Active_Window]);
// memset(TextBuffer[Active_Window], 0, TextSize[Active_Window]+256); // 256 To Avoid Crash 256??? free(TextBuffer[Active_Window]);
TextBuffer[Active_Window] = malloc(TextSize[Active_Window] + ins1 + 256); // 256 To Avoid Crash 256???
strcpy(TextBuffer[Active_Window], TextBuffer[TMP]);
}
switch (Operation) {
case 0:
break;
case -1: // Perform Del Char / Cut. Can Be Simplify???
case -2:
case -3:
TextBuffer[TMP] = malloc(TextSize[Active_Window] + 256); // 256 To Avoid Crash 256???
strcpy(TextBuffer[TMP], TextBuffer[Active_Window]);
TextBuffer[Active_Window][Editor_Cur + del1] = '\0';
strcat(TextBuffer[Active_Window], TextBuffer[TMP] + (Editor_Cur + del2));
strcpy(TextBuffer[TMP], TextBuffer[Active_Window]);
// memset(TextBuffer[Active_Window], 0, TextSize[Active_Window]+256); // 256 To Avoid Crash 256???
free(TextBuffer[Active_Window]);
TextBuffer[Active_Window] = malloc(TextSize[Active_Window] + del3 + 256); // 256 To Avoid Crash 256???
strcpy(TextBuffer[Active_Window], TextBuffer[TMP]);
// memset(TextBuffer[TMP], 0, TextSize[Active_Window]+256); // 256 To Avoid Crash 256???
free(TextBuffer[TMP]);
Editor_Cur += del3, TextSize[Active_Window] += del4;
t = 0;
break;
case 1: // Paste.
for (i = 0; i < ins2; i++)
TextBuffer[Active_Window][i + Editor_Cur] = TextBuffer[EDIT][i];
goto common;
case 2: // Return.
if (Editor_RetMode == OTHER) {
TextBuffer[Active_Window][Editor_Cur + ins2] = '\r';
TextBuffer[Active_Window][Editor_Cur + ins2 + 1] = '\n';
} else if (Editor_RetMode == UNIX) {
TextBuffer[Active_Window][Editor_Cur + ins2] = '\r';
} else if (Editor_RetMode == MAC) {
TextBuffer[Active_Window][Editor_Cur + ins2] = '\n';
}
goto common;
case 3: // Normal characters
TextBuffer[Active_Window][Editor_Cur + ins2] = KeyPress;
common:
TextBuffer[Active_Window][Editor_Cur + ins3] = '\0';
strcat(TextBuffer[Active_Window], TextBuffer[TMP] + (Editor_Cur + ins4));
// memset(TextBuffer[TMP], 0, TextSize[Active_Window]+256); // 256 To Avoid Crash 256???
free(TextBuffer[TMP]);
Editor_Cur += ins5, TextSize[Active_Window] += ins1;
t = 0;
break;
}
abort:
KeyPress = '\0';
} // ends if(PS2KbdRead(&KeyPress)).
return ret;
}
//------------------------------
// endfunc KeyBoard_Entry
//--------------------------------------------------------------
static void Editor_Rules(void)
{
int i;
Editor_nChar = TextSize[Active_Window] + 1;
Top_Height = 0, Top_Width = 0;
Editor_nRowsNum = 0, Editor_nCharRows = 1, Editor_nRowsTop = 1;
for (i = 0; i < Editor_nChar; i++) // Rows Number, Width, Top, Calucations.
{
if ((TextMode[Active_Window] == UNIX && TextBuffer[Active_Window][i] == '\r') || // Text Mode UNIX End Line.
TextBuffer[Active_Window][i] == '\n' || // Text Mode MAC Or OTHER End Line.
Editor_nCharRows >= Rows_Width || // Line Width > Screen Width.
TextBuffer[Active_Window][i] == '\0') { // End Text.
if (i < Editor_Cur) {
if ((Editor_nRowsTop += 1) > Rows_Num) {
Top_Width += Editor_nRowsWidth[Top_Height];
Top_Height += 1;
}
}
Editor_nRowsWidth[Editor_nRowsNum] = Editor_nCharRows;
Editor_nRowsNum++;
Editor_nCharRows = 0;
}
if (TextBuffer[Active_Window][i] == '\0') // End Text Stop Calculations.
break;
Editor_nCharRows++;
}
if (Editor_Home) {
Tmp_Cur = 0;
for (i = 0; i < Editor_nRowsNum; i++) // Home Rules.
{
if ((Tmp_Cur += Editor_nRowsWidth[i]) >= Editor_Cur + 1)
break;
}
Tmp_Cur -= (Editor_nRowsWidth[i] - 1);
Editor_Cur = Tmp_Cur - 1;
Editor_Home = 0;
}
if (Editor_End) {
Tmp_Cur = 0;
for (i = 0; i < Editor_nRowsNum; i++) // End Rules.
{
if ((Tmp_Cur += Editor_nRowsWidth[i]) >= Editor_Cur + 1)
break;
}
Editor_Cur = Tmp_Cur - 1;
Editor_End = 0;
}
if (Editor_PushRows < 0) {
Tmp_Cur = 0;
for (i = 0; i < Editor_nRowsNum; i++) // Line / Page Up Rules.
{
if ((Tmp_Cur += Editor_nRowsWidth[i]) >= Editor_Cur + 1)
break;
}
Tmp_Cur -= (Editor_nRowsWidth[i] - 1);
if (Editor_nRowsWidth[i + 1] <= ((Editor_Cur + 1) - (Tmp_Cur - 1)))
Editor_Cur = Tmp_Cur + Editor_nRowsWidth[i] + Editor_nRowsWidth[i + 1] - 1 - 1;
else
Editor_Cur = Tmp_Cur + Editor_nRowsWidth[i] + ((Editor_Cur + 1) - Tmp_Cur) - 1;
Editor_PushRows++;
if (Editor_Cur + 1 >= Editor_nChar && TextBuffer[Active_Window][Editor_Cur] != '\0') {
Editor_Cur = Editor_nChar - 1;
Editor_PushRows = 0;
}
}
if (Editor_PushRows > 0) {
Tmp_Cur = 0;
for (i = 0; i < Editor_nRowsNum; i++) // Line / Page Down Rules.
{
if ((Tmp_Cur += Editor_nRowsWidth[i]) >= Editor_Cur + 1)
break;
}
Tmp_Cur -= (Editor_nRowsWidth[i] - 1);
if (Editor_nRowsWidth[i - 1] <= ((Editor_Cur + 1) - (Tmp_Cur - 1)))
Editor_Cur = Tmp_Cur - 1 - 1;
else
Editor_Cur = Tmp_Cur - Editor_nRowsWidth[i - 1] + ((Editor_Cur + 1) - Tmp_Cur) - 1;
Editor_PushRows--;
if (Editor_Cur <= 0) {
Editor_Cur = 0;
Editor_PushRows = 0;
}
}
if (Editor_Cur >= Editor_nChar) // Max Char Number Rules.
Editor_Cur = Editor_nChar - 1;
if (Editor_Cur < 0) // Min Char Number Rules.
Editor_Cur = 0;
if (Mark[MARK_ON]) { // Mark Rules.
Mark[MARK_SIZE] = Editor_Cur - Mark[MARK_IN];
if (Mark[MARK_SIZE] > 0) {
Mark[MARK_PRINT] = Mark[MARK_SIZE];
if (Mark[MARK_IN] < Top_Width)
Mark[MARK_PRINT] = Editor_Cur - Top_Width;
} else if (Mark[MARK_SIZE] < 0)
Mark[MARK_PRINT] = 1;
else
Mark[MARK_PRINT] = 0;
}
}
//--------------------------------------------------------------
static int Windows_Selector(void)
{
u64 color;
int x, y, i, Window_Sel = Active_Window;
int event, post_event = 0;
int Window_ch_w = 36; // Total characters in longest Window Name.
int Window_ch_h = 10; // Total number of Window Menu lines.
int wSprite_Y1 = 200; // Top edge of sprite.
int wSprite_X2 = SCREEN_WIDTH - 35; // Right edge of sprite.
int wSprite_X1 = wSprite_X2 - (Window_ch_w + 3) * FONT_WIDTH - 3; // Left edge of sprite.
int wSprite_Y2 = wSprite_Y1 + (Window_ch_h + 1) * FONT_HEIGHT + 3; // Bottom edge of sprite.
char tmp[64];
event = 1; // event = initial entry.
while (1) {
// Pad response section.
waitPadReady(0, 0);
if (readpad()) {
if (new_pad & PAD_UP) {
event |= 2; // event |= valid pad command.
if ((Window_Sel--) <= 0)
Window_Sel = 9;
} else if (new_pad & PAD_DOWN) {
event |= 2; // event |= valid pad command.
if ((Window_Sel++) >= 9)
Window_Sel = 0;
} else if ((new_pad & PAD_TRIANGLE) || (!swapKeys && new_pad & PAD_CROSS) || (swapKeys && new_pad & PAD_CIRCLE)) {
return -1;
} else if ((swapKeys && new_pad & PAD_CROSS) || (!swapKeys && new_pad & PAD_CIRCLE)) {
break;
}
}
if (event || post_event) { // NB: We need to update two frame buffers per event.
// Display section.
drawPopSprite(setting->color[COLOR_BACKGR],
wSprite_X1, wSprite_Y1,
wSprite_X2, wSprite_Y2);
drawFrame(wSprite_X1, wSprite_Y1, wSprite_X2, wSprite_Y2, setting->color[COLOR_FRAME]);
for (i = 0, y = wSprite_Y1 + FONT_HEIGHT / 2; i < 10; i++) {
if (Window_Sel == i)
color = setting->color[COLOR_SELECT];
else
color = setting->color[COLOR_TEXT];
if (!Window[i][OPENED])
printXY(LNG(Free_Window), wSprite_X1 + 2 * FONT_WIDTH, y, color, TRUE, 0);
else if (Window[i][CREATED])
printXY(LNG(Window_Not_Yet_Saved), wSprite_X1 + 2 * FONT_WIDTH, y, color, TRUE, 0);
else
printXY(Path[i], wSprite_X1 + 2 * FONT_WIDTH, y, color, TRUE, 0);
y += FONT_HEIGHT;
}
if (Window_Sel <= 10)
drawChar(LEFT_CUR, wSprite_X1 + FONT_WIDTH, wSprite_Y1 + (FONT_HEIGHT / 2 + Window_Sel * FONT_HEIGHT), setting->color[COLOR_TEXT]);
// Tooltip section.
x = SCREEN_MARGIN;
y = Menu_tooltip_y;
drawSprite(setting->color[COLOR_BACKGR],
0, y - 1,
SCREEN_WIDTH, y + 16);
if (swapKeys)
sprintf(tmp, "\xFF"
"1:%s \xFF"
"0:%s \xFF"
"3:%s",
LNG(OK), LNG(Cancel), LNG(Back));
else
sprintf(tmp, "\xFF"
"0:%s \xFF"
"1:%s \xFF"
"3:%s",
LNG(OK), LNG(Cancel), LNG(Back));
printXY(tmp, x, y, setting->color[COLOR_SELECT], TRUE, 0);
} // ends if(event||post_event).
drawScr();
post_event = event;
event = 0;
} // ends while.
return Window_Sel;
} // ends Window_Selector.
//--------------------------------------------------------------
static void Init(void)
{
int i;
for (i = 0; i < MAX_ENTRY; i++)
Editor_nRowsWidth[i] = 0;
Editor_Cur = 0, Tmp_Cur = 0,
Editor_nChar = 0, Editor_nRowsNum = 0,
Editor_nCharRows = 0, Editor_nRowsTop = 0,
Editor_PushRows = 0, Editor_TextEnd = 0;
Top_Width = 0, Top_Height = 0;
Rows_Width = (SCREEN_WIDTH - SCREEN_MARGIN - LINE_THICKNESS - 26 - Menu_start_x) / FONT_WIDTH;
Rows_Num = (Menu_end_y - Menu_start_y) / FONT_HEIGHT;
KeyBoard_Cur = 2, KeyBoard_Active = 0,