| 1 |
|
| 2 |
|
| 3 |
require 'gtk3' |
| 4 |
|
| 5 |
|
| 6 |
タンを表示するためのモジュール |
| 7 |
|
| 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 |
描画する。 |
| 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 |
ら見たx座標 |
| 58 |
ら見たy座標 |
| 59 |
def point_moved_main_icon(gx, gy) |
| 60 |
icon_position = globalpos2iconpos(gx, gy) |
| 61 |
たらタイムラインをスクロールしない |
| 62 |
|
| 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 |
インタが離れたときに呼ぶ。 |
| 71 |
def iob_main_leave |
| 72 |
if(current_icon_pos) |
| 73 |
@current_icon_pos = nil |
| 74 |
queue_draw |
| 75 |
end |
| 76 |
end |
| 77 |
|
| 78 |
されたことを通知する |
| 79 |
|
| 80 |
ら見たx座標 |
| 81 |
ら見た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 |