Sha256: c74784a778cb8185de2566adc715b45e8589f33abb5127f7739383fb62807bd2

Contents?: true

Size: 1.72 KB

Versions: 9

Compression:

Stored size: 1.72 KB

Contents

# 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.

module Rabbit
  class CursorManager
    @@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
    end

    def keep(name)
      @stocks[name] ||= []
      @stocks[name].push(@current)
    end

    def restore(drawable, name)
      if name.nil?
        type = @current
      else
        type = @stocks[name].pop
      end
      drawable.cursor = type_to_cursor(type)
    end

    def update(drawable, type)
      drawable.cursor = type_to_cursor(type)
    end

    private
    def type_to_cursor(type)
      if type.nil?
        nil
      else
        cursor = self.class.cursors[type]
        if cursor.nil?
          raise UnknownCursorTypeError.new(type)
        end
        cursor
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rabbit-3.0.3 lib/rabbit/cursor-manager.rb
rabbit-3.0.2 lib/rabbit/cursor-manager.rb
rabbit-3.0.1 lib/rabbit/cursor-manager.rb
rabbit-3.0.0 lib/rabbit/cursor-manager.rb
rabbit-2.2.1 lib/rabbit/cursor-manager.rb
rabbit-2.2.0 lib/rabbit/cursor-manager.rb
rabbit-2.1.9 lib/rabbit/cursor-manager.rb
rabbit-2.1.8 lib/rabbit/cursor-manager.rb
rabbit-2.1.7 lib/rabbit/cursor-manager.rb