mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-11 07:04:59 +00:00
Initial proof of concept commit
This commit is contained in:
50
Data/Scripts/905_New controls/007 button.rb
Normal file
50
Data/Scripts/905_New controls/007 button.rb
Normal file
@@ -0,0 +1,50 @@
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
class UIControls::Button < UIControls::BaseControl
|
||||
BUTTON_X = 2
|
||||
BUTTON_PADDING = 10
|
||||
BUTTON_HEIGHT = 28
|
||||
TEXT_OFFSET_Y = 7
|
||||
|
||||
def initialize(width, height, viewport, text = "")
|
||||
super(width, height, viewport)
|
||||
@text = text
|
||||
end
|
||||
|
||||
def set_interactive_rects
|
||||
text_width = self.bitmap.text_size(@text).width
|
||||
@button_rect = Rect.new(BUTTON_X, (height - BUTTON_HEIGHT) / 2,
|
||||
text_width + (BUTTON_PADDING * 2), BUTTON_HEIGHT)
|
||||
@interactions = {
|
||||
:button => @button_rect
|
||||
}
|
||||
end
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
# TODO: Make buttons look more different to text boxes?
|
||||
def refresh
|
||||
super
|
||||
# Draw button outline
|
||||
self.bitmap.outline_rect(@button_rect.x, @button_rect.y,
|
||||
@button_rect.width, @button_rect.height,
|
||||
self.bitmap.font.color)
|
||||
# Draw button text
|
||||
draw_text(self.bitmap, BUTTON_X + BUTTON_PADDING, TEXT_OFFSET_Y, @text)
|
||||
end
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
def on_mouse_release
|
||||
return if !@captured_area # Wasn't captured to begin with
|
||||
# Change this control's value
|
||||
if @captured_area == :button
|
||||
mouse_x, mouse_y = mouse_pos
|
||||
if mouse_x && mouse_y && @interactions[@captured_area].contains?(mouse_x, mouse_y)
|
||||
set_changed
|
||||
end
|
||||
end
|
||||
super # Make this control not busy again
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user