Center text

pull/1/head
E. Almqvist 3 years ago
parent 1a908eb656
commit 697bd19c55
  1. 4
      app.rb
  2. 2
      config.rb
  3. 19
      ui.rb

@ -23,10 +23,12 @@ class Window < Gosu::Window
@font = Gosu::Font.new(self, MAIN_FONT, 18) @font = Gosu::Font.new(self, MAIN_FONT, 18)
@font2 = Gosu::Font.new(self, MAIN_FONT, 20) @font2 = Gosu::Font.new(self, MAIN_FONT, 20)
@font_title = Gosu::Font.new(self, MAIN_FONT, 64)
@fonts = { @fonts = {
normal: @font, normal: @font,
big: @font2 big: @font2,
title: @font_title
} }
@freeze = true @freeze = true

@ -1,7 +1,7 @@
# UI # UI
WINDOW_WIDTH = 1600 WINDOW_WIDTH = 1600
WINDOW_HEIGHT = 900 WINDOW_HEIGHT = 900
WINDOW_FULLSCREEN = false WINDOW_FULLSCREEN = true
MAIN_FONT = "monospace" MAIN_FONT = "monospace"
# Keybinds # Keybinds

19
ui.rb

@ -19,7 +19,7 @@ class UI
return Gosu::Color.argb(color) return Gosu::Color.argb(color)
end end
def draw_text(string, font, x, y, z=0, scale_x=1, scale_y=1, color=0xff_ffffff) def draw_text(string, font, x, y, z=0, color=0xff_ffffff, scale_x=1, scale_y=1)
font.draw_text(string, self.x + x, self.y + y, self.zindex + z, scale_x, scale_y, color) font.draw_text(string, self.x + x, self.y + y, self.zindex + z, scale_x, scale_y, color)
end end
@ -28,10 +28,11 @@ class UI
end end
def draw_rect(x, y, width, height, color=0xff_ffffff, z=0, mode=:default) def draw_rect(x, y, width, height, color=0xff_ffffff, z=0, mode=:default)
v1 = Vector[x, y, color] + self.pos xx, yy = x + self.pos[0], y + self.pos[1]
v2 = Vector[width + x, y, color] + self.pos v1 = Vector[xx, yy, color]
v3 = Vector[x, height + y, color] + self.pos v2 = Vector[width + xx, yy, color]
v4 = Vector[width + x, height + y, color] + self.pos v3 = Vector[xx, height + yy, color]
v4 = Vector[width + xx, height + yy, color]
self.draw_quad(v1, v2, v3, v4, z, mode) self.draw_quad(v1, v2, v3, v4, z, mode)
end end
@ -49,8 +50,12 @@ class MainMenu < UI
def render def render
if( @show ) then if( @show ) then
self.draw_rect(0, 0, self.width, self.height, 0x99_aaaaaa) self.draw_rect(0, 0, self.width, self.height, 0xff_111015)
self.draw_text("Hohmann Miner", self.window.fonts[:big], self.width/2, self.height/2)
titletext = "Hohmann Miner"
titlefont = self.window.fonts[:title]
titlewidth = titlefont.text_width(titletext)
self.draw_text(titletext, self.window.fonts[:title], self.width/2 - titlewidth/2, self.height/4)
end end
end end
end end

Loading…
Cancel
Save