hschumann2/TempleOS-Source-Code
0847
1 2/*After making a font...3 4You can save it as a binary file with:5 FileWrite("filename.BIN.Z",text.font,256*FONT_HEIGHT);6 7You can load it with:8 U64 *my_font=FileRead("filename.BIN.Z");9 text.aux_font=my_font;10 11<CTRL-ALT-f> will toggle main font and aux_font.12 13If you want to change the system font permanently,14save to a file with this font editor program15and cut and paste the code into ::/Kernel/FontStd.HC.16You will need to recompile Kernel by calling BootHDIns().17 18See ::/Demo/ExtChars.HC, ::/Demo/Games/CharDemo.HC,19::/Demo/Graphics/CharAnimation.HC and ::/Demo/ScrnCodes.HC.20*/21 22#define BLOW_UP_CHAR_X (18*FONT_WIDTH)23#define BLOW_UP_CHAR_Y (4*FONT_HEIGHT)24 25U8 cur_ch;26 27U0 DrawIt(CTask *task,CDC *dc)28{29 I64 i,j,k,c;30 TextPrint(task,0,0,BLUE<<4+YELLOW,"Press <CTRL-ALT-f> to Toggle Aux Font.");31 k=0;32 for (i=0;i<16;i++)33 for (j=0;j<16;j++) {34 if (k==cur_ch) {35 if (Blink)36 c=(BLUE<<4+YELLOW)<<8 + k++;37 else38 c=(YELLOW<<4+BLUE)<<8 + k++;39 } else40 c=(BLUE<<4+WHITE)<<8 + k++;41 TextChar(task,,j,i+2,c);42 }43 44 k=0;45 for (i=0;i<FONT_HEIGHT;i++)46 for (j=0;j<FONT_WIDTH;j++) {47 if (Bt(&text.font[cur_ch],k++))48 dc->color=YELLOW;49 else50 dc->color=BLUE;51 GrRect(dc,BLOW_UP_CHAR_X+j*FONT_WIDTH,52 BLOW_UP_CHAR_Y+i*FONT_HEIGHT,53 FONT_WIDTH,FONT_HEIGHT);54 }55}56 57U0 FESave(Bool pmt)58{59 U8 old_draw_it=Fs->draw_it;60 CDoc *doc=DocNew;61 I64 i;62 for (i=0;i<256;i++) {63 DocPrint(doc,"0x%016X,",text.font[i]);64 if (Bt(char_bmp_safe_dollar,i))65 DocPrint(doc,"//%c",i);66 else if (i=='$')67 DocPrint(doc,"//$$",i);68 DocPrint(doc,"\n");69 }70 Fs->draw_it=NULL;71 DocWrite(doc,pmt);72 Fs->draw_it=old_draw_it;73 DocDel(doc);74}75 76U0 FontEd()77{78 I64 msg_code,arg1,arg2,k;79 SettingsPush; //See SettingsPush80 MenuPush(81 "File {"82 " SaveAs(,CH_CTRLA);"83 " Abort(,CH_SHIFT_ESC);"84 " Exit(,CH_ESC);"85 "}");86 AutoComplete;87 DocCursor;88 DocClear;89 Fs->win_inhibit|=WIG_DBL_CLICK;90 cur_ch=0;91 try {92 Fs->draw_it=&DrawIt;93 while (TRUE) {94 switch (msg_code=GetMsg(&arg1,&arg2,95 1<<MSG_KEY_DOWN|1<<MSG_MS_L_DOWN|1<<MSG_MS_R_DOWN|1<<MSG_MS_MOVE)) {96 case MSG_KEY_DOWN:97 switch (arg1) {98 case 0:99 switch (arg2.u8[0]) {100 case SC_CURSOR_LEFT:101 cur_ch--;102 break;103 case SC_CURSOR_RIGHT:104 cur_ch++;105 break;106 case SC_CURSOR_UP:107 cur_ch-=16;108 break;109 case SC_CURSOR_DOWN:110 cur_ch+=16;111 break;112 113 }114 break;115 goto fe_done;116 case CH_CTRLA:117 FESave(TRUE);118 break;119 case CH_ESC:120 FESave(FALSE);121 case CH_SHIFT_ESC:122 goto fe_done;123 default:124 cur_ch=arg1;125 }126 break;127 case MSG_MS_L_DOWN:128 case MSG_MS_R_DOWN:129 if (0<=arg1<FONT_WIDTH*16 && 0<=arg2-2*FONT_HEIGHT<FONT_HEIGHT*16) {130 cur_ch=(arg2/FONT_HEIGHT-2)*16+arg1/FONT_WIDTH;131 break;132 } //fall through133 case MSG_MS_MOVE:134 k=((arg2-BLOW_UP_CHAR_Y)/FONT_HEIGHT)*FONT_WIDTH+135 (arg1-BLOW_UP_CHAR_X)/FONT_WIDTH;136 if (0<=k<FONT_WIDTH*FONT_HEIGHT) {137 if (ms.lb||msg_code==MSG_MS_L_DOWN)138 Bts(&text.font[cur_ch],k);139 if (ms.rb||msg_code==MSG_MS_R_DOWN)140 Btr(&text.font[cur_ch],k);141 }142 break;143 }144 }145fe_done:146 GetMsg(,,1<<MSG_KEY_UP);147 } catch148 PutExcept;149 MenuPop;150 SettingsPop;151}152 153FontEd;154 