Team Ai
Datasetpublic

hschumann2/TempleOS-Source-Code

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes847downloads
WallPaperCtrl.txt110 linesDownload Raw Back to Graphics
1 2/*Done with <CTRL-SHIFT-L> template code3that was modified.4 5This is an advanced demo that shows6that you can place ctrls on the7wall paper.8 9See ::/Demo/Graphics/Slider.HC10and ::/Demo/Graphics/WallPaperFish.HC11before messing with this program.12 13It must be "Adam Included".14*/15 16#define SLIDER_RANGE   3017#define SLIDER_SPACING 2018#define SLIDER_BORDER  219 20class CSliderState21{22  I64 left_pos;23  I64 right_pos;24};25 26U0 DrawCtrlSlider(CDC *dc,CCtrl *c)27{28  CSliderState *s=c->state;29 30  dc->color=LTRED;31  GrRect(dc, c->left,c->top,SLIDER_SPACING*3+2,SLIDER_SPACING*2+SLIDER_RANGE);32  dc->color=BLUE;33  GrRect(dc, c->left+SLIDER_BORDER,c->top+SLIDER_BORDER,34        SLIDER_SPACING*3+2-2*SLIDER_BORDER,35        SLIDER_SPACING*2+SLIDER_RANGE-2*SLIDER_BORDER);36  dc->color=BLACK;37  GrLine(dc,c->left+1*SLIDER_SPACING+0,c->top+SLIDER_SPACING,38        c->left+1*SLIDER_SPACING+0,c->top+SLIDER_SPACING+SLIDER_RANGE-1);39  GrLine(dc,c->left+2*SLIDER_SPACING+1,c->top+SLIDER_SPACING,40        c->left+2*SLIDER_SPACING+1,c->top+SLIDER_SPACING+SLIDER_RANGE-1);41  dc->color=LTRED;42  GrPrint(dc,c->left+1*SLIDER_SPACING+0-FONT_WIDTH/2,43        c->top+SLIDER_SPACING+SLIDER_RANGE+3,44        "%d",s->left_pos*10/SLIDER_RANGE);45  GrPrint(dc,c->left+2*SLIDER_SPACING+1-FONT_WIDTH/2,46        c->top+SLIDER_SPACING+SLIDER_RANGE+3,47        "%d",s->right_pos*10/SLIDER_RANGE);48  GrRect(dc,c->left+1*SLIDER_SPACING+0-3,49        c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->left_pos-2,7,5);50  GrRect(dc,c->left+2*SLIDER_SPACING+1-3,51        c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->right_pos-2,7,5);52  dc->color=YELLOW;53  GrRect(dc,c->left+1*SLIDER_SPACING+0-2,54        c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->left_pos-1,5,3);55  GrRect(dc,c->left+2*SLIDER_SPACING+1-2,56        c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->right_pos-1,5,3);57}58 59U0 UpdateDerivedCtrlSlider(CCtrl *c)60{61  CSliderState *s=c->state;62  c->left=c->win_task->pix_width/2-(SLIDER_SPACING*3+2)/2;63  c->right=c->left+3*SLIDER_SPACING+2;64  c->top=c->win_task->pix_height/2-(SLIDER_SPACING*2+SLIDER_RANGE)/2;65  c->bottom=c->top+SLIDER_SPACING*2+SLIDER_RANGE;66  s->left_pos=ClampI64(s->left_pos,0,SLIDER_RANGE-1);67  s->right_pos=ClampI64(s->right_pos,0,SLIDER_RANGE-1);68}69 70U0 LeftClickSlider(CCtrl *c,I64 x,I64 y,Bool)71{72  CSliderState *s=c->state;73  if (x<c->left+1*SLIDER_SPACING+0+SLIDER_SPACING/2)74    s->left_pos=SLIDER_RANGE-1-(y-(c->top+SLIDER_SPACING));75  else76    s->right_pos=SLIDER_RANGE-1-(y-(c->top+SLIDER_SPACING));77  if (c->update_derived_vals)78    (*c->update_derived_vals)(c);79}80 81CCtrl *SliderNew()82{83  CCtrl *c;84  if (Fs!=adam_task) {85    "Must be Adam Included with SHIFT-F5.\n"86          "(Would crash when code mem was freed.)\n";87    return NULL;88  }89  c=ACAlloc(sizeof(CCtrl));90  c->win_task=sys_winmgr_task;91  c->flags=CTRLF_SHOW|CTRLF_CAPTURE_LEFT_MS;92  c->type=CTRLT_GENERIC;93  c->state=ACAlloc(sizeof(CSliderState));94  c->draw_it=&DrawCtrlSlider;95  c->left_click=&LeftClickSlider;96  c->update_derived_vals=&UpdateDerivedCtrlSlider;97  QueIns(c,sys_winmgr_task->last_ctrl);98  TaskDerivedValsUpdate;99  return c;100}101 102U0 SliderDel(CCtrl *c)103{104  QueRem(c);105  Free(c->state);106  Free(c);107}108 109SliderNew;110