feat: parameterize stroke color and thickness

This commit is contained in:
2026-03-07 14:49:12 +05:30
parent d620caf02b
commit 3a292ea351
10 changed files with 112 additions and 271 deletions

View File

@@ -4,6 +4,7 @@
#include "src/core/primitives.h"
#include "src/core/raster.h"
#include "src/ui/vektorcanvas.h"
#include "src/util/color.h"
typedef struct button_tool_set_data {
GtkRevealer* revealer;
@@ -19,7 +20,7 @@ static void appstate_set_tool(GtkButton* button, gpointer user_data) {
gtk_revealer_set_reveal_child(data->revealer, FALSE);
// setting tool also resets selected primitive
data->state->selectedPrimitive = NULL;
data->state->selectedShape = NULL;
}
static void appstate_reveal_subtools(GtkButton* button, gpointer user_data) {
@@ -57,32 +58,32 @@ void vektor_appstate_canvas_click(VektorAppState* state, double x, double y) {
begin_click_dispatch:
if (state->selectedTool == VektorLineTool) {
// create new polyline primitive if none is selected
if (state->selectedPrimitive == NULL) {
if (state->selectedShape == NULL) {
VektorPolyline* line = vektor_polyline_new();
VektorPrimitive linePrimitive =
(VektorPrimitive){.kind = VEKTOR_POLYLINE, .polyline = line};
vektor_primitivebuffer_add_primitive(state->primitiveBuffer,
linePrimitive);
VektorStyle style =
(VektorStyle){.stroke_color = (VektorColor){255, 0, 0, 1},
.stroke_width = 0.01};
VektorShape shape = (VektorShape){
.primitive = linePrimitive, .z_index = 0, .style = style};
vektor_shapebuffer_add_shape(state->shapeBuffer, shape);
state->selectedPrimitive =
&(state->primitiveBuffer
->primitives[state->primitiveBuffer->count - 1]);
state->selectedShape =
&(state->shapeBuffer->shapes[state->shapeBuffer->count - 1]);
} else if (state->selectedPrimitive->kind != VEKTOR_POLYLINE) {
} else if (state->selectedShape->primitive.kind != VEKTOR_POLYLINE) {
// selecting a tool resets the selection, so this condition
// should not happen
g_warning("Invalid selected primitive; polyline expected");
state->selectedPrimitive = NULL;
state->selectedShape = NULL;
goto begin_click_dispatch; // retry
}
vektor_polyline_add_point(state->selectedPrimitive->polyline, pos);
vektor_polyline_add_point(state->selectedShape->primitive.polyline,
pos);
}
vektor_framebuffer_rasterize(state->frameBuffer, state->primitiveBuffer);
vektor_canvas_drawfrom(state->frameBuffer, state->canvas);
vektor_canvas_update(state->canvas);
}
void vektor_appstate_new(VektorWidgetState* wstate, VektorAppState* stateOut) {
@@ -92,12 +93,10 @@ void vektor_appstate_new(VektorWidgetState* wstate, VektorAppState* stateOut) {
data_linetool->revealer = wstate->workspaceRevealerShapes;
// populate appstate
stateOut->primitiveBuffer = malloc(sizeof(VektorPrimitiveBuffer));
*stateOut->primitiveBuffer = (VektorPrimitiveBuffer){0};
stateOut->frameBuffer = malloc(sizeof(VektorFramebuffer));
*stateOut->frameBuffer = vektor_framebuffer_new(400, 400);
stateOut->shapeBuffer = malloc(sizeof(VektorShapeBuffer));
*stateOut->shapeBuffer = (VektorShapeBuffer){0};
stateOut->canvas = malloc(sizeof(VektorCanvas));
vektor_canvas_init(wstate, stateOut->canvas, stateOut->primitiveBuffer);
vektor_canvas_init(wstate, stateOut->canvas, stateOut->shapeBuffer);
// link all the buttons
g_signal_connect(G_OBJECT(wstate->workspaceButtonLinetool), "clicked",