hschumann2/TempleOS-Source-Code
0847
1 2#help_index "Graphics/Input"3 4public I64 PopUpColor(U8 *header=NULL,5 Bool allow_transparent=TRUE,Bool allow_dft=TRUE)6{//Chooser for 16-color, default or transparent.7 I64 i;8 CDoc *doc=DocNew;9 if (header)10 DocPrint(doc,"%s",header);11 if (allow_transparent)12 DocPrint(doc,"$MU,\"TRANSPARENT\",LE=TRANSPARENT$\n");13 for (i=0;i<COLORS_NUM;i++)14 DocPrint(doc,"$BG,%d$$MU,\"__%-8Z__\",LE=%d$$BG$\n",i,i,"ST_COLORS",i);15 if (allow_dft)16 DocPrint(doc,"$BG,WHITE$$MU,\"DEFAULT\",LE=DOC_DFT$$BG$");17 i=PopUpMenu(doc);18 DocDel(doc);19 return i;20}21 22public I64 PopUpColorLighting(U8 *header=NULL)23{//Chooser for std TempleOS DCLighting() color.24 I64 i;25 CDoc *doc=DocNew;26 if (header)27 DocPrint(doc,"%s",header);28 DocPrint(doc,"\nSingle-Sided means front and back different."29 "\nDouble-Sided means front and back same."30 "\n"31 "\nHalf-Range means 0 to [0,7]"32 "\n [8,15]-8 to [8,15]"33 "\nFull-Range means 0 to [0,7] to [0,7]+8"34 "\n");35 DocPrint(doc,36 "\n$LTPURPLE$Single-Sided Full-Range Double-Sided Full-Range\n$BLACK$");37 for (i=0;i<COLORS_NUM/2;i++) {38 DocPrint(doc,"$BG,%d$$MU,\"__%-19Z__\",LE=%d$$BG$ ",i,i,"ST_COLORS",i);39 DocPrint(doc,"$BG,%d$$MU,\"__%-19Z__\",LE=%d$$BG$\n",i,i,"ST_COLORS",40 ROPF_TWO_SIDED+i);41 }42 DocPrint(doc,43 "\n$LTPURPLE$Single-Sided Half-Range Double-Sided Half-Range\n$BLACK$");44 for (i=0;i<COLORS_NUM;i++) {45 DocPrint(doc,"$BG,%d$$MU,\"__%-19Z__\",LE=%d$$BG$ ",46 i,i,"ST_COLORS",ROPF_HALF_RANGE_COLOR+i);47 DocPrint(doc,"$BG,%d$$MU,\"__%-19Z__\",LE=%d$$BG$\n",48 i,i,"ST_COLORS",ROPF_TWO_SIDED+ROPF_HALF_RANGE_COLOR+i);49 }50 i=PopUpMenu(doc);51 DocDel(doc);52 return i;53}54 55class CTransformForm56{57 F64 x_scale format "$DA-TRM,A=\"X Scale :%12.6f\"$\n";58 F64 y_scale format "$DA-TRM,A=\"Y Scale :%12.6f\"$\n";59 F64 z_scale format "$DA-TRM,A=\"Z Scale :%12.6f\"$\n";60 F64 theta_z format "\nAngles are in degrees\n"61 "$DA-TRM,A=\"Z-Axis :%12.6f\"$\n";62 F64 theta_y format "$DA-TRM,A=\"Y-Axis :%12.6f\"$\n";63 F64 theta_x format "$DA-TRM,A=\"X-Axis :%12.6f\"$\n";64 F64 x_offset format "\n$DA-TRM,A=\"X Offset:%12.6f\"$\n";65 F64 y_offset format "$DA-TRM,A=\"Y Offset:%12.6f\"$\n";66 F64 z_offset format "$DA-TRM,A=\"Z Offset:%12.6f\"$\n";67};68 69#help_index "Graphics/Input;Graphics/Math/3D Transformation"70public Bool PopUpTransform(I64 *r)71{//Prompt for Mat4x4 transform.72 CTransformForm *tf=MAlloc(sizeof(CTransformForm));73 tf->x_scale=1.0;74 tf->y_scale=1.0;75 tf->z_scale=1.0;76 tf->theta_x=0.0;77 tf->theta_y=0.0;78 tf->theta_z=0.0;79 tf->x_offset=0.0;80 tf->y_offset=0.0;81 tf->z_offset=0.0;82 if (PopUpForm(tf)) {83 MemSet(r,0,16*sizeof(I64));84 r[0] =tf->x_scale*GR_SCALE;85 r[5] =tf->y_scale*GR_SCALE;86 r[10]=tf->z_scale*GR_SCALE;87 r[15]=GR_SCALE;88 89 Mat4x4RotZ(r,tf->theta_z*pi/180.0);90 Mat4x4RotY(r,tf->theta_y*pi/180.0);91 Mat4x4RotX(r,tf->theta_x*pi/180.0);92 93 r[3] =tf->x_offset*GR_SCALE;94 r[7] =tf->y_offset*GR_SCALE;95 r[11]=tf->z_offset*GR_SCALE;96 return TRUE;97 } else98 return FALSE;99}100 101#help_index "Graphics/Input"102#define PU_SPACING 10103U0 DrawIt(CTask *task,CDC *dc)104{105 I64 i,j,i1,j1;106 CDoc *doc=DocPut(task);107 for (j=0;j<17;j++)108 for (i=0;i<17;i++) {109 if (j<16)110 j1=j;111 else112 j1=TRANSPARENT;113 if (i<16)114 i1=i;115 else116 i1=TRANSPARENT;117 dc->color=j1+i1<<16+ROPF_DITHER;118 GrRect(dc,i*PU_SPACING,j*PU_SPACING+FramePtr("DitherFrame",task),119 PU_SPACING,PU_SPACING);120 }121 i=(17*PU_SPACING+FONT_WIDTH-1)/FONT_WIDTH;122 if (doc->max_x>i) i=doc->max_x;123 WinHorz(task->win_left,task->win_left+i,task);124 WinVert(task->win_top,task->win_top+doc->max_y+125 (17*PU_SPACING+FONT_WIDTH-1)/FONT_WIDTH,task);126}127 128I64 DitherColor2(U8 *header=NULL)129{130 I64 msg_code,arg1,arg2,res=-1,i,j;131 DocClear;132 "%s",header;133 DocRecalc(DocPut);134 FramePtrAdd("DitherFrame",(DocPut->max_y+1)*FONT_HEIGHT);135 SettingsPush; //See SettingsPush136 Fs->draw_it=&DrawIt;137 do {138 msg_code=GetMsg(&arg1,&arg2,1<<MSG_MS_L_DOWN|1<<MSG_KEY_DOWN);139 if (msg_code==MSG_MS_L_DOWN) {140 msg_code=GetMsg(&arg1,&arg2,1<<MSG_MS_L_UP);141 i=arg1/PU_SPACING;142 j=(arg2-FramePtr("DitherFrame"))/PU_SPACING;143 if (arg1>=0 && arg2>=0 && 0<=j<17 && 0<=i<17) {144 if (j==16) j=TRANSPARENT;145 if (i==16) i=TRANSPARENT;146 res=j+i<<16+ROPF_DITHER;147 goto dc_done;148 }149 }150 } while (!(msg_code==MSG_KEY_DOWN && (arg1==CH_ESC || arg1==CH_SHIFT_ESC)));151 do GetMsg(&arg1,&arg2,1<<MSG_KEY_UP);152 while (!arg1);153dc_done:154 SettingsPop;155 FramePtrDel("DitherFrame");156 return res;157}158 159public I64 PopUpColorDither(U8 *header=NULL)160{//Chooser for 2 x 16 colors or transparent.161 U8 buf[STR_LEN];162 StrPrint(buf,"DitherColor2(0x%X);",header);163 return PopUp(buf,Fs);164}165 