#define LOG
#endif
-typedef enum _vkvg_status {
+typedef enum {
VKVG_STATUS_SUCCESS = 0,
VKVG_STATUS_NO_MEMORY,
VKVG_STATUS_INVALID_RESTORE,
VKVG_STATUS_INVALID_DASH
}vkvg_status_t;
-typedef enum _vkvg_direction {
+typedef enum {
VKVG_HORIZONTAL = 0,
VKVG_VERTICAL = 1
}vkvg_direction_t;
-typedef enum _vkvg_format {
+typedef enum {
VKVG_FORMAT_ARGB32,
VKVG_FORMAT_RGB24,
VKVG_FORMAT_A8,
VKVG_FORMAT_A1
} vkvg_format_t;
-typedef enum _vkvg_extend {
+typedef enum {
VKVG_EXTEND_NONE,
VKVG_EXTEND_REPEAT,
VKVG_EXTEND_REFLECT,
VKVG_EXTEND_PAD
} vkvg_extend_t;
-typedef enum _vkvg_filter {
+typedef enum {
VKVG_FILTER_FAST,
VKVG_FILTER_GOOD,
VKVG_FILTER_BEST,
VKVG_FILTER_GAUSSIAN,
} vkvg_filter_t;
-typedef enum _vkvg_pattern_type {
+typedef enum {
VKVG_PATTERN_TYPE_SOLID,
VKVG_PATTERN_TYPE_SURFACE,
VKVG_PATTERN_TYPE_LINEAR,
VKVG_PATTERN_TYPE_RASTER_SOURCE,
} vkvg_pattern_type_t;
-typedef enum _vkvg_line_cap {
+typedef enum {
VKVG_LINE_CAP_BUTT,
VKVG_LINE_CAP_ROUND,
VKVG_LINE_CAP_SQUARE
} vkvg_line_cap_t;
-typedef enum _vkvg_line_join {
+typedef enum {
VKVG_LINE_JOIN_MITER,
VKVG_LINE_JOIN_ROUND,
VKVG_LINE_JOIN_BEVEL
} vkvg_line_join_t;
-typedef enum _vkvg_fill_rule {
+typedef enum {
VKVG_FILL_RULE_EVEN_ODD,
VKVG_FILL_RULE_NON_ZERO
} vkvg_fill_rule_t;
-typedef struct _vkvg_color_t{
+typedef struct {
float r;
float g;
float b;
void vkvg_set_operator (VkvgContext ctx, vkvg_operator_t op);
void vkvg_set_fill_rule (VkvgContext ctx, vkvg_fill_rule_t fr);
+void vkvg_set_dash (VkvgContext ctx, const float* dashes, uint32_t num_dashes, float offset);
+void vkvg_get_dash (VkvgContext ctx, const float *dashes, uint32_t* num_dashes, float* offset);
float vkvg_get_line_width (VkvgContext ctx);
vkvg_line_cap_t vkvg_get_line_cap (VkvgContext ctx);
ctx->sizeIndices = ctx->sizeIBO = VKVG_IBO_SIZE;
ctx->sizePathes = VKVG_PATHES_SIZE;
ctx->lineWidth = 1;
+ ctx->dashCount = 0;
+ ctx->dashOffset = 0;
+ ctx->dashes = NULL;
ctx->pSurf = surf;
ctx->curOperator = VKVG_OPERATOR_OVER;
ctx->curFillRule = VKVG_FILL_RULE_NON_ZERO;
free(ctx->selectedFont.fontFile);
free(ctx->pathes);
free(ctx->points);
+ if (ctx->dashCount > 0)
+ free(ctx->dashes);
//free saved context stack elmt
vkvg_context_save_t* next = ctx->pSavedCtxs;
vkvg_fill_rule_t vkvg_get_fill_rule (VkvgContext ctx){
return ctx->curFillRule;
}
+/**
+ * @brief This function return the current line width use by vkvg_stroke() as set by vkvg_set_line_width().
+ * @param a vkvg context.
+ * @return current line width.
+ */
float vkvg_get_line_width (VkvgContext ctx){
return ctx->lineWidth;
}
+/**
+ * @brief Sets the dash pattern to be used by vkvg_stroke(). A dash pattern is specified by dashes , an array of positive values. Each value provides the length of alternate "on" and "off" portions of the stroke. The offset specifies an offset into the pattern at which the stroke begins.
+ * @param a vkvg context.
+ * @param a pointer on an array of float values defining alternate lengths of on and off stroke portions.
+ * @param the length of the dash array.
+ * @param an offset into the dash pattern at which the stroke should start.
+ */
+void vkvg_set_dash (VkvgContext ctx, const float* dashes, uint32_t num_dashes, float offset){
+ if (ctx->dashCount > 0)
+ free (ctx->dashes);
+ ctx->dashCount = num_dashes;
+ ctx->dashOffset = offset;
+ if (ctx->dashCount == 0)
+ return;
+ ctx->dashes = (float*)malloc (sizeof(float) * ctx->dashCount);
+ memcpy (ctx->dashes, dashes, sizeof(float) * ctx->dashCount);
+}
+/**
+ * @brief get dash settings. If dashes pointer is NULL, only count and offset are returned.
+ * @param a vkvg context.
+ * @param return value for the dash array. If count is 0, this pointer stay untouched. If NULL, only count and offset are returned.
+ * @param return length of dash array or 0 if dash not set.
+ * @param return value for the current dash offset
+ */
+void vkvg_get_dash (VkvgContext ctx, const float* dashes, uint32_t* num_dashes, float* offset){
+ *num_dashes = ctx->dashCount;
+ *offset = ctx->dashOffset;
+ if (ctx->dashCount == 0 || dashes == NULL)
+ return;
+ memcpy ((float*)dashes, ctx->dashes, sizeof(float) * ctx->dashCount);
+}
+
+
vkvg_line_cap_t vkvg_get_line_cap (VkvgContext ctx){
return ctx->lineCap;
}
_bind_draw_pipeline (ctx);
CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT);
+ sav->dashOffset = ctx->dashOffset;
+ sav->dashCount = ctx->dashCount;
+ if (ctx->dashCount > 0) {
+ sav->dashes = (float*)malloc (sizeof(float) * ctx->dashCount);
+ memcpy (sav->dashes, ctx->dashes, sizeof(float) * ctx->dashCount);
+ }
sav->lineWidth = ctx->lineWidth;
sav->curOperator= ctx->curOperator;
sav->lineCap = ctx->lineCap;
vkh_image_destroy (savStencil);
}
+ ctx->dashOffset = sav->dashOffset;
+ if (ctx->dashCount > 0)
+ free (ctx->dashes);
+ ctx->dashCount = sav->dashCount;
+ if (ctx->dashCount > 0) {
+ ctx->dashes = (float*)malloc (sizeof(float) * ctx->dashCount);
+ memcpy (ctx->dashes, sav->dashes, sizeof(float) * ctx->dashCount);
+ }
+
ctx->lineWidth = sav->lineWidth;
ctx->curOperator= sav->curOperator;
ctx->lineCap = sav->lineCap;
vec2 bisec = vec2_norm(vec2_add(v0n,v1n));
float dot = v0n.x * v1n.x + v0n.y * v1n.y;
- //printf("%f\n", dot);
-
float alpha = acosf(dot)/2;
float cross = v0n.x * v1n.y - v0n.y * v1n.x;
}
void _free_ctx_save (vkvg_context_save_t* sav){
+ if (sav->dashCount > 0)
+ free (sav->dashes);
free(sav->selectedFont.fontFile);
free (sav);
}
struct _vkvg_context_save_t* pNext;
float lineWidth;
+ uint32_t dashCount; //value count in dash array, 0 if dash not set.
+ float dashOffset; //an offset for dash
+ float* dashes; //an array of alternate lengths of on and off stroke.
+
vkvg_operator_t curOperator;
vkvg_line_cap_t lineCap;
uint32_t curvePtr;
float lineWidth;
+ uint32_t dashCount; //value count in dash array, 0 if dash not set.
+ float dashOffset; //an offset for dash
+ float* dashes; //an array of alternate lengths of on and off stroke.
vkvg_operator_t curOperator;
vkvg_line_cap_t lineCap;
--- /dev/null
+#include "test.h"
+
+void test(){
+ VkvgContext ctx = vkvg_create(surf);
+
+ float x = 50, y = 50, width = 150, height = 140, radius = 30;
+
+ vkvg_scale(ctx,2,2);
+ //vkvg_rotate(ctx,0.5f);
+
+ vkvg_set_line_width(ctx,15);
+ vkvg_set_source_rgba(ctx, 0, 0.5f, 0.4f, 1);
+
+
+ if ((radius > height / 2) || (radius > width / 2))
+ radius = MIN(height / 2, width / 2);
+
+ vkvg_move_to(ctx, x, y + radius);
+ vkvg_arc(ctx, x + radius, y + radius, radius, M_PIF, (float)-M_PI_2);
+ vkvg_line_to(ctx, x + width - radius, y);
+ vkvg_arc(ctx, x + width - radius, y + radius, radius, (float)-M_PI_2, 0);
+ vkvg_line_to(ctx, x + width, y + height - radius);
+ vkvg_arc(ctx, x + width - radius, y + height - radius, radius, 0, (float)M_PI_2);
+ vkvg_line_to(ctx, x + radius, y + height);
+ vkvg_arc(ctx, x + radius, y + height - radius, radius, (float)M_PI_2, M_PIF);
+ vkvg_line_to(ctx, x, y + radius);
+ vkvg_close_path(ctx);
+ vkvg_fill_preserve(ctx);
+ vkvg_set_source_rgba(ctx,0.5,0,0,0.5);
+ vkvg_stroke(ctx);
+
+ vkvg_destroy(ctx);
+}
+
+int main(int argc, char *argv[]) {
+
+ perform_test (test, 1024, 768);
+
+ return 0;
+}