Sha256: 63151a116aa3605b145f9260d68ec28e833d0f8bc220ac6bd2a63333c83c1b36

Contents?: true

Size: 1.47 KB

Versions: 2

Compression:

Stored size: 1.47 KB

Contents

# frozen_string_literal: true
class Shoes
  module Swt
    module Common
      module Resource
        OPAQUE = 255

        def reset_graphics_context(graphics_context)
          dispose_previous_contexts
          set_defaults_on_context(graphics_context)
          track_graphics_context(graphics_context)
        end

        def dispose_previous_contexts
          @graphic_contexts ||= []
          @graphic_contexts.each { |g| g&.dispose }
          @graphic_contexts.clear
        end

        def set_defaults_on_context(graphics_context)
          graphics_context.set_alpha OPAQUE
          graphics_context.set_antialias(::Swt::SWT::ON)
          graphics_context.set_line_cap(::Swt::SWT::CAP_FLAT)
          graphics_context.set_transform(nil)
        end

        def track_graphics_context(graphics_context)
          @graphic_contexts << graphics_context
        end

        def clip_context_to(graphics_context, element, use_element_height = true)
          clipping = graphics_context.clipping
          height   = use_element_height ? element.height : element.app.height

          graphics_context.set_clipping(element.absolute_left, element.absolute_top,
                                        element.width, height)
          yield graphics_context
        ensure
          if clipping
            graphics_context.set_clipping(clipping.x, clipping.y,
                                          clipping.width, clipping.height)
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
shoes-swt-4.0.0.pre12 lib/shoes/swt/common/resource.rb
shoes-swt-4.0.0.pre11 lib/shoes/swt/common/resource.rb