Skip to content

Commit

Permalink
Merge pull request #67 from ScenicFramework/draw_rrectv
Browse files Browse the repository at this point in the history
Pull in rrectv work
  • Loading branch information
crertel authored Jun 15, 2024
2 parents 4c2649f + 26cd49d commit cf37613
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
21 changes: 21 additions & 0 deletions c_src/device/nvg/nvg_script_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,27 @@ void script_ops_draw_rrect(void* v_ctx,
if (stroke) nvgStroke(p_ctx);
}

void script_ops_draw_rrectv(void* v_ctx,
float w,
float h,
float ulr,
float urr,
float lrr,
float llr,
bool fill, bool stroke)
{
if (g_opts.debug_mode) {
log_script_ops_draw_rrectv(log_prefix, __func__, log_level_info,
w, h, ulr, urr, lrr, llr, fill, stroke);
}

NVGcontext* p_ctx = (NVGcontext*)v_ctx;
nvgBeginPath(p_ctx);
nvgRoundedRectVarying(p_ctx, 0, 0, w, h, ulr, urr, lrr, llr);
if (fill) nvgFill(p_ctx);
if (stroke) nvgStroke(p_ctx);
}

void script_ops_draw_arc(void* v_ctx,
float radius,
float radians,
Expand Down
12 changes: 12 additions & 0 deletions c_src/scenic/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,18 @@ void render_script(void* v_ctx, sid_t id)
}
i += 12;
break;
case SCRIPT_OP_DRAW_RRECTV:
{
float w = get_float(p, i);
float h = get_float(p, i + 4);
float ulr = get_float(p, i + 8);
float urr = get_float(p, i + 12);
float lrr = get_float(p, i + 16);
float llr = get_float(p, i + 20);
script_ops_draw_rrectv(v_ctx, w, h, ulr, urr, lrr, llr, (param & FLAG_FILL), (param & FLAG_STROKE));
}
i += 24;
break;
case SCRIPT_OP_DRAW_ARC:
{
float radius = get_float(p, i);
Expand Down
29 changes: 29 additions & 0 deletions c_src/scenic/script_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,34 @@ void log_script_ops_draw_rrect(const char* prefix, const char* func, log_level_t
(stroke) ? "true" : "false");
}

__attribute__((weak))
void script_ops_draw_rrectv(void *v_ctx, float w, float h, float ulr, float urr, float lrr, float llr, bool fill, bool stroke)
{
log_script_ops_draw_rrectv(log_prefix, __func__, log_level_warn, w, h, ulr, urr, lrr, llr, fill, stroke);
}
void log_script_ops_draw_rrectv(const char *prefix, const char *func, log_level_t level, float w, float h, float ulr, float urr, float lrr, float llr, bool fill, bool stroke)
{
log_message(level, "%s %s: %{"
"w: %.1f, "
"h: %.1f, "
"ulr: %.1f, "
"urr: %.1f, "
"lrr: %.1f, "
"llr: %.1f, "
"fill: %s, "
"stroke: %s"
"}",
prefix, func,
w,
h,
ulr,
urr,
lrr,
llr,
(fill) ? "true" : "false",
(stroke) ? "true" : "false");
}

__attribute__((weak))
void script_ops_draw_arc(void* v_ctx, float radius, float radians, bool fill, bool stroke)
{
Expand Down Expand Up @@ -797,6 +825,7 @@ const char* script_op_to_string(script_op_t op)
case SCRIPT_OP_DRAW_QUAD: return "script_op_draw_quad";
case SCRIPT_OP_DRAW_RECT: return "script_op_draw_rect";
case SCRIPT_OP_DRAW_RRECT: return "script_op_draw_rrect";
case SCRIPT_OP_DRAW_RRECTV: return "script_op_draw_rrectv";
case SCRIPT_OP_DRAW_ARC: return "script_op_draw_arc";
case SCRIPT_OP_DRAW_SECTOR: return "script_op_draw_sector";
case SCRIPT_OP_DRAW_CIRCLE: return "script_op_draw_circle";
Expand Down
2 changes: 2 additions & 0 deletions c_src/scenic/script_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ typedef enum {
SCRIPT_OP_DRAW_ELLIPSE = 0X09,
SCRIPT_OP_DRAW_TEXT = 0X0A,
SCRIPT_OP_DRAW_SPRITES = 0X0B,
SCRIPT_OP_DRAW_RRECTV = 0X0C,
SCRIPT_OP_DRAW_SCRIPT = 0X0F,

SCRIPT_OP_BEGIN_PATH = 0X20,
Expand Down Expand Up @@ -138,6 +139,7 @@ SCRIPT_FUNC(draw_triangle, coordinates_t a, coordinates_t b, coordinates_t c, bo
SCRIPT_FUNC(draw_quad, coordinates_t a, coordinates_t b, coordinates_t c, coordinates_t d, bool fill, bool stroke);
SCRIPT_FUNC(draw_rect, float w, float h, bool fill, bool stroke);
SCRIPT_FUNC(draw_rrect, float w, float h, float radius, bool fill, bool stroke);
SCRIPT_FUNC(draw_rrectv, float w, float h, float ulr, float urr, float lrr, float llr, bool fill, bool stroke);
SCRIPT_FUNC(draw_arc, float radius, float radians, bool fill, bool stroke);
SCRIPT_FUNC(draw_sector, float radius, float radians, bool fill, bool stroke);
SCRIPT_FUNC(draw_circle, float radius, bool fill, bool stroke);
Expand Down

0 comments on commit cf37613

Please sign in to comment.