lib/dedalus/elements.rb in dedalus-0.2.0 vs lib/dedalus/elements.rb in dedalus-0.2.1
- old
+ new
@@ -6,14 +6,15 @@
def self.active_view
@active_view ||= nil
end
class FontRepository
- def self.get_font(size: 20)
+ def self.get_font(font_name='Helvetica',size: 20)
@fonts ||= {}
- @fonts[size] ||= Gosu::Font.new(size)
- @fonts[size]
+ @fonts[font_name] ||= {}
+ @fonts[font_name][size] ||= Gosu::Font.new(size, name: font_name)
+ @fonts[font_name][size]
end
end
class Element
attr_accessor :position
@@ -29,33 +30,41 @@
def initialize(attrs={})
attrs.each { |(k,v)| instance_variable_set(:"@#{k}",v) } unless attrs.nil?
end
- def draw_bounding_box(origin:, dimensions:, color: Palette.gray) #, highlight: false)
+ def draw_bounding_box(origin:, dimensions:, color: Palette.gray)
x,y = *origin
w,h = *dimensions
raise "Invalid color #{color} given to #{self.class.name} for bounding box" unless color.is_a?(Dedalus::Color)
c = color.to_gosu
- window.draw_quad(x,y,c,
- x,y+h,c,
- x+w,y,c,
- x+w,y+h,c,ZOrder::Background)
+ window.draw_quad(x, y, c,
+ x, y+h, c,
+ x+w, y, c,
+ x+w, y+h, c,ZOrder::Background)
end
def view
Dedalus.active_view
end
+ def tiny_font
+ FontRepository.get_font(size: 14)
+ end
+
+ def code_font
+ FontRepository.get_font('courier new', size: 18)
+ end
+
def font
FontRepository.get_font(size: 20)
end
def big_font
- FontRepository.get_font(size: 36)
+ FontRepository.get_font(size: 24)
end
def huge_font
FontRepository.get_font(size: 120)
end
@@ -65,10 +74,58 @@
end
end
###
+ class Container < Element
+ def initialize(contents, attrs={})
+ @contents = contents
+ super(attrs)
+ end
+
+ def show
+ @contents
+ end
+ end
+
+ # layer is an abstract element...
+ # maybe should also pull out rows and columns?
+ # could cleanup traversal impl, and will be clearer ultimately
+ class Layer < Element
+ def initialize(elements, freeform: false)
+ @elements = elements
+ @freeform = freeform
+ end
+
+ def show
+ @elements
+ end
+
+ def freeform?
+ @freeform == true
+ end
+ end
+
+ # it's like a gluon or something, not sure how to model in nuclear terms
+ class LayerStack < Element
+ attr_reader :layers
+
+ def initialize(layers: [])
+ @layers = []
+ end
+
+ def push(layer_elements)
+ @layers.push(layer_elements)
+ end
+
+ # def each
+ # @layers.each
+ # end
+ end
+
+ ###
+
class Atom < Element
attr_accessor :scale, :padding
end
class Molecule < Element
@@ -85,9 +142,11 @@
class Template < Element
end
class Screen < Element
end
+
+ ###
module ZOrder
Background, Foreground, Text, Overlay = *(0..5)
end
end