egra: added assembler-optimised span blending function for agg
[iv.d.git] / sdpy / ztest.d
blob5f31861594672583306c39c7f1923c10209d16e8
1 /*
2 * Pixel Graphics Library
3 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
4 * Understanding is not required. Only obedience.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, version 3 of the License ONLY.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 import iv.sdpy;
20 import iv.vfs;
23 void main (string[] args) {
24 import std.stdio;
26 { import core.runtime : Runtime; Runtime.traceHandlerAllowTrace = true; }
28 vlProcessArgs(args);
29 vlWidth = 400;
30 vlHeight = 300;
32 auto chr = new BgiChr("chrfonts/v1/thin.chr");
33 writeln("baseline: ", chr.baseline, "; ascent: ", chr.ascent, "; descent: ", chr.descent, "; height: ", chr.height);
35 int gbx = 3, gby = 3;
36 bool gbvis = false;
38 auto gb = GfxBuf(92, 48);
39 gb.clear(VColor.green);
40 gb.region.punch(0, 0);
41 gb.region.punch(gb.width-1, 0);
42 gb.region.punch(0, gb.height-1);
43 gb.region.punch(gb.width-1, gb.height-1);
45 sdpyCloseQueryCB = delegate () {
46 sdpyPostQuitMessage();
49 sdpyClearVScrCB = delegate () {
50 auto vlOvl = GfxBuf.vlVScrBuf;
51 vlOvl.clear(VColor.black);
54 sdpyPreDrawCB = delegate () {
55 import std.string : format;
57 auto vlOvl = GfxBuf.vlVScrBuf;
59 vlOvl.drawText(10, 10, "Text!", VColor.rgb(255, 0, 0));
61 auto s = "%03s,%03s".format(sdpyMouseX, sdpyMouseY);
62 vlOvl.drawText(10, 20, s, VColor.rgb(255, 0, 0));
65 char[3] buf = ' ';
66 if (sdpyMouseButts&SdpyButtonDownLeft) buf[0] = 'L';
67 if (sdpyMouseButts&SdpyButtonDownMiddle) buf[1] = 'M';
68 if (sdpyMouseButts&SdpyButtonDownRight) buf[2] = 'R';
69 vlOvl.drawText(10, 30, buf, VColor.rgb(255, 0, 0));
73 char[4] buf = ' ';
74 if (sdpyKeyMods&SdpyKeyCtrlDown) buf[0] = 'C';
75 if (sdpyKeyMods&SdpyKeyAltDown) buf[1] = 'A';
76 if (sdpyKeyMods&SdpyKeyShiftDown) buf[2] = 'S';
77 if (sdpyKeyMods&SdpyKeyMetaDown) buf[3] = 'M';
78 vlOvl.drawText(10, 40, buf, VColor.rgb(255, 0, 0));
81 int cy = 60;
82 chr.drawText(vlOvl, 10, cy, "Hello from BGI!", VColor.rgb(255, 255, 0));
83 vlOvl.hline(0, cy, 400, VColor.rgb(255, 0, 0));
84 vlOvl.hline(0, cy-chr.height, 400, VColor.rgb(255, 127, 0));
85 vlOvl.hline(0, cy-chr.baseline, 400, VColor.rgb(0, 255, 0));
86 vlOvl.hline(0, cy-chr.ascent, 400, VColor.rgb(0, 127, 0));
87 vlOvl.hline(0, cy-chr.descent, 400, VColor.rgb(127, 127, 0));
89 foreach (int dy; 0..16) {
90 foreach (int dx; 0..16) {
91 int x = dx*14+4;
92 int y = dy*14+cy;
93 chr.drawChar(vlOvl, x, y, cast(char)(dy*16+dx), VColor.white, 1);
97 //vlOvl.drawTextProp(10, 10, "Text", VColor.rgb(255, 127, 0));
100 sdpyPostDrawCB = delegate () {
101 if (gbvis) gb.blitToVScr(gbx, gby);
104 sdpyFrameCB = delegate () {
107 sdpyOnKeyCB = delegate (KeyEvent evt, bool active) {
108 if (!active) return;
109 if (evt.key == Key.Escape) { sdpyPostQuitMessage(); return; }
110 if (!evt.pressed) return;
111 if (!gbvis) return;
112 switch (evt.key) with (Key) {
113 case Left: gbx -= 1; break;
114 case Right: gbx += 1; break;
115 case Up: gby -= 1; break;
116 case Down: gby += 1; break;
117 default:
121 sdpyOnMouseCB = delegate (MouseEvent evt, bool active) {
124 sdpyOnCharCB = delegate (dchar ch, bool active) {
125 if (ch == ' ') gbvis = !gbvis;
128 sdpyMainLoop();