Sha256: 68d83c69927bd9c73cf70db6bbecc1ecf412b33ce6d54df9e9115af3077798a8
Contents?: true
Size: 1.81 KB
Versions: 4
Compression:
Stored size: 1.81 KB
Contents
# frozen_string_literal: true class Shoes module Swt class MouseMoveListener include ::Swt::Events::MouseMoveListener def initialize(app) @app = app end def mouse_move(mouse_event) @app.dsl.mouse_pos = [mouse_event.x, mouse_event.y] @app.dsl.mouse_motion.each { |blk| eval_move_block blk, mouse_event } mouse_shape_control mouse_event mouse_leave_control mouse_event mouse_hover_control mouse_event end private def eval_move_block(blk, event) blk.call event.x, event.y end def mouse_shape_control(mouse_event) cursor = if cursor_over_clickable_element? mouse_event ::Swt::SWT::CURSOR_HAND else ::Swt::SWT::CURSOR_ARROW end @app.shell.setCursor Shoes.display.getSystemCursor(cursor) end def mouse_leave_control(mouse_event) @app.dsl.mouse_hover_controls.each do |element| if !mouse_on?(element, mouse_event) && element.hovered? element.mouse_left end end end def mouse_hover_control(mouse_event) @app.dsl.mouse_hover_controls.each do |element| if mouse_on?(element, mouse_event) && !element.hovered? element.mouse_hovered end end end def mouse_on?(element, mouse_event) element_visible?(element) && element.in_bounds?(mouse_event.x, mouse_event.y) end def element_visible?(element) if element.respond_to?(:visible?) element.visible? else false end end def cursor_over_clickable_element?(mouse_event) @app.clickable_elements.any? do |element| mouse_on? element, mouse_event end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems