Skip to content

Instantly share code, notes, and snippets.

@rhenium
Last active August 29, 2015 14:02
Show Gist options
  • Save rhenium/e134364664847080d41c to your computer and use it in GitHub Desktop.
Save rhenium/e134364664847080d41c to your computer and use it in GitHub Desktop.
mikutter の sub_parts_voter(ツイートをふぁぼ・RT したユーザーの一覧)が複数行対応になるパッチ
diff --git a/core/mui/cairo_sub_parts_voter.rb b/core/mui/cairo_sub_parts_voter.rb
index ae53e07..ac2f86a 100644
--- a/core/mui/cairo_sub_parts_voter.rb
+++ b/core/mui/cairo_sub_parts_voter.rb
@@ -12,57 +12,30 @@ class ::Gdk::SubPartsVoter < Gdk::SubParts
def initialize(*args)
super
@icon_width, @icon_height, @margin, @votes, @user_icon = 24, 24, 2, get_default_votes.to_a, Hash.new
- @avatar_rect = []
@icon_ofst = 0
helper.ssc(:click){ |this, e, x, y|
- ofsty = helper.mainpart_height
- helper.subparts.each{ |part|
- break if part == self
- ofsty += part.height }
- if ofsty <= y and (ofsty + height) >= y
- case e.button
- when 1
- if(x >= @icon_ofst)
- index = @avatar_rect.bsearch_first {|range| range.include?(x) ? 0 : range.first <=> x}
- user = get_user_by_point(x)
- if user
- Plugin.call(:show_profile, Service.primary, user) end end end end
+ case e.button
+ when 1
+ user = get_user_by_point_with_offset(x, y)
+ if user
+ Plugin.call(:show_profile, Service.primary, user) end end
false }
- last_motion_user = nil
usertip = Gtk::Tooltips.new
helper.ssc(:motion_notify_event){ |this, x, y|
- if 0 != height
- tipset = ''
- ofsty = helper.mainpart_height
- helper.subparts.each{ |part|
- break if part == self
- ofsty += part.height }
- if ofsty <= y and (ofsty + height) >= y
- if(x >= @icon_ofst)
- user = get_user_by_point(x)
- last_motion_user = user
- if user
- tipset = user.idname end end end
- usertip.set_tip(helper.tree, tipset, '')
- if tipset == ''
- last_motion_user = nil
- usertip.disable
- else
- usertip.enable end end
+ user = get_user_by_point_with_offset(x, y)
+ if user
+ usertip.set_tip(helper.tree, user.idname, '')
+ usertip.enable
+ else
+ usertip.set_tip(helper.tree, '', '')
+ usertip.disable end
false }
helper.ssc(:leave_notify_event){
usertip.set_tip(helper.tree, '', '')
usertip.disable
- false
- }
+ false }
end
- def get_user_by_point(x)
- if(x >= @icon_ofst)
- index = @avatar_rect.bsearch_first {|range| range.include?(x) ? 0 : range.first <=> x}
- if index
- @votes[index] end end end
-
def render(context)
if get_vote_count != 0
context.save{
@@ -70,20 +43,20 @@ class ::Gdk::SubPartsVoter < Gdk::SubParts
put_title_icon(context)
put_counter(context)
put_voter(context) } end
- @last_height = height end
+ height end
def height
if get_vote_count == 0
0
else
- icon_height end end
+ [(@votes.size.to_f / max_voter_per_line).ceil, 1].max * @icon_height end end
def add(new)
if UserConfig[:"#{name}_by_anyone_show_timeline"]
- if not @votes.include?(new)
+ unless @votes.include?(new)
before_height = height
@votes << new
- if(before_height == height)
+ if before_height == height
helper.on_modify
else
helper.reset_height end
@@ -92,10 +65,10 @@ class ::Gdk::SubPartsVoter < Gdk::SubParts
def delete(user)
if UserConfig[:"#{name}_by_anyone_show_timeline"]
- if not @votes.include?(user)
+ if @votes.include?(user)
before_height = height
@votes.delete(user)
- if(before_height == height)
+ if before_height == height
helper.on_modify
else
helper.reset_height end
@@ -109,6 +82,23 @@ class ::Gdk::SubPartsVoter < Gdk::SubParts
private
+ def get_user_by_point_with_offset(x, y)
+ if height != 0
+ ofsty = helper.mainpart_height
+ helper.subparts.each{ |part|
+ break if part == self
+ ofsty += part.height }
+ if ofsty <= y and (ofsty + height) > y
+ get_user_by_point(x - @margin - @icon_ofst, y - ofsty) end end end
+
+ def get_user_by_point(x, y)
+ if x >= 0 and x < max_voter_per_line * @icon_width
+ index = ((y / @icon_height) * max_voter_per_line) + (x / @icon_width)
+ @votes[index] end end
+
+ def max_voter_per_line
+ ((width - @margin - @icon_ofst) / @icon_width) end
+
def put_title_icon(context)
context.save{
context.set_source_pixbuf(title_icon)
@@ -125,14 +115,10 @@ class ::Gdk::SubPartsVoter < Gdk::SubParts
end
def put_voter(context)
- context.translate(@icon_ofst, 0)
- xpos = @icon_ofst
- @avatar_rect = []
- votes.each{ |user|
- left = xpos
- xpos += render_user(context, user)
- @avatar_rect << (left...xpos)
- break if width <= xpos } end
+ votes.each_with_index{ |user, i|
+ context.save {
+ context.translate(@icon_ofst + (i % max_voter_per_line) * @icon_width, (i / max_voter_per_line) * @icon_height)
+ render_user(context, user) } } end
def render_user(context, user)
render_icon(context, user)
@@ -142,7 +128,6 @@ class ::Gdk::SubPartsVoter < Gdk::SubParts
def render_icon(context, user)
context.set_source_pixbuf(user_icon(user))
context.paint
- context.translate(icon_width, 0)
end
def user_icon(user)
@@ -161,5 +146,4 @@ class ::Gdk::SubPartsVoter < Gdk::SubParts
def get_vote_count
votes.size
end
-
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment