Debian Codegraph @

lib/ninix/dll/bln.rb

raw
1 # -*- coding: utf-8 -*-
2 #
3 # bln.rb - a easyballoon compatible Saori module for ninix
4 # Copyright (C) 2002-2019 by Shyouzou Sugitani <[email protected]>
5 #
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License (version 2) as
8 # published by the Free Software Foundation. It is distributed in the
9 # hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
10 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 # PURPOSE. See the GNU General Public License for more details.
12 #
13
14 # TODO:
15 # - font.face
16
17 require "gtk4"
18
19 require_relative "../pix"
20 require_relative "../script"
21 require_relative "../dll"
22 require_relative "../logging"
23
24
25 module Bln
26
27 class Saori< DLL::SAORI
28
29 def initialize
30 super()
31 @blns = {}
32 @__sakura = nil
33 end
34
35 def need_ghost_backdoor(sakura)
36 @__sakura = sakura
37 end
38
39 def check_import
40 @__sakura.nil? ? 0 : 1
41 end
42
43 def setup
44 @blns = read_bln_txt(@dir)
45 unless @blns.empty?
46 @__sakura.attach_observer(self)
47 return 1
48 else
49 return 0
50 end
51 end
52
53 def read_bln_txt(dir)
54 blns = {}
55 begin
56 open(File.join(dir, 'bln.txt'), 'r', :encoding => 'CP932') do |f|
57 data = {}
58 name = ''
59 for line in f
60 line = line.strip()
61 next if line.empty?
62 next if line.start_with?('//')
63 if line.include?('[')
64 unless name.empty?
65 blns[name] = [data, {}]
66 end
67 data = {}
68 start = line.index('[')
69 end_ = line.index(']')
70 if end_.nil?
71 end_ = line.length
72 end
73 name = line[start + 1..end_-1]
74 else
75 if line.include?(',')
76 key, value = line.split(',', 2)
77 key.strip!
78 value.strip!
79 data[key] = value
80 end
81 end
82 end
83 unless name.empty?
84 blns[name] = [data, {}]
85 end
86 return blns
87 end
88 rescue
89 return {}
90 end
91 end
92
93 def finalize
94 for name in @blns.keys
95 data, bln = @blns[name]
96 for bln_id in bln.keys
97 unless bln[bln_id].nil?
98 bln[bln_id].destroy()
99 bln.delete(bln_id)
100 end
101 end
102 end
103 @blns = {}
104 @__sakura.detach_observer(self)
105 return 1
106 end
107
108 def observer_update(event, args)
109 if event == 'set scale'
110 for name in @blns.keys
111 data, bln = @blns[name]
112 for bln_id in bln.keys
113 unless bln[bln_id].nil?
114 bln[bln_id].reset_scale()
115 end
116 end
117 end
118 end
119 end
120
121 def execute(argument)
122 return RESPONSE[400] if argument.nil? or argument.empty?
123 name = argument[0]
124 if argument.length >= 2
125 text = argument[1]
126 else
127 text = ''
128 end
129 if argument.length >= 3
130 begin
131 offset_x = Integer(argument[2])
132 rescue
133 offset_x = 0
134 end
135 else
136 offset_x = 0
137 end
138 if argument.length >= 4
139 begin
140 offset_y = Integer(argument[3])
141 rescue
142 offset_y = 0
143 end
144 else
145 offset_y = 0
146 end
147 if argument.length >= 5
148 bln_id = argument[4]
149 else
150 bln_id = ''
151 end
152 if argument.length >= 6 and ['1', '2'].include?(argument[5])
153 update = argument[5].to_i
154 else
155 update = 0
156 end
157 if @blns.include?(name)
158 data, bln = @blns[name]
159 if bln.include?(bln_id) and update.zero?
160 bln[bln_id].destroy()
161 bln.delete(bln_id)
162 end
163 unless text.empty?
164 if update.zero? or not bln.include?(bln_id)
165 bln[bln_id] = Balloon.new(@__sakura, @dir,
166 data, text,
167 offset_x, offset_y, name, bln_id)
168 else
169 bln[bln_id].update_script(text, update)
170 end
171 end
172 @blns[name] = [data, bln]
173 elsif name == 'clear'
174 for name in @blns.keys
175 data, bln = @blns[name]
176 new_bln = {}
177 for bln_id in bln.keys
178 if bln[bln_id].get_state() == 'orusuban'
179 new_bln[bln_id] = bln[bln_id]
180 next
181 end
182 bln[bln_id].destroy()
183 end
184 @blns[name] = [data, new_bln]
185 end
186 end
187 return nil
188 end
189 end
190
191
192 class Balloon
193
194 def initialize(sakura, dir, data,
195 text, offset_x, offset_y, name, bln_id)
196 @dir = dir
197 @__sakura = sakura
198 @name = name
199 @id = bln_id
200 @timeout_id = nil
201 @data = data # XXX
202 @window = Pix::TransparentWindow.new()
203 @window.set_title(name)
204 @window.set_skip_taskbar_hint(true)
205 @window.signal_connect('delete_event') do |w, e|
206 next delete(w, e)
207 end
208 if data.include?('position')
209 @position = data['position']
210 else
211 @position = 'sakura'
212 end
213 left, top, scrn_w, scrn_h = @__sakura.get_workarea
214 # -1: left, 1: right
215 if @position == 'sakura'
216 s0_x, s0_y, s0_w, s0_h = get_sakura_status('SurfaceSakura')
217 if (s0_x + (s0_w / 2).to_i) > (left + (scrn_w / 2).to_i)
218 @direction = -1
219 else
220 @direction = 1
221 end
222 elsif @position == 'kero'
223 s1_x, s1_y, s1_w, s1_h = get_sakura_status('SurfaceKero')
224 if (s1_x + (s1_w / 2).to_i) > (left + (scrn_w / 2).to_i)
225 @direction = -1
226 else
227 @direction = 1
228 end
229 else
230 @direction = 1 # XXX
231 end
232 if ['sakura', 'kero'].include?(@position)
233 default = data['skin']
234 if @direction == -1
235 if data.include?('skin.left')
236 skin = data['skin.left']
237 else
238 skin = default
239 end
240 else
241 if data.include?('skin.right')
242 skin = data['skin.right']
243 else
244 skin = default
245 end
246 end
247 else
248 skin = data['skin']
249 end
250 if skin.nil?
251 destroy()
252 return
253 end
254 path = File.join(@dir, skin.gsub("\\", '/'))
255 begin
256 balloon_surface = Pix.create_surface_from_file(path)
257 rescue
258 destroy()
259 return
260 end
261 @reshape = true
262 @balloon_surface = balloon_surface
263 w = balloon_surface.width
264 h = balloon_surface.height
265 @x = @y = 0
266 if data.include?('offset.x')
267 @x += (@direction * data['offset.x'].to_i)
268 end
269 if data.include?('offset.y')
270 @y += data['offset.y'].to_i
271 end
272 if data.include?('offset.random')
273 @x += (data['offset.random'].to_i * Random.rand(-1.0..2.0))
274 @y += (data['offset.random'].to_i * Random.rand(-1.0..2.0))
275 end
276 @x += (@direction * offset_x.to_i)
277 @y += offset_y.to_i
278 @action_x = 0
279 @action_y = 0
280 @vx = 0
281 @vy = 0
282 if data.include?('disparea.left')
283 @left = data['disparea.left'].to_i
284 else
285 @left = 0
286 end
287 if data.include?('disparea.right')
288 @right = data['disparea.right'].to_i
289 else
290 @right = w.to_i
291 end
292 if data.include?('disparea.top')
293 @top = data['disparea.top'].to_i
294 else
295 @top = 0
296 end
297 if data.include?('disparea.bottom')
298 @bottom = data['disparea.bottom'].to_i
299 else
300 @bottom = h.to_i
301 end
302 @script = nil
303 @darea = @window.darea
304 @darea.set_events(Gdk::EventMask::EXPOSURE_MASK|
305 Gdk::EventMask::BUTTON_PRESS_MASK|
306 Gdk::EventMask::BUTTON_RELEASE_MASK|
307 Gdk::EventMask::POINTER_MOTION_MASK|
308 Gdk::EventMask::LEAVE_NOTIFY_MASK)
309 @darea.signal_connect('draw') do |w, e|
310 redraw(w, e)
311 next true
312 end
313 @darea.signal_connect('button_press_event') do |w, e|
314 next button_press(w, e)
315 end
316 @darea.signal_connect('button_release_event') do |w, e|
317 next button_release(w, e)
318 end
319 @darea.signal_connect('motion_notify_event') do |w, e|
320 next motion_notify(w, e)
321 end
322 @darea.signal_connect('leave_notify_event') do |w, e|
323 leave_notify(w, e)
324 next true
325 end
326 set_skin()
327 set_position()
328 @layout = nil
329 if text != 'noscript' and \
330 (@right - @left) > 0 and (@bottom - @top) > 0
331 @script = text
332 if data.include?('font.color')
333 fontcolor_r = (data['font.color'][0..1].to_i(16) / 255.0)
334 fontcolor_g = (data['font.color'][2..3].to_i(16) /255.0)
335 fontcolor_b = (data['font.color'][4..5].to_i(16) / 255.0)
336 @fontcolor = [fontcolor_r, fontcolor_g, fontcolor_b]
337 else
338 @fontcolor = [0.0, 0.0, 0.0] # XXX
339 end
340 default_font_size = 12 # for Windows environment
341 if data.include?('font.size')
342 @font_size = data['font.size'].to_i
343 else
344 @font_size = default_font_size
345 end
346 @layout = Pango::Layout.new(@darea.pango_context)
347 @font_desc = Pango::FontDescription.new
348 @font_desc.set_family('Sans')
349 if data.include?('font.bold') and data['font.bold'] == 'on'
350 @font_desc.set_weight(:bold)
351 end
352 @layout.set_wrap(:char)
353 set_layout()
354 end
355 if data.include?('slide.vx')
356 @slide_vx = data['slide.vx'].to_i
357 else
358 @slide_vx = 0
359 end
360 if data.include?('slide.vy')
361 @slide_vy = data['slide.vy'].to_i
362 else
363 @slide_vy = 0
364 end
365 if data.include?('slide.autostop')
366 @slide_autostop = data['slide.autostop'].to_i
367 else
368 @slide_autostop = 0
369 end
370 if ['sinwave', 'vibrate'].include?(data['action.method'])
371 action = data['action.method']
372 if data.include?('action.reference0')
373 ref0 = data['action.reference0'].to_i
374 else
375 ref0 = 0
376 end
377 if data.include?('action.reference1')
378 ref1 = data['action.reference1'].to_i
379 else
380 ref1 = 0
381 end
382 if data.include?('action.reference2')
383 ref2 = data['action.reference2'].to_i
384 else
385 ref2 = 0
386 end
387 if data.include?('action.reference3')
388 ref3 = data['action.reference3'].to_i
389 else
390 ref3 = 0
391 end
392 unless ref2.zero?
393 @action = {'method' => action,
394 'ref0' => ref0,
395 'ref1' => ref1,
396 'ref2' => ref2,
397 'ref3' => ref3}
398 else
399 @action = nil
400 end
401 else
402 @action = nil
403 end
404 @move_notify_time = nil
405 @life_time = nil
406 @state = ''
407 if data.include?('life')
408 life = data['life']
409 else
410 life = 'auto'
411 end
412 if life == 'auto'
413 @life_time = 16000
414 elsif ['infinitely', '0'].include?(life)
415 #pass
416 elsif life == 'orusuban'
417 @state = 'orusuban'
418 else
419 begin
420 @life_time = Integer(life)
421 rescue
422 #pass
423 end
424 end
425 @start_time = Time.now
426 if data.include?('startdelay')
427 @startdelay = data['startdelay'].to_i
428 else
429 @startdelay = 0
430 end
431 if data.include?('nooverlap')
432 @nooverlap = 1
433 else
434 @nooverlap = 0
435 end
436 @talking = get_sakura_is_talking()
437 @move_notify_time = Time.new
438 @visible = false
439 @x_root = nil
440 @y_root = nil
441 @processed_script = []
442 @processed_text = ''
443 @text = ''
444 @script_wait = nil
445 @quick_session = false
446 @script_parser = Script::Parser.new(:error => 'loose')
447 begin
448 @processed_script = @script_parser.parse(@script)
449 rescue Script::ParserError => e
450 @processed_script = []
451 Logging::Logging.error('-' * 50)
452 Logging::Logging.error(e.format)
453 Logging::Logging.error(@script.encode('utf-8', :invalid => :replace, :undef => :replace))
454 end
455 @timeout_id = GLib::Timeout.add(10) { do_idle_tasks }
456 end
457
458 def set_position
459 return if @window.nil?
460 new_x = (@base_x + ((@x + @action_x + @vx) * @scale / 100.0).to_i)
461 new_y = (@base_y + ((@y + @action_y + @vy) * @scale / 100.0).to_i)
462 @window.move(new_x, new_y)
463 end
464
465 def set_skin
466 return if @window.nil?
467 @scale = get_sakura_status('SurfaceScale')
468 w = @balloon_surface.width
469 h = @balloon_surface.height
470 w = [8, (w * @scale / 100).to_i].max
471 h = [8, (h * @scale / 100).to_i].max
472 @base_x, @base_y = get_coordinate(w, h)
473 end
474
475 def set_layout
476 return if @window.nil?
477 return if @layout.nil?
478 font_size = (@font_size * 3 / 4).to_i # convert from Windows to GTK+
479 font_size = font_size * Pango::SCALE
480 @font_desc.set_size(font_size)
481 @layout.set_font_description(@font_desc)
482 @layout.set_width(((@right - @left) * 1024).to_i)
483 end
484
485 def reset_scale
486 return if @window.nil?
487 set_skin()
488 set_position()
489 end
490
491 def clickerase
492 return (not @data.include?('clickerase') or @data['clickerase'] == 'on') # default: ON
493 end
494
495 def dragmove_horizontal
496 return (@data.include?('dragmove.horizontal') and @data['dragmove.horizontal'] == 'on')
497 end
498
499 def dragmove_vertical
500 return (@data.include?('dragmove.vertical') and @data['dragmove.vertical'] == 'on')
501 end
502
503 def get_coordinate(w, h)
504 left, top, scrn_w, scrn_h = @__sakura.get_workarea
505 s0_x, s0_y, s0_w, s0_h = get_sakura_status('SurfaceSakura')
506 s1_x, s1_y, s1_w, s1_h = get_sakura_status('SurfaceKero')
507 b0_x, b0_y, b0_w, b0_h = get_sakura_status('BalloonSakura')
508 b1_x, b1_y, b1_w, b1_h = get_sakura_status('BalloonKero')
509 x = left
510 y = top
511 case @position
512 when 'lefttop'
513 #pass
514 when 'leftbottom'
515 y = (top + scrn_h - h)
516 when 'righttop'
517 x = (left + scrn_w - w)
518 when 'rightbottom'
519 x = (left + scrn_w - w)
520 y = (top + scrn_h - h)
521 when 'center'
522 x = (left + ((scrn_w - w) / 2).to_i)
523 y = (top + ((scrn_h - h) / 2).to_i)
524 when 'leftcenter'
525 y = (top + ((scrn_h - h) / 2).to_i)
526 when 'rightcenter'
527 x = (left + scrn_w - w)
528 y = (top + ((scrn_h - h) / 2).to_i)
529 when 'centertop'
530 x = (left + ((scrn_w - w) / 2).to_i)
531 when 'centerbottom'
532 x = (left + ((scrn_w - w) / 2).to_i)
533 y = (top + scrn_h - h)
534 when 'sakura'
535 if @direction == 1 # right
536 x = (s0_x + s0_w)
537 else
538 x = (s0_x - w)
539 end
540 y = s0_y
541 when 'kero'
542 if @direction == 1 # right
543 x = (s1_x + s1_w)
544 else
545 x = (s1_x - w)
546 end
547 y = s1_y
548 when 'sakurab'
549 x = b0_x
550 y = b0_y
551 when 'kerob'
552 x = b1_x
553 y = b1_y
554 end
555 return x, y
556 end
557
558 def update_script(text, mode)
559 return if @timeout_id.nil? # XXX
560 return unless text
561 if mode == 2 and not @script.nil?
562 @script = [@script, text].join("")
563 else
564 @script = text
565 end
566 @processed_script = []
567 @processed_text = ''
568 @text = ''
569 @script_wait = nil
570 @quick_session = false
571 begin
572 @processed_script = @script_parser.parse(@script)
573 rescue Script::ParserError => e
574 @processed_script = []
575 Logging::Logging.error('-' * 50)
576 Logging::Logging.error(e.format)
577 Logging::Logging.error(@script.encode('utf-8', :invalid => :replace, :undef => :replace))
578 end
579 end
580
581 def get_sakura_is_talking
582 talking = false
583 begin
584 if @__sakura.is_talking()
585 talking = true
586 else
587 talking = false
588 end
589 rescue
590 #pass
591 end
592 return talking
593 end
594
595 def get_sakura_status(key)
596 case key
597 when 'SurfaceScale'
598 result = @__sakura.get_surface_scale()
599 when 'SurfaceSakura_Shown'
600 if @__sakura.surface_is_shown(0)
601 result = true
602 else
603 result = false
604 end
605 when 'SurfaceSakura'
606 begin
607 s0_x, s0_y = @__sakura.get_surface_position(0)
608 s0_w, s0_h = @__sakura.get_surface_size(0)
609 rescue
610 s0_x, s0_y = 0, 0
611 s0_w, s0_h = 0, 0
612 end
613 result = s0_x, s0_y, s0_w, s0_h
614 when 'SurfaceKero_Shown'
615 if @__sakura.surface_is_shown(1)
616 result = true
617 else
618 result = false
619 end
620 when 'SurfaceKero'
621 begin
622 s1_x, s1_y = @__sakura.get_surface_position(1)
623 s1_w, s1_h = @__sakura.get_surface_size(1)
624 rescue
625 s1_x, s1_y = 0, 0
626 s1_w, s1_h = 0, 0
627 end
628 result = s1_x, s1_y, s1_w, s1_h
629 when 'BalloonSakura_Shown'
630 if @__sakura.balloon_is_shown(0)
631 result = true
632 else
633 result = false
634 end
635 when 'BalloonSakura'
636 begin
637 b0_x, b0_y = @__sakura.get_balloon_position(0)
638 b0_w, b0_h = @__sakura.get_balloon_size(0)
639 rescue
640 b0_x, b0_y = 0, 0
641 b0_w, b0_h = 0, 0
642 end
643 result = b0_x, b0_y, b0_w, b0_h
644 when 'BalloonKero_Shown'
645 if @__sakura.balloon_is_shown(1)
646 result = true
647 else
648 result = false
649 end
650 when 'BalloonKero'
651 begin
652 b1_x, b1_y = @__sakura.get_balloon_position(1)
653 b1_w, b1_h = @__sakura.get_balloon_size(1)
654 rescue
655 b1_x, b1_y = 0, 0
656 b1_w, b1_h = 0, 0
657 end
658 result = b1_x, b1_y, b1_w, b1_h
659 else
660 result = nil
661 end
662 return result
663 end
664
665 def do_idle_tasks
666 return if @window.nil?
667 s0_shown = get_sakura_status('SurfaceSakura_Shown')
668 s1_shown = get_sakura_status('SurfaceKero_Shown')
669 b0_shown = get_sakura_status('BalloonSakura_Shown')
670 b1_shown = get_sakura_status('BalloonKero_Shown')
671 sakura_talking = get_sakura_is_talking()
672 if @state == 'orusuban'
673 if @visible
674 if s0_shown or s1_shown
675 destroy()
676 return nil
677 end
678 else
679 unless s0_shown or s1_shown
680 @start_time = Time.now
681 @visible = true
682 @window.show()
683 @life_time = 300000
684 end
685 end
686 else
687 if @visible
688 if (@position == 'sakura' and not s0_shown) or \
689 (@position == 'kero' and not s1_shown) or \
690 (@position == 'sakurab' and not b0_shown) or \
691 (@position == 'kerob' and not b1_shown) or \
692 (@nooverlap == 1 and not @talking and sakura_talking)
693 destroy()
694 return nil
695 end
696 else
697 if (Time.now - @start_time) >= (@startdelay * 0.001)
698 @start_time = Time.now
699 @visible = true
700 @window.show()
701 end
702 end
703 end
704 if @visible
705 unless @life_time.nil?
706 if (Time.now - @start_time) >= (@life_time * 0.001) and \
707 (@processed_script.empty? and @processed_text.empty?)
708 destroy()
709 return nil
710 end
711 end
712 unless @action.nil?
713 if @action['method'] == 'sinwave'
714 offset = (@action['ref1'] \
715 * Math.sin(2.0 * Math::PI \
716 * (((Time.now - \
717 @start_time) * 1000).to_i \
718 % @action['ref2']).to_f / @action['ref2']))
719 if @action['ref0'] == 1
720 @action_y = offset.to_i
721 else
722 @action_x = offset.to_i
723 end
724 elsif @action['method'] == 'vibrate'
725 offset = ((((Time.now - @start_time) * 1000).to_i / \
726 @action['ref2']).to_i % 2)
727 @action_x = (offset * @action['ref0']).to_i
728 @action_y = (offset * @action['ref1']).to_i
729 end
730 end
731 if (not @slide_vx.zero? or not @slide_vy.zero?) and \
732 @slide_autostop > 0 and \
733 (@slide_autostop * 0.001 + 0.05) <= (Time.now - @start_time)
734 @vx = (@direction * ((@slide_autostop / 50.0 + 1) * @slide_vx).to_i)
735 @slide_vx = 0
736 @vy = ((@slide_autostop / 50.0 + 1) * @slide_vy).to_i
737 @slide_vy = 0
738 end
739 unless @slide_vx.zero?
740 @vx = (@direction * (((Time.now - @start_time) * @slide_vx) / 50 * 1000.-).to_i)
741 end
742 unless @slide_vy.zero?
743 @vy = (((Time.now - @start_time) * @slide_vy) / 50 * 1000.0).to_i
744 end
745 set_position()
746 unless @processed_script.empty? and @processed_text.empty?
747 interpret_script()
748 end
749 end
750 if @talking and not sakura_talking
751 @talking = false
752 else
753 @talking = sakura_talking
754 end
755 return true
756 end
757
758 def redraw(widget, cr)
759 @window.set_surface(cr, @balloon_surface, @scale, @reshape)
760 cr.set_operator(Cairo::OPERATOR_OVER) # restore default
761 cr.translate(*@window.get_draw_offset) # XXX
762 unless @layout.nil?
763 cr.set_source_rgb(*@fontcolor)
764 cr.move_to(@left.to_i, @top.to_i)
765 cr.show_pango_layout(@layout)
766 end
767 @window.set_shape(cr, @reshape)
768 @reshape = false
769 end
770
771 def get_state
772 @state
773 end
774
775 def interpret_script
776 unless @script_wait.nil?
777 return if Time.now < @script_wait
778 @script_wait = nil
779 end
780 unless @processed_text.empty?
781 if @quick_session or @state == 'orusuban'
782 @text = [@text, @processed_text].join("")
783 draw_text(@text)
784 @processed_text = ''
785 else
786 @text = [@text, @processed_text[0]].join("")
787 draw_text(@text)
788 @processed_text = @processed_text[1..-1]
789 @script_wait = (Time.now + 0.014)
790 end
791 return
792 end
793 node = @processed_script.shift
794 if node[0] == Script::SCRIPT_TAG
795 name, args = node[1], node[2..-1]
796 case name
797 when '\n'
798 @text = [@text, "\n"].join("")
799 draw_text(@text)
800 when '\w'
801 unless args.nil?
802 begin
803 amount = (Integer(args[0]) * 0.05 - 0.01)
804 rescue
805 amount = 0
806 end
807 else
808 amount = (1 * 0.05 - 0.01)
809 end
810 if amount > 0
811 @script_wait = (Time.now + amount)
812 end
813 when '\b'
814 unless args.nil?
815 begin
816 amount = Integer(args[0])
817 rescue
818 amount = 0
819 end
820 else
821 amount = 1
822 end
823 if amount > 0
824 @text = @text[0..-amount-1]
825 end
826 when '\c'
827 @text = ''
828 when '\_q'
829 @quick_session = (not @quick_session)
830 when '\l'
831 @life_time = nil
832 update_script('', 2)
833 end
834 elsif node[0] == Script::SCRIPT_TEXT
835 text = ''
836 for chunk in node[1]
837 text = [text, chunk[1]].join("")
838 end
839 @processed_text = text
840 end
841 end
842
843 def draw_text(text)
844 @layout.set_text(text)
845 @darea.queue_draw()
846 end
847
848 def button_press(widget, event)
849 @x_root = event.x_root
850 @y_root = event.y_root
851 if event.event_type == Gdk::EventType::DOUBLE_BUTTON_PRESS
852 x, y = @window.winpos_to_surfacepos(
853 event.x.to_i, event.y.to_i, @scale)
854 @__sakura.notify_event(
855 'OnEBMouseDoubleClick', @name, x, y, @id)
856 end
857 return true
858 end
859
860 def button_release(widget, event)
861 @x_root = nil
862 @y_root = nil
863 x, y = @window.winpos_to_surfacepos(
864 event.x.to_i, event.y.to_i, @scale)
865 if event.event_type == Gdk::EventType::BUTTON_RELEASE
866 case event.button
867 when 1
868 @__sakura.notify_event(
869 'OnEBMouseClick', @name, x, y, @id, 0)
870 when 3
871 @__sakura.notify_event(
872 'OnEBMouseClick', @name, x, y, @id, 1)
873 end
874 end
875 destroy if @clickerase
876 return true
877 end
878
879 def motion_notify(widget, event)
880 unless @x_root.nil? or @y_root.nil?
881 x_delta = (event.x_root - @x_root).to_i
882 y_delta = (event.y_root - @y_root).to_i
883 unless (event.state & Gdk::ModifierType::BUTTON1_MASK).zero?
884 @x += x_delta if @dragmove_horizontal
885 @y += y_delta if @dragmove_vertical
886 set_position()
887 @x_root = event.x_root
888 @y_root = event.y_root
889 end
890 end
891 if @move_notify_time.nil? or \
892 (Time.now - @move_notify_time) > (500 * 0.001)
893 x, y = @window.winpos_to_surfacepos(
894 event.x.to_i, event.y.to_i, @scale)
895 @__sakura.notify_event(
896 'OnEBMouseMove', @name, x, y, @id)
897 @move_notify_time = Time.now
898 end
899 return true
900 end
901
902 def leave_notify(widget, event)
903 @move_notify_time = nil
904 end
905
906 def delete(window, event)
907 return true
908 end
909
910 def destroy
911 @visible = false
912 @window.destroy() unless @window.nil?
913 @window = nil
914 GLib::Source.remove(@timeout_id) unless @timeout_id.nil?
915 @timeout_id = nil
916 end
917 end
918 end