From: Jean-Philippe Bruyère Date: Sat, 27 Nov 2021 05:08:28 +0000 (+0100) Subject: quadratic, don't fault on missing current point for relative funcs X-Git-Tag: v0.2.0~50 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=7c3e512ac9b46f77c3a667bd4fe19c7849082c82;p=jp%2Fvkvg.git quadratic, don't fault on missing current point for relative funcs --- diff --git a/include/vkvg.h b/include/vkvg.h index 638c84e..99a6a1b 100644 --- a/include/vkvg.h +++ b/include/vkvg.h @@ -310,14 +310,6 @@ vkvg_debug_stats_t vkvg_device_reset_stats (VkvgDevice dev); * Matrix computations in vkvg are taken from the cairo library. * @{ */ #define VKVG_IDENTITY_MATRIX {1,0,0,1,0,0}/*!< The identity matrix*/ -/** - * @xx: xx component of the affine transformation - * @yx: yx component of the affine transformation - * @xy: xy component of the affine transformation - * @yy: yy component of the affine transformation - * @x0: X translation component of the affine transformation - * @y0: Y translation component of the affine transformation - * /** * @brief vkvg matrix structure * @@ -328,6 +320,12 @@ vkvg_debug_stats_t vkvg_device_reset_stats (VkvgDevice dev); * x_new = xx * x + xy * y + x0; * y_new = yx * x + yy * y + y0; * @endcode + * @xx: xx component of the affine transformation + * @yx: yx component of the affine transformation + * @xy: xy component of the affine transformation + * @yy: yy component of the affine transformation + * @x0: X translation component of the affine transformation + * @y0: Y translation component of the affine transformation */ typedef struct { float xx; float yx; @@ -829,6 +827,14 @@ void vkvg_new_sub_path (VkvgContext ctx); */ vkvg_public void vkvg_path_extents (VkvgContext ctx, float *x1, float *y1, float *x2, float *y2); +/** + * @brief Get the current point of the context, return 0,0 if no point is defined. + * @param ctx + * @param x + * @param y + */ +vkvg_public +void vkvg_get_current_point (VkvgContext ctx, float* x, float* y); /** * @brief Add a line to the current path from the current point to the coordinate given in arguments. * @@ -941,6 +947,46 @@ void vkvg_arc_negative (VkvgContext ctx, float xc, float yc, float radius, float vkvg_public void vkvg_curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, float x3, float y3); /** + * @brief Adds a cubic Bézier spline to the current path relative to the current point. + * + * Adds a cubic Bézier spline to the path from the current point to position (x3, y3) in relative coordinate to the current point, + * using (x1, y1) and (x2, y2) as the control points relative to the current point. + * After this call the current point will be (x3, y3). + * + * If there is no current point before the call to vkvg_rel_curve_to() => error:VKVG_STATUS_NO_CURRENT_POINT. + * @param ctx The vkvg context pointer. + * @param x1 The X coordinate of the first control point. + * @param y1 The Y coordinate of the first control point. + * @param x2 The X coordinate of the second control point. + * @param y2 The Y coordinate of the second control point. + * @param x3 The X coordinate of the end of the curve. + * @param y3 The Y coordinate of the end of the curve. + */ +vkvg_public +void vkvg_rel_curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, float x3, float y3); +/** + * @brief Add a quadratic Bezizer curve to the current path + * + * If there is no current point before the call to vkvg_quadratic_to() this function will behave as if preceded by a call to vkvg_move_to(ctx, x1, y1). + * @param ctx The vkvg context pointer. + * @param x1 The X coordinate of the control point. + * @param y1 The Y coordinate of the control point. + * @param x2 The X coordinate of the end point of the curve. + * @param y2 The Y coordinate of the end point of the curve. + */ +vkvg_public +void vkvg_quadratic_to (VkvgContext ctx, float x1, float y1, float x2, float y2); +/** + * @brief Add a quadratic Bezizer curve to the current path relative to the current point + * + * @param ctx The vkvg context pointer. + * @param x1 The X coordinate of the control point relative to the current point. + * @param y1 The Y coordinate of the control point relative to the current point. + * @param x2 The X coordinate of the end point of the curve relative to the current point. + * @param y2 The Y coordinate of the end point of the curve relative to the current point. + */ +vkvg_public +void vkvg_rel_quadratic_to (VkvgContext ctx, float x1, float y1, float x2, float y2);/** * @brief Add an axis aligned rectangle subpath to the current path. * * Adds a closed sub-path rectangle of the given size to the current path at position (x, y). @@ -1016,7 +1062,13 @@ void vkvg_clip (VkvgContext ctx); */ vkvg_public void vkvg_clip_preserve (VkvgContext ctx); - +/** + * @brief Set current source for drawing to the solid color defined by the supplied 32bit integer. + * @param ctx a valid vkvg @ref context + * @param rgba color coded in 32bit integer. + */ +vkvg_public +void vkvg_set_source_color (VkvgContext ctx, uint32_t c); /** * @brief set color with alpha. * diff --git a/src/vkvg_context.c b/src/vkvg_context.c index 65374bb..5f912e6 100644 --- a/src/vkvg_context.c +++ b/src/vkvg_context.c @@ -327,10 +327,8 @@ void vkvg_close_path (VkvgContext ctx){ void vkvg_rel_line_to (VkvgContext ctx, float dx, float dy){ if (ctx->status) return; - if (_current_path_is_empty(ctx)){ - ctx->status = VKVG_STATUS_NO_CURRENT_POINT; - return; - } + if (_current_path_is_empty(ctx)) + _add_point(ctx, 0, 0); vec2 cp = _get_current_position(ctx); vkvg_line_to(ctx, cp.x + dx, cp.y + dy); } @@ -441,10 +439,8 @@ void vkvg_rel_move_to (VkvgContext ctx, float x, float y) { if (ctx->status) return; - if (_current_path_is_empty(ctx)){ - ctx->status = VKVG_STATUS_NO_CURRENT_POINT; - return; - } + if (_current_path_is_empty(ctx)) + _add_point(ctx, 0, 0); vec2 cp = _get_current_position(ctx); vkvg_move_to(ctx, cp.x + x, cp.y + y); } @@ -455,7 +451,37 @@ void vkvg_move_to (VkvgContext ctx, float x, float y) _finish_path(ctx); _add_point (ctx, x, y); } - +void vkvg_get_current_point (VkvgContext ctx, float* x, float* y) { + if (_current_path_is_empty(ctx)) { + *x = *y = 0; + return; + } + vec2 cp = _get_current_position(ctx); + *x = cp.x; + *y = cp.y; +} +void vkvg_rel_quadratic_to (VkvgContext ctx, float x1, float y1, float x2, float y2) { + if (ctx->status) + return; + vec2 cp = _get_current_position(ctx); + vkvg_quadratic_to (ctx, cp.x + x1, cp.y + y1, cp.x + x2, cp.y + y2); +} +void vkvg_quadratic_to (VkvgContext ctx, float x1, float y1, float x2, float y2) { + if (ctx->status) + return; + _set_curve_start (ctx); + if (_current_path_is_empty(ctx)) + _add_point(ctx, x1, y1); + float x0, y0; + vkvg_get_current_point (ctx, &x0, &y0); + vkvg_curve_to (ctx, + 2.0 / 3.0 * x1 + 1.0 / 3.0 * x0, + 2.0 / 3.0 * y1 + 1.0 / 3.0 * y0, + 2.0 / 3.0 * x1 + 1.0 / 3.0 * x2, + 2.0 / 3.0 * y1 + 1.0 / 3.0 * y2, + y1, y2); + _set_curve_end (ctx); +} void vkvg_curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, float x3, float y3) { if (ctx->status) return; @@ -480,10 +506,6 @@ void vkvg_curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, flo void vkvg_rel_curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, float x3, float y3) { if (ctx->status) return; - if (_current_path_is_empty(ctx)){ - ctx->status = VKVG_STATUS_NO_CURRENT_POINT; - return; - } vec2 cp = _get_current_position(ctx); vkvg_curve_to (ctx, cp.x + x1, cp.y + y1, cp.x + x2, cp.y + y2, cp.x + x3, cp.y + y3); } @@ -888,6 +910,12 @@ void vkvg_paint (VkvgContext ctx){ _ensure_renderpass_is_started (ctx); _draw_full_screen_quad (ctx, true); } +void vkvg_set_source_color (VkvgContext ctx, uint32_t c) { + if (ctx->status) + return; + ctx->curColor = c; + _update_cur_pattern (ctx, NULL); +} void vkvg_set_source_rgb (VkvgContext ctx, float r, float g, float b) { vkvg_set_source_rgba (ctx, r, g, b, 1); } diff --git a/src/vkvg_device.c b/src/vkvg_device.c index 251e5bf..2eb833e 100644 --- a/src/vkvg_device.c +++ b/src/vkvg_device.c @@ -36,8 +36,8 @@ VkvgDevice vkvg_device_create_multisample(VkInstance inst, VkPhysicalDevice phy, VkvgDevice dev = (vkvg_device*)calloc(1,sizeof(vkvg_device)); dev->instance = inst; - dev->hdpi = 96; - dev->vdpi = 96; + dev->hdpi = 72; + dev->vdpi = 72; dev->samples= samples; dev->deferredResolve = deferredResolve; dev->vkDev = vkdev; diff --git a/tests/common/test.c b/tests/common/test.c index 4fbc818..f0d47ec 100644 --- a/tests/common/test.c +++ b/tests/common/test.c @@ -150,9 +150,6 @@ void init_test (uint32_t width, uint32_t height){ bool deferredResolve = false; device = vkvg_device_create_multisample(vkh_app_get_inst(e->app), r->dev->phy, r->dev->dev, r->qFam, 0, samples, deferredResolve); - - vkvg_device_set_dpy(device, 96, 96); - surf = vkvg_surface_create(device, width, height); vkh_presenter_build_blit_cmd (r, vkvg_surface_get_vk_image(surf), width, height); @@ -392,7 +389,7 @@ void perform_test_offscreen (void(*testfunc)(void), const char *testName, int ar device = vkvg_device_create_multisample(vkh_app_get_inst(app), dev->phy, dev->dev, pi->gQueue, 0, samples, deferredResolve); - vkvg_device_set_dpy(device, 96, 96); + //vkvg_device_set_dpy(device, 96, 96); vkh_app_free_phyinfos (phyCount, phys); diff --git a/vkh b/vkh index 97cdc0f..7dfff1a 160000 --- a/vkh +++ b/vkh @@ -1 +1 @@ -Subproject commit 97cdc0fb23b33356cc1d4c1be8973891d7661ac5 +Subproject commit 7dfff1a2e601e142583c122c9f716578d8e85039