Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # * Config
- #==============================================================================
- module Clock
- #--------------------------------------------------------------------------
- # |0 1|
- # | |
- # | |
- # |2 3|
- #--------------------------------------------------------------------------
- @position = 0
- #--------------------------------------------------------------------------
- # You can change position later with Clock.position = new-position
- # Example: Clock.position = 2
- #--------------------------------------------------------------------------
- #==============================================================================
- # * Config Ends.
- #==============================================================================
- #--------------------------------------------------------------------------
- # *
- #--------------------------------------------------------------------------
- def self.position=(pos)
- @position = pos
- @clock.x, @clock.ox, @clock.y, @clock.oy = *clock_pos
- end
- #--------------------------------------------------------------------------
- # *
- #--------------------------------------------------------------------------
- def self.clock_pos
- x = @position % 2 == 0 ? 0 : Graphics.width
- ox = x == 0 ? 0 : 50
- y = @position / 2 == 0 ? 0 : Graphics.height
- oy = y == 0 ? 0 : 24
- return x, ox, y, oy
- end
- #--------------------------------------------------------------------------
- # *
- #--------------------------------------------------------------------------
- def self.start
- @clock = Sprite.new
- @clock.z = 1000
- @clock.x, @clock.ox, @clock.y, @clock.oy = *clock_pos
- @bitmap = Bitmap.new(50,24)
- @clock.bitmap = @bitmap
- end
- #--------------------------------------------------------------------------
- # *
- #--------------------------------------------------------------------------
- def self.update
- time = Time.now
- tick = (time.sec % 2 == 0) ? " " : ":"
- return if @tick == tick
- @tick = tick
- text = sprintf("%02d%s%02d", time.hour, tick, time.min)
- @bitmap.clear
- @bitmap.draw_text(0,0,50,24,text)
- end
- #--------------------------------------------------------------------------
- # *
- #--------------------------------------------------------------------------
- def self.stop
- @clock.visible = false
- @updater.stop
- end
- #--------------------------------------------------------------------------
- # *
- #--------------------------------------------------------------------------
- def self.run
- @clock.visible = true
- @updater.run
- end
- #--------------------------------------------------------------------------
- # *
- #--------------------------------------------------------------------------
- start
- unless @updater
- @updater = Thread.new {
- loop do
- sleep(0.1)
- Clock.update rescue start
- end
- }
- end
- end
- #==============================================================================
- # *
- #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement