Make GRAPHIC select the text plane
Some checks failed
akbasic CI Build / cmake_build (push) Failing after 3m22s
akbasic CI Build / sanitizers (push) Failing after 4m43s
akbasic CI Build / coverage (push) Failing after 3m43s
akbasic CI Build / akgl_build (push) Failing after 4m48s
akbasic CI Build / mutation_test (push) Failing after 3m31s

Co-authored-by: Andrew Kesterson <andrew@aklabs.net>
This commit is contained in:
2026-08-03 08:08:34 -04:00
parent c5d13f00f6
commit 3342f2b569
13 changed files with 345 additions and 79 deletions

View File

@@ -1173,6 +1173,78 @@ static akerr_ErrorContext AKERR_NOIGNORE *test_drawing_layer_persists(void)
SUCCEED_RETURN(errctx);
}
/**
* @brief GRAPHIC selects whether the AKGL text plane covers the drawing layer.
*
* `PRINT` always writes into the retained grid. In a full bitmap mode the grid
* is simply not composited; returning to mode zero reveals it. Split mode moves
* the text region below the requested row, leaving the drawing visible above.
*/
static akerr_ErrorContext AKERR_NOIGNORE *test_graphic_text_composition(void)
{
PREPARE_ERROR(errctx);
SDL_Surface *shot = NULL;
int fullrows = 0;
PASS(errctx, akbasic_sink_init_akgl(&AKGLSINK, &AKGLSINKSTATE, akgl_renderer, font,
TARGET_SIZE, TARGET_SIZE));
PASS(errctx, akbasic_runtime_init(&RUNTIME, &AKGLSINK));
PASS(errctx, akbasic_graphics_init_akgl(&GRAPHICS, &GRAPHICSSTATE, akgl_renderer));
PASS(errctx, akbasic_runtime_set_devices(&RUNTIME, &GRAPHICS, NULL, NULL, NULL));
PASS(errctx, akbasic_runtime_load(&RUNTIME,
"10 GRAPHIC 1, 1\n"
"20 COLOR 1, 3\n"
"30 DRAW 1, 40, 40\n"
"40 PRINT \"HIDDEN\"\n"));
PASS(errctx, akbasic_runtime_start(&RUNTIME, AKBASIC_MODE_RUN));
PASS(errctx, akbasic_graphics_akgl_begin(&GRAPHICS));
PASS(errctx, akbasic_runtime_run(&RUNTIME, 0));
PASS(errctx, akbasic_graphics_akgl_end(&GRAPHICS));
TEST_REQUIRE_INT(AKGLSINKSTATE.graphicmode, 1);
TEST_REQUIRE_STR(AKGLSINKSTATE.text[0], "HIDDEN");
PASS(errctx, clear_target());
PASS(errctx, akbasic_graphics_akgl_render(&GRAPHICS));
PASS(errctx, akbasic_sink_akgl_render(&AKGLSINK));
shot = SDL_RenderReadPixels(akgl_renderer->sdl_renderer, NULL);
TEST_REQUIRE(shot != NULL, "could not read the full-bitmap frame back");
TEST_REQUIRE(pixel_is(shot, 40, 40, 0x88, 0x39, 0x32),
"GRAPHIC 1 must show DRAW even after PRINT wrote the hidden text grid");
SDL_DestroySurface(shot);
PASS(errctx, AKGLSINK.graphic(&AKGLSINK, 0, -1));
PASS(errctx, clear_target());
PASS(errctx, akbasic_graphics_akgl_render(&GRAPHICS));
PASS(errctx, akbasic_sink_akgl_render(&AKGLSINK));
shot = SDL_RenderReadPixels(akgl_renderer->sdl_renderer, NULL);
TEST_REQUIRE(shot != NULL, "could not read the text frame back");
TEST_REQUIRE(!pixel_is(shot, 40, 40, 0x88, 0x39, 0x32),
"GRAPHIC 0 must put the retained text plane back over the drawing");
SDL_DestroySurface(shot);
PASS(errctx, AKGLSINK.clear(&AKGLSINK));
fullrows = TARGET_SIZE / AKGLSINKSTATE.cellh;
PASS(errctx, AKGLSINK.graphic(&AKGLSINK, 2, 3));
TEST_REQUIRE_INT(AKGLSINKSTATE.y, 3 * AKGLSINKSTATE.cellh);
TEST_REQUIRE_INT(AKGLSINKSTATE.rows, fullrows - 3);
PASS(errctx, AKGLSINK.writeln(&AKGLSINK, "BOTTOM"));
PASS(errctx, clear_target());
PASS(errctx, akbasic_graphics_akgl_render(&GRAPHICS));
PASS(errctx, akbasic_sink_akgl_render(&AKGLSINK));
shot = SDL_RenderReadPixels(akgl_renderer->sdl_renderer, NULL);
TEST_REQUIRE(shot != NULL, "could not read the split-screen frame back");
TEST_REQUIRE(pixel_is(shot, 40, 40, 0x88, 0x39, 0x32),
"GRAPHIC 2 must leave the graphics region above its text rows visible");
SDL_DestroySurface(shot);
PASS(errctx, AKGLSINK.graphic(&AKGLSINK, 0, -1));
TEST_REQUIRE_INT(AKGLSINKSTATE.texttop, 0);
TEST_REQUIRE_INT(AKGLSINKSTATE.rows, fullrows);
akbasic_graphics_akgl_shutdown(&GRAPHICS);
SUCCEED_RETURN(errctx);
}
/**
* @brief The contact says which way to push out and how far.
*
@@ -1339,6 +1411,7 @@ int main(void)
CATCH(errctx, test_static_geometry());
CATCH(errctx, test_contact_geometry());
CATCH(errctx, test_drawing_layer_persists());
CATCH(errctx, test_graphic_text_composition());
} CLEANUP {
if ( font != NULL ) {
TTF_CloseFont(font);