123 lines
10 KiB
HTML
Executable File
123 lines
10 KiB
HTML
Executable File
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="generator" content="TempleOS V5.03">
|
|
<meta name="viewport" content="width=device-width">
|
|
<link rel="stylesheet" href="/style/templeos.css">
|
|
<script src="/script/templeos.js"></script>
|
|
<style type="text/css">
|
|
.cF0{color:#000000;background-color:#ffffff;}
|
|
.cF1{color:#0000aa;background-color:#ffffff;}
|
|
.cF2{color:#00aa00;background-color:#ffffff;}
|
|
.cF3{color:#00aaaa;background-color:#ffffff;}
|
|
.cF4{color:#aa0000;background-color:#ffffff;}
|
|
.cF5{color:#aa00aa;background-color:#ffffff;}
|
|
.cF6{color:#aa5500;background-color:#ffffff;}
|
|
.cF7{color:#aaaaaa;background-color:#ffffff;}
|
|
.cF8{color:#555555;background-color:#ffffff;}
|
|
.cF9{color:#5555ff;background-color:#ffffff;}
|
|
.cFA{color:#55ff55;background-color:#ffffff;}
|
|
.cFB{color:#55ffff;background-color:#ffffff;}
|
|
.cFC{color:#ff5555;background-color:#ffffff;}
|
|
.cFD{color:#ff55ff;background-color:#ffffff;}
|
|
.cFE{color:#ffff55;background-color:#ffffff;}
|
|
.cFF{color:#ffffff;background-color:#ffffff;}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<pre id="content">
|
|
<a name="l1"></a><span class=cF0>#</span><span class=cF1>define</span><span class=cF0> </span><span class=cF3>BTTN_BORDER</span><span class=cF0> 2
|
|
<a name="l2"></a>
|
|
<a name="l3"></a>#</span><span class=cF1>define</span><span class=cF0> </span><span class=cF3>BTF_DONT_FREE</span><span class=cF0> 1
|
|
<a name="l4"></a>
|
|
<a name="l5"></a></span><span class=cF1>class</span><span class=cF0> </span><span class=cF9>CCtrlBttnState</span><span class=cF0>
|
|
<a name="l6"></a>{
|
|
<a name="l7"></a> </span><span class=cF9>I64</span><span class=cF0> state,num_states,flags;
|
|
<a name="l8"></a> </span><span class=cF1>U8</span><span class=cF0> *state_texts;
|
|
<a name="l9"></a> </span><span class=cF9>CColorROPU32</span><span class=cF0> *state_colors;
|
|
<a name="l10"></a>};
|
|
<a name="l11"></a>
|
|
<a name="l12"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>DrawCtrlBttn</span><span class=cF0>(</span><span class=cF9>CDC</span><span class=cF0> *dc,</span><span class=cF9>CCtrl</span><span class=cF0> *c)
|
|
<a name="l13"></a>{
|
|
<a name="l14"></a> </span><span class=cF9>CCtrlBttnState</span><span class=cF0> *s=c->state;
|
|
<a name="l15"></a> </span><span class=cF9>I64</span><span class=cF0> l;
|
|
<a name="l16"></a> </span><span class=cF1>U8</span><span class=cF0> *st;
|
|
<a name="l17"></a>
|
|
<a name="l18"></a> dc->color=</span><span class=cF3>BLACK</span><span class=cF0>;
|
|
<a name="l19"></a> </span><span class=cF5>GrRect</span><span class=cF0>(dc,c->left,c->top,c->right-c->left+1,c->bottom-c->top+1);
|
|
<a name="l20"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>st=</span><span class=cF5>LstSub</span><span class=cF0>(s->state,s->state_texts)</span><span class=cF7>)</span><span class=cF0>)
|
|
<a name="l21"></a> st=s->state_texts;
|
|
<a name="l22"></a> dc->color=s->state_colors[s->state];
|
|
<a name="l23"></a> l=</span><span class=cF5>StrLen</span><span class=cF0>(st);
|
|
<a name="l24"></a> </span><span class=cF5>GrRect</span><span class=cF0>(dc,c->left+</span><span class=cF3>BTTN_BORDER</span><span class=cF0>,c->top+</span><span class=cF3>BTTN_BORDER</span><span class=cF0>,
|
|
<a name="l25"></a> c->right-c->left+1-</span><span class=cF3>BTTN_BORDER</span><span class=cF0>*2,
|
|
<a name="l26"></a> c->bottom-c->top+1-</span><span class=cF3>BTTN_BORDER</span><span class=cF0>*2);
|
|
<a name="l27"></a> dc->color=s->state_colors[s->state]^(</span><span class=cF3>WHITE</span><span class=cF0><<16+</span><span class=cF3>WHITE</span><span class=cF0>);
|
|
<a name="l28"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc,</span><span class=cF7>(</span><span class=cF0>c->left+c->right+1-l*</span><span class=cF3>FONT_WIDTH</span><span class=cF7>)</span><span class=cF0>>>1,
|
|
<a name="l29"></a> </span><span class=cF7>(</span><span class=cF0>c->top+c->bottom+1-</span><span class=cF3>FONT_HEIGHT</span><span class=cF7>)</span><span class=cF0>>>1,</span><span class=cF6>"%s"</span><span class=cF0>,st);
|
|
<a name="l30"></a>}
|
|
<a name="l31"></a>
|
|
<a name="l32"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>LeftClickCtrlBttn</span><span class=cF0>(</span><span class=cF9>CCtrl</span><span class=cF0> *c,</span><span class=cF9>I64</span><span class=cF0>,</span><span class=cF9>I64</span><span class=cF0>,</span><span class=cF1>Bool</span><span class=cF0> down)
|
|
<a name="l33"></a>{
|
|
<a name="l34"></a> </span><span class=cF9>CCtrlBttnState</span><span class=cF0> *s=c->state;
|
|
<a name="l35"></a> </span><span class=cF1>if</span><span class=cF0> (down) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l36"></a> s->state++;
|
|
<a name="l37"></a> </span><span class=cF1>if</span><span class=cF0> (s->state==s->num_states)
|
|
<a name="l38"></a> s->state=0;
|
|
<a name="l39"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l40"></a>}
|
|
<a name="l41"></a>
|
|
<a name="l42"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF9>CCtrl</span><span class=cF0> *</span><span class=cF5>CtrlBttnNew</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> x,</span><span class=cF9>I64</span><span class=cF0> y,</span><span class=cF9>I64</span><span class=cF0> width=-1,</span><span class=cF9>I64</span><span class=cF0> height=-1,
|
|
<a name="l43"></a> </span><span class=cF9>I64</span><span class=cF0> num_states=1,</span><span class=cF1>U8</span><span class=cF0> *state_texts,
|
|
<a name="l44"></a> </span><span class=cF9>I32</span><span class=cF0> *state_colors,</span><span class=cF9>CCtrlBttnState</span><span class=cF0> *_s=</span><span class=cF3>NULL</span><span class=cF0>)
|
|
<a name="l45"></a>{</span><span class=cF2>//Create bttn ctrl. See </span><a href="/Wb/Apps/Strut/Strut.HC.HTML#l1"><span class=cF4>::/Apps/Strut/Strut.HC</span></a><span class=cF2>.</span><span class=cF0>
|
|
<a name="l46"></a> </span><span class=cF9>CCtrl</span><span class=cF0> *res;
|
|
<a name="l47"></a> </span><span class=cF9>CCtrlBttnState</span><span class=cF0> *s;
|
|
<a name="l48"></a> </span><span class=cF9>I64</span><span class=cF0> i,j,l;
|
|
<a name="l49"></a> </span><span class=cF1>U8</span><span class=cF0> *st;
|
|
<a name="l50"></a> </span><span class=cF1>if</span><span class=cF0> (width<0) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l51"></a> l=1;
|
|
<a name="l52"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i<num_states;i++)
|
|
<a name="l53"></a> </span><span class=cF1>if</span><span class=cF0> (st=</span><span class=cF5>LstSub</span><span class=cF7>(</span><span class=cF0>i,state_texts</span><span class=cF7>)</span><span class=cF0>) {
|
|
<a name="l54"></a> j=</span><span class=cF5>StrLen</span><span class=cF0>(st);
|
|
<a name="l55"></a> </span><span class=cF1>if</span><span class=cF0> (j>l) l=j;
|
|
<a name="l56"></a> }
|
|
<a name="l57"></a> width=</span><span class=cF3>BTTN_BORDER</span><span class=cF0>*4+l*</span><span class=cF3>FONT_WIDTH</span><span class=cF0>;
|
|
<a name="l58"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l59"></a> </span><span class=cF1>if</span><span class=cF0> (height<0) height=</span><span class=cF3>BTTN_BORDER</span><span class=cF0>*4+</span><span class=cF3>FONT_HEIGHT</span><span class=cF0>;
|
|
<a name="l60"></a> res=</span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CCtrl</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l61"></a> </span><span class=cF1>if</span><span class=cF0> (_s) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l62"></a> s=_s;
|
|
<a name="l63"></a> </span><span class=cF5>MemSet</span><span class=cF0>(s,0,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CCtrlBttnState</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l64"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l65"></a> s=</span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CCtrlBttnState</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l66"></a> s->flags=</span><span class=cF3>BTF_DONT_FREE</span><span class=cF0>;
|
|
<a name="l67"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l68"></a> s->num_states=num_states;
|
|
<a name="l69"></a> s->state_texts=state_texts;
|
|
<a name="l70"></a> s->state_colors=state_colors;
|
|
<a name="l71"></a> res->win_task=</span><span class=cF5>Fs</span><span class=cF0>;
|
|
<a name="l72"></a> res->flags=</span><span class=cF3>CTRLF_SHOW</span><span class=cF0>;
|
|
<a name="l73"></a> res->type=</span><span class=cF3>CTRLT_GENERIC</span><span class=cF0>;
|
|
<a name="l74"></a> res->state=s;
|
|
<a name="l75"></a> res->draw_it=&</span><span class=cF5>DrawCtrlBttn</span><span class=cF0>;
|
|
<a name="l76"></a> res->left_click=&</span><span class=cF5>LeftClickCtrlBttn</span><span class=cF0>;
|
|
<a name="l77"></a> res->left=x;
|
|
<a name="l78"></a> res->top=y;
|
|
<a name="l79"></a> res->right=res->left+width-1;
|
|
<a name="l80"></a> res->bottom=res->top+height-1;
|
|
<a name="l81"></a> </span><span class=cF5>QueIns</span><span class=cF0>(res,</span><span class=cF5>Fs</span><span class=cF0>->last_ctrl);
|
|
<a name="l82"></a> </span><span class=cF1>return</span><span class=cF0> res;
|
|
<a name="l83"></a>}
|
|
<a name="l84"></a>
|
|
<a name="l85"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>CtrlBttnDel</span><span class=cF0>(</span><span class=cF9>CCtrl</span><span class=cF0> *c)
|
|
<a name="l86"></a>{</span><span class=cF2>//Free bttn ctrl.</span><span class=cF0>
|
|
<a name="l87"></a> </span><span class=cF5>QueRem</span><span class=cF0>(c);
|
|
<a name="l88"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>c->flags&</span><span class=cF3>BTF_DONT_FREE</span><span class=cF7>)</span><span class=cF0>)
|
|
<a name="l89"></a> </span><span class=cF5>Free</span><span class=cF0>(c->state);
|
|
<a name="l90"></a> </span><span class=cF5>Free</span><span class=cF0>(c);
|
|
<a name="l91"></a>}
|
|
</span></pre></body>
|
|
</html>
|