TempleOSTS_140317.ISO
This commit is contained in:
1 parent
2d2a65d572
commit
7ef616a20e
1416 files changed
+223873
-53917
No files matched your search
@@ -0,0 +1,8 @@
|
||||
#help_index "Ctrls"
|
||||
#help_file "::/Doc/Ctrls"
|
||||
|
||||
#include "Ctrls2a"
|
||||
#include "CtrlsButton"
|
||||
#include "CtrlsSlider"
|
||||
|
||||
#help_index ""
|
||||
@@ -0,0 +1,393 @@
|
||||
public CCtrl *CtrlFindUnique(CTask *haystack_task,I64 needle_type)
|
||||
{
|
||||
CCtrl *c;
|
||||
Bool old_preempt=Preempt(OFF);
|
||||
c=haystack_task->next_ctrl;
|
||||
while (c!=&haystack_task->next_ctrl) {
|
||||
if (c->type==needle_type) {
|
||||
Preempt(old_preempt);
|
||||
return c;
|
||||
}
|
||||
c=c->next;
|
||||
}
|
||||
Preempt(old_preempt);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
U0 CtrlsUpdate(CTask *task)
|
||||
{
|
||||
CCtrl *c;
|
||||
Bool old_preempt=Preempt(OFF);
|
||||
c=task->next_ctrl;
|
||||
while (c!=&task->next_ctrl) {
|
||||
if (c->update_derived_vals)
|
||||
(*c->update_derived_vals)(c);
|
||||
if (c->flags&CTRLF_BORDER) {
|
||||
c->screen_left =gr_pan_text_x+task->pix_left+c->left-FONT_WIDTH;
|
||||
c->screen_right =gr_pan_text_x+task->pix_left+c->right-FONT_WIDTH;
|
||||
c->screen_top =gr_pan_text_y+task->pix_top+c->top-FONT_HEIGHT;
|
||||
c->screen_bottom=gr_pan_text_y+task->pix_top+c->bottom-FONT_HEIGHT;
|
||||
} else {
|
||||
c->screen_left =gr_pan_text_x+task->pix_left+c->left;
|
||||
c->screen_right =gr_pan_text_x+task->pix_left+c->right;
|
||||
c->screen_top =gr_pan_text_y+task->pix_top+c->top;
|
||||
c->screen_bottom=gr_pan_text_y+task->pix_top+c->bottom;
|
||||
}
|
||||
c=c->next;
|
||||
}
|
||||
Preempt(old_preempt);
|
||||
}
|
||||
|
||||
fp_update_ctrls=&CtrlsUpdate;
|
||||
|
||||
|
||||
Bool CtrlInsideRect(CCtrl *c,I64 x,I64 y)
|
||||
{//screen coordinates
|
||||
if (c->screen_left<=x<=c->screen_right &&
|
||||
c->screen_top<=y<=c->screen_bottom)
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
public Bool CtrlInside(CCtrl *c,I64 x,I64 y)
|
||||
{
|
||||
if (c->flags&CTRLF_SHOW) {
|
||||
if (c->inside_ctrl)
|
||||
return (*c->inside_ctrl)(c,x,y);
|
||||
else
|
||||
return CtrlInsideRect(c,x,y);
|
||||
} else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
U0 DrawCtrls(CTask *task)
|
||||
{
|
||||
CCtrl *c;
|
||||
CDC *dc=DCAlias(gr_dc2,task);
|
||||
Bool old_preempt=Preempt(OFF);
|
||||
c=task->next_ctrl;
|
||||
while (c!=&task->next_ctrl) {
|
||||
if (c->flags&CTRLF_SHOW) {
|
||||
if (c->flags&CTRLF_BORDER) {
|
||||
if (!Bt(&task->display_flags,DISPLAYf_NO_BORDER)) {
|
||||
PUSHFD
|
||||
CLI
|
||||
while (LBts(&task->locked_flags,TASKLf_TASK_LOCK))
|
||||
PAUSE
|
||||
|
||||
task->win_left--; //Allow drawing on border
|
||||
task->win_right++;
|
||||
task->win_top--;
|
||||
task->win_bottom++;
|
||||
WinDerivedValsUpdate(task);
|
||||
|
||||
LBtr(&task->locked_flags,TASKLf_TASK_LOCK);
|
||||
POPFD
|
||||
|
||||
if (c->draw_it)
|
||||
(*c->draw_it)(dc,c);
|
||||
|
||||
PUSHFD
|
||||
CLI
|
||||
while (LBts(&task->locked_flags,TASKLf_TASK_LOCK))
|
||||
PAUSE
|
||||
|
||||
task->win_left++;
|
||||
task->win_right--;
|
||||
task->win_top++;
|
||||
task->win_bottom--;
|
||||
WinDerivedValsUpdate(task);
|
||||
|
||||
LBtr(&task->locked_flags,TASKLf_TASK_LOCK);
|
||||
POPFD
|
||||
}
|
||||
} else
|
||||
if (c->draw_it)
|
||||
(*c->draw_it)(dc,c);
|
||||
}
|
||||
c=c->next;
|
||||
}
|
||||
Preempt(old_preempt);
|
||||
DCDel(dc);
|
||||
}
|
||||
|
||||
|
||||
#define WIN_SCROLL_SIZE 8
|
||||
#define WIN_SCROLL_BORDER_BONUS 4
|
||||
U0 DrawWinScroll(CDC *dc,CCtrl *c)
|
||||
{
|
||||
CWinScroll *s=c->state;
|
||||
Bool old_preempt=Preempt(OFF);
|
||||
|
||||
if (c->flags&CTRLF_CLICKED)
|
||||
dc->color=s->color>>4;
|
||||
else
|
||||
dc->color=s->color&0xF;
|
||||
GrRect(dc,c->left,c->top,c->right-c->left+1,c->bottom-c->top+1);
|
||||
|
||||
if (c->flags&CTRLF_CLICKED)
|
||||
dc->color=s->color&0xF;
|
||||
else
|
||||
dc->color=s->color>>4;
|
||||
GrRect(dc,c->left+2,c->top+2,c->right-c->left+1-4,c->bottom-c->top+1-4);
|
||||
Preempt(old_preempt);
|
||||
}
|
||||
|
||||
U0 WinDerivedScrollValsUpdate(CCtrl *c)
|
||||
{
|
||||
CWinScroll *s=c->state;
|
||||
I64 range;
|
||||
if (s->max<s->min) s->max=s->min;
|
||||
if (s->pos<s->min) s->pos=s->min;
|
||||
if (s->pos>s->max) s->pos=s->max;
|
||||
s->color=c->win_task->border_attr&0xF^0xF+
|
||||
(c->win_task->border_attr&0xF)<<4;
|
||||
range=s->max-s->min;
|
||||
if (!range) range=1;
|
||||
switch (c->type) {
|
||||
case CTRLT_WIN_HSCROLL:
|
||||
c->left =gr_pan_text_x+FONT_WIDTH-WIN_SCROLL_BORDER_BONUS+(s->pos-s->min)*(c->win_task->pix_width+2*WIN_SCROLL_BORDER_BONUS-WIN_SCROLL_SIZE)/range;
|
||||
c->right =c->left+WIN_SCROLL_SIZE-1;
|
||||
c->top =gr_pan_text_y+FONT_HEIGHT+(FONT_WIDTH-WIN_SCROLL_SIZE)/2+c->win_task->pix_height;
|
||||
c->bottom=c->top+WIN_SCROLL_SIZE-1;
|
||||
break;
|
||||
case CTRLT_WIN_VSCROLL:
|
||||
c->left =gr_pan_text_x+FONT_WIDTH+(FONT_WIDTH-WIN_SCROLL_SIZE)/2+c->win_task->pix_width;
|
||||
c->right =c->left+WIN_SCROLL_SIZE-1;
|
||||
c->top =gr_pan_text_y+FONT_HEIGHT-WIN_SCROLL_BORDER_BONUS+(s->pos-s->min)*(c->win_task->pix_height+2*WIN_SCROLL_BORDER_BONUS-WIN_SCROLL_SIZE)/range;
|
||||
c->bottom=c->top+WIN_SCROLL_SIZE-1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
U0 LeftClickHWinScroll(CCtrl *c,I64 x,I64,Bool down)
|
||||
{
|
||||
CTask *task=c->win_task;
|
||||
CWinScroll *s=c->state;
|
||||
I64 range=task->pix_width+2*WIN_SCROLL_BORDER_BONUS-WIN_SCROLL_SIZE;
|
||||
LBts(&s->flags,WSSf_SET_TO_POS);
|
||||
s->pos=((x-(FONT_WIDTH-WIN_SCROLL_BORDER_BONUS))*(s->max-s->min+1)+range/2)/range+s->min;
|
||||
if (down)
|
||||
c->flags|=CTRLF_CLICKED;
|
||||
else
|
||||
c->flags&=~CTRLF_CLICKED;
|
||||
if (c->update_derived_vals)
|
||||
(*c->update_derived_vals)(c);
|
||||
}
|
||||
|
||||
U0 LeftClickVWinScroll(CCtrl *c,I64,I64 y,Bool down)
|
||||
{
|
||||
CTask *task=c->win_task;
|
||||
CWinScroll *s=c->state;
|
||||
I64 range=task->pix_height+2*WIN_SCROLL_BORDER_BONUS-WIN_SCROLL_SIZE;
|
||||
LBts(&s->flags,WSSf_SET_TO_POS);
|
||||
s->pos=((y-(FONT_HEIGHT-WIN_SCROLL_BORDER_BONUS))*(s->max-s->min+1)+range/2)/range+s->min;
|
||||
if (down)
|
||||
c->flags|=CTRLF_CLICKED;
|
||||
else
|
||||
c->flags&=~CTRLF_CLICKED;
|
||||
if (c->update_derived_vals)
|
||||
(*c->update_derived_vals)(c);
|
||||
}
|
||||
|
||||
U0 WheelChangeWinScroll(CCtrl *c,I64 delta)
|
||||
{
|
||||
CWinScroll *s=c->state;
|
||||
LBts(&s->flags,WSSf_SET_TO_POS);
|
||||
s->pos+=delta;
|
||||
if (c->update_derived_vals)
|
||||
(*c->update_derived_vals)(c);
|
||||
}
|
||||
|
||||
U0 WinScrollsInit(CTask *task)
|
||||
{
|
||||
Bool old_preempt=Preempt(OFF);
|
||||
CCtrl *c;
|
||||
|
||||
if (!CtrlFindUnique(task,CTRLT_WIN_HSCROLL)) {
|
||||
c=CAlloc(sizeof(CCtrl));
|
||||
c->win_task=task;
|
||||
c->flags=CTRLF_SHOW|CTRLF_BORDER|CTRLF_CAPTURE_LEFT_IP;
|
||||
c->type=CTRLT_WIN_HSCROLL;
|
||||
c->state=&task->horz_scroll;
|
||||
c->update_derived_vals=&WinDerivedScrollValsUpdate;
|
||||
c->draw_it=&DrawWinScroll;
|
||||
c->left_click=&LeftClickHWinScroll;
|
||||
QueIns(c,task->last_ctrl);
|
||||
}
|
||||
|
||||
if (!CtrlFindUnique(task,CTRLT_WIN_VSCROLL)) {
|
||||
c=CAlloc(sizeof(CCtrl));
|
||||
c->win_task=task;
|
||||
c->flags=CTRLF_SHOW|CTRLF_BORDER|CTRLF_CAPTURE_LEFT_IP;
|
||||
c->type=CTRLT_WIN_VSCROLL;
|
||||
c->state=&task->vert_scroll;
|
||||
c->update_derived_vals=&WinDerivedScrollValsUpdate;
|
||||
c->draw_it=&DrawWinScroll;
|
||||
c->left_click=&LeftClickVWinScroll;
|
||||
c->wheel_chg=&WheelChangeWinScroll;
|
||||
QueIns(c,task->last_ctrl);
|
||||
}
|
||||
TaskDerivedValsUpdate(task);
|
||||
Preempt(old_preempt);
|
||||
}
|
||||
#define VIEWANGLES_SPACING 22
|
||||
#define VIEWANGLES_RANGE 48
|
||||
#define VIEWANGLES_BORDER 2
|
||||
#define VIEWANGLES_SNAP 2
|
||||
|
||||
U0 DrawViewAnglesCtrl(CDC *dc,CCtrl *c)
|
||||
{
|
||||
I64 i,j;
|
||||
CViewAngles *s=c->state;
|
||||
|
||||
dc->color=s->cbd;
|
||||
GrRect(dc, c->left,c->top,VIEWANGLES_SPACING*4+3,VIEWANGLES_SPACING*2+VIEWANGLES_RANGE);
|
||||
dc->color=s->cbg;
|
||||
GrRect(dc, c->left+VIEWANGLES_BORDER,c->top+VIEWANGLES_BORDER,
|
||||
VIEWANGLES_SPACING*4+3-2*VIEWANGLES_BORDER,VIEWANGLES_SPACING*2+VIEWANGLES_RANGE-2*VIEWANGLES_BORDER);
|
||||
dc->color=s->cfg;
|
||||
GrLine(dc,c->left+VIEWANGLES_SPACING,c->top+VIEWANGLES_SPACING,
|
||||
c->left+VIEWANGLES_SPACING,c->top+VIEWANGLES_SPACING+VIEWANGLES_RANGE-1);
|
||||
GrLine(dc,c->left+2*VIEWANGLES_SPACING+1,c->top+VIEWANGLES_SPACING,
|
||||
c->left+2*VIEWANGLES_SPACING+1,c->top+VIEWANGLES_SPACING+VIEWANGLES_RANGE-1);
|
||||
GrLine(dc,c->left+3*VIEWANGLES_SPACING+2,c->top+VIEWANGLES_SPACING,
|
||||
c->left+3*VIEWANGLES_SPACING+2,c->top+VIEWANGLES_SPACING+VIEWANGLES_RANGE-1);
|
||||
for (i=1;i<VIEWANGLES_RANGE+1;i+=2*VIEWANGLES_SNAP) {
|
||||
j=2-i/3&1;
|
||||
GrLine(dc,c->left+VIEWANGLES_SPACING-j,c->bottom-VIEWANGLES_SPACING-i,
|
||||
c->left+VIEWANGLES_SPACING+j,c->bottom-VIEWANGLES_SPACING-i);
|
||||
GrLine(dc,c->left+2*VIEWANGLES_SPACING+1-j,c->bottom-VIEWANGLES_SPACING-i,
|
||||
c->left+2*VIEWANGLES_SPACING+1+j,c->bottom-VIEWANGLES_SPACING-i);
|
||||
GrLine(dc,c->left+3*VIEWANGLES_SPACING+2-j,c->bottom-VIEWANGLES_SPACING-i,
|
||||
c->left+3*VIEWANGLES_SPACING+2+j,c->bottom-VIEWANGLES_SPACING-i);
|
||||
}
|
||||
|
||||
dc->color=s->cx;
|
||||
GrPrint(dc,c->left+VIEWANGLES_SPACING-FONT_WIDTH/2,
|
||||
c->top+VIEWANGLES_SPACING-(1+FONT_HEIGHT),"X");
|
||||
GrPrint(dc,c->left+VIEWANGLES_SPACING-3*FONT_WIDTH/2,
|
||||
c->top+VIEWANGLES_SPACING+VIEWANGLES_RANGE+3,
|
||||
"%3d",s->sx*360/VIEWANGLES_RANGE);
|
||||
i=c->left+VIEWANGLES_SPACING;
|
||||
if (s->sx>VIEWANGLES_RANGE/2)
|
||||
j=-VIEWANGLES_RANGE/2+s->sx;
|
||||
else
|
||||
j=s->sx+VIEWANGLES_RANGE/2;
|
||||
j=c->top+VIEWANGLES_SPACING+VIEWANGLES_RANGE-1-j;
|
||||
GrRect(dc,i-3,j-2,7,5);
|
||||
dc->color=s->cx^8;
|
||||
GrRect(dc,i-2,j-1,5,3);
|
||||
|
||||
|
||||
dc->color=s->cy;
|
||||
GrPrint(dc,c->left+2*VIEWANGLES_SPACING+1-FONT_WIDTH/2,
|
||||
c->top+VIEWANGLES_SPACING-(1+FONT_HEIGHT),"Y");
|
||||
GrPrint(dc,c->left+2*VIEWANGLES_SPACING+1-3*FONT_WIDTH/2,
|
||||
c->top+VIEWANGLES_SPACING+VIEWANGLES_RANGE+3,
|
||||
"%3d",s->sy*360/VIEWANGLES_RANGE);
|
||||
i=c->left+2*VIEWANGLES_SPACING+1;
|
||||
if (s->sy>VIEWANGLES_RANGE/2)
|
||||
j=-VIEWANGLES_RANGE/2+s->sy;
|
||||
else
|
||||
j=s->sy+VIEWANGLES_RANGE/2;
|
||||
j=c->top+VIEWANGLES_SPACING+VIEWANGLES_RANGE-1-j;
|
||||
GrRect(dc,i-3,j-2,7,5);
|
||||
dc->color=s->cy^8;
|
||||
GrRect(dc,i-2,j-1,5,3);
|
||||
|
||||
|
||||
dc->color=s->cz;
|
||||
GrPrint(dc,c->left+3*VIEWANGLES_SPACING+2-FONT_WIDTH/2,
|
||||
c->top+VIEWANGLES_SPACING-(1+FONT_HEIGHT),"Z");
|
||||
GrPrint(dc,c->left+3*VIEWANGLES_SPACING+2-3*FONT_WIDTH/2,
|
||||
c->top+VIEWANGLES_SPACING+VIEWANGLES_RANGE+3,
|
||||
"%3d",s->sz*360/VIEWANGLES_RANGE);
|
||||
i=c->left+3*VIEWANGLES_SPACING+2;
|
||||
if (s->sz>VIEWANGLES_RANGE/2)
|
||||
j=-VIEWANGLES_RANGE/2+s->sz;
|
||||
else
|
||||
j=s->sz+VIEWANGLES_RANGE/2;
|
||||
j=c->top+VIEWANGLES_SPACING+VIEWANGLES_RANGE-1-j;
|
||||
GrRect(dc,i-3,j-2,7,5);
|
||||
dc->color=s->cz^8;
|
||||
GrRect(dc,i-2,j-1,5,3);
|
||||
}
|
||||
|
||||
U0 UpdateDerivedViewAnglesCtrl(CCtrl *c)
|
||||
{
|
||||
CViewAngles *s=c->state;
|
||||
c->left=c->win_task->pix_width-(VIEWANGLES_SPACING*4+3);
|
||||
c->right=c->left+VIEWANGLES_SPACING*4+3;
|
||||
c->top=c->win_task->pix_height-(VIEWANGLES_SPACING*2+VIEWANGLES_RANGE);
|
||||
c->bottom=c->top+VIEWANGLES_SPACING*2+VIEWANGLES_RANGE;
|
||||
s->sx=ClampI64(RoundI64(s->sx,VIEWANGLES_SNAP),0,VIEWANGLES_RANGE-1);
|
||||
s->sy=ClampI64(RoundI64(s->sy,VIEWANGLES_SNAP),0,VIEWANGLES_RANGE-1);
|
||||
s->sz=ClampI64(RoundI64(s->sz,VIEWANGLES_SNAP),0,VIEWANGLES_RANGE-1);
|
||||
s->ax=2*ã*s->sx/VIEWANGLES_RANGE;
|
||||
s->ay=2*ã*s->sy/VIEWANGLES_RANGE;
|
||||
s->az=2*ã*s->sz/VIEWANGLES_RANGE;
|
||||
}
|
||||
|
||||
U0 LeftClickViewAngles(CCtrl *c,I64 x,I64 y,Bool)
|
||||
{
|
||||
CViewAngles *s=c->state;
|
||||
I64 i;
|
||||
i=VIEWANGLES_RANGE-1-(y-(c->top+VIEWANGLES_SPACING));
|
||||
if (i>=VIEWANGLES_RANGE/2)
|
||||
i-=VIEWANGLES_RANGE/2;
|
||||
else
|
||||
i+=VIEWANGLES_RANGE/2;
|
||||
if (x<c->left+(c->right-c->left)/3)
|
||||
s->sx=i;
|
||||
else if (x<c->left+2*(c->right-c->left)/3)
|
||||
s->sy=i;
|
||||
else
|
||||
s->sz=i;
|
||||
if (c->update_derived_vals)
|
||||
(*c->update_derived_vals)(c);
|
||||
}
|
||||
|
||||
public CCtrl *ViewAnglesNew(CTask *task=NULL)
|
||||
{
|
||||
Bool old_preempt;
|
||||
CCtrl *c;
|
||||
CViewAngles *s;
|
||||
if (!task) task=Fs;
|
||||
if (!(c=CtrlFindUnique(task,CTRLT_VIEWING_ANGLES))) {
|
||||
s=CAlloc(sizeof(CViewAngles),task);
|
||||
c=CAlloc(sizeof(CCtrl));
|
||||
s->cbd=BLUE;
|
||||
s->cbg=LTBLUE;
|
||||
s->cfg=BLACK;
|
||||
s->cx=LTGREEN;
|
||||
s->cy=GREEN;
|
||||
s->cz=LTGREEN;
|
||||
c->win_task=task;
|
||||
c->flags=CTRLF_SHOW|CTRLF_CAPTURE_LEFT_IP;
|
||||
c->type=CTRLT_VIEWING_ANGLES;
|
||||
c->state=s;
|
||||
c->draw_it=&DrawViewAnglesCtrl;
|
||||
c->left_click=&LeftClickViewAngles;
|
||||
c->update_derived_vals=&UpdateDerivedViewAnglesCtrl;
|
||||
old_preempt=Preempt(OFF);
|
||||
QueIns(c,task->last_ctrl);
|
||||
TaskDerivedValsUpdate(task);
|
||||
Preempt(old_preempt);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
public U0 ViewAnglesDel(CTask *task=NULL)
|
||||
{
|
||||
CCtrl *c;
|
||||
Bool old_preempt=Preempt(OFF);
|
||||
if (!task) task=Fs;
|
||||
if (c=CtrlFindUnique(task,CTRLT_VIEWING_ANGLES)) {
|
||||
QueRem(c);
|
||||
Free(c->state);
|
||||
Free(c);
|
||||
}
|
||||
Preempt(old_preempt);
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
#define BUTTON_BORDER 2
|
||||
|
||||
#define BTF_DONT_FREE 1
|
||||
|
||||
class CCtrlButtonState
|
||||
{
|
||||
I64 state,num_states,flags;
|
||||
U8 *state_texts;
|
||||
CColorROPU32 *state_colors;
|
||||
};
|
||||
|
||||
U0 DrawCtrlButton(CDC *dc,CCtrl *c)
|
||||
{
|
||||
CCtrlButtonState *s=c->state;
|
||||
I64 l;
|
||||
U8 *st;
|
||||
|
||||
dc->color=BLACK;
|
||||
GrRect(dc,c->left,c->top,c->right-c->left+1,c->bottom-c->top+1);
|
||||
if (!(st=LstSub(s->state,s->state_texts)))
|
||||
st=s->state_texts;
|
||||
dc->color=s->state_colors[s->state];
|
||||
l=StrLen(st);
|
||||
GrRect(dc,c->left+BUTTON_BORDER,c->top+BUTTON_BORDER,
|
||||
c->right-c->left+1-BUTTON_BORDER*2,c->bottom-c->top+1-BUTTON_BORDER*2);
|
||||
dc->color=s->state_colors[s->state]^(WHITE<<16+WHITE);
|
||||
GrPrint(dc,(c->left+c->right+1-l*FONT_WIDTH)>>1,
|
||||
(c->top+c->bottom+1-FONT_HEIGHT)>>1,"%s",st);
|
||||
}
|
||||
|
||||
U0 LeftClickCtrlButton(CCtrl *c,I64,I64,Bool down)
|
||||
{
|
||||
CCtrlButtonState *s=c->state;
|
||||
if (down) {
|
||||
s->state++;
|
||||
if (s->state==s->num_states)
|
||||
s->state=0;
|
||||
}
|
||||
}
|
||||
|
||||
public CCtrl *CtrlButtonNew(I64 x,I64 y,I64 width=-1,I64 height=-1,
|
||||
I64 num_states=1,U8 *state_texts,I32 state_colors[],CCtrlButtonState *_s=NULL)
|
||||
{
|
||||
Bool old_preempt;
|
||||
CCtrl *result;
|
||||
CCtrlButtonState *s;
|
||||
I64 i,j,l;
|
||||
U8 *st;
|
||||
if (width<0) {
|
||||
l=1;
|
||||
for (i=0;i<num_states;i++)
|
||||
if (st=LstSub(i,state_texts)) {
|
||||
j=StrLen(st);
|
||||
if (j>l) l=j;
|
||||
}
|
||||
width=BUTTON_BORDER*4+l*FONT_WIDTH;
|
||||
}
|
||||
if (height<0) height=BUTTON_BORDER*4+FONT_HEIGHT;
|
||||
result=CAlloc(sizeof(CCtrl));
|
||||
if (_s) {
|
||||
s=_s;
|
||||
MemSet(s,0,sizeof(CCtrlButtonState));
|
||||
} else {
|
||||
s=CAlloc(sizeof(CCtrlButtonState));
|
||||
s->flags=BTF_DONT_FREE;
|
||||
}
|
||||
s->num_states=num_states;
|
||||
s->state_texts=state_texts;
|
||||
s->state_colors=state_colors;
|
||||
result->win_task=Fs;
|
||||
result->flags=CTRLF_SHOW;
|
||||
result->type=CTRLT_GENERIC;
|
||||
result->state=s;
|
||||
result->draw_it=&DrawCtrlButton;
|
||||
result->left_click=&LeftClickCtrlButton;
|
||||
result->left=x;
|
||||
result->top=y;
|
||||
result->right=result->left+width-1;
|
||||
result->bottom=result->top+height-1;
|
||||
old_preempt=Preempt(OFF);
|
||||
QueIns(result,Fs->last_ctrl);
|
||||
Preempt(old_preempt);
|
||||
return result;
|
||||
}
|
||||
|
||||
public U0 CtrlButtonDel(CCtrl *c)
|
||||
{
|
||||
Bool old_preempt=Preempt(OFF);
|
||||
QueRem(c);
|
||||
Preempt(old_preempt);
|
||||
if (!(c->flags&BTF_DONT_FREE))
|
||||
Free(c->state);
|
||||
Free(c);
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
class CMgdSCSlider
|
||||
{
|
||||
CMgdSCSlider *next,*last;
|
||||
U8 *name;
|
||||
I64 num;
|
||||
};
|
||||
|
||||
class CMgdSC
|
||||
{
|
||||
CMgdSCSlider *next_slider,*last_slider;
|
||||
I64 num_sliders,range,spacing,border;
|
||||
U8 *glbl_name;
|
||||
};
|
||||
|
||||
|
||||
CMgdSC *PmtSliderCtrl()
|
||||
{
|
||||
CMgdSCSlider *temps;
|
||||
U8 *st,pmt[136];
|
||||
CMgdSC *result=CAlloc(sizeof(CMgdSC));
|
||||
|
||||
"$$PURPLE$$Slider Ctrl$$FG$$\n\n";
|
||||
|
||||
result->glbl_name=PmtStr("Glbl Struct Name (ENTER for No Glbl):");
|
||||
result->range=PmtI64 ("Range (%4d):",30);
|
||||
result->spacing=PmtI64("Spacing (%4d):",20);
|
||||
result->border=PmtI64 ("Border (%4d):",2);
|
||||
|
||||
result->next_slider=result->last_slider=&result->next_slider;
|
||||
while (TRUE) {
|
||||
SPrint(pmt,"Slider #%d Name:",result->num_sliders+1);
|
||||
st=PmtStr(pmt);
|
||||
if (!*st) {
|
||||
Free(st);
|
||||
break;
|
||||
}
|
||||
temps=CAlloc(sizeof(CMgdSCSlider));
|
||||
temps->name=st;
|
||||
QueIns(temps,result->last_slider);
|
||||
temps->num=result->num_sliders++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
U0 MgdSliderCtrl(CDoc *doc)
|
||||
{
|
||||
CTask *task;
|
||||
CMgdSC *m=NULL;
|
||||
CMgdSCSlider *temps;
|
||||
I64 i;
|
||||
|
||||
DocUnlock(doc);
|
||||
DocRecalc(doc);
|
||||
DocCaptureUndo(doc,TRUE);
|
||||
|
||||
task=SpawnUser("CMgdSC **_m=0x%X;*_m=PmtSliderCtrl;\n",&m);
|
||||
while (!m)
|
||||
Yield;
|
||||
|
||||
DocPrint(doc,
|
||||
"#define SLIDER_RANGE %d
|
||||
#define SLIDER_SPACING %d
|
||||
#define SLIDER_BORDER %d
|
||||
|
||||
class CSliderState
|
||||
{
|
||||
",m->range,m->spacing,m->border);
|
||||
|
||||
|
||||
temps=m->next_slider;
|
||||
while (temps!=&m->next_slider) {
|
||||
DocPrint(doc," I64 %s;\n",temps->name);
|
||||
temps=temps->next;
|
||||
}
|
||||
if (*m->glbl_name)
|
||||
DocPrint(doc,"} %s;\n",m->glbl_name);
|
||||
else
|
||||
DocPrint(doc,"};\n");
|
||||
|
||||
|
||||
DocPrint(doc,
|
||||
"
|
||||
U0 DrawSliderCtrl(CDC *dc,CCtrl *c)
|
||||
{
|
||||
CSliderState *s=c->state;
|
||||
|
||||
dc->color=LTRED;
|
||||
GrRect(dc, c->left,c->top,%d*SLIDER_SPACING+%d,SLIDER_SPACING*2+SLIDER_RANGE);
|
||||
dc->color=BLUE;
|
||||
GrRect(dc, c->left+SLIDER_BORDER,c->top+SLIDER_BORDER,
|
||||
%d*SLIDER_SPACING+%d-2*SLIDER_BORDER,SLIDER_SPACING*2+SLIDER_RANGE-2*SLIDER_BORDER);
|
||||
dc->color=BLACK;
|
||||
",m->num_sliders+1,m->num_sliders,m->num_sliders+1,m->num_sliders);
|
||||
|
||||
for (i=0;i<m->num_sliders;i++)
|
||||
DocPrint(doc,
|
||||
" GrLine(dc,c->left+%d*SLIDER_SPACING+%d,c->top+SLIDER_SPACING,
|
||||
c->left+%d*SLIDER_SPACING+%d,c->top+SLIDER_SPACING+SLIDER_RANGE-1);
|
||||
",i+1,i,i+1,i);
|
||||
|
||||
DocPrint(doc," dc->color=LTRED;\n");
|
||||
|
||||
temps=m->next_slider;
|
||||
while (temps!=&m->next_slider) {
|
||||
DocPrint(doc,
|
||||
" GrPrint(dc,c->left+%d*SLIDER_SPACING+%d-FONT_WIDTH/2,
|
||||
c->top+SLIDER_SPACING+SLIDER_RANGE+3,
|
||||
\"%%d\",s->%s*10/SLIDER_RANGE);\n",
|
||||
temps->num+1,temps->num,temps->name);
|
||||
temps=temps->next;
|
||||
}
|
||||
|
||||
temps=m->next_slider;
|
||||
while (temps!=&m->next_slider) {
|
||||
DocPrint(doc," GrRect(dc,c->left+%d*SLIDER_SPACING+%d-3,c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->%s-2,7,5);\n",
|
||||
temps->num+1,temps->num,temps->name);
|
||||
temps=temps->next;
|
||||
}
|
||||
DocPrint(doc," dc->color=YELLOW;\n");
|
||||
|
||||
temps=m->next_slider;
|
||||
while (temps!=&m->next_slider) {
|
||||
DocPrint(doc," GrRect(dc,c->left+%d*SLIDER_SPACING+%d-2,c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->%s-1,5,3);\n",
|
||||
temps->num+1,temps->num,temps->name);
|
||||
temps=temps->next;
|
||||
}
|
||||
DocPrint(doc,
|
||||
"}
|
||||
|
||||
U0 UpdateDerivedSliderCtrl(CCtrl *c)
|
||||
{
|
||||
CSliderState *s=c->state;
|
||||
c->left=c->win_task->pix_width/2-(SLIDER_SPACING*3+2)/2;
|
||||
c->right=c->left+%d*SLIDER_SPACING+%d;
|
||||
c->top=c->win_task->pix_height/2-(SLIDER_SPACING*2+SLIDER_RANGE)/2;
|
||||
c->bottom=c->top+SLIDER_SPACING*2+SLIDER_RANGE;
|
||||
",m->num_sliders+1,m->num_sliders);
|
||||
|
||||
temps=m->next_slider;
|
||||
while (temps!=&m->next_slider) {
|
||||
DocPrint(doc," s->%s=ClampI64(s->%s,0,SLIDER_RANGE-1);\n",temps->name,temps->name);
|
||||
temps=temps->next;
|
||||
}
|
||||
DocPrint(doc,
|
||||
"}
|
||||
|
||||
U0 LeftClickSlider(CCtrl *c,I64 x,I64 y,Bool down)
|
||||
{
|
||||
nounusedwarn down;
|
||||
CSliderState *s=c->state;
|
||||
");
|
||||
|
||||
temps=m->next_slider;
|
||||
while (temps!=&m->next_slider) {
|
||||
DocPrint(doc," ");
|
||||
if (temps!=m->next_slider)
|
||||
DocPrint(doc,"else ");
|
||||
if (temps->next==&m->next_slider)
|
||||
DocPrint(doc,"\n");
|
||||
else
|
||||
DocPrint(doc,"if (x<c->left+%d*SLIDER_SPACING+%d+SLIDER_SPACING/2)\n",
|
||||
temps->num+1,temps->num);
|
||||
DocPrint(doc," s->%s=SLIDER_RANGE-1-(y-(c->top+SLIDER_SPACING));\n",
|
||||
temps->name);
|
||||
temps=temps->next;
|
||||
}
|
||||
|
||||
DocPrint(doc,
|
||||
" if (c->update_derived_vals)
|
||||
(*c->update_derived_vals)(c);
|
||||
}
|
||||
|
||||
CCtrl *SliderNew()
|
||||
{
|
||||
Bool old_preempt;
|
||||
CCtrl *c=CAlloc(sizeof(CCtrl));
|
||||
c->win_task=Fs;
|
||||
c->flags=CTRLF_SHOW|CTRLF_CAPTURE_LEFT_IP;
|
||||
c->type=CTRLT_GENERIC;
|
||||
");
|
||||
if (*m->glbl_name)
|
||||
DocPrint(doc," c->state=&%s;\n"
|
||||
" MemSet(&%s,0,sizeof(CSliderState));\n",m->glbl_name,m->glbl_name);
|
||||
else
|
||||
DocPrint(doc, " c->state=CAlloc(sizeof(CSliderState));\n");
|
||||
DocPrint(doc,
|
||||
" c->draw_it=&DrawSliderCtrl;
|
||||
c->left_click=&LeftClickSlider;
|
||||
c->update_derived_vals=&UpdateDerivedSliderCtrl;
|
||||
old_preempt=Preempt(OFF);
|
||||
QueIns(c,Fs->last_ctrl);
|
||||
TaskDerivedValsUpdate;
|
||||
Preempt(old_preempt);
|
||||
return c;
|
||||
}
|
||||
|
||||
U0 SliderDel(CCtrl *c)
|
||||
{
|
||||
Bool old_preempt=Preempt(OFF);
|
||||
QueRem(c);
|
||||
Preempt(old_preempt);
|
||||
");
|
||||
if (!*m->glbl_name)
|
||||
DocPrint(doc," Free(c->state);\n");
|
||||
DocPrint(doc,
|
||||
" Free(c);
|
||||
}
|
||||
");
|
||||
|
||||
Kill(task); //This frees memory.
|
||||
|
||||
AcctOneTimePopUp(ARf_MANAGE_SLIDER,
|
||||
"Modify the code to your heart's content.\n"
|
||||
"The code is no longer managed.\n");
|
||||
|
||||
DocLock(doc);
|
||||
}
|
||||
Reference in new issue
Block a user