mirror of
https://github.com/Zeal-Operating-System/ZealOS.git
synced 2024-12-29 16:56:30 +00:00
123 lines
11 KiB
HTML
Executable file
123 lines
11 KiB
HTML
Executable file
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
|
|
<meta name="generator" content="ZealOS V0.10">
|
|
<style type="text/css">
|
|
body {background-color:#000000;}
|
|
.cF0{color:#ffffff;background-color:#000000;}
|
|
.cF1{color:#3465a4;background-color:#000000;}
|
|
.cF2{color:#4e9a06;background-color:#000000;}
|
|
.cF3{color:#06989a;background-color:#000000;}
|
|
.cF4{color:#a24444;background-color:#000000;}
|
|
.cF5{color:#75507b;background-color:#000000;}
|
|
.cF6{color:#ce982f;background-color:#000000;}
|
|
.cF7{color:#bcc0b9;background-color:#000000;}
|
|
.cF8{color:#555753;background-color:#000000;}
|
|
.cF9{color:#729fcf;background-color:#000000;}
|
|
.cFA{color:#82bc49;background-color:#000000;}
|
|
.cFB{color:#34e2e2;background-color:#000000;}
|
|
.cFC{color:#ac3535;background-color:#000000;}
|
|
.cFD{color:#ad7fa8;background-color:#000000;}
|
|
.cFE{color:#fce94f;background-color:#000000;}
|
|
.cFF{color:#000000;background-color:#000000;}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<pre style="font-family:monospace;font-size:12pt">
|
|
<a name="l1"></a><span class=cFA>
|
|
<a name="l2"></a><1>/* Graphics Not Rendered in HTML */</span><span class=cF0>
|
|
<a name="l3"></a>
|
|
<a name="l4"></a>#</span><span class=cF1>define</span><span class=cF0> APPLES_NUM </span><span class=cFE>128</span><span class=cF0>
|
|
<a name="l5"></a>
|
|
<a name="l6"></a></span><span class=cF9>I64</span><span class=cF0> x[APPLES_NUM], y[APPLES_NUM], cur_apple, cur_dist;
|
|
<a name="l7"></a></span><span class=cF1>Bool</span><span class=cF0> trigger;
|
|
<a name="l8"></a>
|
|
<a name="l9"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>DrawIt</span><span class=cF0>(</span><span class=cF9>CTask</span><span class=cF0> *, </span><span class=cF9>CDC</span><span class=cF0> *dc)
|
|
<a name="l10"></a>{
|
|
<a name="l11"></a> </span><span class=cF9>I64</span><span class=cF0> i, best_dist = </span><span class=cF3>I64_MAX</span><span class=cF0>, best_apple = </span><span class=cFE>0</span><span class=cF0>;
|
|
<a name="l12"></a>
|
|
<a name="l13"></a> dc->flags |= </span><span class=cF3>DCF_LOCATE_NEAREST</span><span class=cF0>;
|
|
<a name="l14"></a> dc->cur_x = </span><span class=cFB>mouse</span><span class=cF0>.pos.x;
|
|
<a name="l15"></a> dc->cur_y = </span><span class=cFB>mouse</span><span class=cF0>.pos.y;
|
|
<a name="l16"></a> dc->cur_z = </span><span class=cFE>0</span><span class=cF0>;
|
|
<a name="l17"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i < APPLES_NUM; i++)
|
|
<a name="l18"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l19"></a> </span><span class=cF5>Sprite3</span><span class=cF0>(dc, x[i], y[i], </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFA><1></span><span class=cF0>);
|
|
<a name="l20"></a> </span><span class=cF1>if</span><span class=cF0> (dc->nearest_dist <= best_dist)
|
|
<a name="l21"></a> {
|
|
<a name="l22"></a> </span><span class=cF2>//Distance to nearest pix, squared</span><span class=cF0>
|
|
<a name="l23"></a> </span><span class=cF2>//</span><a href="https://tomawezome.github.io/ZealOS/Kernel/KernelB.HH.html#l84"><span class=cF4>Sqrt</span></a><span class=cF2>() is expensive so we work with distance squared.</span><span class=cF0>
|
|
<a name="l24"></a> best_dist = dc->nearest_dist;
|
|
<a name="l25"></a> best_apple = i;
|
|
<a name="l26"></a> }
|
|
<a name="l27"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l28"></a> </span><span class=cF1>if</span><span class=cF0> (trigger)
|
|
<a name="l29"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l30"></a> cur_apple = best_apple;
|
|
<a name="l31"></a> cur_dist = best_dist;
|
|
<a name="l32"></a> trigger = </span><span class=cF3>FALSE</span><span class=cF0>;
|
|
<a name="l33"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l34"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc, </span><span class=cF3>FONT_WIDTH</span><span class=cF0>, </span><span class=cF3>FONT_HEIGHT</span><span class=cF0>, </span><span class=cF6>"Dist Squared:%d"</span><span class=cF0>, cur_dist);
|
|
<a name="l35"></a>}
|
|
<a name="l36"></a>
|
|
<a name="l37"></a></span><span class=cF1>U0</span><span class=cF0> Pick()
|
|
<a name="l38"></a>{
|
|
<a name="l39"></a> </span><span class=cF9>I64</span><span class=cF0> i, message_code, arg1, arg2, delta_x, delta_y;
|
|
<a name="l40"></a>
|
|
<a name="l41"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i < APPLES_NUM; i++)
|
|
<a name="l42"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l43"></a> x[i] = </span><span class=cF5>RandU16</span><span class=cF0> % </span><span class=cF3>GR_WIDTH</span><span class=cF0>;
|
|
<a name="l44"></a> y[i] = </span><span class=cF5>RandU16</span><span class=cF0> % (</span><span class=cF3>GR_HEIGHT</span><span class=cF0> - </span><span class=cF3>FONT_HEIGHT</span><span class=cF0> * </span><span class=cFE>3</span><span class=cF0>) + </span><span class=cF3>FONT_HEIGHT</span><span class=cF0> * </span><span class=cFE>3</span><span class=cF0>;
|
|
<a name="l45"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l46"></a> </span><span class=cF5>SettingsPush</span><span class=cF0>; </span><span class=cF2>//See </span><a href="https://tomawezome.github.io/ZealOS/System/TaskSettings.CC.html#l3"><span class=cF4>SettingsPush</span></a><span class=cF0>
|
|
<a name="l47"></a> </span><span class=cF5>AutoComplete</span><span class=cF0>;
|
|
<a name="l48"></a> </span><span class=cF5>DocCursor</span><span class=cF0>;
|
|
<a name="l49"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
|
|
<a name="l50"></a>
|
|
<a name="l51"></a> trigger = </span><span class=cF3>FALSE</span><span class=cF0>;
|
|
<a name="l52"></a> cur_apple = cur_dist = </span><span class=cFE>0</span><span class=cF0>;
|
|
<a name="l53"></a>
|
|
<a name="l54"></a> </span><span class=cF5>Fs</span><span class=cF0>->draw_it = &</span><span class=cF5>DrawIt</span><span class=cF0>;
|
|
<a name="l55"></a> </span><span class=cF5>Fs</span><span class=cF0>->win_inhibit = </span><span class=cF3>WIG_TASK_DEFAULT</span><span class=cF0> - </span><span class=cF3>WIF_SELF_FOCUS</span><span class=cF0> - </span><span class=cF3>WIF_SELF_BORDER</span><span class=cF0>;
|
|
<a name="l56"></a>
|
|
<a name="l57"></a> </span><span class=cF1>try</span><span class=cF0>
|
|
<a name="l58"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l59"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>)
|
|
<a name="l60"></a> {
|
|
<a name="l61"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>MessageGet</span><span class=cF7>(</span><span class=cF0>&arg1, &arg2, </span><span class=cFE>1</span><span class=cF0> << </span><span class=cF3>MESSAGE_KEY_DOWN</span><span class=cF0> | </span><span class=cFE>1</span><span class=cF0> << </span><span class=cF3>MESSAGE_MS_L_DOWN</span><span class=cF7>)</span><span class=cF0> == </span><span class=cF3>MESSAGE_KEY_DOWN</span><span class=cF0>)
|
|
<a name="l62"></a> </span><span class=cF1>goto</span><span class=cF0> pi_done;
|
|
<a name="l63"></a>
|
|
<a name="l64"></a> </span><span class=cF2>//Wait for window mgr to call DrawIt()</span><span class=cF0>
|
|
<a name="l65"></a> trigger = </span><span class=cF3>TRUE</span><span class=cF0>;
|
|
<a name="l66"></a> </span><span class=cF1>do</span><span class=cF0> </span><span class=cF5>Refresh</span><span class=cF0>;
|
|
<a name="l67"></a> </span><span class=cF1>while</span><span class=cF0> (trigger);
|
|
<a name="l68"></a>
|
|
<a name="l69"></a> </span><span class=cF2>//Use screen coordinates, not window (arg1,arg2)</span><span class=cF0>
|
|
<a name="l70"></a> </span><span class=cF2>//</span><a href="https://tomawezome.github.io/ZealOS/Kernel/KGlobals.CC.html#l25"><span class=cF4>mouse.pos.x</span></a><span class=cF2> and </span><a href="https://tomawezome.github.io/ZealOS/Kernel/KGlobals.CC.html#l25"><span class=cF4>mouse.pos.y</span></a><span class=cF2> are global vars updated</span><span class=cF0>
|
|
<a name="l71"></a> </span><span class=cF2>//updated by the window mgr to hold the</span><span class=cF0>
|
|
<a name="l72"></a> </span><span class=cF2>//screen coordinates of the mouse.</span><span class=cF0>
|
|
<a name="l73"></a> delta_x = x[cur_apple] - </span><span class=cFB>mouse</span><span class=cF0>.pos.x;
|
|
<a name="l74"></a> delta_y = y[cur_apple] - </span><span class=cFB>mouse</span><span class=cF0>.pos.y;
|
|
<a name="l75"></a>
|
|
<a name="l76"></a> </span><span class=cF1>do</span><span class=cF0>
|
|
<a name="l77"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l78"></a> message_code = </span><span class=cF5>MessageGet</span><span class=cF0>(&arg1, &arg2, </span><span class=cFE>1</span><span class=cF0> << </span><span class=cF3>MESSAGE_KEY_DOWN</span><span class=cF0> | </span><span class=cFE>1</span><span class=cF0> << </span><span class=cF3>MESSAGE_MS_MOVE</span><span class=cF0> | </span><span class=cFE>1</span><span class=cF0> << </span><span class=cF3>MESSAGE_MS_L_UP</span><span class=cF0>);
|
|
<a name="l79"></a> </span><span class=cF1>if</span><span class=cF0> (message_code == </span><span class=cF3>MESSAGE_KEY_DOWN</span><span class=cF0>)
|
|
<a name="l80"></a> </span><span class=cF1>goto</span><span class=cF0> pi_done;
|
|
<a name="l81"></a> x[cur_apple] = </span><span class=cFB>mouse</span><span class=cF0>.pos.x + delta_x;
|
|
<a name="l82"></a> y[cur_apple] = </span><span class=cFB>mouse</span><span class=cF0>.pos.y + delta_y;
|
|
<a name="l83"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l84"></a> </span><span class=cF1>while</span><span class=cF0> (message_code != </span><span class=cF3>MESSAGE_MS_L_UP</span><span class=cF0>);
|
|
<a name="l85"></a> }
|
|
<a name="l86"></a>pi_done:
|
|
<a name="l87"></a> </span><span class=cF5>MessageGet</span><span class=cF0>(,, </span><span class=cFE>1</span><span class=cF0> << </span><span class=cF3>MESSAGE_KEY_UP</span><span class=cF0>);
|
|
<a name="l88"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l89"></a> </span><span class=cF1>catch</span><span class=cF0>
|
|
<a name="l90"></a> </span><span class=cF5>PutExcept</span><span class=cF0>;
|
|
<a name="l91"></a> </span><span class=cF5>SettingsPop</span><span class=cF0>;
|
|
<a name="l92"></a>}
|
|
<a name="l93"></a>
|
|
<a name="l94"></a>Pick;
|
|
</span></pre></body>
|
|
</html>
|