Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
963 changes: 963 additions & 0 deletions src/Demo/Games/VaroomTrueColors.ZC

Large diffs are not rendered by default.

17 changes: 11 additions & 6 deletions src/Demo/Graphics/Mandel.ZC
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ U0 MandelFrame(I64 core)
F64 ymin = yCenter - (xExtent / aspect / 2.0);
F64 ymax = ymin + (xExtent / aspect);

F64 x, y, x0, y0, x2, y2;
F64 x, y, x0, y0, x2, y2, t;
F64 xscale = (xmax - xmin) / ToF64(width);
F64 yscale = (ymax - ymin) / ToF64(height);
I64 iteration;
I64 px, py;
I64 px, py, r, g, b;

for (py = startY; py < maxY; py++) {
y0 = ymin + ToF64(py) * yscale;
Expand Down Expand Up @@ -76,11 +76,16 @@ U0 MandelFrame(I64 core)
// Instead of getting a DC handle
// every time, we can just poke
// into the body of the DC.
// (is that ok?)
// Native 32-bit pixs: smooth sine-based coloring, 16M colors.
if (iteration >= iterations)
image->body[py*width+px] = 15;
else
image->body[py*width+px] = iteration % 15;
image->body[py*width+px] = 0; //Inside the set: black.
else {
t = iteration * 0.35;
r = 128 + 127.0 * Sin(t);
g = 128 + 127.0 * Sin(t + 2.094);
b = 128 + 127.0 * Sin(t + 4.188);
image->body[py*width+px] = r << 16 | g << 8 | b;
}


}
Expand Down
58 changes: 58 additions & 0 deletions src/Demo/Graphics/TrueColor/Colorize.ZC
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Colorize the whole OS: a truecolor gradient desktop + a matched truecolor
// theme (border frames + title bars). Everything else keeps working.
//
// Colorize; enable the gradient desktop + Midnight chrome
// Decolorize; restore the flat desktop + 16-color chrome
//
// NOTE: this installs a wallpaper callback from a JIT'd script; it stays active
// for the session. Run Decolorize; before recompiling the OS or clearing heaps.

U0 (*colorize_prev_wp)(CTask *task) = NULL;

U0 ColorizeWallPaper(CTask *task)
{//Fill the desktop (winmgr) cells with a dark Zeal-blue gradient, then chain to
//the previous wallpaper (the stats readout). Windows draw over, so only the
//uncovered desktop shows the gradient. Kept DARK so overlaid text stays readable.
I64 x, y, idx, r, g, b, fx, fy;

for (y = 0; y < TEXT_ROWS; y++)
{
fy = 255 * y / TEXT_ROWS;
for (x = 0; x < TEXT_COLS; x++)
{
fx = 255 * x / TEXT_COLS;
//Deep navy at top-left, dark blue-cyan toward bottom-right. Zeal blue.
r = 5 + ((fx * 10) >> 8); //5..15
g = 9 + ((fy * 18) >> 8); //9..27
b = 20 + ((fy * 26) >> 8) + ((fx * 14) >> 8); //20..60
idx = y * TEXT_COLS + x;
gr.text_base[idx] = gr.text_base[idx] & 0xFF | ATTRF_TRUE_COLOR;
gr.text_fg[idx] = 0x1A2438;
gr.text_bg[idx] = r << 16 | g << 8 | b;
}
}

if (colorize_prev_wp)
(*colorize_prev_wp)(task);
}

U0 Colorize()
{//Turn the OS colorful.
GuiThemeMidnight;
if (gr.fp_wall_paper != &ColorizeWallPaper)
colorize_prev_wp = gr.fp_wall_paper;
gr.fp_wall_paper = &ColorizeWallPaper;
"Colorized. Gradient desktop + Midnight chrome. Run Decolorize; to revert.\n";
}

U0 Decolorize()
{//Restore the plain desktop + 16-color chrome + palette syntax.
if (colorize_prev_wp)
gr.fp_wall_paper = colorize_prev_wp;
GuiChromePalette;
GuiSyntaxPalette;
PaletteSetSlate;
"Restored.\n";
}

Colorize;
88 changes: 88 additions & 0 deletions src/Demo/Graphics/TrueColor/TCProbe.ZC
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Truecolor crash probe. Exercises each Varoom-style code path with ColorRGB
// pens, one step at a time. The LAST number printed before a hang/crash names
// the faulting API. All steps together take a few seconds.

CDC *probe_map;

I64 probe_flags;

U0 ProbeMPJob(CDC *dc2)
{//Minimal multicore job like Varoom's MPUpdateWin: TC draw from another core.
CDC *dc = DCAlias(gr.dc2, dc2->win_task);

dc->color = ColorRGB(0x20, 0xC0, 0x80);
GrRect(dc, 300 + 20 * Gs->num, 60, 16, 16);
DCDel(dc);
LBtr(&probe_flags, Gs->num);
}

U0 TCProbe()
{
I64 i;
CD3I32 poly[4];
CDC *dc = DCAlias(gr.dc2, Fs);

"1 plain-DC TC GrRect...\n";
probe_map = DCNew(128, 128);
probe_map->color = ColorRGB(0x26, 0x2A, 0x36);
GrRect(probe_map, 0, 0, 128, 128);

"2 plain-DC TC GrPlot3 thick=3...\n";
probe_map->color = ColorRGB(0xFF, 0xD0, 0x40);
probe_map->thick = 3;
for (i = 0; i < 64; i++)
GrPlot3(probe_map, i * 2, 64, 0);
probe_map->thick = 1;

"3 screen TC GrRect...\n";
dc->color = ColorRGB(0x3C, 0x78, 0xC8);
GrRect(dc, 8, 8, 200, 60);

"4a screen TC GrCircle...\n";
dc->color = ColorRGB(0xFF, 0x9A, 0x30);
GrCircle(dc, 60, 40, 15);

"4b screen TC GrFloodFill inside rim...\n";
dc->color = ColorRGB(0xFF, 0xE6, 0x66);
GrFloodFill(dc, 60, 40);

"5 depth-buf TC GrFillPoly3...\n";
DCDepthBufAlloc(dc);
poly[0].x = 240; poly[0].y = 20; poly[0].z = GR_Z_ALL;
poly[1].x = 290; poly[1].y = 24; poly[1].z = GR_Z_ALL;
poly[2].x = 286; poly[2].y = 70; poly[2].z = GR_Z_ALL;
poly[3].x = 244; poly[3].y = 66; poly[3].z = GR_Z_ALL;
dc->color = ColorRGB(0xE0, 0x30, 0x30);
GrFillPoly3(dc, 4, poly);
Free(dc->depth_buf);
dc->depth_buf = NULL;

"6 TC GrBlot of plain DC...\n";
GrBlot(dc, 8, 90, probe_map);

"7 TC GrPrint...\n";
dc->color = ColorRGB(0xF0, 0xF8, 0xFF);
GrPrint(dc, 8, 240, "probe print ok");

"8 multicore TC jobs...\n";
probe_flags = 1 << mp_count - 1;
for (i = 1; i < mp_count; i++)
JobQueue(&ProbeMPJob, dc, i);
LBtr(&probe_flags, 0);
while (probe_flags)
Yield;

"9 TC GrLine3 + GrPlot w/ thick...\n";
dc->color = ColorRGB(0x80, 0xFF, 0x40);
dc->thick = 2;
GrLine3(dc, 8, 300, 0, 200, 330, 0);
dc->thick = 1;

DCDel(dc);
DCDel(probe_map);
"\nALL STEPS PASSED. Press a key.\n";
PressAKey;
DCFill;
}

TCProbe;
86 changes: 86 additions & 0 deletions src/Demo/Graphics/TrueColor/TrueColor.ZC
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Native 32-bit truecolor demo. Proves the graphics API carries 16M colors.
//
// The gradients below are drawn once into an offscreen device context using
// the normal Gr* API with the new ColorRGB() pen (no direct framebuffer
// pokes), then blotted to the window every frame. Press any key to exit.

CDC *tc_image;

U0 TrueColorDraw(CTask *task, CDC *dc)
{
GrBlot(dc, 0, 0, tc_image);
}

U0 TrueColorDemo()
{
I64 x, y, r, g, b, band;
F64 t;

SettingsPush;
AutoComplete;
WinBorder;
WinMax;
DocClear;
DCFill;

Fs->win_inhibit = WIG_TASK_DEFAULT - WIF_SELF_FOCUS - WIF_SELF_BORDER;

tc_image = DCNew(GR_WIDTH, GR_HEIGHT);
tc_image->flags |= DCF_NO_TRANSPARENTS;
band = GR_HEIGHT / 4;

//Band 1: horizontal red<->green gradient.
for (x = 0; x < GR_WIDTH; x++)
{
r = 255 * x / GR_WIDTH;
g = 255 - r;
tc_image->color = ColorRGB(r, g, 64);
GrVLine(tc_image, x, 0, band - 1);
}

//Band 2: full hue sweep via sine channels.
for (x = 0; x < GR_WIDTH; x++)
{
t = 6.283 * x / GR_WIDTH;
r = 128 + 127.0 * Sin(t);
g = 128 + 127.0 * Sin(t + 2.094);
b = 128 + 127.0 * Sin(t + 4.188);
tc_image->color = ColorRGB(r, g, b);
GrVLine(tc_image, x, band, 2 * band - 1);
}

//Band 3: smooth 2D gradient, R across and B down.
for (y = 2 * band; y < 3 * band; y++)
{
b = 255 * (y - 2 * band) / band;
for (x = 0; x < GR_WIDTH; x++)
{
r = 255 * x / GR_WIDTH;
tc_image->color = ColorRGB(r, 32, b);
GrPlot(tc_image, x, y);
}
}

//Band 4: 256-shade grayscale ramp the legacy 16-color palette can't show.
for (x = 0; x < GR_WIDTH; x++)
{
g = 255 * x / GR_WIDTH;
tc_image->color = ColorRGB(g, g, g);
GrVLine(tc_image, x, 3 * band, GR_HEIGHT - 1);
}

tc_image->color = ColorRGB(255, 255, 255);
GrPrint(tc_image, 8, 8, "Native 32-bit truecolor - press any key");

Fs->draw_it = &TrueColorDraw;

while (!CharScan)
Refresh;

Fs->draw_it = NULL;
DCDel(tc_image);
DCFill;
SettingsPop;
}

TrueColorDemo;
40 changes: 40 additions & 0 deletions src/Demo/Graphics/TrueColor/TrueColorAlpha.ZC
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Transparency demo. GrRectAlpha() alpha-blends over whatever is already drawn,
// so the backdrop shows through. Real per-pixel blending, not a color trick.
//
// Runs in a normal window. Press any key to exit.

U0 AlphaDraw(CTask *task, CDC *dc)
{
I64 x, w = task->pix_width, h = task->pix_height, r, g, b;
F64 t;

//Backdrop: full hue sweep so the transparency is obvious.
for (x = 0; x < w; x++)
{
t = 6.283 * x / w;
r = 128 + 127.0 * Sin(t);
g = 128 + 127.0 * Sin(t + 2.094);
b = 128 + 127.0 * Sin(t + 4.188);
dc->color = ColorRGB(r, g, b);
GrVLine(dc, x, 0, h - 1);
}

//Translucent panes over the gradient - the backdrop shows through each.
GrRectAlpha(dc, w / 12, h / 6, w / 3, h * 2 / 3, 0x000000, 128); // 50% black glass
GrRectAlpha(dc, w / 2, h / 6, w / 3, h * 2 / 3, 0xFFFFFF, 128); // 50% white frost
GrRectAlpha(dc, w / 4, h / 2, w / 2, h / 3, 0xFF3040, 110); // red tint
GrRectAlpha(dc, w / 3, h / 8, w / 3, h / 4, 0x30A0FF, 90); // blue tint

dc->color = ColorRGB(255, 255, 255);
GrPrint(dc, 8, 8, "GrRectAlpha transparency - press any key");
}

U0 TrueColorAlpha()
{
SettingsPush;
Fs->draw_it = &AlphaDraw;
PressAKey;
SettingsPop;
}

TrueColorAlpha;
33 changes: 33 additions & 0 deletions src/Demo/Graphics/TrueColor/TrueColorChrome.ZC
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Truecolor window CHROME demo. Every window's border frame animates through
// 24-bit color, driven by the theme API GuiChromeTrueColor().
//
// This is global chrome: open other windows (e.g. a Dir; or Ed) alongside and
// their borders cycle too. Press any key to stop and restore the palette border.

U0 TrueColorChrome()
{
I64 r, g, b;
F64 t = 0;

"\nTruecolor window chrome demo.\n";
"All window BORDERS now cycle through 24-bit colors.\n";
"Open another window (Dir; or Ed(\"foo\");) to see it too.\n";
"Press any key to stop and restore the 16-color border.\n\n";

while (!CharScan)
{
t += 0.04;
r = 128 + 127.0 * Sin(t);
g = 128 + 127.0 * Sin(t + 2.094);
b = 128 + 127.0 * Sin(t + 4.188);
//Bright focused border, dark matching background.
GuiChromeTrueColor(ColorRGB(r, g, b), ColorRGB(r / 5, g / 5, b / 5));
Refresh;
Sleep(20);
}

GuiChromePalette;
"\nRestored.\n";
}

TrueColorChrome;
35 changes: 35 additions & 0 deletions src/Demo/Graphics/TrueColor/TrueColorDoc.ZC
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Truecolor DolDoc text demo. Proves $FG24 / $BG24 control codes drive the
// TextBase RGB planes through the normal document rasterizer.
//
// $FG24,0xRRGGBB$ sets a 24-bit foreground; $BG24,0xRRGGBB$ a background.
// $FD / $BD restore the default (legacy palette) fg/bg. All existing $FG,$BG$
// codes are unchanged. (Doubled $$ below = one runtime $ control code.)

U0 TrueColorDoc()
{
I64 i, r, g, b;
F64 t;

DocClear;

"\n$$FG24,0xFF8800$$ Truecolor document text, orange fg $$FD$$\n\n";

for (i = 0; i < 24; i++)
{
t = 6.283 * i / 24;
r = 128 + 127.0 * Sin(t);
g = 128 + 127.0 * Sin(t + 2.094);
b = 128 + 127.0 * Sin(t + 4.188);
"$$FG24,%d$$ Row %02d smooth 24-bit spectrum in a normal document $$FD$$\n",
r << 16 | g << 8 | b, i;
}

"\n$$BG24,0x102040$$$$FG24,0xFFEEAA$$ Truecolor background works too $$FD$$$$BD$$\n";
"\n$$LTGREEN$$Legacy 16-color text still renders exactly as before.$$FG$$\n\n";

"Press any key.\n";
PressAKey;
DocClear;
}

TrueColorDoc;
Loading
Loading