Class: Fidgit::ImageFrame

Inherits:
Element show all
Defined in:
lib/fidgit/elements/image_frame.rb

Overview

A wrapper around a Gosu::Image to show it in the GUI.

Constant Summary

ENABLED_COLOR =
Gosu::Color::WHITE
DISABLED_COLOR =
Gosu::Color.rgb(150, 150, 150)

Constants inherited from Element

Element::DEFAULT_SCHEMA_FILE, Element::VALID_ALIGN_H, Element::VALID_ALIGN_V

Instance Attribute Summary collapse

Attributes inherited from Element

#align_h, #align_v, #background_color, #border_thickness, #font, #padding_bottom, #padding_left, #padding_right, #padding_top, #parent, #tip, #z

Instance Method Summary collapse

Methods inherited from Element

#default, #drag?, #draw, #draw_frame, #draw_rect, #enabled=, #enabled?, #height, #height=, #hit?, #max_height, #max_width, #min_height, #min_width, new, original_new, #outer_height, #outer_width, #recalc, schema, #to_s, #update, #width, #width=, #with, #x, #x=, #y, #y=

Methods included from Event

#events, included, new_event_handlers, #publish, #subscribe, #unsubscribe

Constructor Details

#initialize(image, options = {}) ⇒ ImageFrame

Returns a new instance of ImageFrame

Parameters:

  • image (Gosu::Image)

    Gosu image to display.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :thumbnail (Boolean) — default: false

    Is the image expanded to be square?



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fidgit/elements/image_frame.rb', line 16

def initialize(image, options = {})
  options = {
      thumbnail: false,
      factor: 1,
  }.merge! options

  @thumbnail = options[:thumbnail]
  @factor_x = options[:factor_x] || options[:factor]
  @factor_y = options[:factor_y] || options[:factor]

  super(options)

  self.image = image
end

Instance Attribute Details

#factor_xObject (readonly)

Returns the value of attribute factor_x



7
8
9
# File 'lib/fidgit/elements/image_frame.rb', line 7

def factor_x
  @factor_x
end

#factor_yObject (readonly)

Returns the value of attribute factor_y



7
8
9
# File 'lib/fidgit/elements/image_frame.rb', line 7

def factor_y
  @factor_y
end

#imageObject

Returns the value of attribute image



7
8
9
# File 'lib/fidgit/elements/image_frame.rb', line 7

def image
  @image
end

Instance Method Details

#draw_foregroundObject



40
41
42
# File 'lib/fidgit/elements/image_frame.rb', line 40

def draw_foreground
  @image.draw(x + padding_left, y + padding_top, z, factor_x, factor_y, enabled? ? ENABLED_COLOR : DISABLED_COLOR) if @image
end

#thumbnail?Boolean

Returns:

  • (Boolean)


9
# File 'lib/fidgit/elements/image_frame.rb', line 9

def thumbnail?; @thumbnail; end