Class: JLDrill::Gtk::KanjiPopupFactory
- Inherits:
-
PopupFactory
- Object
- PopupFactory
- JLDrill::Gtk::KanjiPopupFactory
- Defined in:
- lib/jldrill/views/gtk/widgets/KanjiPopupFactory.rb
Instance Method Summary collapse
- #dictionaryLoaded? ⇒ Boolean
- #getCharAt(widget, window, x, y) ⇒ Object
- #getPopupString(char) ⇒ Object
-
#initialize(view) ⇒ KanjiPopupFactory
constructor
A new instance of KanjiPopupFactory.
- #legalChar?(char) ⇒ Boolean
- #notify(event) ⇒ Object
- #sameCharacter?(character, x, y) ⇒ Boolean
Methods inherited from PopupFactory
#belowRect, #block, #closePopup, #createPopup, #showBusy, #toAbsPos, #unblock
Constructor Details
#initialize(view) ⇒ KanjiPopupFactory
Returns a new instance of KanjiPopupFactory.
7 8 9 |
# File 'lib/jldrill/views/gtk/widgets/KanjiPopupFactory.rb', line 7 def initialize(view) super(view) end |
Instance Method Details
#dictionaryLoaded? ⇒ Boolean
11 12 13 |
# File 'lib/jldrill/views/gtk/widgets/KanjiPopupFactory.rb', line 11 def dictionaryLoaded? @context.kanjiLoaded? end |
#getCharAt(widget, window, x, y) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/jldrill/views/gtk/widgets/KanjiPopupFactory.rb', line 24 def getCharAt(, window, x, y) type = .get_window_type(window) coords = .window_to_buffer_coords(type, x, y) iter, tr = .get_iter_at_position(coords[0], coords[1]) char = iter.char pos = .get_iter_location(iter) if (coords[0] > pos.x) && (coords[0] < pos.x + pos.width) && char != "" rect = .buffer_to_window_coords(type, pos.x, pos.y) charPos = belowRect([rect[0], rect[1], pos.width, pos.height]) screenPos = toAbsPos(, charPos[0], charPos[1]) [char, screenPos] else [nil, nil] end end |
#getPopupString(char) ⇒ Object
20 21 22 |
# File 'lib/jldrill/views/gtk/widgets/KanjiPopupFactory.rb', line 20 def getPopupString(char) return @context.kanjiInfo(char) end |
#legalChar?(char) ⇒ Boolean
41 42 43 |
# File 'lib/jldrill/views/gtk/widgets/KanjiPopupFactory.rb', line 41 def legalChar?(char) !char.nil? && !(char =~ /[a-zA-Z0-9 \s]/) end |
#notify(event) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/jldrill/views/gtk/widgets/KanjiPopupFactory.rb', line 45 def notify(event) if @blocked || !dictionaryLoaded? return end char, screenPos = getCharAt(event., event.motion.window, event.motion.x, event.motion.y) if !legalChar?(char) || screenPos.nil? closePopup return elsif sameCharacter?(char, screenPos[0], screenPos[1]) return end createPopup(char, screenPos[0], screenPos[1]) end |
#sameCharacter?(character, x, y) ⇒ Boolean
15 16 17 18 |
# File 'lib/jldrill/views/gtk/widgets/KanjiPopupFactory.rb', line 15 def sameCharacter?(character, x, y) !@currentPopup.nil? && @currentPopup.character == character && @currentPopup.x == x && @currentPopup.y == y end |