diff options
Diffstat (limited to 'graphics.c')
| -rw-r--r-- | graphics.c | 101 |
1 files changed, 13 insertions, 88 deletions
@@ -177,30 +177,27 @@ void render_frame(client_state *state) { glClearColor(background_color.r,background_color.g,background_color.b,background_color.a); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - // bind shader and texture - glUseProgram(state->text_shader); - glUniform2f(state->t_screen_size_uniform, state->width, state->height); - glUniform4f(state->t_color_uniform, text_color.r,text_color.g,text_color.b,text_color.a); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, state->atlas.texture); - // calculate input buffer size - Rect input = { .x = 0, .y = state->line_height * state->lines, .dx = state->width, .dy = state->line_height }; - if (state->lines == 0 && array_size(state->filtered_items) != 0) { - input.dx = state->width / 3.0f; - } + rect_t input, options; + calculate_layout(state, &input, &options, false); // draw input buffer + glUseProgram(state->text_shader); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, state->atlas.texture); glScissor(input.x, input.y, input.dx - state->horizontal_spacing / 2.0f, input.dy); glBindVertexArray(state->input_buffer_grafix.vao); + glUniform2f(state->t_screen_size_uniform, state->width, state->height); + glUniform4f(state->t_color_uniform, text_color.r,text_color.g,text_color.b,text_color.a); glUniform2f(state->t_offset_uniform, input.x + state->horizontal_spacing / 2.0f, input.y - state->atlas.vert_shift); glDrawElements(GL_TRIANGLES, state->input_buffer_grafix.num_elements, GL_UNSIGNED_INT, 0); - // draw cursor box + // calculate cursor size float cursor_size = state->atlas.metrics['M'].bitmap_width; if (state->cursor_index != array_size(state->input_buffer)) { cursor_size = state->atlas.metrics[(int)state->input_buffer[state->cursor_index]].advance_x; } + // draw cursor glUseProgram(state->box_shader); glUniform4f(state->b_color_uniform, cursor_color.r,cursor_color.g,cursor_color.b,cursor_color.a); glUniform2f(state->b_screen_size_uniform, state->width, state->height); @@ -208,80 +205,18 @@ void render_frame(client_state *state) { glUniform2f(state->b_size_uniform, cursor_size, input.dy); glDrawArrays(GL_TRIANGLES, 0, 6); - Rect options = {0}; - float start; - // set up starting pen and scissor for options - if (state->lines) { - options.dx = state->width; - options.dy = input.y; - - start = input.y - state->line_height + state->scroll; - - if (array_size(state->filtered_items) != 0) { - // calc scroll - float selected_bot = start - state->filtered_items[state->selected_filtered_item].offset; - float selected_top = selected_bot + state->line_height; - if (selected_bot < 0) { - state->scroll -= selected_bot; - start -= selected_bot; - } - float diff = selected_top - input.y; - if (diff > 0) { - state->scroll -= diff; - start -= diff; - } - } - } else { - options.x = input.x + input.dx; - options.dx = state->width - options.x; - options.dy = state->line_height; - - start = input.dx + state->scroll; - - if (array_size(state->filtered_items) != 0) { - // calc scroll - item_display_t* selected = &state->filtered_items[state->selected_filtered_item]; - float selected_len = selected->item->pixel_len + state->horizontal_spacing; - float selected_left = start + selected->offset; - float selected_right = selected_left + selected_len; - float right_diff = selected_right - state->width; - float left_diff = selected_left - input.dx; - if (selected_len > state->width - input.dx) { - state->scroll -= left_diff; - start -= left_diff; - } - else if (right_diff > 0) { - state->scroll -= right_diff; - start -= right_diff; - } - else if (left_diff < 0) { - state->scroll -= left_diff; - start -= left_diff; - } - } - } + // scissor options glScissor(options.x, options.y, options.dx, options.dy); // draw highlighted option box if (state->selected_filtered_item != -1) { item_display_t* display = &state->filtered_items[state->selected_filtered_item]; - item_t* item = display->item; - - float x,y; - if (state->lines) { - x = 0; - y = start - display->offset; - } - else { - x = start + display->offset; - y = 0; - } glUseProgram(state->box_shader); glUniform4f(state->b_color_uniform, highlight_color.r,highlight_color.g,highlight_color.b,highlight_color.a); glUniform2f(state->b_screen_size_uniform, state->width, state->height); - glUniform2f(state->b_start_uniform, x, y); - glUniform2f(state->b_size_uniform, (state->lines) ? state->width : item->pixel_len + state->horizontal_spacing, state->line_height); + glUniform2f(state->b_start_uniform, display->r.x, display->r.y); + glUniform2f(state->b_size_uniform, display->r.dx, display->r.dy); glDrawArrays(GL_TRIANGLES, 0, 6); } @@ -295,18 +230,8 @@ void render_frame(client_state *state) { item_display_t* display = &state->filtered_items[i]; item_t* item = display->item; - float x,y; - if (state->lines) { - x = 0; - y = start - display->offset; - } - else { - x = start + display->offset; - y = 0; - } - glBindVertexArray(item->text_buffer.vao); - glUniform2f(state->t_offset_uniform, x + state->horizontal_spacing / 2.0f, y - state->atlas.vert_shift); + glUniform2f(state->t_offset_uniform, display->r.x + state->horizontal_spacing / 2.0f, display->r.y - state->atlas.vert_shift); glDrawElements(GL_TRIANGLES, item->text_buffer.num_elements, GL_UNSIGNED_INT, 0); } |
