diff --git a/src/application/applicationstate.c b/src/application/applicationstate.c index 85f22fa..b4efdab 100644 --- a/src/application/applicationstate.c +++ b/src/application/applicationstate.c @@ -61,8 +61,7 @@ static void appstate_on_color_change(VektorColorWheel* wheel, gtk_editable_set_text(GTK_EDITABLE(appstate->widgetState->sidepanelEntryB), str_b); - /*gtk_gl_area_queue_render( - GTK_GL_AREA(appstate->widgetState->workspaceCanvas));*/ + vektor_canvas_geometry_changed(appstate->renderInfo); } static void appstate_on_entry_update(GtkEntry* entry, gpointer user_data) { @@ -96,7 +95,11 @@ static void canvas_onclick(GtkGestureClick* gesture, int n_press, double x, vektor_appstate_canvas_click(state, normalized_coords.x, normalized_coords.y); - // gtk_gl_area_queue_render(GTK_GL_AREA(widget)); + // technically there are cases when a click would not result in change of the geometry + // but this is more concise then writing it inside that function + // a bunch of times and burder future click dispatches with + // handling this signal + vektor_canvas_geometry_changed(state->renderInfo); } void vektor_appstate_canvas_click(VektorAppState* state, double x, double y) { @@ -253,6 +256,7 @@ void vektor_appstate_canvas_drag_begin(GtkGestureDrag* gesture, gdouble x, if(vektor_bbox_isinside(bbox, position)) { // clicked inside handle state->heldHandleIndex = i; + vektor_canvas_geometry_changed(state->renderInfo); break; } } @@ -282,6 +286,7 @@ void vektor_appstate_canvas_drag_update(GtkGestureDrag* gesture, gdouble x, if(state->selectedShape != NULL && state->heldHandleIndex != -1) { state->selectedShape->handles[state->heldHandleIndex] = position; vektor_shape_handles_updated(state->selectedShape, &state->heldHandleIndex); + vektor_canvas_geometry_changed(state->renderInfo); } } @@ -293,6 +298,7 @@ void vektor_appstate_canvas_drag_end(GtkGestureDrag* gesture, gdouble x, // if we were dragging a handle if(state->selectedShape != NULL && state->heldHandleIndex != -1) { state->heldHandleIndex = -1; // ...then remove handle drag flag + vektor_canvas_geometry_changed(state->renderInfo); } } diff --git a/src/ui/vektorcanvas.c b/src/ui/vektorcanvas.c index 4de0059..e149d41 100644 --- a/src/ui/vektorcanvas.c +++ b/src/ui/vektorcanvas.c @@ -45,6 +45,7 @@ static GLuint shader_selection_uMaxLoc; static GLuint vao; VertexBuffer vb; +static size_t shape_vertex_count = 0; static GLuint compile_shader(GLenum type, const char* src) { GLuint shader = glCreateShader(type); @@ -135,13 +136,11 @@ static void init_geometry(void) { glBindVertexArray(0); } -static gboolean render(GtkGLArea* a, GdkGLContext* ctx, - VektorCanvasRenderInfo* renderInfo) { - vb.count = 0; +void vektor_canvas_geometry_changed(VektorCanvasRenderInfo* renderInfo) { + vb.count = 0; vektor_rasterize(&vb, renderInfo->shapes, renderInfo->zoom); - size_t shape_vertex_count = - vb.count; // remember how many vertices belong to shapes + shape_vertex_count = vb.count; if (renderInfo->selectedShape != NULL && *(renderInfo->selectedShape) != NULL) { @@ -166,6 +165,13 @@ static gboolean render(GtkGLArea* a, GdkGLContext* ctx, vektor_vb_add_quad(&vb, bbox.min, bbox.max, vektor_color_new(255, 255, 255, 255)); } +} + +static gboolean render(GtkGLArea* a, GdkGLContext* ctx, + VektorCanvasRenderInfo* renderInfo) { + //vektor_canvas_geometry_changed(renderInfo); + + glBufferData(GL_ARRAY_BUFFER, vb.count * sizeof(Vertex), vb.vertices, GL_STATIC_DRAW); diff --git a/src/ui/vektorcanvas.h b/src/ui/vektorcanvas.h index 873f7d3..15e0dfc 100644 --- a/src/ui/vektorcanvas.h +++ b/src/ui/vektorcanvas.h @@ -44,6 +44,7 @@ typedef struct VektorCanvasRenderInfo { void vektor_canvas_init(VektorWidgetState* state, VektorCanvas* canvasOut, VektorCanvasRenderInfo* renderInfo); +void vektor_canvas_geometry_changed(VektorCanvasRenderInfo* renderInfo); // void vektor_canvas_update(VektorCanvas* canvas); // void vektor_canvas_fill(VektorCanvas* canvas, VektorColor color); // void vektor_canvas_drawfrom(VektorFramebuffer* fb, VektorCanvas* canvas);