lib/rays/painter.rb in rays-0.1.3 vs lib/rays/painter.rb in rays-0.1.4
- old
+ new
@@ -1,60 +1,36 @@
# -*- coding: utf-8 -*-
-require 'rays/native'
+require 'xot/blockutil'
+require 'rays/ext'
module Rays
class Painter
- attr_accessor :font
+ alias end end_paint
- def initialize ()
- @font = Rays::Font.new
- end
-
- def line (*args)
- args = args[0] if !args.empty? && args[0] === Array
- draw_rect *args
- end
-
- def rect (*args)
- args = args[0] if !args.empty? && args[0] === Array
- draw_rect *args
- end
-
- def ellipse (*args)
- args = args[0] if !args.empty? && args[0] === Array
- draw_ellipse *args
- end
-
- def arc (*args)
- args = args[0] if !args.empty? && args[0] === Array
- draw_arc *args
- end
-
- alias image draw_image
-
- def text (*args)
- case args.size
- when 1 then args << 0 << 0 << @font
- when 2 then args << 0 << @font
- when 3 then args << @font
+ def begin (&block)
+ if block
+ begin_paint
+ Xot::BlockUtil.instance_eval_or_block_call self, &block
+ end_paint
+ else
+ begin_paint
end
- draw_text *args
end
- def clear (*args)
- send :clear=, *args unless args.empty?
- get_clear
+ def background (*args)
+ send :background=, *args unless args.empty?
+ get_background
end
- def clear= (*args)
- send_set :set_clear, :no_clear, args
+ def background= (*args)
+ send_set :set_background, :no_background, args
end
def fill (*args)
send :fill=, *args unless args.empty?
get_fill
@@ -80,15 +56,38 @@
def clip= (*args)
send_set :set_clip, :no_clip, args
end
+ def font (*args)
+ send :font=, *args unless args.empty?
+ get_font
+ end
+
+ def font= (*args)
+ send_set :set_font, nil, args
+ end
+
+ def push (&block)
+ push_matrix
+ push_attrs
+ if block
+ block.call
+ pop
+ end
+ end
+
+ def pop ()
+ pop_attrs
+ pop_matrix
+ end
+
private
def send_set (set, no, args)
- args = args[0] if args[0].kind_of?(Array)
+ args = args[0] if Array === args[0]
if args.size == 1 && [nil, :no, :none].include?(args[0])
- send no
+ no ? send(no) : send(set, nil)
else
send set, *args
end
end