Skip to content

Commit

Permalink
text measure
Browse files Browse the repository at this point in the history
  • Loading branch information
steeljustify committed Jan 28, 2025
1 parent b426326 commit cb11aca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
12 changes: 4 additions & 8 deletions actrwasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,16 @@ void actr_canvas2d_ellipse(double x, double y, double radiusX, double radiusY, d

void actr_canvas2d_fill();
void actr_canvas2d_fillRect(double x, double y, double w, double h);
void actr_canvas2d_fillTextLength(double x, double y, char *text, int length);
void actr_canvas2d_fillText(double x, double y, char *text, int length);

void actr_canvas2d_measureText(char * text, int length);

void actr_canvas2d_stroke();
void actr_canvas2d_strokeRect(double x, double y, double w, double h);

void actr_sizeSanity(char *text, int length);
// end externs

// helpers
void actr_canvas2d_fillText(double x, double y, char *text)
{
actr_canvas2d_fillTextLength(x, y, text, strlen(text));
}
// end helpers

struct ActrPoint
{
int x;
Expand All @@ -38,6 +33,7 @@ struct ActrState
{
struct ActrPoint canvasSize;
struct ActrPoint pointerPosition;
struct ActrPoint textSize;
};
static struct ActrState actrState;

Expand Down
8 changes: 5 additions & 3 deletions script.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,19 @@ void EMSCRIPTEN_KEEPALIVE step(double delta)
snprintf(buffer, SIZE, "click count: %i x:%i y:%i w:%i h:%i", click, actrState.pointerPosition.x, actrState.pointerPosition.y, actrState.canvasSize.x, actrState.canvasSize.y);


actr_canvas2d_fillStyle(0, 0, 0, 10);
actr_canvas2d_fillStyle(0, 0, 0, 100);
actr_canvas2d_fillRect(0, 0, 9999, 9999);

actr_canvas2d_fillStyle(255, 0, 0, 50);
actr_canvas2d_strokeStyle(255, 255, 255, 100);

int top = 10;
// actr_canvas2d_fillRect(x, 10, 60, 15);
actr_canvas2d_strokeRect(x, 10, 60, 14);
actr_canvas2d_measureText(buffer, strlen(buffer));
actr_canvas2d_strokeRect(x - 2, top -2, actrState.textSize.x + 4, actrState.textSize.y + 4);

actr_canvas2d_fillStyle(0, 200, 200, 100);
actr_canvas2d_fillText(x + 5, 20, buffer);
actr_canvas2d_fillText(x, top + actrState.textSize.y, buffer, strlen(buffer));

actr_canvas2d_fillStyle(255, 0, 0, 50);
actr_canvas2d_beginPath();
Expand Down

0 comments on commit cb11aca

Please sign in to comment.