Team Ai
Datasetpublic

hschumann2/TempleOS-Source-Code

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes847downloads
Slider.txt112 linesDownload Raw Back to Graphics
1 2/*This was done with <CTRL-SHIFT-L> template code.3It's conceptually easy to do a ctrl,4but tedious.  You have complete freedom.5 6See CCtrl.7*/8 9//Start of autocreated Code10#define SLIDER_RANGE   3011#define SLIDER_SPACING 2012#define SLIDER_BORDER  213 14class CSliderState15{16  I64 left_pos;17  I64 right_pos;18} sld;19 20U0 DrawCtrlSlider(CDC *dc,CCtrl *c)21{22  CSliderState *s=c->state;23 24  dc->color=LTRED;25  GrRect(dc, c->left,c->top,SLIDER_SPACING*3+2,SLIDER_SPACING*2+SLIDER_RANGE);26  dc->color=BLUE;27  GrRect(dc, c->left+SLIDER_BORDER,c->top+SLIDER_BORDER,28        SLIDER_SPACING*3+2-2*SLIDER_BORDER,29        SLIDER_SPACING*2+SLIDER_RANGE-2*SLIDER_BORDER);30  dc->color=BLACK;31  GrLine(dc,c->left+1*SLIDER_SPACING+0,c->top+SLIDER_SPACING,32        c->left+1*SLIDER_SPACING+0,c->top+SLIDER_SPACING+SLIDER_RANGE-1);33  GrLine(dc,c->left+2*SLIDER_SPACING+1,c->top+SLIDER_SPACING,34        c->left+2*SLIDER_SPACING+1,c->top+SLIDER_SPACING+SLIDER_RANGE-1);35  dc->color=LTRED;36  GrPrint(dc,c->left+1*SLIDER_SPACING+0-FONT_WIDTH/2,37        c->top+SLIDER_SPACING+SLIDER_RANGE+3,38        "%d",s->left_pos*10/SLIDER_RANGE);39  GrPrint(dc,c->left+2*SLIDER_SPACING+1-FONT_WIDTH/2,40        c->top+SLIDER_SPACING+SLIDER_RANGE+3,41        "%d",s->right_pos*10/SLIDER_RANGE);42  GrRect(dc,c->left+1*SLIDER_SPACING+0-3,43        c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->left_pos-2,7,5);44  GrRect(dc,c->left+2*SLIDER_SPACING+1-3,45        c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->right_pos-2,7,5);46  dc->color=YELLOW;47  GrRect(dc,c->left+1*SLIDER_SPACING+0-2,48        c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->left_pos-1,5,3);49  GrRect(dc,c->left+2*SLIDER_SPACING+1-2,50        c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->right_pos-1,5,3);51}52 53U0 UpdateDerivedCtrlSlider(CCtrl *c)54{55  CSliderState *s=c->state;56  c->left=c->win_task->pix_width/2-(SLIDER_SPACING*3+2)/2;57  c->right=c->left+3*SLIDER_SPACING+2;58  c->top=c->win_task->pix_height/2-(SLIDER_SPACING*2+SLIDER_RANGE)/2;59  c->bottom=c->top+SLIDER_SPACING*2+SLIDER_RANGE;60  s->left_pos=ClampI64(s->left_pos,0,SLIDER_RANGE-1);61  s->right_pos=ClampI64(s->right_pos,0,SLIDER_RANGE-1);62}63 64U0 LeftClickSlider(CCtrl *c,I64 x,I64 y,Bool)65{66  CSliderState *s=c->state;67  if (x<c->left+1*SLIDER_SPACING+0+SLIDER_SPACING/2)68    s->left_pos=SLIDER_RANGE-1-(y-(c->top+SLIDER_SPACING));69  else70    s->right_pos=SLIDER_RANGE-1-(y-(c->top+SLIDER_SPACING));71  if (c->update_derived_vals)72    (*c->update_derived_vals)(c);73}74 75CCtrl *SliderNew()76{77  CCtrl *c=CAlloc(sizeof(CCtrl));78  c->win_task=Fs;79  c->flags=CTRLF_SHOW|CTRLF_CAPTURE_LEFT_MS;80  c->type=CTRLT_GENERIC;81  c->state=&sld;82  MemSet(&sld,0,sizeof(CSliderState));83  c->draw_it=&DrawCtrlSlider;84  c->left_click=&LeftClickSlider;85  c->update_derived_vals=&UpdateDerivedCtrlSlider;86  QueIns(c,Fs->last_ctrl);87  TaskDerivedValsUpdate;88  return c;89}90 91U0 SliderDel(CCtrl *c)92{93  QueRem(c);94  Free(c);95}96 97//End of autocreated Code98 99U0 Main()100{101  "This is to demo ctrls.\n";102  CCtrl *c=SliderNew;103  PressAKey;104  "Left: %d  Right: %d\n",105        sld.left_pos*10/SLIDER_RANGE,106        sld.right_pos*10/SLIDER_RANGE;107  SliderDel(c);108  DocBottom;109}110 111Main;112