summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile11
-rw-r--r--src/text.cc11
-rw-r--r--src/text.h14
-rw-r--r--src/wayclock.cc26
4 files changed, 54 insertions, 8 deletions
diff --git a/Makefile b/Makefile
index a4a1675..21c9120 100644
--- a/Makefile
+++ b/Makefile
@@ -41,8 +41,14 @@ GLAD_SOURCE = $(GLAD_DIR)/glad.c
FREETYPE_DIR = $(WORK_DIR)/freetype
FREETYPE_BUILD = $(FREETYPE_DIR)/build
-FREETYPE_INCLUDE = $(FREETYPE_BUILD)/include
+FREETYPE_INCLUDE = $(FREETYPE_DIR)/include
FREETYPE_ARCHIVE = $(FREETYPE_BUILD)/libfreetype.a
+FREETYPE_FLAGS = \
+ -DFT_DISABLE_ZLIB=ON \
+ -DFT_DISABLE_BZIP2=ON \
+ -DFT_DISABLE_PNG=ON \
+ -DFT_DISABLE_BROTLI=ON \
+ -DFT_DISABLE_HARFBUZZ=ON
CSH_FLAGS += \
-I$(MI_INCLUDE) \
@@ -61,6 +67,7 @@ SOURCES = \
$(SRC_DIR)/events.c \
$(SRC_DIR)/window.c \
$(SRC_DIR)/graphics.cc \
+ $(SRC_DIR)/text.cc \
$(GLAD_DIR)/glad.c \
$(HASHMAP_SOURCE)
@@ -76,7 +83,7 @@ all: $(WAYCLOCK)
$(FREETYPE_BUILD):
@echo " CMAKE $@"
- @$(CMAKE) $(FREETYPE_DIR) -B $@ -G $(CMAKE_GENERATOR)
+ @$(CMAKE) $(FREETYPE_DIR) -B $@ -G $(CMAKE_GENERATOR) $(FREETYPE_FLAGS)
$(FREETYPE_ARCHIVE): | $(FREETYPE_BUILD)
@echo " MAKE $@"
diff --git a/src/text.cc b/src/text.cc
new file mode 100644
index 0000000..cf5345d
--- /dev/null
+++ b/src/text.cc
@@ -0,0 +1,11 @@
+#include "text.h"
+
+enum font_context_error_e wayc_font_context_init(struct font_context_s* ctx) {
+ FT_Error err = FT_Init_FreeType(&ctx->library);
+ if (err) return FONT_CONTEXT_ERROR_LIBRARY;
+ return FONT_CONTEXT_ERROR_NONE;
+}
+
+void wayc_font_context_deinit(struct font_context_s* ctx) {
+ FT_Done_FreeType(ctx->library);
+} \ No newline at end of file
diff --git a/src/text.h b/src/text.h
index 4cf6e2a..65e4d73 100644
--- a/src/text.h
+++ b/src/text.h
@@ -1,7 +1,15 @@
#pragma once
-#include "utils.h"
-#include "vec.h"
+#include "freetype/freetype.h"
+enum font_context_error_e {
+ FONT_CONTEXT_ERROR_NONE,
+ FONT_CONTEXT_ERROR_LIBRARY,
+};
-struct font_s {};
+struct font_context_s {
+ FT_Library library;
+};
+
+enum font_context_error_e wayc_font_context_init(struct font_context_s* ctx);
+void wayc_font_context_deinit(struct font_context_s* ctx);
diff --git a/src/wayclock.cc b/src/wayclock.cc
index d381641..3911ca0 100644
--- a/src/wayclock.cc
+++ b/src/wayclock.cc
@@ -3,6 +3,7 @@
#include "events.h"
#include "glad.h"
#include "graphics.h"
+#include "text.h"
#include "utils.h"
#include "window.h"
@@ -10,6 +11,11 @@
#define WAYC_APP_WIDTH 1280
#define WAYC_APP_HEIGHT 1080
+struct app_s {
+ struct renderer_s* renderer;
+ struct font_context_s* fctx;
+};
+
void wayc_frame(struct renderer_s* renderer, struct window_s* window,
struct eventloop_s* loop) {
wayc_notnull(window);
@@ -26,7 +32,8 @@ void wayc_handle(u8* user, struct eventloop_s* loop, struct event_s* event) {
wayc_notnull(loop);
wayc_notnull(event);
- struct renderer_s* renderer = (struct renderer_s*)user;
+ struct app_s* app = (struct app_s*)user;
+ struct renderer_s* renderer = app->renderer;
struct window_s* window = event->window;
union event_data_u data = event->data;
@@ -48,9 +55,15 @@ void wayc_handle(u8* user, struct eventloop_s* loop, struct event_s* event) {
}
int main() {
+ struct font_context_s fctx;
+ if (wayc_font_context_init(&fctx) != FONT_CONTEXT_ERROR_NONE)
+ wayc_panic("Failed to initialize font context");
+
struct eventloop_s loop;
- if (wayc_eventloop_init(&loop, wayc_handle) != EVENTLOOP_ERROR_NONE)
+ if (wayc_eventloop_init(&loop, wayc_handle) != EVENTLOOP_ERROR_NONE) {
+ wayc_font_context_deinit(&fctx);
wayc_panic("Failed to initialize event loop");
+ }
struct graphics_s graphics;
if (wayc_graphics_init(&graphics, &loop.state) != GRAPHICS_ERROR_NONE)
@@ -78,8 +91,13 @@ int main() {
wayc_renderer_use(&renderer);
wayc_window_redraw(&window, &loop);
+ struct app_s app = {
+ &renderer,
+ &fctx,
+ };
+
while (wayc_eventloop_running(&loop)) {
- wayc_eventloop_update(&loop, (u8*)&renderer);
+ wayc_eventloop_update(&loop, (u8*)&app);
wayc_window_redraw(&window, &loop);
}
@@ -87,5 +105,7 @@ int main() {
wayc_window_deinit(&window);
wayc_graphics_deinit(&graphics);
wayc_eventloop_deinit(&loop);
+
+ wayc_font_context_deinit(&fctx);
return 0;
} \ No newline at end of file