aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--font.c1
-rw-r--r--graphics.c35
-rw-r--r--input_field.c4
-rw-r--r--layer_surface.c2
-rw-r--r--main.c9
-rw-r--r--state.h3
6 files changed, 41 insertions, 13 deletions
diff --git a/font.c b/font.c
index dc8f03c..569d283 100644
--- a/font.c
+++ b/font.c
@@ -138,6 +138,7 @@ void atlas_create_texture(client_state* state) {
int atlas_get_strwidth(client_state* state, const char* str) {
float width = 0;
+ // TODO - UNICODE MAKE WORKY
for (int i = 0; i < strlen(str); i++) {
width += ceil(state->atlas.metrics[(int)str[i]].advance_x);
}
diff --git a/graphics.c b/graphics.c
index 03122a7..f9ce27e 100644
--- a/graphics.c
+++ b/graphics.c
@@ -1,4 +1,5 @@
#include "graphics.h"
+#include "array.h"
#include "shader.h"
void GLAPIENTRY
@@ -132,16 +133,33 @@ void render_frame(client_state *state) {
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- // bind vertex and texture
- glBindVertexArray(state->input_buffer_text.vao);
+ // bind shader and texture
+ glUseProgram(state->text_shader);
+ glUniform2f(state->screen_size_uniform, state->width, state->height);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, state->atlas.texture);
- // bind shader and draw
- glUseProgram(state->text_shader);
- glUniform2f(state->screen_size_uniform, state->width, state->height);
- glUniform2f(state->offset_uniform, 0.0f, state->line_height * state->lines - state->atlas.vert_shift);
- glDrawElements(GL_TRIANGLES, state->input_buffer_text.num_elements, GL_UNSIGNED_INT, 0);
+ float pen_x = 5.0f;
+ float pen_y = state->line_height * state->lines - state->atlas.vert_shift;
+
+ // draw input buffer
+ glBindVertexArray(state->input_buffer_grafix.vao);
+ glUniform2f(state->offset_uniform, pen_x, pen_y);
+ glDrawElements(GL_TRIANGLES, state->input_buffer_grafix.num_elements, GL_UNSIGNED_INT, 0);
+ // shift pen
+ if (state->lines > 0) pen_y -= state->line_height;
+ else pen_x += state->input_buffer_grafix.pixel_len;
+
+ // draw options
+ array_for_all(item_t, item, state->items) {
+ glBindVertexArray(item->text_buffer.vao);
+ glUniform2f(state->offset_uniform, pen_x, pen_y);
+ glDrawElements(GL_TRIANGLES, item->text_buffer.num_elements, GL_UNSIGNED_INT, 0);
+
+ // shift pen
+ if (state->lines > 0) pen_y -= state->line_height;
+ else pen_x += item->pixel_len;
+ }
// present screen
eglSwapBuffers(state->egl_display, state->egl_surface);
@@ -152,6 +170,8 @@ typedef struct {
} vert_t;
void init_text_buffer(client_state* state, text_buffer_t* buffer, char* text, size_t text_len) {
+ buffer->pixel_len = 0;
+
// generate openg bullshit
glGenVertexArrays(1, &buffer->vao);
glBindVertexArray(buffer->vao);
@@ -213,6 +233,7 @@ void init_text_buffer(client_state* state, text_buffer_t* buffer, char* text, si
// go forward
pen_x += m->advance_x;
+ buffer->pixel_len += ceil(m->advance_x);
}
// vertex buffer
diff --git a/input_field.c b/input_field.c
index 4bd09bb..03ddbcf 100644
--- a/input_field.c
+++ b/input_field.c
@@ -5,8 +5,8 @@
#include "graphics.h"
void regenerate_text_buffer(client_state* state) {
- destroy_text_buffer(&state->input_buffer_text);
- init_text_buffer(state, &state->input_buffer_text, state->input_buffer, array_size(state->input_buffer));
+ destroy_text_buffer(&state->input_buffer_grafix);
+ init_text_buffer(state, &state->input_buffer_grafix, state->input_buffer, array_size(state->input_buffer));
}
bool type_key(client_state* state, xkb_keysym_t keysym) {
diff --git a/layer_surface.c b/layer_surface.c
index 017ac8a..fc0a7e2 100644
--- a/layer_surface.c
+++ b/layer_surface.c
@@ -16,7 +16,7 @@ void create_surface(client_state* state) {
uint32_t desired_width = 0;
uint32_t desired_height = state->line_height;
if (state->lines > 0) {
- desired_width = 600; // figure out later
+ desired_width = 600; // calculate based on width of option strings
desired_height = (state->lines + 1) * state->line_height;
}
diff --git a/main.c b/main.c
index 794bb2a..1d899a0 100644
--- a/main.c
+++ b/main.c
@@ -36,6 +36,7 @@ int main(int argc, char* argv[]) {
state.running = true;
state.input_buffer = array_new(char, 0);
+ // read input
parse_args(&state, argc, argv);
read_stdin(&state);
@@ -48,7 +49,6 @@ int main(int argc, char* argv[]) {
// create font atlas
atlas_init(&state);
-
atlas_calc_item_widths(&state);
// start wayland
@@ -76,7 +76,12 @@ int main(int argc, char* argv[]) {
// create font altas textures
atlas_create_texture(&state);
- init_text_buffer(&state, &state.input_buffer_text, "", 0);
+ // create text buffers
+ init_text_buffer(&state, &state.input_buffer_grafix, "", 0);
+ array_for_all(item_t, item, state.items) {
+ init_text_buffer(&state, &item->text_buffer, item->text, strlen(item->text));
+ printf("%s\n", item->text);
+ }
// event loop
while (state.running) {
diff --git a/state.h b/state.h
index 87c3126..f1b3327 100644
--- a/state.h
+++ b/state.h
@@ -22,6 +22,7 @@
typedef struct {
GLuint vbo, ebo, vao;
uint32_t num_elements;
+ size_t pixel_len;
} text_buffer_t;
typedef struct {
@@ -79,7 +80,7 @@ typedef struct {
GLuint text_shader;
GLuint screen_size_uniform;
GLuint offset_uniform;
- text_buffer_t input_buffer_text;
+ text_buffer_t input_buffer_grafix;
// fonts
FT_Library ft_library;