aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-03-30 16:10:56 +0200
committerdec05eba <dec05eba@protonmail.com>2022-03-30 16:10:56 +0200
commit956c86fe4728e6e5239202f1402fd65260ece7c8 (patch)
tree70b638cac96eb164c5320be05d14e07a142794d7
parent131a2f0b5c51fc821224bf7637ba58df0a5ae15a (diff)
Proper y offset for text, add option to create hidden window and add function to make it visible (map, unmap)
-rw-r--r--include/mgl/window/window.h2
-rw-r--r--src/graphics/font.c2
-rw-r--r--src/graphics/text.c2
-rw-r--r--src/window/window.c15
4 files changed, 18 insertions, 3 deletions
diff --git a/include/mgl/window/window.h b/include/mgl/window/window.h
index a948932..27e4409 100644
--- a/include/mgl/window/window.h
+++ b/include/mgl/window/window.h
@@ -50,6 +50,7 @@ typedef struct {
mgl_vec2i min_size; /* (0, 0) = no limit */
mgl_vec2i max_size; /* (0, 0) = no limit */
mgl_window_handle parent_window; /* 0 = root window */
+ bool hidden;
} mgl_window_create_params;
int mgl_window_create(mgl_window *self, const char *title, const mgl_window_create_params *params);
@@ -80,6 +81,7 @@ void mgl_window_get_view(mgl_window *self, mgl_view *view);
void mgl_window_set_scissor(mgl_window *self, mgl_scissor *new_scissor);
void mgl_window_get_scissor(mgl_window *self, mgl_scissor *scissor);
+void mgl_window_set_visible(mgl_window *self, bool visible);
bool mgl_window_is_open(const mgl_window *self);
bool mgl_window_has_focus(const mgl_window *self);
bool mgl_window_is_key_pressed(const mgl_window *self, mgl_key key);
diff --git a/src/graphics/font.c b/src/graphics/font.c
index 8c55044..9a99f22 100644
--- a/src/graphics/font.c
+++ b/src/graphics/font.c
@@ -227,7 +227,7 @@ int mgl_font_get_glyph(mgl_font *self, uint32_t codepoint, mgl_font_glyph *glyph
render_offset.y = self->font_atlas.pointer_position.y;
mgl_font_glyph new_glyph;
- new_glyph.position = (mgl_vec2i){ xoff/GLYPH_UPSAMPLE, yoff/GLYPH_UPSAMPLE };
+ new_glyph.position = (mgl_vec2i){ xoff/GLYPH_UPSAMPLE, self->ascent + yoff/GLYPH_UPSAMPLE };
new_glyph.size = (mgl_vec2i){ width/GLYPH_UPSAMPLE, height/GLYPH_UPSAMPLE };
new_glyph.texture_position = (mgl_vec2i){ render_offset.x, render_offset.y };
new_glyph.texture_size = (mgl_vec2i){ width, height };
diff --git a/src/graphics/text.c b/src/graphics/text.c
index 61c2919..92c578c 100644
--- a/src/graphics/text.c
+++ b/src/graphics/text.c
@@ -217,7 +217,7 @@ void mgl_text_draw(mgl_context *context, mgl_text *text) {
mgl_text_get_bounds(text);
TextDrawUserdata text_draw_userdata;
- text_draw_userdata.position = (mgl_vec2f){ text->position.x, text->position.y + text->font->character_size };
+ text_draw_userdata.position = (mgl_vec2f){ text->position.x, text->position.y };
text_draw_userdata.text = text;
text_draw_userdata.context = context;
text_draw_userdata.prev_codepoint = 0;
diff --git a/src/window/window.c b/src/window/window.c
index 3f902e3..1b15558 100644
--- a/src/window/window.c
+++ b/src/window/window.c
@@ -293,6 +293,8 @@ static int mgl_window_init(mgl_window *self, const char *title, const mgl_window
PointerMotionMask | Button1MotionMask | Button2MotionMask | Button3MotionMask | Button4MotionMask | Button5MotionMask | ButtonMotionMask |
StructureNotifyMask | EnterWindowMask | LeaveWindowMask | VisibilityChangeMask | PropertyChangeMask | FocusChangeMask;
+ const bool hide_window = params ? params->hidden : false;
+
if(existing_window) {
if(!XChangeWindowAttributes(context->connection, existing_window, CWColormap | CWEventMask, &window_attr)) {
fprintf(stderr, "XChangeWindowAttributes failed\n");
@@ -301,6 +303,8 @@ static int mgl_window_init(mgl_window *self, const char *title, const mgl_window
}
self->window = existing_window;
+ if(hide_window)
+ XUnmapWindow(context->connection, existing_window);
} else {
self->window = XCreateWindow(context->connection, parent_window, params->position.x, params->position.y,
window_size.x, window_size.y, 0,
@@ -313,7 +317,8 @@ static int mgl_window_init(mgl_window *self, const char *title, const mgl_window
}
XStoreName(context->connection, self->window, title);
- XMapWindow(context->connection, self->window);
+ if(!hide_window)
+ XMapWindow(context->connection, self->window);
}
if(params)
@@ -744,6 +749,14 @@ void mgl_window_get_scissor(mgl_window *self, mgl_scissor *scissor) {
*scissor = self->scissor;
}
+void mgl_window_set_visible(mgl_window *self, bool visible) {
+ mgl_context *context = mgl_get_context();
+ if(visible)
+ XMapWindow(context->connection, self->window);
+ else
+ XUnmapWindow(context->connection, self->window);
+}
+
bool mgl_window_is_open(const mgl_window *self) {
return self->open;
}