diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2026-09-30 00:08:37 +0200 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2026-10-01 13:29:27 +0200 |
| commit | 9dab17b080f715c9597fa5d5a285ed81d600a8a0 (patch) | |
| tree | 012d573debc6a18035f1b029453bfe4877646473 | |
| parent | 55a7ec40d62b3ddc89e05e9295d0c5ab06860120 (diff) | |
ctx init memcpy from const, add zoom handling for bezier tests
| -rw-r--r-- | src/vkvg_context.c | 37 | ||||
| -rw-r--r-- | tests/bezier.c | 37 |
2 files changed, 49 insertions, 25 deletions
diff --git a/src/vkvg_context.c b/src/vkvg_context.c index dd9faa2..2acf2e7 100644 --- a/src/vkvg_context.c +++ b/src/vkvg_context.c @@ -21,11 +21,31 @@ const float DBG_LAB_COLOR_CLIP[4] = {0, 1, 1, 1}; static VkClearValue clearValues[3] = { {.color.float32 = {0, 0, 0, 0}}, {.depthStencil = {1.0f, 0}}, {.color.float32 = {0, 0, 0, 0}}}; +static const vkvg_context_save_t CTX_INIT = { + 0xff000000, // opaque black + 1.f, + 10.f, + 0, + 0.f, + {0}, + VKVG_OPERATOR_OVER, + VKVG_LINE_CAP_BUTT, + VKVG_LINE_JOIN_MITER, + VKVG_FILL_RULE_NON_ZERO, + VKVG_HORIZONTAL, + 10 << 6, + 0, + {0}, + NULL +}; + void _init_ctx(VkvgContext ctx) { - ctx->lineWidth = 1.f; - ctx->miterLimit = 10.f; - ctx->curOperator = VKVG_OPERATOR_OVER; - ctx->curFillRule = VKVG_FILL_RULE_NON_ZERO; + memcpy((void*)&(ctx->curColor), (void*)&CTX_INIT, (void*)&(ctx->pattern) - (void*)&(ctx->curColor)); + + ctx->cmdStarted = false; + ctx->curClipState = vkvg_clip_state_none; + ctx->vertCount = ctx->indCount = 0; + ctx->bounds = (VkRect2D){{0, 0}, {ctx->pSurf->width, ctx->pSurf->height}}; ctx->pushConsts = (push_constants){{.a = 1}, {(float)ctx->pSurf->width, (float)ctx->pSurf->height}, @@ -54,15 +74,6 @@ void _init_ctx(VkvgContext ctx) { ctx->renderPassBeginInfo.clearValueCount = ctx->dev->samples == VK_SAMPLE_COUNT_1_BIT ? 2 : 3; - ctx->selectedCharSize = 10 << 6; - //ctx->currentFont = NULL; - ctx->selectedFont = 0; - ctx->pattern = NULL; - ctx->curColor = 0xff000000; // opaque black - ctx->cmdStarted = false; - ctx->curClipState = vkvg_clip_state_none; - - ctx->vertCount = ctx->indCount = 0; #ifdef VKVG_ENABLE_VK_TIMELINE_SEMAPHORE ctx->timelineStep = 0; #endif diff --git a/tests/bezier.c b/tests/bezier.c index 20013db..39cbdf9 100644 --- a/tests/bezier.c +++ b/tests/bezier.c @@ -11,10 +11,10 @@ bool isClosed = false, isFilled = false; int ptsCount = 4; int initPtsCount = 4; vec2 pts[] = { - {150, 150}, - {500, 340}, - {470, 150}, - {160, 350}, + {1000, 1000}, + {50, 50}, + {2000, 50}, + {1200, 1000}, }; /*vec2 pts[] = { {150,150}, @@ -34,6 +34,8 @@ void draw() { VkvgContext ctx = vkvg_create(surf); vkvg_clear(ctx); + vkvg_scale(ctx, zoom, zoom); + #ifdef VKVG_WIRED_DEBUG vkvg_wired_debug = _wired_debug; #endif @@ -62,7 +64,7 @@ void draw() { vkvg_wired_debug = vkvg_wired_debug_mode_normal; #endif - vkvg_set_line_width(ctx, 1); + vkvg_set_line_width(ctx, 1.f / zoom); vkvg_set_source_rgba(ctx, 0.5, 0.5, 0.5, 0.6); for (int i = 0; i < ptsCount; i++) { @@ -81,10 +83,10 @@ void draw() { if (hoverPt >= 0) { vkvg_stroke_preserve(ctx); vkvg_set_dash(ctx, NULL, 0, 0); - vkvg_set_line_width(ctx, 2); - vkvg_set_source_rgba(ctx, 0, 0, 0, 1); + vkvg_set_line_width(ctx, 2.f / zoom); + vkvg_set_source_rgba(ctx, 0, 1, 0, 1); vkvg_stroke(ctx); - vkvg_set_source_rgba(ctx, 0.5f, 0.5f, 1.0f, 0.7f); + vkvg_set_source_rgba(ctx, 0.2f, 0.2f, 1.0f, 0.7f); vkvg_arc(ctx, pts[hoverPt].x, pts[hoverPt].y, pointSize, 0, M_PIF * 2); vkvg_fill_preserve(ctx); vkvg_stroke(ctx); @@ -139,6 +141,8 @@ static void key_callback(GLFWwindow* window, int key, int scancode, int action, } } static void mouse_move_callback(GLFWwindow* window, double x, double y) { + x /= zoom; + y /= zoom; if (mouseDown) { if (hoverPt < 0) return; @@ -156,10 +160,19 @@ static void mouse_move_callback(GLFWwindow* window, double x, double y) { } } static void scroll_callback(GLFWwindow* window, double x, double y) { - if (y < 0.f) - zoom *= 0.5f; - else - zoom *= 2.0f; + float mult = y < 0.f ? 0.5f : 2.0f; + if ((y < 0 && zoom < 0.000001f) || (y > 0 && zoom > 70000.f)) + return; + zoom *= mult; + for (int i = 0; i < ptsCount; ++i) { + pts[i].x /= mult; + pts[i].y /= mult; + } + hoverPointSize /= mult; + pointSize /= mult; + lineWidth /= mult; + printf("zoom = %f\n", zoom); + fflush(stdout); } static void mouse_button_callback(GLFWwindow* window, int but, int state, int modif) { if (but != GLFW_MOUSE_BUTTON_1) |