format: update .clang-format
This commit is contained in:
@@ -2,4 +2,7 @@ BasedOnStyle: LLVM
|
|||||||
ColumnLimit: 80
|
ColumnLimit: 80
|
||||||
BreakBeforeBraces: Attach
|
BreakBeforeBraces: Attach
|
||||||
IndentWidth: 4
|
IndentWidth: 4
|
||||||
|
TabWidth: 4
|
||||||
ContinuationIndentWidth: 4
|
ContinuationIndentWidth: 4
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
PointerAlignment: Left
|
||||||
@@ -5,24 +5,24 @@
|
|||||||
#include "src/ui/vektorcanvas.h"
|
#include "src/ui/vektorcanvas.h"
|
||||||
|
|
||||||
typedef struct button_tool_set_data {
|
typedef struct button_tool_set_data {
|
||||||
VektorAppState *state;
|
VektorAppState* state;
|
||||||
VektorAppTool tool;
|
VektorAppTool tool;
|
||||||
} button_tool_set_data;
|
} button_tool_set_data;
|
||||||
|
|
||||||
static void appstate_set_tool(GtkButton *button, gpointer user_data) {
|
static void appstate_set_tool(GtkButton* button, gpointer user_data) {
|
||||||
button_tool_set_data *data = (button_tool_set_data *)user_data;
|
button_tool_set_data* data = (button_tool_set_data*)user_data;
|
||||||
data->state->selectedTool = data->tool;
|
data->state->selectedTool = data->tool;
|
||||||
|
|
||||||
// setting tool also resets selected primitive
|
// setting tool also resets selected primitive
|
||||||
data->state->selectedPrimitive = NULL;
|
data->state->selectedPrimitive = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void canvas_onclick(GtkGestureClick *gesture, int n_press, double x,
|
static void canvas_onclick(GtkGestureClick* gesture, int n_press, double x,
|
||||||
double y, gpointer user_data) {
|
double y, gpointer user_data) {
|
||||||
|
|
||||||
VektorAppState *state = user_data;
|
VektorAppState* state = user_data;
|
||||||
|
|
||||||
GtkWidget *widget =
|
GtkWidget* widget =
|
||||||
gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture));
|
gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture));
|
||||||
|
|
||||||
int widget_w = gtk_widget_get_width(widget);
|
int widget_w = gtk_widget_get_width(widget);
|
||||||
@@ -38,7 +38,7 @@ static void canvas_onclick(GtkGestureClick *gesture, int n_press, double x,
|
|||||||
vektor_appstate_canvas_click(state, x * sx, y * sy);
|
vektor_appstate_canvas_click(state, x * sx, y * sy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vektor_appstate_canvas_click(VektorAppState *state, double x, double y) {
|
void vektor_appstate_canvas_click(VektorAppState* state, double x, double y) {
|
||||||
V2 pos = (V2){x, y};
|
V2 pos = (V2){x, y};
|
||||||
|
|
||||||
begin_click_dispatch:
|
begin_click_dispatch:
|
||||||
@@ -46,7 +46,7 @@ begin_click_dispatch:
|
|||||||
// create new polyline primitive if none is selected
|
// create new polyline primitive if none is selected
|
||||||
if (state->selectedPrimitive == NULL) {
|
if (state->selectedPrimitive == NULL) {
|
||||||
|
|
||||||
VektorPolyline *line = vektor_polyline_new();
|
VektorPolyline* line = vektor_polyline_new();
|
||||||
VektorPrimitive linePrimitive =
|
VektorPrimitive linePrimitive =
|
||||||
(VektorPrimitive){.kind = VEKTOR_POLYLINE, .polyline = line};
|
(VektorPrimitive){.kind = VEKTOR_POLYLINE, .polyline = line};
|
||||||
vektor_primitivebuffer_add_primitive(state->primitiveBuffer,
|
vektor_primitivebuffer_add_primitive(state->primitiveBuffer,
|
||||||
@@ -72,8 +72,8 @@ begin_click_dispatch:
|
|||||||
vektor_canvas_update(state->canvas);
|
vektor_canvas_update(state->canvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vektor_appstate_new(VektorWidgetState *wstate, VektorAppState *stateOut) {
|
void vektor_appstate_new(VektorWidgetState* wstate, VektorAppState* stateOut) {
|
||||||
button_tool_set_data *data_linetool = malloc(sizeof(button_tool_set_data));
|
button_tool_set_data* data_linetool = malloc(sizeof(button_tool_set_data));
|
||||||
data_linetool->state = stateOut;
|
data_linetool->state = stateOut;
|
||||||
data_linetool->tool = VektorLineTool;
|
data_linetool->tool = VektorLineTool;
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ void vektor_appstate_new(VektorWidgetState *wstate, VektorAppState *stateOut) {
|
|||||||
G_CALLBACK(appstate_set_tool), data_linetool);
|
G_CALLBACK(appstate_set_tool), data_linetool);
|
||||||
|
|
||||||
// Add click gesture to canvas
|
// Add click gesture to canvas
|
||||||
GtkGesture *canvasClickGesture = gtk_gesture_click_new();
|
GtkGesture* canvasClickGesture = gtk_gesture_click_new();
|
||||||
g_signal_connect(G_OBJECT(canvasClickGesture), "pressed",
|
g_signal_connect(G_OBJECT(canvasClickGesture), "pressed",
|
||||||
G_CALLBACK(canvas_onclick), stateOut);
|
G_CALLBACK(canvas_onclick), stateOut);
|
||||||
gtk_widget_add_controller(GTK_WIDGET(wstate->workspaceCanvas),
|
gtk_widget_add_controller(GTK_WIDGET(wstate->workspaceCanvas),
|
||||||
|
|||||||
@@ -10,18 +10,18 @@ typedef enum VektorAppTool { VektorLineTool } VektorAppTool;
|
|||||||
|
|
||||||
typedef struct VektorAppState {
|
typedef struct VektorAppState {
|
||||||
VektorAppTool selectedTool;
|
VektorAppTool selectedTool;
|
||||||
VektorPrimitive *selectedPrimitive;
|
VektorPrimitive* selectedPrimitive;
|
||||||
|
|
||||||
// Logic space
|
// Logic space
|
||||||
VektorPrimitiveBuffer *primitiveBuffer;
|
VektorPrimitiveBuffer* primitiveBuffer;
|
||||||
// Pixel space
|
// Pixel space
|
||||||
VektorFramebuffer *frameBuffer;
|
VektorFramebuffer* frameBuffer;
|
||||||
// View space
|
// View space
|
||||||
VektorCanvas *canvas;
|
VektorCanvas* canvas;
|
||||||
|
|
||||||
} VektorAppState;
|
} VektorAppState;
|
||||||
|
|
||||||
void vektor_appstate_new(VektorWidgetState *wstate, VektorAppState *stateOut);
|
void vektor_appstate_new(VektorWidgetState* wstate, VektorAppState* stateOut);
|
||||||
void vektor_appstate_canvas_click(VektorAppState *state, double x, double y);
|
void vektor_appstate_canvas_click(VektorAppState* state, double x, double y);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
#include "primitives.h"
|
#include "primitives.h"
|
||||||
|
|
||||||
VektorPolyline *vektor_polyline_new(void) {
|
VektorPolyline* vektor_polyline_new(void) {
|
||||||
VektorPolyline *pl = malloc(sizeof(VektorPolyline));
|
VektorPolyline* pl = malloc(sizeof(VektorPolyline));
|
||||||
pl->count = 0;
|
pl->count = 0;
|
||||||
pl->capacity = 4;
|
pl->capacity = 4;
|
||||||
pl->points = malloc(sizeof(V2) * pl->capacity);
|
pl->points = malloc(sizeof(V2) * pl->capacity);
|
||||||
return pl;
|
return pl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void vektor_polyline_add_point(VektorPolyline *pl, V2 point) {
|
void vektor_polyline_add_point(VektorPolyline* pl, V2 point) {
|
||||||
if (pl->count >= pl->capacity) {
|
if (pl->count >= pl->capacity) {
|
||||||
pl->capacity *= 2;
|
pl->capacity *= 2;
|
||||||
pl->points = realloc(pl->points, sizeof(V2) * pl->capacity);
|
pl->points = realloc(pl->points, sizeof(V2) * pl->capacity);
|
||||||
@@ -16,22 +16,22 @@ void vektor_polyline_add_point(VektorPolyline *pl, V2 point) {
|
|||||||
pl->points[pl->count++] = point;
|
pl->points[pl->count++] = point;
|
||||||
}
|
}
|
||||||
|
|
||||||
void vektor_polyline_free(VektorPolyline *pl) {
|
void vektor_polyline_free(VektorPolyline* pl) {
|
||||||
if (!pl)
|
if (!pl)
|
||||||
return;
|
return;
|
||||||
free(pl->points);
|
free(pl->points);
|
||||||
free(pl);
|
free(pl);
|
||||||
}
|
}
|
||||||
|
|
||||||
VektorPolygon *vektor_polygon_new(void) {
|
VektorPolygon* vektor_polygon_new(void) {
|
||||||
VektorPolygon *pg = malloc(sizeof(VektorPolygon));
|
VektorPolygon* pg = malloc(sizeof(VektorPolygon));
|
||||||
pg->count = 0;
|
pg->count = 0;
|
||||||
pg->capacity = 4;
|
pg->capacity = 4;
|
||||||
pg->points = malloc(sizeof(V2) * pg->capacity);
|
pg->points = malloc(sizeof(V2) * pg->capacity);
|
||||||
return pg;
|
return pg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void vektor_polygon_add_point(VektorPolygon *pg, V2 point) {
|
void vektor_polygon_add_point(VektorPolygon* pg, V2 point) {
|
||||||
if (pg->count >= pg->capacity) {
|
if (pg->count >= pg->capacity) {
|
||||||
pg->capacity *= 2;
|
pg->capacity *= 2;
|
||||||
pg->points = realloc(pg->points, sizeof(V2) * pg->capacity);
|
pg->points = realloc(pg->points, sizeof(V2) * pg->capacity);
|
||||||
@@ -39,14 +39,14 @@ void vektor_polygon_add_point(VektorPolygon *pg, V2 point) {
|
|||||||
pg->points[pg->count++] = point;
|
pg->points[pg->count++] = point;
|
||||||
}
|
}
|
||||||
|
|
||||||
void vektor_polygon_free(VektorPolygon *pg) {
|
void vektor_polygon_free(VektorPolygon* pg) {
|
||||||
if (!pg)
|
if (!pg)
|
||||||
return;
|
return;
|
||||||
free(pg->points);
|
free(pg->points);
|
||||||
free(pg);
|
free(pg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vektor_primitivebuffer_add_primitive(VektorPrimitiveBuffer *buffer,
|
void vektor_primitivebuffer_add_primitive(VektorPrimitiveBuffer* buffer,
|
||||||
VektorPrimitive prim) {
|
VektorPrimitive prim) {
|
||||||
if (buffer->count >= buffer->capacity) {
|
if (buffer->count >= buffer->capacity) {
|
||||||
buffer->capacity = buffer->capacity ? buffer->capacity * 2 : 4;
|
buffer->capacity = buffer->capacity ? buffer->capacity * 2 : 4;
|
||||||
|
|||||||
@@ -11,13 +11,13 @@ typedef struct {
|
|||||||
} VektorLine;
|
} VektorLine;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
V2 *points;
|
V2* points;
|
||||||
size_t count;
|
size_t count;
|
||||||
size_t capacity;
|
size_t capacity;
|
||||||
} VektorPolyline;
|
} VektorPolyline;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
V2 *points;
|
V2* points;
|
||||||
size_t count;
|
size_t count;
|
||||||
size_t capacity;
|
size_t capacity;
|
||||||
} VektorPolygon;
|
} VektorPolygon;
|
||||||
@@ -38,27 +38,27 @@ typedef struct {
|
|||||||
VektorPrimitiveKind kind;
|
VektorPrimitiveKind kind;
|
||||||
union {
|
union {
|
||||||
VektorLine line;
|
VektorLine line;
|
||||||
VektorPolyline *polyline;
|
VektorPolyline* polyline;
|
||||||
VektorPolygon *polygon;
|
VektorPolygon* polygon;
|
||||||
VektorCircle circle;
|
VektorCircle circle;
|
||||||
};
|
};
|
||||||
} VektorPrimitive;
|
} VektorPrimitive;
|
||||||
|
|
||||||
VektorPolyline *vektor_polyline_new(void);
|
VektorPolyline* vektor_polyline_new(void);
|
||||||
void vektor_polyline_add_point(VektorPolyline *pl, V2 point);
|
void vektor_polyline_add_point(VektorPolyline* pl, V2 point);
|
||||||
void vektor_polyline_free(VektorPolyline *pl);
|
void vektor_polyline_free(VektorPolyline* pl);
|
||||||
|
|
||||||
VektorPolygon *vektor_polygon_new(void);
|
VektorPolygon* vektor_polygon_new(void);
|
||||||
void vektor_polygon_add_point(VektorPolygon *pl, V2 point);
|
void vektor_polygon_add_point(VektorPolygon* pl, V2 point);
|
||||||
void vektor_polygon_free(VektorPolygon *pl);
|
void vektor_polygon_free(VektorPolygon* pl);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
VektorPrimitive *primitives;
|
VektorPrimitive* primitives;
|
||||||
size_t count;
|
size_t count;
|
||||||
size_t capacity;
|
size_t capacity;
|
||||||
} VektorPrimitiveBuffer;
|
} VektorPrimitiveBuffer;
|
||||||
|
|
||||||
void vektor_primitivebuffer_add_primitive(VektorPrimitiveBuffer *edges,
|
void vektor_primitivebuffer_add_primitive(VektorPrimitiveBuffer* edges,
|
||||||
VektorPrimitive edge);
|
VektorPrimitive edge);
|
||||||
|
|
||||||
#endif // PRIMITIVES_H_
|
#endif // PRIMITIVES_H_
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include "stddef.h"
|
#include "stddef.h"
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
void vektor_edgebuffer_add_edge(EdgeBuffer *buffer, Edge edge) {
|
void vektor_edgebuffer_add_edge(EdgeBuffer* buffer, Edge edge) {
|
||||||
if (buffer->count >= buffer->capacity) {
|
if (buffer->count >= buffer->capacity) {
|
||||||
buffer->capacity = buffer->capacity ? buffer->capacity * 2 : 4;
|
buffer->capacity = buffer->capacity ? buffer->capacity * 2 : 4;
|
||||||
buffer->edges = realloc(buffer->edges, sizeof(Edge) * buffer->capacity);
|
buffer->edges = realloc(buffer->edges, sizeof(Edge) * buffer->capacity);
|
||||||
@@ -11,18 +11,18 @@ void vektor_edgebuffer_add_edge(EdgeBuffer *buffer, Edge edge) {
|
|||||||
buffer->edges[buffer->count++] = edge;
|
buffer->edges[buffer->count++] = edge;
|
||||||
}
|
}
|
||||||
|
|
||||||
void vektor_line_flatten(EdgeBuffer *buffer, VektorLine line) {
|
void vektor_line_flatten(EdgeBuffer* buffer, VektorLine line) {
|
||||||
vektor_edgebuffer_add_edge(buffer, (Edge){line.p1, line.p2, 0});
|
vektor_edgebuffer_add_edge(buffer, (Edge){line.p1, line.p2, 0});
|
||||||
}
|
}
|
||||||
|
|
||||||
void vektor_polyline_flatten(EdgeBuffer *buffer, VektorPolyline *line) {
|
void vektor_polyline_flatten(EdgeBuffer* buffer, VektorPolyline* line) {
|
||||||
for (size_t i = 0; i + 1 < line->count; i++) {
|
for (size_t i = 0; i + 1 < line->count; i++) {
|
||||||
vektor_edgebuffer_add_edge(
|
vektor_edgebuffer_add_edge(
|
||||||
buffer, (Edge){line->points[i], line->points[i + 1], 0});
|
buffer, (Edge){line->points[i], line->points[i + 1], 0});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void vektor_polygon_flatten(EdgeBuffer *buffer, VektorPolygon *pg) {
|
void vektor_polygon_flatten(EdgeBuffer* buffer, VektorPolygon* pg) {
|
||||||
size_t n = pg->count;
|
size_t n = pg->count;
|
||||||
if (n < 3)
|
if (n < 3)
|
||||||
return;
|
return;
|
||||||
@@ -42,7 +42,7 @@ inline VektorFramebuffer vektor_framebuffer_new(unsigned int W,
|
|||||||
return fb;
|
return fb;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void vektor_framebuffer_putpixel(VektorFramebuffer *fb, int x, int y,
|
inline void vektor_framebuffer_putpixel(VektorFramebuffer* fb, int x, int y,
|
||||||
VektorColor color) {
|
VektorColor color) {
|
||||||
if ((unsigned)x >= fb->width || (unsigned)y >= fb->height)
|
if ((unsigned)x >= fb->width || (unsigned)y >= fb->height)
|
||||||
return;
|
return;
|
||||||
@@ -54,7 +54,7 @@ inline void vektor_framebuffer_putpixel(VektorFramebuffer *fb, int x, int y,
|
|||||||
fb->pixels[i + 3] = color.a;
|
fb->pixels[i + 3] = color.a;
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_filled_circle(VektorFramebuffer *fb, int cx, int cy, int r,
|
void draw_filled_circle(VektorFramebuffer* fb, int cx, int cy, int r,
|
||||||
VektorColor color) {
|
VektorColor color) {
|
||||||
for (int y = -r; y <= r; y++) {
|
for (int y = -r; y <= r; y++) {
|
||||||
int dx = (int)sqrt(r * r - y * y);
|
int dx = (int)sqrt(r * r - y * y);
|
||||||
@@ -64,7 +64,7 @@ void draw_filled_circle(VektorFramebuffer *fb, int cx, int cy, int r,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void vektor_framebuffer_drawline(VektorFramebuffer *fb, V2 a, V2 b,
|
void vektor_framebuffer_drawline(VektorFramebuffer* fb, V2 a, V2 b,
|
||||||
VektorColor color, double thickness) {
|
VektorColor color, double thickness) {
|
||||||
int x0 = (int)a.x;
|
int x0 = (int)a.x;
|
||||||
int y0 = (int)a.y;
|
int y0 = (int)a.y;
|
||||||
@@ -94,11 +94,11 @@ void vektor_framebuffer_drawline(VektorFramebuffer *fb, V2 a, V2 b,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void vektor_framebuffer_rasterize(VektorFramebuffer *fb,
|
void vektor_framebuffer_rasterize(VektorFramebuffer* fb,
|
||||||
VektorPrimitiveBuffer *prims) {
|
VektorPrimitiveBuffer* prims) {
|
||||||
EdgeBuffer edges = {0};
|
EdgeBuffer edges = {0};
|
||||||
for (size_t i = 0; i < prims->count; i++) {
|
for (size_t i = 0; i < prims->count; i++) {
|
||||||
VektorPrimitive *p = &prims->primitives[i];
|
VektorPrimitive* p = &prims->primitives[i];
|
||||||
|
|
||||||
switch (p->kind) {
|
switch (p->kind) {
|
||||||
case VEKTOR_LINE:
|
case VEKTOR_LINE:
|
||||||
|
|||||||
@@ -14,33 +14,33 @@ typedef struct {
|
|||||||
} Edge;
|
} Edge;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Edge *edges;
|
Edge* edges;
|
||||||
size_t count;
|
size_t count;
|
||||||
size_t capacity;
|
size_t capacity;
|
||||||
} EdgeBuffer;
|
} EdgeBuffer;
|
||||||
|
|
||||||
void vektor_edgebuffer_add_edge(EdgeBuffer *edges, Edge edge);
|
void vektor_edgebuffer_add_edge(EdgeBuffer* edges, Edge edge);
|
||||||
|
|
||||||
void vektor_line_flatten(EdgeBuffer *edges, VektorLine line);
|
void vektor_line_flatten(EdgeBuffer* edges, VektorLine line);
|
||||||
void vektor_polyline_flatten(EdgeBuffer *edges, VektorPolyline *line);
|
void vektor_polyline_flatten(EdgeBuffer* edges, VektorPolyline* line);
|
||||||
void vektor_polygon_flatten(EdgeBuffer *buffer, VektorPolygon *line);
|
void vektor_polygon_flatten(EdgeBuffer* buffer, VektorPolygon* line);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned int width;
|
unsigned int width;
|
||||||
unsigned int height;
|
unsigned int height;
|
||||||
unsigned char *pixels; // Flat RGBA8 array
|
unsigned char* pixels; // Flat RGBA8 array
|
||||||
} VektorFramebuffer;
|
} VektorFramebuffer;
|
||||||
|
|
||||||
VektorFramebuffer vektor_framebuffer_new(unsigned int width,
|
VektorFramebuffer vektor_framebuffer_new(unsigned int width,
|
||||||
unsigned int height);
|
unsigned int height);
|
||||||
|
|
||||||
void vektor_framebuffer_putpixel(VektorFramebuffer *fb, int x, int y,
|
void vektor_framebuffer_putpixel(VektorFramebuffer* fb, int x, int y,
|
||||||
VektorColor color);
|
VektorColor color);
|
||||||
|
|
||||||
void vektor_framebuffer_drawline(VektorFramebuffer *fb, V2 a, V2 b,
|
void vektor_framebuffer_drawline(VektorFramebuffer* fb, V2 a, V2 b,
|
||||||
VektorColor color, double thickness);
|
VektorColor color, double thickness);
|
||||||
|
|
||||||
void vektor_framebuffer_rasterize(VektorFramebuffer *fb,
|
void vektor_framebuffer_rasterize(VektorFramebuffer* fb,
|
||||||
VektorPrimitiveBuffer *primitives);
|
VektorPrimitiveBuffer* primitives);
|
||||||
|
|
||||||
#endif // RASTER_H_
|
#endif // RASTER_H_
|
||||||
|
|||||||
17
src/main.c
17
src/main.c
@@ -10,17 +10,16 @@
|
|||||||
#include "./ui/vektorcanvas.h"
|
#include "./ui/vektorcanvas.h"
|
||||||
#include "./util/color.h"
|
#include "./util/color.h"
|
||||||
|
|
||||||
static void on_map(GtkWidget *window, gpointer user_data) {
|
static void on_map(GtkWidget* window, gpointer user_data) {
|
||||||
vektor_uictrl_map((VektorWidgetState *)user_data);
|
vektor_uictrl_map((VektorWidgetState*)user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void activate(GtkApplication *app, gpointer user_data) {
|
static void activate(GtkApplication* app, gpointer user_data) {
|
||||||
|
|
||||||
VektorWidgetState *widget_state =
|
VektorWidgetState* widget_state =
|
||||||
(VektorWidgetState *)malloc(sizeof(VektorWidgetState));
|
(VektorWidgetState*)malloc(sizeof(VektorWidgetState));
|
||||||
vektor_uictrl_init(app, widget_state);
|
vektor_uictrl_init(app, widget_state);
|
||||||
VektorAppState *app_state =
|
VektorAppState* app_state = (VektorAppState*)malloc(sizeof(VektorAppState));
|
||||||
(VektorAppState *)malloc(sizeof(VektorAppState));
|
|
||||||
vektor_appstate_new(widget_state, app_state);
|
vektor_appstate_new(widget_state, app_state);
|
||||||
|
|
||||||
g_signal_connect(widget_state->window, "map", G_CALLBACK(on_map),
|
g_signal_connect(widget_state->window, "map", G_CALLBACK(on_map),
|
||||||
@@ -29,9 +28,9 @@ static void activate(GtkApplication *app, gpointer user_data) {
|
|||||||
gtk_window_present(widget_state->window);
|
gtk_window_present(widget_state->window);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char** argv) {
|
||||||
|
|
||||||
GtkApplication *app;
|
GtkApplication* app;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
app = gtk_application_new("dev.frox.vektor", G_APPLICATION_DEFAULT_FLAGS);
|
app = gtk_application_new("dev.frox.vektor", G_APPLICATION_DEFAULT_FLAGS);
|
||||||
|
|||||||
@@ -4,9 +4,9 @@
|
|||||||
#include "gtk/gtk.h"
|
#include "gtk/gtk.h"
|
||||||
#include "gtk/gtkcssprovider.h"
|
#include "gtk/gtkcssprovider.h"
|
||||||
|
|
||||||
void vektor_uictrl_init(GtkApplication *app, VektorWidgetState *stateOut) {
|
void vektor_uictrl_init(GtkApplication* app, VektorWidgetState* stateOut) {
|
||||||
GtkBuilder *builder = gtk_builder_new();
|
GtkBuilder* builder = gtk_builder_new();
|
||||||
GError *error = NULL;
|
GError* error = NULL;
|
||||||
|
|
||||||
// TODO: .ui files as resources instead of sketchy relative paths
|
// TODO: .ui files as resources instead of sketchy relative paths
|
||||||
if (!gtk_builder_add_from_file(builder, "./ui/main.ui", &error)) {
|
if (!gtk_builder_add_from_file(builder, "./ui/main.ui", &error)) {
|
||||||
@@ -14,7 +14,7 @@ void vektor_uictrl_init(GtkApplication *app, VektorWidgetState *stateOut) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load css
|
// Load css
|
||||||
GtkCssProvider *provider = gtk_css_provider_new();
|
GtkCssProvider* provider = gtk_css_provider_new();
|
||||||
gtk_css_provider_load_from_path(provider, "./ui/main.css");
|
gtk_css_provider_load_from_path(provider, "./ui/main.css");
|
||||||
gtk_style_context_add_provider_for_display(
|
gtk_style_context_add_provider_for_display(
|
||||||
gdk_display_get_default(), GTK_STYLE_PROVIDER(provider),
|
gdk_display_get_default(), GTK_STYLE_PROVIDER(provider),
|
||||||
@@ -38,7 +38,7 @@ void vektor_uictrl_init(GtkApplication *app, VektorWidgetState *stateOut) {
|
|||||||
g_object_unref(builder);
|
g_object_unref(builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vektor_uictrl_map(VektorWidgetState *state) {
|
void vektor_uictrl_map(VektorWidgetState* state) {
|
||||||
|
|
||||||
// set the workspace divider to 7:3 ratio
|
// set the workspace divider to 7:3 ratio
|
||||||
int window_width = gtk_widget_get_width(GTK_WIDGET(state->window));
|
int window_width = gtk_widget_get_width(GTK_WIDGET(state->window));
|
||||||
|
|||||||
@@ -8,16 +8,16 @@ Global application widget state, holding references to
|
|||||||
all the widgets used in internal logic of the program
|
all the widgets used in internal logic of the program
|
||||||
*/
|
*/
|
||||||
typedef struct VektorWidgetState {
|
typedef struct VektorWidgetState {
|
||||||
GtkWindow *window;
|
GtkWindow* window;
|
||||||
GtkPaned *workspacePaned;
|
GtkPaned* workspacePaned;
|
||||||
GtkPicture *workspaceCanvas;
|
GtkPicture* workspaceCanvas;
|
||||||
|
|
||||||
GtkButton *workspaceButtonLinetool;
|
GtkButton* workspaceButtonLinetool;
|
||||||
|
|
||||||
// GtkWidget* Workspace
|
// GtkWidget* Workspace
|
||||||
} VektorWidgetState;
|
} VektorWidgetState;
|
||||||
|
|
||||||
void vektor_uictrl_init(GtkApplication *app, VektorWidgetState *stateOut);
|
void vektor_uictrl_init(GtkApplication* app, VektorWidgetState* stateOut);
|
||||||
void vektor_uictrl_map(VektorWidgetState *state);
|
void vektor_uictrl_map(VektorWidgetState* state);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
#define VKTR_CANVAS_HEIGHT 400
|
#define VKTR_CANVAS_HEIGHT 400
|
||||||
#define VKTR_CANVAS_SIZE (VKTR_CANVAS_WIDTH * VKTR_CANVAS_HEIGHT * 4)
|
#define VKTR_CANVAS_SIZE (VKTR_CANVAS_WIDTH * VKTR_CANVAS_HEIGHT * 4)
|
||||||
|
|
||||||
void vektor_canvas_init(VektorWidgetState *state, VektorCanvas *canvasOut) {
|
void vektor_canvas_init(VektorWidgetState* state, VektorCanvas* canvasOut) {
|
||||||
canvasOut->canvasWidget = state->workspaceCanvas;
|
canvasOut->canvasWidget = state->workspaceCanvas;
|
||||||
canvasOut->width = VKTR_CANVAS_WIDTH;
|
canvasOut->width = VKTR_CANVAS_WIDTH;
|
||||||
canvasOut->height = VKTR_CANVAS_HEIGHT;
|
canvasOut->height = VKTR_CANVAS_HEIGHT;
|
||||||
@@ -28,7 +28,7 @@ void vektor_canvas_init(VektorWidgetState *state, VektorCanvas *canvasOut) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Generate new texture based on canvasPixels*/
|
/* Generate new texture based on canvasPixels*/
|
||||||
void vektor_canvas_update(VektorCanvas *canvas) {
|
void vektor_canvas_update(VektorCanvas* canvas) {
|
||||||
g_bytes_unref(canvas->canvasPixelBytes);
|
g_bytes_unref(canvas->canvasPixelBytes);
|
||||||
canvas->canvasPixelBytes =
|
canvas->canvasPixelBytes =
|
||||||
g_bytes_new(canvas->canvasPixels, VKTR_CANVAS_SIZE);
|
g_bytes_new(canvas->canvasPixels, VKTR_CANVAS_SIZE);
|
||||||
@@ -42,7 +42,7 @@ void vektor_canvas_update(VektorCanvas *canvas) {
|
|||||||
GDK_PAINTABLE(canvas->canvasTexture));
|
GDK_PAINTABLE(canvas->canvasTexture));
|
||||||
}
|
}
|
||||||
|
|
||||||
void vektor_canvas_fill(VektorCanvas *canvas, VektorColor color) {
|
void vektor_canvas_fill(VektorCanvas* canvas, VektorColor color) {
|
||||||
for (int x = 0; x < VKTR_CANVAS_WIDTH; x++) {
|
for (int x = 0; x < VKTR_CANVAS_WIDTH; x++) {
|
||||||
for (int y = 0; y < VKTR_CANVAS_HEIGHT; y++) {
|
for (int y = 0; y < VKTR_CANVAS_HEIGHT; y++) {
|
||||||
int i = (y * VKTR_CANVAS_WIDTH + x) * 4;
|
int i = (y * VKTR_CANVAS_WIDTH + x) * 4;
|
||||||
@@ -54,7 +54,7 @@ void vektor_canvas_fill(VektorCanvas *canvas, VektorColor color) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void vektor_canvas_drawfrom(VektorFramebuffer *fb, VektorCanvas *target) {
|
void vektor_canvas_drawfrom(VektorFramebuffer* fb, VektorCanvas* target) {
|
||||||
for (int x = 0; x < fb->width; x++) {
|
for (int x = 0; x < fb->width; x++) {
|
||||||
for (int y = 0; y < fb->height; y++) {
|
for (int y = 0; y < fb->height; y++) {
|
||||||
|
|
||||||
|
|||||||
@@ -6,20 +6,20 @@
|
|||||||
#include "uicontroller.h"
|
#include "uicontroller.h"
|
||||||
|
|
||||||
typedef struct VektorCanvas {
|
typedef struct VektorCanvas {
|
||||||
GtkPicture *canvasWidget;
|
GtkPicture* canvasWidget;
|
||||||
|
|
||||||
// texture related stuff
|
// texture related stuff
|
||||||
guchar *canvasPixels;
|
guchar* canvasPixels;
|
||||||
GdkTexture *canvasTexture;
|
GdkTexture* canvasTexture;
|
||||||
GBytes *canvasPixelBytes;
|
GBytes* canvasPixelBytes;
|
||||||
|
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
} VektorCanvas;
|
} VektorCanvas;
|
||||||
|
|
||||||
void vektor_canvas_init(VektorWidgetState *state, VektorCanvas *canvasOut);
|
void vektor_canvas_init(VektorWidgetState* state, VektorCanvas* canvasOut);
|
||||||
void vektor_canvas_update(VektorCanvas *canvas);
|
void vektor_canvas_update(VektorCanvas* canvas);
|
||||||
void vektor_canvas_fill(VektorCanvas *canvas, VektorColor color);
|
void vektor_canvas_fill(VektorCanvas* canvas, VektorColor color);
|
||||||
void vektor_canvas_drawfrom(VektorFramebuffer *fb, VektorCanvas *canvas);
|
void vektor_canvas_drawfrom(VektorFramebuffer* fb, VektorCanvas* canvas);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user