diff options
| author | Louis Burda <quent.burda@gmail.com> | 2024-10-24 00:57:06 +0200 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2024-10-24 00:57:06 +0200 |
| commit | f05fff6f3fce40a786454fe3c38e53d43bab7bfe (patch) | |
| tree | 2d436168f312cd7930d287db9b7e655afd0ca1b9 | |
| parent | d7ad64f906143097ff984f14095f825bb9ebae2e (diff) | |
| download | xnote-f05fff6f3fce40a786454fe3c38e53d43bab7bfe.tar.gz xnote-f05fff6f3fce40a786454fe3c38e53d43bab7bfe.zip | |
Add text alignment
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | xnote.c | 33 |
2 files changed, 30 insertions, 5 deletions
@@ -2,7 +2,7 @@ PREFIX ?= /usr/local BINDIR ?= /bin LDLIBS = -lglfw -lGL $(shell pkg-config --libs freetype2 fontconfig) -CFLAGS = $(shell pkg-config --cflags freetype2 fontconfig) +CFLAGS = $(shell pkg-config --cflags freetype2 fontconfig) $(CFLAGS_EXTRA) ifeq ($(DEBUG),1) CFLAGS += -Og -g @@ -11,6 +11,12 @@ #include <stdarg.h> #include <stdbool.h> +enum align { + CENTER, + LEFT, + RIGHT +}; + struct point { double x, y; }; @@ -23,6 +29,7 @@ struct line { struct note { double x, y; char *text; + enum align align; size_t len, cap; }; @@ -235,7 +242,8 @@ mouse_press_cb(GLFWwindow *window, int button, int action, int mods) push_event(EVENT_END_SHAPE); } } - } else if (button == GLFW_MOUSE_BUTTON_RIGHT) { + } else if (button == GLFW_MOUSE_BUTTON_RIGHT + || button == GLFW_MOUSE_BUTTON_MIDDLE) { if (action == GLFW_PRESS) { drag_canvas_x = canvas_x; drag_canvas_y = canvas_y; @@ -255,6 +263,18 @@ key_press_cb(GLFWwindow *window, int key, int scancode, int action, int mods) const char *keysym = glfwGetKeyName(key, scancode); if ((mods & GLFW_MOD_CONTROL) && keysym && !strcmp(keysym, "z")) { if (event_count) undo(); + } else if ((mods & GLFW_MOD_CONTROL) + && keysym && !strcmp(keysym, "l") + && last_event() == EVENT_START_NOTE) { + notes[note_count-1].align = LEFT; + } else if ((mods & GLFW_MOD_CONTROL) + && keysym && !strcmp(keysym, "r") + && last_event() == EVENT_START_NOTE) { + notes[note_count-1].align = RIGHT; + } else if ((mods & GLFW_MOD_CONTROL) + && keysym && !strcmp(keysym, "c") + && last_event() == EVENT_START_NOTE) { + notes[note_count-1].align = CENTER; } else if (action == GLFW_PRESS && (mods & GLFW_MOD_CONTROL) && keysym && !strcmp(keysym, "r")) { struct line *line = append(&lines, @@ -315,7 +335,7 @@ draw_texture(int texture, double x, double y) } static void -draw_text(const char *text, size_t len, GLint x, GLint y) +draw_text(const char *text, enum align align, size_t len, GLint x, GLint y) { if (len == 0) return; @@ -325,7 +345,12 @@ draw_text(const char *text, size_t len, GLint x, GLint y) } width -= glyph_advance[text[len-1]].x; width += glyph_size[text[len-1]].x; - x -= width / 2; + + if (align == CENTER) { + x -= width / 2; + } else if (align == RIGHT) { + x -= width; + } glEnable(GL_TEXTURE_2D); for (size_t i = 0; i < len; i++) { @@ -426,7 +451,7 @@ main(void) for (size_t i = 0; i < note_count; i++) { struct note *note = ¬es[i]; - draw_text(note->text, note->len, + draw_text(note->text, note->align, note->len, note->x - canvas_x, note->y - canvas_y); } |
