Compare commits
16 Commits
ed9aca01e4
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
90eec8d301 | ||
|
|
e9d1e5c47e | ||
| 31b2196976 | |||
|
|
bd586cda6a | ||
|
|
ae58a60be9 | ||
|
|
43b6d284dd | ||
| 1fb4b1c1e1 | |||
| af6b0c4d30 | |||
|
|
e054fc4fe7 | ||
|
|
e7dc799f54 | ||
|
|
5e883e2d27 | ||
|
|
09b84a2aa8 | ||
|
|
7bc94d3a96 | ||
|
|
f96d6066ee | ||
| 237bb02a8c | |||
|
|
562cbc12da |
8
icons/hicolor/scalable/actions/tool-brush-symbolic.svg
Normal file
8
icons/hicolor/scalable/actions/tool-brush-symbolic.svg
Normal file
@@ -0,0 +1,8 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 22 22">
|
||||
<defs>
|
||||
<style id="current-color-scheme" type="text/css">
|
||||
.ColorScheme-Text { color:#444444; } .ColorScheme-Highlight { color:#4285f4; } .ColorScheme-NeutralText { color:#ff9800; } .ColorScheme-PositiveText { color:#4caf50; } .ColorScheme-NegativeText { color:#f44336; }
|
||||
</style>
|
||||
</defs>
|
||||
<path style="fill:currentColor" class="ColorScheme-Text" d="M 14.574219 1.0058594 C 13.520146 0.87298937 10.770478 2.75775 8.0605469 5.46875 C 6.8520776 6.67795 5.8032796 7.8729 5 9 C 5.9414561 9.29995 6.7002076 10.0582 7 11 C 8.1266713 10.19649 9.3243336 9.1522594 10.533203 7.9433594 C 13.607725 4.8675594 15.546263 1.8205187 14.863281 1.1367188 C 14.793083 1.0660188 14.697306 1.0216494 14.574219 1.0058594 z M 4.5 10.330078 L 4.5 10.332031 C 1.0001889 11.270271 3.6248533 13.4865 1 15 C 4.4998111 15 6.25 13.248178 6.25 12.080078 C 6.25 11.497798 6.3093545 10.426978 4.5 10.330078 z" transform="translate(3 3)"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1005 B |
10
icons/hicolor/scalable/actions/tool-pencil-symbolic.svg
Normal file
10
icons/hicolor/scalable/actions/tool-pencil-symbolic.svg
Normal file
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" version="1.1">
|
||||
<defs>
|
||||
<style id="current-color-scheme" type="text/css">
|
||||
.ColorScheme-Text { color:#444444; } .ColorScheme-Highlight { color:#4285f4; } .ColorScheme-NeutralText { color:#ff9800; } .ColorScheme-PositiveText { color:#4caf50; } .ColorScheme-NegativeText { color:#f44336; }
|
||||
</style>
|
||||
</defs>
|
||||
<g transform="translate(3,3)">
|
||||
<path style="fill:currentColor" class="ColorScheme-Text" d="M 12.778,1.2222 C 12.778,1.2222 12.278,0.72224 11.778,1.2222 L 10,3 13,6 14.778,4.2222 C 15.278,3.7222 14.778,3.2222 14.778,3.2222 Z M 9,4 1,12 V 15 H 4 L 12,7 Z"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 646 B |
14
meson.build
14
meson.build
@@ -10,14 +10,22 @@ project(
|
||||
],
|
||||
)
|
||||
|
||||
gtk = dependency('gtk4', required: true)
|
||||
epoxy = dependency('epoxy')
|
||||
c_args = meson.get_compiler('c').get_supported_arguments([
|
||||
'-Wno-unused-variable',
|
||||
'-Wno-unused-parameter',
|
||||
'-Wno-pedantic'
|
||||
])
|
||||
add_project_arguments(c_args, language: 'c')
|
||||
|
||||
gtk = dependency('gtk4', required: true, include_type: 'system')
|
||||
epoxy = dependency('epoxy', include_type: 'system')
|
||||
|
||||
src = files(
|
||||
'src/main.c',
|
||||
'src/core/matrix.c',
|
||||
'src/core/primitives.c',
|
||||
'src/core/raster.c',
|
||||
'src/core/modifier.c',
|
||||
'src/ui/uicontroller.c',
|
||||
'src/ui/vektorcanvas.c',
|
||||
'src/ui/widgets/colorwheel.c',
|
||||
@@ -27,7 +35,7 @@ src = files(
|
||||
executable(
|
||||
'vektor',
|
||||
src,
|
||||
dependencies: [gtk,epoxy],
|
||||
dependencies: [gtk, epoxy],
|
||||
link_args: ['-lm'],
|
||||
install: true,
|
||||
)
|
||||
|
||||
@@ -5,6 +5,7 @@ in vec2 vPos;
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform float uTime;
|
||||
uniform float uScale;
|
||||
uniform vec4 uColor1;
|
||||
uniform vec4 uColor2;
|
||||
uniform vec2 uMin;
|
||||
@@ -12,7 +13,7 @@ uniform vec2 uMax;
|
||||
|
||||
void main()
|
||||
{
|
||||
float borderWidth = 0.008;
|
||||
float borderWidth = 0.008 / uScale;
|
||||
|
||||
|
||||
float distX = min(vPos.x - uMin.x, uMax.x - vPos.x);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "src/core/matrix.h"
|
||||
#include "src/core/modifier.h"
|
||||
#include "src/ui/uicontroller.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
@@ -7,7 +8,7 @@
|
||||
#include "gtk/gtk.h"
|
||||
#include "gtk/gtkrevealer.h"
|
||||
#include "src/core/primitives.h"
|
||||
#include "src/core/raster.h"
|
||||
|
||||
#include "src/ui/vektorcanvas.h"
|
||||
#include "src/ui/widgets/colorwheel.h"
|
||||
#include "src/util/color.h"
|
||||
@@ -46,7 +47,7 @@ static void appstate_on_color_change(VektorColorWheel* wheel,
|
||||
appstate->currentColor = c;
|
||||
|
||||
if (appstate->selectedShape != NULL) {
|
||||
appstate->selectedShape->style.stroke_color = c;
|
||||
appstate->selectedShape->base->style.stroke_color = c;
|
||||
}
|
||||
|
||||
// set entry fields under the color selector
|
||||
@@ -61,8 +62,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 +96,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) {
|
||||
@@ -114,23 +118,30 @@ begin_click_dispatch:
|
||||
VektorStyle style = (VektorStyle){
|
||||
.stroke_color = state->currentColor, .stroke_width = 0.01};
|
||||
|
||||
vektor_shapebuffer_add_shape(
|
||||
state->shapeBuffer, vektor_shape_new(linePrimitive, style, 0));
|
||||
vektor_shapenodebuf_add(state->shapeBuffer,
|
||||
vektor_shapenode_new(vektor_shape_new(
|
||||
linePrimitive, style, 0)));
|
||||
|
||||
state->selectedShape =
|
||||
&(state->shapeBuffer->shapes[state->shapeBuffer->count - 1]);
|
||||
&(state->shapeBuffer->nodes[state->shapeBuffer->count - 1]);
|
||||
|
||||
} else if (state->selectedShape->primitive.kind != VEKTOR_POLYLINE) {
|
||||
} else if (state->selectedShape->base->primitive.kind !=
|
||||
VEKTOR_POLYLINE) {
|
||||
// selecting a tool resets the selection, so this condition
|
||||
// should not happen
|
||||
g_warning("Invalid selected primitive; polyline expected");
|
||||
state->selectedShape = NULL;
|
||||
vektor_appstate_deselect_shape(state);
|
||||
goto begin_click_dispatch; // retry
|
||||
}
|
||||
|
||||
vektor_polyline_add_point(state->selectedShape->primitive.polyline,
|
||||
vektor_polyline_add_point(state->selectedShape->base->primitive.polyline,
|
||||
pos);
|
||||
vektor_shapes_update_bbox(state->shapeBuffer);
|
||||
state->selectedShape->base->bbox =
|
||||
vektor_primitive_get_bbox(state->selectedShape->base->primitive);
|
||||
|
||||
// polyline's handle count is not fixed, so we have to add them manually
|
||||
vektor_shape_add_handle(state->selectedShape->base, pos);
|
||||
|
||||
} else if (state->selectedTool == VektorPolygonTool) {
|
||||
// create new polygon shape if none is selected
|
||||
if (state->selectedShape == NULL) {
|
||||
@@ -140,21 +151,28 @@ begin_click_dispatch:
|
||||
(VektorPrimitive){.kind = VEKTOR_POLYGON, .polygon = polygon};
|
||||
VektorStyle style = (VektorStyle){
|
||||
.stroke_color = state->currentColor, .stroke_width = 0.01};
|
||||
vektor_shapebuffer_add_shape(
|
||||
state->shapeBuffer,
|
||||
vektor_shape_new(polygonPrimitive, style, 0));
|
||||
vektor_shapenodebuf_add(state->shapeBuffer,
|
||||
vektor_shapenode_new(vektor_shape_new(
|
||||
polygonPrimitive, style, 0)));
|
||||
|
||||
state->selectedShape =
|
||||
&(state->shapeBuffer->shapes[state->shapeBuffer->count - 1]);
|
||||
&(state->shapeBuffer->nodes[state->shapeBuffer->count - 1]);
|
||||
|
||||
} else if (state->selectedShape->primitive.kind != VEKTOR_POLYGON) {
|
||||
} else if (state->selectedShape->base->primitive.kind !=
|
||||
VEKTOR_POLYGON) {
|
||||
g_warning("Invalid selected primitive; polygon expected");
|
||||
state->selectedShape = NULL;
|
||||
vektor_appstate_deselect_shape(state);
|
||||
goto begin_click_dispatch; // retry
|
||||
}
|
||||
|
||||
vektor_polygon_add_point(state->selectedShape->primitive.polygon, pos);
|
||||
vektor_shapes_update_bbox(state->shapeBuffer);
|
||||
vektor_polygon_add_point(state->selectedShape->base->primitive.polygon,
|
||||
pos);
|
||||
state->selectedShape->base->bbox =
|
||||
vektor_primitive_get_bbox(state->selectedShape->base->primitive);
|
||||
|
||||
// polygon's handle count is not fixed, so we have to add them manually
|
||||
vektor_shape_add_handle(state->selectedShape->base, pos);
|
||||
|
||||
} else if (state->selectedTool == VektorCircleTool) {
|
||||
|
||||
VektorCircle* circle = vektor_circle_new();
|
||||
@@ -162,18 +180,27 @@ begin_click_dispatch:
|
||||
(VektorPrimitive){.kind = VEKTOR_CIRCLE, .circle = *circle};
|
||||
VektorStyle style = (VektorStyle){.stroke_color = state->currentColor,
|
||||
.stroke_width = 0.01};
|
||||
vektor_shapebuffer_add_shape(
|
||||
state->shapeBuffer, vektor_shape_new(circlePrimitive, style, 0));
|
||||
vektor_shapenodebuf_add(
|
||||
state->shapeBuffer,
|
||||
vektor_shapenode_new(vektor_shape_new(circlePrimitive, style, 0)));
|
||||
|
||||
state->selectedShape =
|
||||
&(state->shapeBuffer->shapes[state->shapeBuffer->count - 1]);
|
||||
&(state->shapeBuffer->nodes[state->shapeBuffer->count - 1]);
|
||||
|
||||
vektor_circle_free(circle);
|
||||
|
||||
vektor_circle_set_center(&state->selectedShape->primitive.circle, pos);
|
||||
vektor_circle_set_radius(&state->selectedShape->primitive.circle, 0.1f);
|
||||
vektor_circle_set_center(&state->selectedShape->base->primitive.circle,
|
||||
pos);
|
||||
vektor_circle_set_radius(&state->selectedShape->base->primitive.circle,
|
||||
0.1f);
|
||||
|
||||
vektor_shapes_update_bbox(state->shapeBuffer);
|
||||
state->selectedShape->base->bbox =
|
||||
vektor_primitive_get_bbox(state->selectedShape->base->primitive);
|
||||
|
||||
vektor_circle_create_handles(
|
||||
&state->selectedShape->base->primitive.circle,
|
||||
&state->selectedShape->base->handles,
|
||||
&state->selectedShape->base->handleCount);
|
||||
} else if (state->selectedTool == VektorRectangleTool) {
|
||||
|
||||
VektorRectangle* rect = vektor_rectangle_new();
|
||||
@@ -181,31 +208,44 @@ begin_click_dispatch:
|
||||
(VektorPrimitive){.kind = VEKTOR_RECTANGLE, .rectangle = *rect};
|
||||
VektorStyle style = (VektorStyle){.stroke_color = state->currentColor,
|
||||
.stroke_width = 0.01};
|
||||
vektor_shapebuffer_add_shape(state->shapeBuffer,
|
||||
vektor_shape_new(rectPrimitive, style, 0));
|
||||
vektor_shapenodebuf_add(
|
||||
state->shapeBuffer,
|
||||
vektor_shapenode_new(vektor_shape_new(rectPrimitive, style, 0)));
|
||||
|
||||
state->selectedShape =
|
||||
&(state->shapeBuffer->shapes[state->shapeBuffer->count - 1]);
|
||||
&(state->shapeBuffer->nodes[state->shapeBuffer->count - 1]);
|
||||
|
||||
vektor_rectangle_free(rect);
|
||||
|
||||
vektor_rectangle_set_start(&state->selectedShape->primitive.rectangle,
|
||||
pos);
|
||||
vektor_rectangle_set_end(&state->selectedShape->primitive.rectangle,
|
||||
vec2_add(pos, (V2){0.1f, 0.1f}));
|
||||
// state->selectedShape = NULL;
|
||||
vektor_shapes_update_bbox(state->shapeBuffer);
|
||||
vektor_rectangle_set_start(
|
||||
&state->selectedShape->base->primitive.rectangle, pos);
|
||||
vektor_rectangle_set_end(
|
||||
&state->selectedShape->base->primitive.rectangle,
|
||||
vec2_add(pos, (V2){0.1f, 0.1f}));
|
||||
vektor_rectangle_create_handles(
|
||||
&state->selectedShape->base->primitive.rectangle,
|
||||
&state->selectedShape->base->handles,
|
||||
&state->selectedShape->base->handleCount);
|
||||
|
||||
state->selectedShape->base->bbox =
|
||||
vektor_primitive_get_bbox(state->selectedShape->base->primitive);
|
||||
|
||||
} else if (state->selectedTool == VektorSelectionTool) {
|
||||
for (size_t i = 0; i < state->shapeBuffer->count; i++) {
|
||||
VektorBBox bbox = vektor_primitive_get_bbox(
|
||||
state->shapeBuffer->shapes[i].primitive);
|
||||
state->shapeBuffer->nodes[i].base->primitive);
|
||||
|
||||
// expand the bbox a little so its not painful to
|
||||
// try to grab handles located on the border of said bbox
|
||||
bbox = vektor_bbox_expand(bbox, 0.02);
|
||||
|
||||
if (vektor_bbox_isinside(bbox, pos)) {
|
||||
state->selectedShape = &(state->shapeBuffer->shapes[i]);
|
||||
state->selectedShape = &(state->shapeBuffer->nodes[i]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// was clicked outside any shapes - reset selection
|
||||
state->selectedShape = NULL;
|
||||
vektor_appstate_deselect_shape(state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,29 +254,72 @@ void vektor_appstate_canvas_drag_begin(GtkGestureDrag* gesture, gdouble x,
|
||||
GtkWidget* widget =
|
||||
gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture));
|
||||
|
||||
VektorAppState* state = (VektorAppState*)user_data;
|
||||
|
||||
int widget_w = gtk_widget_get_width(widget);
|
||||
int widget_h = gtk_widget_get_height(widget);
|
||||
|
||||
V2 normalized_coords =
|
||||
(V2){(2 * (x / widget_w)) - 1, 1 - (2 * (y / widget_h))};
|
||||
V2 position = (V2){(2 * (x / widget_w)) - 1, 1 - (2 * (y / widget_h))};
|
||||
position = m33_transform(m33_inverse(state->renderInfo->canvasMat),
|
||||
(V2){position.x, position.y});
|
||||
|
||||
if (state->selectedShape != NULL) {
|
||||
VektorShapeNode* selectedShape = state->selectedShape;
|
||||
|
||||
// get selected shape's handles and check
|
||||
// if we click any of them
|
||||
for (size_t i = 0; i < selectedShape->base->handleCount; i++) {
|
||||
VektorBBox bbox =
|
||||
vektor_shape_get_handle_bbox(selectedShape->base->handles[i]);
|
||||
if (vektor_bbox_isinside(bbox, position)) {
|
||||
// clicked inside handle
|
||||
state->heldHandleIndex = i;
|
||||
vektor_canvas_geometry_changed(state->renderInfo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void vektor_appstate_canvas_drag_update(GtkGestureDrag* gesture,
|
||||
gdouble x, gdouble y,
|
||||
gpointer user_data) {
|
||||
void vektor_appstate_canvas_drag_update(GtkGestureDrag* gesture, gdouble x,
|
||||
gdouble y, gpointer user_data) {
|
||||
|
||||
// ---- setup normalized coordinates (boilerplate) ----
|
||||
gdouble start_x, start_y;
|
||||
gtk_gesture_drag_get_start_point(gesture, &start_x, &start_y);
|
||||
|
||||
GtkWidget* widget =
|
||||
gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture));
|
||||
|
||||
VektorAppState* state = (VektorAppState*)user_data;
|
||||
|
||||
int widget_w = gtk_widget_get_width(widget);
|
||||
int widget_h = gtk_widget_get_height(widget);
|
||||
|
||||
V2 norm =
|
||||
(V2){(2 * ( (x+start_x) / widget_w)) - 1, 1 - (2 * ( (y+start_y) / widget_h))};
|
||||
V2 position = (V2){(2 * ((x + start_x) / widget_w)) - 1,
|
||||
1 - (2 * ((y + start_y) / widget_h))};
|
||||
position = m33_transform(m33_inverse(state->renderInfo->canvasMat),
|
||||
(V2){position.x, position.y});
|
||||
|
||||
// drag handle if selected
|
||||
if (state->selectedShape != NULL && state->heldHandleIndex != -1) {
|
||||
state->selectedShape->base->handles[state->heldHandleIndex] = position;
|
||||
vektor_shape_handles_updated(state->selectedShape->base,
|
||||
&state->heldHandleIndex);
|
||||
vektor_canvas_geometry_changed(state->renderInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void vektor_appstate_canvas_drag_end(GtkGestureDrag* gesture, gdouble x,
|
||||
gdouble y, gpointer user_data) {
|
||||
|
||||
VektorAppState* state = (VektorAppState*)user_data;
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
void vektor_appstate_new(VektorWidgetState* wstate, VektorAppState* stateOut) {
|
||||
@@ -270,12 +353,13 @@ void vektor_appstate_new(VektorWidgetState* wstate, VektorAppState* stateOut) {
|
||||
|
||||
// populate appstate
|
||||
stateOut->startupTime = g_get_monotonic_time();
|
||||
stateOut->shapeBuffer = malloc(sizeof(VektorShapeBuffer));
|
||||
*stateOut->shapeBuffer = (VektorShapeBuffer){0};
|
||||
stateOut->shapeBuffer = malloc(sizeof(VektorShapeNodeBuffer));
|
||||
*stateOut->shapeBuffer = (VektorShapeNodeBuffer){0};
|
||||
stateOut->canvas = malloc(sizeof(VektorCanvas));
|
||||
stateOut->widgetState = wstate;
|
||||
stateOut->currentColor = vektor_color_solid(0, 0, 0);
|
||||
stateOut->selectedShape = NULL;
|
||||
stateOut->heldHandleIndex = -1;
|
||||
|
||||
VektorCanvasRenderInfo* renderInfo = malloc(sizeof(VektorCanvasRenderInfo));
|
||||
renderInfo->zoom = 1;
|
||||
@@ -335,7 +419,14 @@ void vektor_appstate_new(VektorWidgetState* wstate, VektorAppState* stateOut) {
|
||||
G_CALLBACK(vektor_appstate_canvas_drag_update), stateOut);
|
||||
g_signal_connect(G_OBJECT(canvasDragGesture), "drag-begin",
|
||||
G_CALLBACK(vektor_appstate_canvas_drag_begin), stateOut);
|
||||
g_signal_connect(G_OBJECT(canvasDragGesture), "drag-end",
|
||||
G_CALLBACK(vektor_appstate_canvas_drag_end), stateOut);
|
||||
|
||||
gtk_widget_add_controller(GTK_WIDGET(wstate->workspaceCanvas),
|
||||
GTK_EVENT_CONTROLLER(canvasDragGesture));
|
||||
}
|
||||
|
||||
void vektor_appstate_deselect_shape(VektorAppState* state) {
|
||||
state->heldHandleIndex = -1;
|
||||
state->selectedShape = NULL;
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "../core/primitives.h"
|
||||
#include "../ui/uicontroller.h"
|
||||
#include "../ui/vektorcanvas.h"
|
||||
#include "src/core/raster.h"
|
||||
#include "src/core/modifier.h"
|
||||
|
||||
typedef enum VektorAppTool {
|
||||
VektorSelectionTool,
|
||||
@@ -20,12 +20,13 @@ typedef struct VektorAppState {
|
||||
VektorWidgetState* widgetState;
|
||||
|
||||
VektorAppTool selectedTool;
|
||||
VektorShape* selectedShape;
|
||||
VektorShapeNode* selectedShape;
|
||||
int heldHandleIndex;
|
||||
|
||||
VektorColor currentColor;
|
||||
|
||||
// Logic space
|
||||
VektorShapeBuffer* shapeBuffer;
|
||||
VektorShapeNodeBuffer* shapeBuffer;
|
||||
// View space
|
||||
VektorCanvas* canvas;
|
||||
VektorCanvasRenderInfo* renderInfo;
|
||||
@@ -33,5 +34,6 @@ typedef struct VektorAppState {
|
||||
|
||||
void vektor_appstate_new(VektorWidgetState* wstate, VektorAppState* stateOut);
|
||||
void vektor_appstate_canvas_click(VektorAppState* state, double x, double y);
|
||||
void vektor_appstate_deselect_shape(VektorAppState* state);
|
||||
|
||||
#endif
|
||||
83
src/core/modifier.c
Normal file
83
src/core/modifier.c
Normal file
@@ -0,0 +1,83 @@
|
||||
#include "modifier.h"
|
||||
#include <glib.h>
|
||||
|
||||
VektorShapeNode vektor_shapenode_new(VektorShape* shape) {
|
||||
VektorShapeNode node = (VektorShapeNode){
|
||||
.base = shape,
|
||||
.modifier_count = 0,
|
||||
.evaluated = shape,
|
||||
.base_dirty = true
|
||||
};
|
||||
return node;
|
||||
}
|
||||
|
||||
void vektor_shapenode_free(VektorShapeNode* shapeNode) {
|
||||
if(shapeNode->base == shapeNode->evaluated) {
|
||||
free(shapeNode->base); // avoid double free()
|
||||
} else {
|
||||
free(shapeNode->base);
|
||||
free(shapeNode->evaluated);
|
||||
}
|
||||
free(shapeNode->modifiers);
|
||||
}
|
||||
|
||||
VektorShape* vektor_shapenode_get_evaluated(VektorShapeNode* shapeNode) {
|
||||
return shapeNode->evaluated;
|
||||
}
|
||||
|
||||
VektorShape vektor_modifier_apply(VektorModifier* mod, VektorShape* input) {
|
||||
mod->cachedEvaluatedShape = mod->apply(mod, input);
|
||||
return mod->cachedEvaluatedShape;
|
||||
}
|
||||
|
||||
// lots of copies by value here, could be problematic
|
||||
void vektor_shapenode_update(VektorShapeNode* shapeNode) {
|
||||
// if the base is dirty, apply EVERY modifier
|
||||
if(shapeNode->base_dirty) {
|
||||
VektorShape* evaluated = shapeNode->base;
|
||||
for(size_t i = 0; i < shapeNode->modifier_count; i++) {
|
||||
*evaluated = vektor_modifier_apply(&shapeNode->modifiers[i], evaluated);
|
||||
shapeNode->modifiers[i].dirty = false;
|
||||
}
|
||||
shapeNode->evaluated = evaluated;
|
||||
shapeNode->base_dirty = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// if the base is not dirty, start applying modifiers upstream
|
||||
// starting from the first dirty
|
||||
bool encountered_dirty = false;
|
||||
|
||||
for(size_t i = 0; i < shapeNode->modifier_count; i++) {
|
||||
if(shapeNode->modifiers[i].dirty) { encountered_dirty = true; }
|
||||
if(encountered_dirty) {
|
||||
if(i == 0) {
|
||||
vektor_modifier_apply(&shapeNode->modifiers[i], shapeNode->base);
|
||||
} else {
|
||||
vektor_modifier_apply(&shapeNode->modifiers[i], &shapeNode->modifiers[i - 1].cachedEvaluatedShape);
|
||||
}
|
||||
shapeNode->modifiers[i].dirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (encountered_dirty) {
|
||||
*shapeNode->evaluated = shapeNode->modifiers[shapeNode->modifier_count - 1].cachedEvaluatedShape;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void vektor_shapenodebuf_add(VektorShapeNodeBuffer* buffer,
|
||||
VektorShapeNode node) {
|
||||
if (buffer->count >= buffer->capacity) {
|
||||
buffer->capacity = buffer->capacity ? buffer->capacity * 2 : 4;
|
||||
buffer->nodes =
|
||||
realloc(buffer->nodes, sizeof(VektorShapeNode) * buffer->capacity);
|
||||
}
|
||||
buffer->nodes[buffer->count++] = node;
|
||||
|
||||
if (buffer->count <= buffer->capacity / 4) {
|
||||
buffer->capacity /= 2;
|
||||
buffer->nodes =
|
||||
realloc(buffer->nodes, sizeof(VektorShapeNode) * buffer->capacity);
|
||||
}
|
||||
}
|
||||
53
src/core/modifier.h
Normal file
53
src/core/modifier.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#ifndef VKTR_MODIFIER_H
|
||||
#define VKTR_MODIFIER_H
|
||||
|
||||
#include "src/core/primitives.h"
|
||||
|
||||
typedef enum {
|
||||
VEKTOR_MODIFIER_IDENTITY,
|
||||
VEKTOR_MODIFIER_BEVEL
|
||||
} VektorModifierType;
|
||||
|
||||
typedef struct VektorModifier {
|
||||
VektorModifierType type;
|
||||
bool enabled;
|
||||
bool dirty;
|
||||
void* parameters;
|
||||
|
||||
VektorShape (*apply)(struct VektorModifier* mod, VektorShape* input);
|
||||
VektorShape cachedEvaluatedShape;
|
||||
|
||||
} VektorModifier;
|
||||
|
||||
typedef struct VektorShapeNode {
|
||||
VektorShape* base;
|
||||
VektorShape* evaluated;
|
||||
|
||||
VektorModifier* modifiers;
|
||||
size_t modifier_count;
|
||||
|
||||
bool base_dirty;
|
||||
} VektorShapeNode;
|
||||
|
||||
typedef struct VektorShapeNodeBuffer {
|
||||
VektorShapeNode* nodes;
|
||||
size_t count;
|
||||
size_t capacity;
|
||||
} VektorShapeNodeBuffer;
|
||||
|
||||
VektorShape vektor_modifier_apply(VektorModifier* mod, VektorShape* input);
|
||||
|
||||
VektorShapeNode vektor_shapenode_new(VektorShape* shape);
|
||||
void vektor_shapenode_free(VektorShapeNode* shapeNode);
|
||||
VektorShape* vektor_shapenode_get_evaluated(VektorShapeNode* shapeNode);
|
||||
void vektor_shapenode_update(VektorShapeNode* shapeNode);
|
||||
void vektor_shapenode_modifier_add(VektorShapeNode* shapeNode,
|
||||
VektorModifier* mod);
|
||||
void vektor_shapenode_modifier_remove(VektorShapeNode* shapeNode,
|
||||
VektorModifier* mod);
|
||||
void vektor_shapenode_free(VektorShapeNode* shapeNode);
|
||||
|
||||
void vektor_shapenodebuf_add(VektorShapeNodeBuffer* buffer,
|
||||
VektorShapeNode node);
|
||||
|
||||
#endif
|
||||
16
src/core/modifiers/m_identity.c
Normal file
16
src/core/modifiers/m_identity.c
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "../modifier.h"
|
||||
|
||||
static VektorShape vektor_m_identity_apply(VektorModifier* m, VektorShape* input) {
|
||||
return *input;
|
||||
}
|
||||
|
||||
VektorModifier vektor_m_identity_new() {
|
||||
return (VektorModifier) {
|
||||
.type = VEKTOR_MODIFIER_IDENTITY,
|
||||
.enabled = true,
|
||||
.dirty = true,
|
||||
.parameters = NULL,
|
||||
.apply = vektor_m_identity_apply
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "primitives.h"
|
||||
#include "glib.h"
|
||||
#include "src/core/matrix.h"
|
||||
#include "src/core/vector.h"
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
@@ -78,9 +79,7 @@ void vektor_circle_set_radius(VektorCircle* circle, double radius) {
|
||||
circle->radius = radius;
|
||||
}
|
||||
|
||||
void vektor_circle_free(VektorCircle* circle) {
|
||||
free(circle);
|
||||
}
|
||||
void vektor_circle_free(VektorCircle* circle) { free(circle); }
|
||||
|
||||
VektorRectangle* vektor_rectangle_new(void) {
|
||||
VektorRectangle* rct = malloc(sizeof(VektorRectangle));
|
||||
@@ -147,8 +146,7 @@ VektorBBox vektor_rectangle_get_bbox(VektorPrimitive prim) {
|
||||
VektorBBox vektor_circle_get_bbox(VektorPrimitive prim) {
|
||||
return (VektorBBox){
|
||||
vec2_sub(prim.circle.center, vec2_fromfloat(prim.circle.radius)),
|
||||
vec2_add(prim.circle.center, vec2_fromfloat(prim.circle.radius))
|
||||
};
|
||||
vec2_add(prim.circle.center, vec2_fromfloat(prim.circle.radius))};
|
||||
}
|
||||
|
||||
VektorBBox vektor_primitive_get_bbox(VektorPrimitive prim) {
|
||||
@@ -178,145 +176,256 @@ VektorBBox vektor_primitive_get_bbox(VektorPrimitive prim) {
|
||||
// ------ PRIMITIVE HANDLES GENERATION ------
|
||||
|
||||
/* [n]: polyline vertices */
|
||||
void vektor_polyline_create_handles(VektorPolyline* polyline, V2** handleArr, size_t* count) {
|
||||
void vektor_polyline_create_handles(VektorPolyline* polyline, V2** handleArr,
|
||||
size_t* count) {
|
||||
*count = 0;
|
||||
*handleArr = NULL;
|
||||
}
|
||||
|
||||
/* [n]: polygon vertices */
|
||||
void vektor_polygon_create_handles(VektorPolygon* polygon, V2** handleArr, size_t* count) {
|
||||
void vektor_polygon_create_handles(VektorPolygon* polygon, V2** handleArr,
|
||||
size_t* count) {
|
||||
*count = 0;
|
||||
*handleArr = NULL;
|
||||
}
|
||||
|
||||
/* [0]: center; [1]: radius */
|
||||
void vektor_circle_create_handles(VektorCircle* circle, V2** handleArr, size_t* count) {
|
||||
void vektor_circle_create_handles(VektorCircle* circle, V2** handleArr,
|
||||
size_t* count) {
|
||||
*count = 2;
|
||||
*handleArr = (V2*)malloc(sizeof(V2)*(*count));
|
||||
*handleArr = (V2*)malloc(sizeof(V2) * (*count));
|
||||
(*handleArr)[0] = circle->center;
|
||||
(*handleArr)[1] = (V2){circle->radius + circle->center.x, circle->center.y};
|
||||
}
|
||||
|
||||
/* [0]: center; [1-4]: corners (l2r, t2b); */
|
||||
void vektor_rectangle_create_handles(VektorRectangle* rectangle, V2** handleArr, size_t* count) {
|
||||
void vektor_rectangle_create_handles(VektorRectangle* rectangle, V2** handleArr,
|
||||
size_t* count) {
|
||||
*count = 5;
|
||||
free(*handleArr);
|
||||
*handleArr = (V2*)malloc(sizeof(V2)*(*count));
|
||||
*handleArr = (V2*)malloc(sizeof(V2) * (*count));
|
||||
|
||||
V2 halfdist = vec2_scale(vec2_sub(rectangle->end, rectangle->start), 0.5f);
|
||||
V2 center = vec2_add(rectangle->start, halfdist);
|
||||
|
||||
(*handleArr)[0] = center;
|
||||
(*handleArr)[1] = vec2_add( center, vec2_mul(halfdist, (V2){-1.0f, 1.0f}) );
|
||||
(*handleArr)[2] = vec2_add( center, halfdist);
|
||||
(*handleArr)[3] = vec2_add( center, vec2_mul(halfdist, (V2){-1.0f, -1.0f}) );
|
||||
(*handleArr)[4] = vec2_add( center, vec2_mul(halfdist, (V2){1.0f, -1.0f}) );
|
||||
(*handleArr)[1] = vec2_add(center, vec2_mul(halfdist, (V2){-1.0f, 1.0f}));
|
||||
(*handleArr)[2] = vec2_add(center, halfdist);
|
||||
(*handleArr)[3] = vec2_add(center, vec2_mul(halfdist, (V2){-1.0f, -1.0f}));
|
||||
(*handleArr)[4] = vec2_add(center, vec2_mul(halfdist, (V2){1.0f, -1.0f}));
|
||||
}
|
||||
|
||||
void vektor_shape_create_handles(VektorShape* shape) {
|
||||
switch(shape->primitive.kind) {
|
||||
case VEKTOR_POLYLINE:
|
||||
vektor_polyline_create_handles(shape->primitive.polyline, &shape->handles, &shape->handleCount);
|
||||
break;
|
||||
case VEKTOR_POLYGON:
|
||||
vektor_polygon_create_handles(shape->primitive.polygon, &shape->handles, &shape->handleCount);
|
||||
break;
|
||||
case VEKTOR_CIRCLE:
|
||||
vektor_circle_create_handles(&shape->primitive.circle, &shape->handles, &shape->handleCount);
|
||||
break;
|
||||
case VEKTOR_RECTANGLE:
|
||||
vektor_rectangle_create_handles(&shape->primitive.rectangle, &shape->handles, &shape->handleCount);
|
||||
break;
|
||||
switch (shape->primitive.kind) {
|
||||
case VEKTOR_POLYLINE:
|
||||
vektor_polyline_create_handles(shape->primitive.polyline,
|
||||
&shape->handles, &shape->handleCount);
|
||||
break;
|
||||
case VEKTOR_POLYGON:
|
||||
vektor_polygon_create_handles(shape->primitive.polygon, &shape->handles,
|
||||
&shape->handleCount);
|
||||
break;
|
||||
case VEKTOR_CIRCLE:
|
||||
vektor_circle_create_handles(&shape->primitive.circle, &shape->handles,
|
||||
&shape->handleCount);
|
||||
break;
|
||||
case VEKTOR_RECTANGLE:
|
||||
vektor_rectangle_create_handles(&shape->primitive.rectangle,
|
||||
&shape->handles, &shape->handleCount);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ------ AUXILIARY HANDLE METHODS ------
|
||||
|
||||
void vektor_shape_add_handle(VektorShape* shape, V2 handle) {
|
||||
// could be optimised with capacity property
|
||||
// but this function is only called when adding new
|
||||
// points to polyline and polygon, so it should
|
||||
// not be that much of an overhead
|
||||
shape->handles =
|
||||
realloc(shape->handles, sizeof(V2) * shape->handleCount + 1);
|
||||
shape->handles[shape->handleCount++] = handle;
|
||||
}
|
||||
|
||||
VektorBBox vektor_shape_get_handle_bbox(V2 handle) {
|
||||
return vektor_bbox_fromcenter(handle, 0.02);
|
||||
}
|
||||
|
||||
// ------ PRIMITIVE HANDLES UPDATING ------
|
||||
|
||||
void vektor_polyline_handles_updated(VektorPolyline* polyline, V2** handles, size_t* count) {
|
||||
if(*count != polyline->count) {
|
||||
void vektor_polyline_handles_updated(VektorPolyline* polyline, V2** handles,
|
||||
size_t* count, int* heldHandleIndex) {
|
||||
if (*count != polyline->count) {
|
||||
g_warning("handle count & point count mismatch in polyline");
|
||||
return;
|
||||
}
|
||||
for(size_t i = 0; i < *count; i++) {
|
||||
for (size_t i = 0; i < *count; i++) {
|
||||
polyline->points[i] = (*handles)[i];
|
||||
}
|
||||
}
|
||||
|
||||
void vektor_polygon_handles_updated(VektorPolygon* polygon, V2** handles, size_t* count) {
|
||||
if(*count != polygon->count) {
|
||||
void vektor_polygon_handles_updated(VektorPolygon* polygon, V2** handles,
|
||||
size_t* count, int* heldHandleIndex) {
|
||||
if (*count != polygon->count) {
|
||||
g_warning("handle count & point count mismatch in polygon");
|
||||
return;
|
||||
}
|
||||
for(size_t i = 0; i < *count; i++) {
|
||||
for (size_t i = 0; i < *count; i++) {
|
||||
polygon->points[i] = (*handles)[i];
|
||||
}
|
||||
}
|
||||
|
||||
void vektor_circle_handles_updated(VektorCircle* circle, V2** handles, size_t* count) {
|
||||
if(*count != 2) {
|
||||
void vektor_circle_handles_updated(VektorCircle* circle, V2** handles,
|
||||
size_t* count, int* heldHandleIndex) {
|
||||
if (*count != 2) {
|
||||
g_warning("unexpected circle handle count (%zu)", *count);
|
||||
return;
|
||||
}
|
||||
circle->center = (*handles)[0];
|
||||
circle->radius = vec2_length(vec2_sub((*handles)[0], (*handles)[1]));
|
||||
|
||||
if (*heldHandleIndex == 0) { // dragging center
|
||||
V2 translation = vec2_sub((*handles)[0], circle->center);
|
||||
circle->center = (*handles)[0];
|
||||
(*handles)[1] = vec2_add(translation, (*handles)[1]);
|
||||
} else {
|
||||
circle->radius = vec2_length(vec2_sub((*handles)[0], (*handles)[1]));
|
||||
}
|
||||
}
|
||||
|
||||
void vektor_rectangle_handles_updated(VektorRectangle* rectangle, V2** handles, size_t* count) {
|
||||
if(*count != 5) {
|
||||
// this shi is big because it dynamically handles handle remapping when
|
||||
// rectangle enters an invalid state (end < start)
|
||||
// creating the illusion of an invertable rect, while also keeping it
|
||||
// valid at all times
|
||||
void vektor_rectangle_handles_updated(VektorRectangle* rectangle, V2** handles,
|
||||
size_t* count, int* heldHandleIndex) {
|
||||
if (*count != 5) {
|
||||
g_warning("unexpected rectangle handle count (%zu)", *count);
|
||||
return;
|
||||
}
|
||||
|
||||
// get rectangle center
|
||||
V2 halfdist = vec2_scale(vec2_sub(rectangle->end, rectangle->start), 0.5f);
|
||||
V2 rectcenter = vec2_add(rectangle->start, halfdist);
|
||||
V2 start = rectangle->start;
|
||||
V2 end = rectangle->end;
|
||||
|
||||
// center according to handles
|
||||
V2 center = (*handles)[0];
|
||||
switch (*heldHandleIndex) {
|
||||
case 0: // center drag
|
||||
{
|
||||
V2 oldCenter = vec2_scale(vec2_add(start, end), 0.5f);
|
||||
V2 newCenter = (*handles)[0];
|
||||
|
||||
if(vec2_equals(center, rectcenter)) { // corner handles were changed
|
||||
V2 p1 = (*handles)[1];
|
||||
V2 p2 = (*handles)[2];
|
||||
V2 p3 = (*handles)[3];
|
||||
V2 p4 = (*handles)[4];
|
||||
V2 translation = vec2_sub(newCenter, oldCenter);
|
||||
|
||||
float min_x = fminf(p1.x, fminf(p2.x, fminf(p3.x, p4.x)));
|
||||
float min_y = fminf(p1.y, fminf(p2.y, fminf(p3.y, p4.y)));
|
||||
float max_x = fmaxf(p1.x, fmaxf(p2.x, fmaxf(p3.x, p4.x)));
|
||||
float max_y = fmaxf(p1.y, fmaxf(p2.y, fmaxf(p3.y, p4.y)));
|
||||
|
||||
V2 min = (V2){min_x, min_y};
|
||||
V2 max = (V2){max_x, max_y};
|
||||
|
||||
VektorRectangle propertRect = (VektorRectangle){min,max};
|
||||
// overwrite handles array (create_handles() frees the passed one)
|
||||
vektor_rectangle_create_handles(&propertRect, handles, count);
|
||||
|
||||
} else { // corner was dragged
|
||||
V2 translation = vec2_sub(center, rectcenter);
|
||||
V2 newmax = vec2_add((*handles)[2], translation);
|
||||
V2 newmin = vec2_add((*handles)[3], translation);
|
||||
|
||||
VektorRectangle propertRect = (VektorRectangle){newmin,newmax};
|
||||
vektor_rectangle_create_handles(&propertRect, handles, count);
|
||||
start = vec2_add(start, translation);
|
||||
end = vec2_add(end, translation);
|
||||
break;
|
||||
}
|
||||
|
||||
case 1: // top-left
|
||||
start.x = (*handles)[1].x;
|
||||
end.y = (*handles)[1].y;
|
||||
break;
|
||||
|
||||
case 2: // top-right
|
||||
end.x = (*handles)[2].x;
|
||||
end.y = (*handles)[2].y;
|
||||
break;
|
||||
|
||||
case 3: // bottom-left
|
||||
start.x = (*handles)[3].x;
|
||||
start.y = (*handles)[3].y;
|
||||
break;
|
||||
|
||||
case 4: // bottom-right
|
||||
end.x = (*handles)[4].x;
|
||||
start.y = (*handles)[4].y;
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
// Store raw values before normalization
|
||||
float raw_min_x = start.x;
|
||||
float raw_max_x = end.x;
|
||||
float raw_min_y = start.y;
|
||||
float raw_max_y = end.y;
|
||||
|
||||
// Normalize rectangle
|
||||
float min_x = fminf(start.x, end.x);
|
||||
float max_x = fmaxf(start.x, end.x);
|
||||
float min_y = fminf(start.y, end.y);
|
||||
float max_y = fmaxf(start.y, end.y);
|
||||
|
||||
bool flipX = raw_min_x > raw_max_x;
|
||||
bool flipY = raw_min_y > raw_max_y;
|
||||
|
||||
// Remap handle if we crossed axes
|
||||
if (*heldHandleIndex != 0) {
|
||||
if (flipX) {
|
||||
switch (*heldHandleIndex) {
|
||||
case 1:
|
||||
*heldHandleIndex = 2;
|
||||
break;
|
||||
case 2:
|
||||
*heldHandleIndex = 1;
|
||||
break;
|
||||
case 3:
|
||||
*heldHandleIndex = 4;
|
||||
break;
|
||||
case 4:
|
||||
*heldHandleIndex = 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (flipY) {
|
||||
switch (*heldHandleIndex) {
|
||||
case 1:
|
||||
*heldHandleIndex = 3;
|
||||
break;
|
||||
case 3:
|
||||
*heldHandleIndex = 1;
|
||||
break;
|
||||
case 2:
|
||||
*heldHandleIndex = 4;
|
||||
break;
|
||||
case 4:
|
||||
*heldHandleIndex = 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VektorRectangle properRect = {.start = {min_x, min_y},
|
||||
.end = {max_x, max_y}};
|
||||
|
||||
vektor_rectangle_set_start(rectangle, properRect.start);
|
||||
vektor_rectangle_set_end(rectangle, properRect.end);
|
||||
|
||||
// regenerate handle positions
|
||||
vektor_rectangle_create_handles(&properRect, handles, count);
|
||||
}
|
||||
|
||||
void vektor_shape_handles_updated(VektorShape* shape) {
|
||||
switch(shape->primitive.kind) {
|
||||
case VEKTOR_POLYLINE:
|
||||
vektor_polyline_handles_updated(shape->primitive.polyline, &shape->handles, &shape->handleCount);
|
||||
break;
|
||||
case VEKTOR_POLYGON:
|
||||
vektor_polygon_handles_updated(shape->primitive.polygon, &shape->handles, &shape->handleCount);
|
||||
break;
|
||||
case VEKTOR_CIRCLE:
|
||||
vektor_circle_handles_updated(&shape->primitive.circle, &shape->handles, &shape->handleCount);
|
||||
break;
|
||||
case VEKTOR_RECTANGLE:
|
||||
vektor_rectangle_handles_updated(&shape->primitive.rectangle, &shape->handles, &shape->handleCount);
|
||||
break;
|
||||
void vektor_shape_handles_updated(VektorShape* shape, int* heldHandleIndex) {
|
||||
switch (shape->primitive.kind) {
|
||||
case VEKTOR_POLYLINE:
|
||||
vektor_polyline_handles_updated(shape->primitive.polyline,
|
||||
&shape->handles, &shape->handleCount,
|
||||
heldHandleIndex);
|
||||
break;
|
||||
case VEKTOR_POLYGON:
|
||||
vektor_polygon_handles_updated(shape->primitive.polygon,
|
||||
&shape->handles, &shape->handleCount,
|
||||
heldHandleIndex);
|
||||
break;
|
||||
case VEKTOR_CIRCLE:
|
||||
vektor_circle_handles_updated(&shape->primitive.circle, &shape->handles,
|
||||
&shape->handleCount, heldHandleIndex);
|
||||
break;
|
||||
case VEKTOR_RECTANGLE:
|
||||
vektor_rectangle_handles_updated(&shape->primitive.rectangle,
|
||||
&shape->handles, &shape->handleCount,
|
||||
heldHandleIndex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,17 +440,33 @@ VektorBBox vektor_bbox_fromcenter(V2 center, float dist) {
|
||||
V2 v2dist = vec2_fromfloat(dist);
|
||||
V2 min = vec2_sub(center, v2dist);
|
||||
V2 max = vec2_add(center, v2dist);
|
||||
return (VektorBBox){min,max};
|
||||
return (VektorBBox){min, max};
|
||||
}
|
||||
|
||||
VektorBBox vektor_bbox_expand(VektorBBox bbox, float val) {
|
||||
return (VektorBBox){vec2_sub(bbox.min, vec2_fromfloat(val)),
|
||||
vec2_add(bbox.max, vec2_fromfloat(val))};
|
||||
}
|
||||
|
||||
// ------ SHAPE METHODS ------
|
||||
|
||||
VektorShape vektor_shape_new(VektorPrimitive prim, VektorStyle style,
|
||||
VektorShape* vektor_shape_new(VektorPrimitive prim, VektorStyle style,
|
||||
int z_index) {
|
||||
return (VektorShape){.primitive = prim,
|
||||
.style = style,
|
||||
.z_index = z_index,
|
||||
.bbox = vektor_primitive_get_bbox(prim)};
|
||||
VektorShape* shape = malloc(sizeof(VektorShape));
|
||||
*shape = (VektorShape){.primitive = prim,
|
||||
.style = style,
|
||||
.transform = m33_identity(),
|
||||
.z_index = z_index,
|
||||
.bbox = vektor_primitive_get_bbox(prim)};
|
||||
|
||||
/*
|
||||
create_handles() allocates new buffer for handles,
|
||||
and even if the local shape variable goes out of scope and deallocates,
|
||||
the passed value's pointer to an array of handles remains valid in the
|
||||
passed copy.
|
||||
*/
|
||||
vektor_shape_create_handles(shape);
|
||||
return shape;
|
||||
}
|
||||
|
||||
void vektor_shapes_update_bbox(VektorShapeBuffer* buffer) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef PRIMITIVES_H_
|
||||
#define PRIMITIVES_H_
|
||||
|
||||
#include "src/core/matrix.h"
|
||||
#include "src/util/color.h"
|
||||
#include "stddef.h"
|
||||
#include "stdlib.h"
|
||||
@@ -58,6 +59,7 @@ typedef struct {
|
||||
typedef struct {
|
||||
VektorStyle style;
|
||||
int z_index;
|
||||
M33 transform;
|
||||
VektorBBox bbox;
|
||||
VektorPrimitive primitive;
|
||||
|
||||
@@ -83,7 +85,8 @@ void vektor_rectangle_set_end(VektorRectangle* rct, V2 point);
|
||||
void vektor_rectangle_set_start(VektorRectangle* rct, V2 point);
|
||||
void vektor_rectangle_free(VektorRectangle* rct);
|
||||
|
||||
VektorShape vektor_shape_new(VektorPrimitive prim, VektorStyle style, int z_index);
|
||||
VektorShape* vektor_shape_new(VektorPrimitive prim, VektorStyle style,
|
||||
int z_index);
|
||||
|
||||
VektorBBox vektor_polyline_get_bbox(VektorPrimitive prim);
|
||||
VektorBBox vektor_polygon_get_bbox(VektorPrimitive prim);
|
||||
@@ -93,20 +96,32 @@ VektorBBox vektor_rectangle_get_bbox(VektorPrimitive prim);
|
||||
VektorBBox vektor_primitive_get_bbox(VektorPrimitive prim);
|
||||
bool vektor_bbox_isinside(VektorBBox bbox, V2 point);
|
||||
VektorBBox vektor_bbox_fromcenter(V2 center, float dist);
|
||||
VektorBBox vektor_bbox_expand(VektorBBox bbox, float val);
|
||||
|
||||
// shape handles
|
||||
void vektor_polyline_create_handles(VektorPolyline* polyline, V2** handleArr, size_t* count);
|
||||
void vektor_polygon_create_handles(VektorPolygon* polygon, V2** handleArr, size_t* count);
|
||||
void vektor_circle_create_handles(VektorCircle* circle, V2** handleArr, size_t* count);
|
||||
void vektor_rectangle_create_handles(VektorRectangle* rectangle, V2** handleArr, size_t* count);
|
||||
void vektor_polyline_create_handles(VektorPolyline* polyline, V2** handleArr,
|
||||
size_t* count);
|
||||
void vektor_polygon_create_handles(VektorPolygon* polygon, V2** handleArr,
|
||||
size_t* count);
|
||||
void vektor_circle_create_handles(VektorCircle* circle, V2** handleArr,
|
||||
size_t* count);
|
||||
void vektor_rectangle_create_handles(VektorRectangle* rectangle, V2** handleArr,
|
||||
size_t* count);
|
||||
void vektor_shape_create_handles(VektorShape* shape);
|
||||
|
||||
/* reconstructs the shape based on handles alone */
|
||||
void vektor_polyline_handles_updated(VektorPolyline* polyline, V2** handles, size_t* count);
|
||||
void vektor_polygon_handles_updated(VektorPolygon* polygon, V2** handles, size_t* count);
|
||||
void vektor_circle_handles_updated(VektorCircle* circle, V2** handles, size_t* count);
|
||||
void vektor_rectangle_handles_updated(VektorRectangle* rectangle, V2** handles, size_t* count);
|
||||
void vektor_shape_handles_updated(VektorShape* shape);
|
||||
void vektor_shape_add_handle(VektorShape* shape, V2 handle);
|
||||
VektorBBox vektor_shape_get_handle_bbox(V2 handle);
|
||||
|
||||
/* reconstructs the shape based on handles alone */
|
||||
void vektor_polyline_handles_updated(VektorPolyline* polyline, V2** handles,
|
||||
size_t* count, int* heldHandleIndex);
|
||||
void vektor_polygon_handles_updated(VektorPolygon* polygon, V2** handles,
|
||||
size_t* count, int* heldHandleIndex);
|
||||
void vektor_circle_handles_updated(VektorCircle* circle, V2** handles,
|
||||
size_t* count, int* heldHandleIndex);
|
||||
void vektor_rectangle_handles_updated(VektorRectangle* rectangle, V2** handles,
|
||||
size_t* count, int* heldHandleIndex);
|
||||
void vektor_shape_handles_updated(VektorShape* shape, int* heldHandleIndex);
|
||||
|
||||
typedef struct {
|
||||
VektorShape* shapes;
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#include "raster.h"
|
||||
#include "epoxy/gl.h"
|
||||
#include "glib.h"
|
||||
#include "primitives.h"
|
||||
#include "src/core/matrix.h"
|
||||
#include "src/core/modifier.h"
|
||||
#include "src/core/vector.h"
|
||||
#include "stddef.h"
|
||||
#include <math.h>
|
||||
@@ -37,7 +40,7 @@ void vektor_polygon_tessellate(EdgeBuffer* buffer, VektorPolygon* polygon,
|
||||
|
||||
void vektor_circle_tessellate(EdgeBuffer* buffer, VektorCircle* circle,
|
||||
size_t j, double scale) {
|
||||
double err = 0.000025;
|
||||
double err = 0.0025;
|
||||
size_t res = PI * sqrt((scale * circle->radius) / (2 * err));
|
||||
for (size_t i = 0; i < res; i++) {
|
||||
double theta1 = (2 * PI * i) / res;
|
||||
@@ -67,27 +70,37 @@ void vektor_rectangle_tessellate(EdgeBuffer* buffer, VektorRectangle* rct,
|
||||
vektor_edgebuffer_add_edge(buffer, left);
|
||||
}
|
||||
|
||||
void vektor_rasterize(VertexBuffer* vb, VektorShapeBuffer* shapes,
|
||||
double scale) {
|
||||
EdgeBuffer edges = {0};
|
||||
for (size_t i = 0; i < shapes->count; i++) {
|
||||
VektorPrimitive* p = &shapes->shapes[i].primitive;
|
||||
void vektor_vb_rasterize(VertexBuffer* vb, VektorShapeNodeBuffer* nodebuf,
|
||||
double scale) {
|
||||
for (size_t i = 0; i < nodebuf->count; i++) {
|
||||
EdgeBuffer edges = {0};
|
||||
|
||||
vektor_shapenode_update(&nodebuf->nodes[i]);
|
||||
VektorShape* currentShape = vektor_shapenode_get_evaluated(&nodebuf->nodes[i]);
|
||||
|
||||
VektorPrimitive* p = ¤tShape->primitive;
|
||||
VektorStyle style = currentShape->style;
|
||||
M33 transform = currentShape->transform;
|
||||
|
||||
switch (p->kind) {
|
||||
case VEKTOR_POLYLINE:
|
||||
vektor_polyline_tessellate(&edges, p->polyline, i, scale);
|
||||
vektor_edges_to_triangles(vb, &edges, &transform, style, FALSE);
|
||||
break;
|
||||
|
||||
case VEKTOR_POLYGON:
|
||||
vektor_polygon_tessellate(&edges, p->polygon, i, scale);
|
||||
vektor_edges_to_triangles(vb, &edges, &transform, style, TRUE);
|
||||
break;
|
||||
|
||||
case VEKTOR_CIRCLE:
|
||||
vektor_circle_tessellate(&edges, &p->circle, i, scale);
|
||||
vektor_edges_to_triangles(vb, &edges, &transform, style, TRUE);
|
||||
break;
|
||||
|
||||
case VEKTOR_RECTANGLE:
|
||||
vektor_rectangle_tessellate(&edges, &p->rectangle, i, scale);
|
||||
vektor_edges_to_triangles(vb, &edges, &transform, style, TRUE);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -95,8 +108,6 @@ void vektor_rasterize(VertexBuffer* vb, VektorShapeBuffer* shapes,
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
vektor_edges_to_triangles(vb, &edges, shapes);
|
||||
}
|
||||
|
||||
void vektor_vb_add_triangle(VertexBuffer* vb, V2 v0, V2 v1, V2 v2,
|
||||
@@ -131,33 +142,109 @@ void vektor_vb_add_quad(VertexBuffer* vb, V2 a, V2 b, VektorColor color) {
|
||||
vektor_vb_add_triangle(vb, tl, br, tr, color);
|
||||
}
|
||||
|
||||
void vektor_edge_to_triangles(VertexBuffer* vb, Edge e,
|
||||
VektorShapeBuffer* shape_buffer) {
|
||||
float dx = e.p2.x - e.p1.x;
|
||||
float dy = e.p2.y - e.p1.y;
|
||||
float len = sqrtf(dx * dx + dy * dy);
|
||||
if (len == 0)
|
||||
return;
|
||||
Edge edge_transform(const Edge* e, const M33* t) {
|
||||
Edge out = *e;
|
||||
out.p1 = m33_transform(*t, e->p1);
|
||||
out.p2 = m33_transform(*t, e->p2);
|
||||
return out;
|
||||
}
|
||||
|
||||
float px =
|
||||
-dy / len * (shape_buffer->shapes[e.shape_id].style.stroke_width / 2);
|
||||
float py =
|
||||
dx / len * (shape_buffer->shapes[e.shape_id].style.stroke_width / 2);
|
||||
|
||||
V2 v0 = {e.p1.x + px, e.p1.y + py};
|
||||
V2 v1 = {e.p1.x - px, e.p1.y - py};
|
||||
V2 v2 = {e.p2.x + px, e.p2.y + py};
|
||||
V2 v3 = {e.p2.x - px, e.p2.y - py};
|
||||
|
||||
vektor_vb_add_triangle(vb, v0, v1, v2,
|
||||
shape_buffer->shapes[e.shape_id].style.stroke_color);
|
||||
vektor_vb_add_triangle(vb, v2, v1, v3,
|
||||
shape_buffer->shapes[e.shape_id].style.stroke_color);
|
||||
V2 line_intersection(V2 p, V2 r, V2 q, V2 s) {
|
||||
float t = vec2_cross(vec2_sub(q, p), s) / vec2_cross(r, s);
|
||||
return vec2_add(p, vec2_scale(r, t));
|
||||
}
|
||||
|
||||
void vektor_edges_to_triangles(VertexBuffer* vb, EdgeBuffer* edges,
|
||||
VektorShapeBuffer* shape_buffer) {
|
||||
M33* transform, VektorStyle style, bool closed) {
|
||||
if (!edges || edges->count < 1)
|
||||
return;
|
||||
|
||||
float hw = style.stroke_width * 0.5f;
|
||||
|
||||
for (size_t i = 0; i < edges->count; i++) {
|
||||
vektor_edge_to_triangles(vb, edges->edges[i], shape_buffer);
|
||||
Edge e = edge_transform(&edges->edges[i], transform);
|
||||
|
||||
V2 d = vec2_normalize(vec2_sub(e.p2, e.p1));
|
||||
V2 n = vec2_perp(d);
|
||||
V2 off = vec2_scale(n, hw);
|
||||
|
||||
V2 v0 = vec2_add(e.p1, off);
|
||||
V2 v1 = vec2_sub(e.p1, off);
|
||||
V2 v2 = vec2_add(e.p2, off);
|
||||
V2 v3 = vec2_sub(e.p2, off);
|
||||
|
||||
vektor_vb_add_triangle(vb, v0, v1, v2, style.stroke_color);
|
||||
vektor_vb_add_triangle(vb, v2, v1, v3, style.stroke_color);
|
||||
}
|
||||
|
||||
size_t limit = closed ? edges->count : edges->count - 1;
|
||||
|
||||
for (size_t i = 0; i < limit; i++) {
|
||||
Edge e1 = edge_transform(&edges->edges[i], transform);
|
||||
Edge e2 =
|
||||
edge_transform(&edges->edges[(i + 1) % edges->count], transform);
|
||||
|
||||
V2 corner = e1.p2;
|
||||
|
||||
V2 d1 = vec2_normalize(vec2_sub(e1.p2, e1.p1));
|
||||
V2 d2 = vec2_normalize(vec2_sub(e2.p2, e2.p1));
|
||||
|
||||
V2 n1 = vec2_perp(d1);
|
||||
V2 n2 = vec2_perp(d2);
|
||||
|
||||
V2 off1 = vec2_scale(n1, hw);
|
||||
V2 off2 = vec2_scale(n2, hw);
|
||||
|
||||
V2 v10 = vec2_add(e1.p1, off1);
|
||||
V2 v11 = vec2_sub(e1.p1, off1);
|
||||
V2 v12 = vec2_add(e1.p2, off1);
|
||||
V2 v13 = vec2_sub(e1.p2, off1);
|
||||
|
||||
V2 v20 = vec2_add(e2.p1, off2);
|
||||
V2 v21 = vec2_sub(e2.p1, off2);
|
||||
V2 v22 = vec2_add(e2.p2, off2);
|
||||
V2 v23 = vec2_sub(e2.p2, off2);
|
||||
|
||||
V2 outer1 = vec2_add(corner, off1);
|
||||
V2 outer2 = vec2_add(corner, off2);
|
||||
|
||||
V2 inner1 = vec2_sub(corner, off1);
|
||||
V2 inner2 = vec2_sub(corner, off2);
|
||||
|
||||
float cos_theta = vec2_dot(d1, d2);
|
||||
float sin_half = sqrtf((1.0f - cos_theta) * 0.5f);
|
||||
float miter_len = hw / sin_half;
|
||||
|
||||
if (miter_len > 4.0 * hw || miter_len < 1.05 * hw) {
|
||||
vektor_vb_add_triangle(vb, outer1, corner, outer2,
|
||||
style.stroke_color);
|
||||
vektor_vb_add_triangle(vb, inner1, corner, inner2,
|
||||
style.stroke_color);
|
||||
continue;
|
||||
}
|
||||
|
||||
V2 outer_miter = line_intersection(vec2_add(corner, off1), d1,
|
||||
vec2_add(corner, off2), d2);
|
||||
|
||||
V2 inner_miter = line_intersection(vec2_sub(corner, off1), d1,
|
||||
vec2_sub(corner, off2), d2);
|
||||
|
||||
V2 mo = vec2_sub(outer_miter, corner);
|
||||
V2 mi = vec2_sub(inner_miter, corner);
|
||||
|
||||
V2 vo1 = line_intersection(corner, vec2_normalize(vec2_perp(mo)),
|
||||
vec2_add(corner, off1), d1);
|
||||
V2 vo2 = line_intersection(corner,
|
||||
vec2_negate(vec2_normalize(vec2_perp(mo))),
|
||||
vec2_add(corner, off2), d2);
|
||||
|
||||
V2 vi1 = line_intersection(corner, vec2_normalize(vec2_perp(mi)),
|
||||
vec2_sub(corner, off1), d1);
|
||||
V2 vi2 = line_intersection(corner,
|
||||
vec2_negate(vec2_normalize(vec2_perp(mi))),
|
||||
vec2_sub(corner, off2), d2);
|
||||
|
||||
vektor_vb_add_triangle(vb, vo1, outer_miter, vo2, style.stroke_color);
|
||||
vektor_vb_add_triangle(vb, vi1, inner_miter, vi2, style.stroke_color);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "primitives.h"
|
||||
|
||||
#include "../util/color.h"
|
||||
#include "src/core/modifier.h"
|
||||
#include "stddef.h"
|
||||
#include "vector.h"
|
||||
#include <stddef.h>
|
||||
@@ -48,10 +49,10 @@ void vektor_vb_add_triangle(VertexBuffer* vb, V2 v0, V2 v1, V2 v2,
|
||||
void vektor_vb_add_quad(VertexBuffer* vb, V2 v0, V2 v1, VektorColor color);
|
||||
|
||||
void vektor_edge_to_triangles(VertexBuffer* vb, Edge e,
|
||||
VektorShapeBuffer* shape_buffer);
|
||||
VektorShapeNodeBuffer* node_buffer);
|
||||
void vektor_edges_to_triangles(VertexBuffer* vb, EdgeBuffer* edges,
|
||||
VektorShapeBuffer* shape_buffer);
|
||||
void vektor_rasterize(VertexBuffer* vb, VektorShapeBuffer* shapes,
|
||||
double scale);
|
||||
M33* transform, VektorStyle style, bool closed);
|
||||
void vektor_vb_rasterize(VertexBuffer* vb, VektorShapeNodeBuffer* shapes,
|
||||
double scale);
|
||||
|
||||
#endif // RASTER_H_
|
||||
|
||||
@@ -14,12 +14,16 @@ typedef struct {
|
||||
double z;
|
||||
} V3;
|
||||
|
||||
static inline V2 vec2_fromfloat(const float f) { return (V2){f,f}; }
|
||||
static inline V2 vec2_fromfloat(const float f) { return (V2){f, f}; }
|
||||
|
||||
static inline V3 vec2_vector(const V2 v) { return (V3){v.x, v.y, 0}; }
|
||||
|
||||
static inline V3 vec2_point(const V2 v) { return (V3){v.x, v.y, 1}; }
|
||||
|
||||
static inline V2 vec2_perp(const V2 v) { return (V2){-v.y, v.x}; }
|
||||
|
||||
static inline V2 vec2_negate(const V2 v) { return (V2){-v.x, -v.y}; }
|
||||
|
||||
static inline V2 vec2_add(const V2 v1, const V2 v2) {
|
||||
return (V2){v1.x + v2.x, v1.y + v2.y};
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include "./application/applicationstate.h"
|
||||
#include "./ui/uicontroller.h"
|
||||
|
||||
|
||||
static int update_callback(gpointer data) {
|
||||
VektorAppState* appstate = (VektorAppState*)data;
|
||||
gtk_gl_area_queue_render(
|
||||
|
||||
@@ -38,6 +38,7 @@ static GLuint shader_standard_uProjMatrixLoc;
|
||||
|
||||
static GLuint shader_selection_uProjMatrixLoc;
|
||||
static GLuint shader_selection_uTimeLoc;
|
||||
static GLuint shader_selection_uScaleLoc;
|
||||
static GLuint shader_selection_uC1Loc;
|
||||
static GLuint shader_selection_uC2Loc;
|
||||
static GLuint shader_selection_uMinLoc;
|
||||
@@ -45,6 +46,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);
|
||||
@@ -102,6 +104,8 @@ static void init_shader(void) {
|
||||
glGetUniformLocation(selection_shader_program, "uProjection");
|
||||
shader_selection_uTimeLoc =
|
||||
glGetUniformLocation(selection_shader_program, "uTime");
|
||||
shader_selection_uScaleLoc =
|
||||
glGetUniformLocation(selection_shader_program, "uScale");
|
||||
shader_selection_uC1Loc =
|
||||
glGetUniformLocation(selection_shader_program, "uColor1");
|
||||
shader_selection_uC2Loc =
|
||||
@@ -135,23 +139,41 @@ static void init_geometry(void) {
|
||||
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
static gboolean render(GtkGLArea* a, GdkGLContext* ctx,
|
||||
VektorCanvasRenderInfo* renderInfo) {
|
||||
|
||||
void vektor_canvas_geometry_changed(VektorCanvasRenderInfo* renderInfo) {
|
||||
vb.count = 0;
|
||||
vektor_vb_rasterize(&vb, renderInfo->shapes, renderInfo->zoom);
|
||||
shape_vertex_count = vb.count;
|
||||
|
||||
vektor_rasterize(&vb, renderInfo->shapes, renderInfo->zoom);
|
||||
size_t shape_vertex_count =
|
||||
vb.count; // remember how many vertices belong to shapes
|
||||
|
||||
// create selection quad if a shape is selected
|
||||
if (renderInfo->selectedShape != NULL &&
|
||||
*(renderInfo->selectedShape) != NULL) {
|
||||
VektorBBox bbox = vektor_primitive_get_bbox(
|
||||
(*(renderInfo->selectedShape))->primitive);
|
||||
|
||||
VektorShapeNode* selectedShape = *renderInfo->selectedShape;
|
||||
|
||||
// create handle quads if a shape is selected
|
||||
for (size_t i = 0; i < selectedShape->base->handleCount; i++) {
|
||||
V2 handle = selectedShape->base->handles[i];
|
||||
VektorBBox handleBbox = vektor_shape_get_handle_bbox(handle);
|
||||
vektor_vb_add_quad(&vb, handleBbox.min, handleBbox.max,
|
||||
vektor_color_new(255, 255, 255, 255));
|
||||
}
|
||||
|
||||
shape_vertex_count = vb.count;
|
||||
|
||||
// create selection quad if a shape is selected
|
||||
VektorBBox bbox =
|
||||
vektor_primitive_get_bbox(selectedShape->base->primitive);
|
||||
// expand it a little so it is not inset
|
||||
bbox = vektor_bbox_expand(bbox, 0.03f);
|
||||
|
||||
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);
|
||||
@@ -166,7 +188,7 @@ static gboolean render(GtkGLArea* a, GdkGLContext* ctx,
|
||||
|
||||
glBindVertexArray(vao);
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
@@ -174,18 +196,21 @@ static gboolean render(GtkGLArea* a, GdkGLContext* ctx,
|
||||
|
||||
// PASS 2 - draw selection quads
|
||||
if (vb.count > shape_vertex_count) {
|
||||
// g_print("vdelta: %zu\n", vb.count - shape_vertex_count);
|
||||
float time =
|
||||
(g_get_monotonic_time() - renderInfo->startupTime) / 10000000.0f;
|
||||
|
||||
// re-fetch bbox (we know a shape is selected)
|
||||
VektorBBox bbox = vektor_primitive_get_bbox(
|
||||
(*(renderInfo->selectedShape))->primitive);
|
||||
(*(renderInfo->selectedShape))->base->primitive);
|
||||
bbox = vektor_bbox_expand(bbox, 0.03f);
|
||||
|
||||
glUseProgram(selection_shader_program);
|
||||
|
||||
glUniformMatrix4fv(shader_selection_uProjMatrixLoc, 1, GL_FALSE,
|
||||
renderInfo->canvasTransform);
|
||||
glUniform1f(shader_selection_uTimeLoc, time);
|
||||
glUniform1f(shader_selection_uScaleLoc, renderInfo->zoom);
|
||||
glUniform2f(shader_selection_uMinLoc, bbox.min.x, bbox.min.y);
|
||||
glUniform2f(shader_selection_uMaxLoc, bbox.max.x, bbox.max.y);
|
||||
glUniform4f(shader_selection_uC1Loc, 0, 0, 0, 0);
|
||||
@@ -256,16 +281,15 @@ static void on_scroll(GtkEventControllerScroll* controller, double dx,
|
||||
M33 mat =
|
||||
m33_mul(m33_translate(s->panX, s->panY),
|
||||
m33_mul(m33_rotate(s->rotation), m33_scale(s->zoom, s->zoom)));
|
||||
// M33 mat = m33_mul(m33_mul(m33_scale(s->zoom, s->zoom),
|
||||
// m33_translate(s->panX, s->panY)),
|
||||
// m33_rotate(s->rotation));
|
||||
|
||||
m33_to_gl4(mat, s->canvasTransform);
|
||||
s->canvasMat = mat;
|
||||
|
||||
GtkWidget* widget =
|
||||
gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(controller));
|
||||
gtk_gl_area_queue_render(GTK_GL_AREA(widget));
|
||||
// }
|
||||
|
||||
vektor_canvas_geometry_changed(s);
|
||||
|
||||
}
|
||||
|
||||
static void on_pan_begin(GtkGestureDrag* gesture, double start_x,
|
||||
@@ -337,7 +361,9 @@ static void on_pan_drag(GtkGestureDrag* gesture, double offset_x,
|
||||
}
|
||||
GtkWidget* widget =
|
||||
gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture));
|
||||
gtk_gl_area_queue_render(GTK_GL_AREA(widget));
|
||||
|
||||
//gtk_gl_area_queue_render(GTK_GL_AREA(widget));
|
||||
vektor_canvas_geometry_changed(s);
|
||||
}
|
||||
|
||||
void vektor_canvas_init(VektorWidgetState* state, VektorCanvas* canvasOut,
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "../util/color.h"
|
||||
#include "gtk/gtk.h"
|
||||
#include "src/core/matrix.h"
|
||||
#include "src/core/modifier.h"
|
||||
#include "src/core/primitives.h"
|
||||
#include "uicontroller.h"
|
||||
|
||||
@@ -22,10 +23,10 @@ typedef struct VektorCanvas {
|
||||
|
||||
typedef struct VektorCanvasRenderInfo {
|
||||
gint64 startupTime;
|
||||
VektorShapeBuffer* shapes;
|
||||
VektorShapeNodeBuffer* shapes;
|
||||
|
||||
// a pointer to appstate->selectedShape
|
||||
VektorShape** selectedShape;
|
||||
VektorShapeNode** selectedShape;
|
||||
float zoom;
|
||||
float panX;
|
||||
float panY;
|
||||
@@ -44,6 +45,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);
|
||||
|
||||
23
ui/main.ui
23
ui/main.ui
@@ -31,6 +31,29 @@
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<!--Another topbar for style control-->
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">horizontal</property>
|
||||
<property name="hexpand">true</property>
|
||||
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="icon-name">tool-pencil-symbolic</property>
|
||||
<property name="margin-start">10</property>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<object class="GtkEntry" id="thickness_entry">
|
||||
<property name="text">1</property>
|
||||
<property name="margin-start">10</property>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<!--Main area below-->
|
||||
<child>
|
||||
<object class="GtkPaned" id="workspace_paned">
|
||||
|
||||
Reference in New Issue
Block a user