Debian Codegraph @

core/mui/cairo_icon_over_button.rb

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 require 'gtk3'
4
5 =begin rdoc
6 アイコン上にボタンを表示するためのモジュール
7 =end
8 module Gdk::IconOverButton
9
10 attr_accessor :current_icon_pos
11
12 def _schemer
13 {x_count: 2, y_count: 2} end
14
15 # アイコンインデックスからアイコンの左上座標を計算する
16 def index2point(index)
17 x, y = _schemer[:x_count], _schemer[:y_count]
18 (index / y)*x + index % x
19 end
20
21 def get_icon_rectangle(ipx, ipy)
22 w, h = main_icon_rect.width / _schemer[:x_count], main_icon_rect.height / _schemer[:y_count]
23 Gdk::Rectangle.new(w * ipx, h * ipy, w, h)
24 end
25
26 def globalpos2iconpos(gx, gy)
27 lx, ly = gx - main_icon_rect.x, gy - main_icon_rect.y
28 w, h = main_icon_rect.width / _schemer[:x_count], main_icon_rect.height / _schemer[:y_count]
29 ipx, ipy = (lx / w).to_i, (ly / h).to_i
30 if ipx >= 0 and ipx < _schemer[:x_count] and ipy >= 0 and ipy < _schemer[:y_count]
31 [ipx, ipy]
32 else
33 nil end end
34
35 # _context_ にicon over buttonを描画する。
36 def render_icon_over_button(context)
37 context.save{
38 context.translate(main_icon_rect.x, main_icon_rect.y)
39 _schemer[:y_count].times{ |posy|
40 _schemer[:x_count].times{ |posx|
41 pos = [posx, posy]
42 ir = get_icon_rectangle(*pos)
43 icon_file_name = (current_icon_pos ? iob_icon_pixbuf : iob_icon_pixbuf_off)[posx][posy]
44 if(icon_file_name)
45 if(current_icon_pos)
46 context.save{
47 pb_filename = current_icon_pos == pos ? 'overbutton_mouseover.png' : 'overbutton.png'
48 context.translate(ir.x, ir.y)
49 context.set_source_pixbuf(Skin[pb_filename].pixbuf(width: ir.width, height: ir.height))
50 context.paint } end
51 context.save{
52 context.translate(ir.x, ir.y)
53 context.set_source_pixbuf(Skin[icon_file_name].pixbuf(width: ir.width, height: ir.height))
54 context.paint } end } } } end
55
56 # アイコン上でマウスポインタが動いた時に呼ぶ。
57 # - _gx_ MiraclePainter全体から見たx座標
58 # - _gy_MiraclePainter 全体から見たy座標
59 def point_moved_main_icon(gx, gy)
60 icon_position = globalpos2iconpos(gx, gy)
61 # TODO: gtk3 iobがホバーされていたらタイムラインをスクロールしない
62 # @tree.pointer_on_main_icon = !!icon_position
63 if icon_position
64 if current_icon_pos != icon_position
65 queue_draw
66 @current_icon_pos = icon_position end
67 else
68 iob_main_leave end end
69
70 # icon over buttonからマウスポインタが離れたときに呼ぶ。
71 def iob_main_leave
72 if(current_icon_pos)
73 @current_icon_pos = nil
74 queue_draw
75 end
76 end
77
78 # icon over buttonがクリックされたことを通知する
79 # ==== Args
80 # [gx] MiraclePainter全体から見たx座標
81 # [gy] MiraclePainter全体から見たy座標
82 def iob_clicked(gx, gy)
83 icon_position = globalpos2iconpos(gx, gy)
84 return if message.system?
85 if icon_position
86 __send__([ [:iob_reply_clicked, :iob_etc_clicked],
87 [:iob_retweet_clicked, :iob_fav_clicked]][icon_position[0]][icon_position[1]]) end end
88
89 end