From: Brendan Hansen Date: Mon, 7 Jun 2021 05:14:49 +0000 (-0500) Subject: alpha fixes and ui updates X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=e7aa99d55982f086e469e45a952932cca82e3d01;p=tower.git alpha fixes and ui updates --- diff --git a/src/tower.onyx b/src/tower.onyx index 76a4f1e..aa27e79 100644 --- a/src/tower.onyx +++ b/src/tower.onyx @@ -16,7 +16,7 @@ main :: (args: [] cstr) { ui.init_ui(); gl.enable(gl.BLEND); - gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); + gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA); start_loop :: () -> void #foreign "game" "start_loop" --- start_loop(); @@ -42,7 +42,17 @@ window_height := 0 poll_events :: () { for event: events.consume() { switch event.kind { - case .MouseDown do println("Mouse was down!"); + case .MouseDown do switch event.mouse.button { + case .Left do ui.button_pressed(.Left); + case .Right do ui.button_pressed(.Right); + } + + case .MouseUp do switch event.mouse.button { + case .Left do ui.button_released(.Left); + case .Right do ui.button_released(.Right); + } + + case .MouseMove do ui.update_mouse_position(~~ event.mouse.pos_x, ~~ event.mouse.pos_y); case .Resize { printf("Window was resized to: %i %i\n", event.resize.width, event.resize.height); @@ -56,7 +66,7 @@ poll_events :: () { } } - #if DEBUG { events_this_frame += 1; } + #if DEBUG do events_this_frame += 1; } } @@ -71,10 +81,16 @@ update :: (dt: f32) { fps_timer = 1.0f; } } + + opacity -= dt * 3; + opacity = math.max(opacity, 0); } +opacity := 1.0f; +counter := 0; + draw :: () { - gl.clearColor(0.1, 0.1, 0.1, 1); + gl.clearColor(0, 0, 0, 1); gl.clear(gl.COLOR_BUFFER_BIT); master_rectangle := ui.Rectangle.{ x1 = ~~window_width, y1 = ~~window_height }; @@ -85,27 +101,54 @@ draw :: () { ui.draw_rect(left, .{ 0.2, 0.15, 0.15 }); ui.draw_rect(right, .{ 0, 0.25, 0.5 }); ui.draw_rect(right_top, .{ 1, 0, 0 }); - ui.draw_text("Something here", right_bottom.x0, right_bottom.y0, 48, .{ 1, 1, 1 }); { - button_rect, _ := ui.Flow.split_horizontal(left, top_height=75); + text_theme := ui.default_text_theme; + text_theme.font_size = .2; + text_theme.text_color = .{ 0.6, 0.6, 1.0 }; + ui.draw_text(right_bottom, "Something here", ^text_theme); + } + + { + button_rect: ui.Rectangle; + sidebar := left; + + button_rect, sidebar = ui.Flow.split_horizontal(sidebar, top_height=75); ui.draw_button(button_rect, "Test Button"); + + red_theme := ui.default_button_theme; + red_theme.text_color = .{ 1, 0, 0 }; + button_rect, sidebar = ui.Flow.split_horizontal(sidebar, top_height=75); + if ui.draw_button(button_rect, "Red", ^red_theme) { + counter += 1; + } + + if counter % 2 == 0 { + red_theme = ui.default_button_theme; + red_theme.font_size = .3; + button_rect, sidebar = ui.Flow.split_horizontal(sidebar, top_height=75); + ui.draw_button(button_rect, "Another Button", ^red_theme); + } } + if opacity > 0 do ui.draw_rect(master_rectangle, .{ 0, 0, 0, opacity }); + #if DEBUG { Debug_Info_Font_Size :: 16; - gfx.set_texture(); - gfx.rect(.{ 0, 0 }, .{ 160, 36 }, .{0,0,0,.8}); + box_top_left := cast(f32) (window_width - 160); + ui.draw_rect(box_top_left, 0, 160, 36, .{0,0,0,.7}); str_buffer : [32] u8; - conv.str_format("FPS: %i", ~~ str_buffer, fps) |> ui.draw_text(0, 0, ~~Debug_Info_Font_Size, .{0,1,0}); - conv.str_format("Events: %i", ~~ str_buffer, events_this_frame) |> ui.draw_text(0, 20, ~~Debug_Info_Font_Size, .{0,1,0}); + conv.str_format("FPS: %i", ~~ str_buffer, fps) |> ui.draw_text_raw(box_top_left, 0, ~~Debug_Info_Font_Size, .{0,1,0}); + conv.str_format("Events: %i", ~~ str_buffer, events_this_frame) |> ui.draw_text_raw(box_top_left, 20, ~~Debug_Info_Font_Size, .{0,1,0}); events_this_frame = 0; } gfx.flush(); + + ui.clear_buttons(); }