Sha256: 09f59ca2096883de592b78510c3b8cf27fb3f895985a50f3f306c64cf9a38585

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

# text.rb

module Ruby2D
  class Text
    
    attr_accessor :x, :y, :data
    attr_reader :text, :size, :font, :color
    
    def initialize(x=0, y=0, text="Hello World!", size=20, font=nil, c="white")
      
      # if File.exists? font
        @font = font
      # else
      #   @font = resolve_path(font)
      # end
      
      @type_id = 5
      @x, @y, @size = x, y, size
      @text = text
      @color = Color.new(c)
      init
      add
    end
    
    def color=(c)
      @color = Color.new(c)
    end
    
    def add
      if Module.const_defined? :DSL
        Application.add(self)
      end
    end
    
    def remove
      if Module.const_defined? :DSL
        Application.remove(self)
      end
    end
    
    private
    
    def resolve_path(font)
      if RUBY_PLATFORM =~ /darwin/
        font_path = "/Library/Fonts/#{font}.ttf"
      else
        # Linux
        font_path = "/usr/share/fonts/truetype/#{font}.ttf"
      end
      
      unless File.exists? font_path
        raise Error, "Cannot find system font"
      else
        font_path
      end
    end
    
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ruby2d-0.3.1 lib/ruby2d/text.rb
ruby2d-0.3.0 lib/ruby2d/text.rb