Class: Pomodoro::Gui::Window

Inherits:
Gosu::Window
  • Object
show all
Defined in:
lib/pomodoro/gui/window.rb

Constant Summary collapse

IMAGE_ASSETS =
{
  background: "assets/images/background.png",
  pomodoro: "assets/images/pomodoro.png",
  occupied: "assets/images/occupied.png",
  rest: "assets/images/rest.png"
}
AUDIO_ASSETS =
{
  start: "assets/sounds/start.wav",
  rest: "assets/sounds/rest.wav"
}
FONT_ASSETS =
{
  font: "assets/fonts/roboto.ttf",
  bold: "assets/fonts/roboto_bold.ttf"
}

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Window

Returns a new instance of Window.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/pomodoro/gui/window.rb', line 24

def initialize(options={})
  super 304, 488

  @images = {}
  @audio = {}
  @interval = options[:interval]
  @rest = options[:rest]
  @state = 0
  @cycles = 0

  self.caption = "Pomodoro GUI"
  self.load_assets
  self.reset_timer
end

Instance Method Details

#drawObject



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pomodoro/gui/window.rb', line 43

def draw
  @images[:background].draw(0, 0, 0)
  @images[:pomodoro].draw(32, 16, 1)

  if @state == 0
    @images[:occupied].draw(104, 364, 1)
  else
    @images[:rest].draw(104, 364, 1)
  end

  @font.draw("This is your pomodoro ##{@cycles.to_s.rjust(2, '0')}", 20, 268, 3, 1, 1, Gosu::Color::BLACK)
  @font_time.draw("#{(@t + @seconds).strftime('%M:%S')}", 92, 292, 3, 1, 1, @timer_colour)
end

#launch!Object



39
40
41
# File 'lib/pomodoro/gui/window.rb', line 39

def launch!
  self.show
end

#needs_cursor?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/pomodoro/gui/window.rb', line 70

def needs_cursor?
  true
end

#updateObject



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/pomodoro/gui/window.rb', line 57

def update
  if @seconds == 0
    @state = @state == 0 ? 1 : 0
    self.reset_timer
  else
    @tick += 1
    if @tick == 60
      @seconds -= 1
      @tick = 0
    end
  end
end