Class: JLDrill::Gtk::KanjiPopupFactory

Inherits:
PopupFactory show all
Defined in:
lib/jldrill/views/gtk/widgets/KanjiPopupFactory.rb

Instance Method Summary collapse

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

Returns:

  • (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(widget, window, x, y)
    type = widget.get_window_type(window)
    coords = widget.window_to_buffer_coords(type, x, y)
    iter, tr = widget.get_iter_at_position(coords[0], coords[1])
    char = iter.char
    pos = widget.get_iter_location(iter)
    if (coords[0] > pos.x) && (coords[0] < pos.x + pos.width) &&
            char != ""
        rect = widget.buffer_to_window_coords(type, pos.x, pos.y)
        charPos = belowRect([rect[0], rect[1], pos.width, pos.height])
        screenPos = toAbsPos(widget, 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

Returns:

  • (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.widget, 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

Returns:

  • (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