class Metasm::Gui::DrawableWidget::Button

represents a clickable area with a label (aka button)

Attributes

action[RW]
c1[RW]
c2[RW]
down[RW]
h[RW]
text[RW]
w[RW]
x[RW]
y[RW]

Public Class Methods

new(text='Ok', c1=:palegrey, c2=:grey, &b) click to toggle source

create a new Button with the specified text & border color

# File metasm/gui/win32.rb, line 1961
def initialize(text='Ok', c1=:palegrey, c2=:grey, &b)
        @x = @y = @w = @h = 0
        @c1, @c2 = c1, c2
        @text = text
        @down = false
        @action = b
end

Public Instance Methods

click(x, y) click to toggle source

checks if the click is on the button, returns true if so

# File metasm/gui/win32.rb, line 1986
def click(x, y)
        @down = true if x >= @x and x < @x+@w and y >= @y and y < @y+@h
end
mouserelease(x, y) click to toggle source
# File metasm/gui/win32.rb, line 1990
def mouserelease(x, y)
        if @down
                @down = false
                @action.call
                true
        end
end
move(nx=@x, ny=@y, nw=@w, nh=@h) click to toggle source

move the button (x y w h)

# File metasm/gui/win32.rb, line 1970
def move(nx=@x, ny=@y, nw=@w, nh=@h)
        @x, @y, @w, @h = nx, ny, nw, nh
end
paint(w) click to toggle source

draw the button on the parent widget

# File metasm/gui/win32.rb, line 1975
def paint(w)
        c1, c2 = @c1, @c2
        c1, c2 = c2, c1 if @down
        w.draw_string_color(:text, @x+(@w-w.font_width*@text.length)/2, @y+(@h - w.font_height)/2, @text)
        w.draw_line_color(c1, @x, @y, @x, @y+@h)
        w.draw_line_color(c1, @x, @y, @x+@w, @y)
        w.draw_line_color(c2, @x+@w, @y+@h, @x, @y+@h)
        w.draw_line_color(c2, @x+@w, @y+@h, @x+@w, @y)
end