lib/rabbit/cursor-manager.rb in rabbit-2.1.6 vs lib/rabbit/cursor-manager.rb in rabbit-2.1.7
- old
+ new
@@ -1,20 +1,39 @@
-require 'rabbit/gtk'
+# Copyright (C) 2006-2015 Kouhei Sutou <kou@cozmixng.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-require 'rabbit/rabbit'
-
module Rabbit
class CursorManager
- @@blank_cursor = nil
+ @@cursors = nil
+ class << self
+ def cursors
+ @@cursors ||= {
+ :blank => Gdk::Cursor.new(:blank_cursor),
+ :pencil => Gdk::Cursor.new(:pencil),
+ :hand => Gdk::Cursor.new(:hand1),
+ }
+ end
+ end
+
attr_accessor :current
def initialize
@stocks = {}
@current = nil
- @blank_cursor = blank_cursor
- @pencil_cursor = Gdk::Cursor.new(Gdk::Cursor::PENCIL)
- @hand_cursor = Gdk::Cursor.new(Gdk::Cursor::HAND1)
end
def keep(name)
@stocks[name] ||= []
@stocks[name].push(@current)
@@ -36,27 +55,15 @@
private
def type_to_cursor(type)
if type.nil?
nil
else
- name = "@#{type}_cursor"
- unless instance_variable_defined?(name)
+ cursor = self.class.cursors[type]
+ if cursor.nil?
raise UnknownCursorTypeError.new(type)
end
- instance_variable_get(name)
+ cursor
end
- end
-
- def blank_cursor
- if @@blank_cursor.nil?
- source = Gdk::Pixmap.new(nil, 1, 1, 1)
- mask = Gdk::Pixmap.new(nil, 1, 1, 1)
- gc = Gdk::GC.new(source)
- fg = gc.foreground
- bg = gc.background
- @@blank_cursor = Gdk::Cursor.new(source, mask, fg, bg, 1, 1)
- end
- @@blank_cursor
end
end
end