Sha256: f56f998f8f4b9e5ed9f38d0248f046a6e3d123d63345557d0f6a581ffb155ff0

Contents?: true

Size: 1.61 KB

Versions: 32

Compression:

Stored size: 1.61 KB

Contents

require 'gtk2'

module Rabbit
  module Renderer
    module Display
      module Mask
        MASK_SIZE_STEP = 0.05

        def initialize(*args, &block)
          super
          init_mask
        end

        def expand_hole
          if @mask_size < 0
            @mask_size = MASK_SIZE_STEP
          else
            @mask_size = [@mask_size + MASK_SIZE_STEP, 1.0].min
          end
          set_hole
        end

        def narrow_hole
          if @mask_size < 0
            @mask_size = 0
          else
            @mask_size = [@mask_size - MASK_SIZE_STEP, 0.0].max
          end
          set_hole
        end

        def set_hole
          if @mask_size <= 0
            @window.shape_combine_mask(nil, 0, 0)
          else
            setup_mask if @mask.nil?
            w, h = width, height
            @mask.draw_rectangle(@set_gc, true, 0, 0, w, h)
            mw = w * @mask_size
            mh = h * @mask_size
            mx = (w - mw) / 2
            my = (h - mh) / 2
            @mask.draw_rectangle(@xor_gc, true, mx, my, mw, mh)
            @window.shape_combine_mask(@mask, 0, 0)
          end
          update_title # for xfwm
        end

        private
        def init_mask
          @mask = nil
          @mask_size = 0
        end

        def setup_mask
          @mask = Gdk::Pixmap.new(nil, width, height, 1)
          @xor_gc = Gdk::GC.new(@mask)
          @xor_gc.set_function(Gdk::GC::INVERT)
          @set_gc = Gdk::GC.new(@mask)
          @set_gc.set_function(Gdk::GC::SET)
          @clear_gc = Gdk::GC.new(@mask)
          @clear_gc.set_function(Gdk::GC::CLEAR)
        end
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
rabbit-1.0.4 lib/rabbit/renderer/display/mask.rb
rabbit-1.0.3 lib/rabbit/renderer/display/mask.rb
rabbit-1.0.2 lib/rabbit/renderer/display/mask.rb
rabbit-1.0.1 lib/rabbit/renderer/display/mask.rb
rabbit-1.0.0 lib/rabbit/renderer/display/mask.rb
rabbit-0.9.3 lib/rabbit/renderer/display/mask.rb
rabbit-0.9.2 lib/rabbit/renderer/display/mask.rb
rabbit-0.9.1 lib/rabbit/renderer/display/mask.rb
rabbit-0.9.0 lib/rabbit/renderer/display/mask.rb
rabbit-0.6.4 lib/rabbit/renderer/display/mask.rb
rabbit-0.6.3 lib/rabbit/renderer/display/mask.rb
rabbit-0.6.2 lib/rabbit/renderer/display/mask.rb