class Etti::LabelElements
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/etti/ui/label-elements.rb, line 8 def initialize super :vertical @elements = [] pack_start Gtk::Label.new.set_markup(_('<b><big> Data </big></b>')), :expand => false, :fill => false @eventBox = Gtk::EventBox.new pack_start @eventBox, :expand => true, :fill => true, :padding => 4 @list = Rgw::BigList.new 1 @eventBox.add @list @eventBox.add_events Gdk::Event::Mask::BUTTON_PRESS_MASK | Gdk::Event::Mask::BUTTON_RELEASE_MASK @eventBox.signal_connect(:drag_begin) {|widget, context| on_drag_begin context} @eventBox.signal_connect(:button_press_event){|widget, event| on_button_press event} @eventBox.drag_source_set :button1_mask, [['elements2area', :same_app, 123]], :copy end
Public Instance Methods
dnd_data()
click to toggle source
# File lib/etti/ui/label-elements.rb, line 44 def dnd_data @dnd_data end
elements=(elements)
click to toggle source
# File lib/etti/ui/label-elements.rb, line 28 def elements=(elements) if elements.nil? @list.data = nil else @list.data = elements.map {|e| [e]} end end
on_drag_begin(context)
click to toggle source
# File lib/etti/ui/label-elements.rb, line 49 def on_drag_begin context # get the text extends from the list element text = @list.row_at_pos(@pressX, @pressY)[0] @eventBox.dnd_data = Etti::DndData.new :data, text @dnd_data = text ct = @list.window.create_cairo_context ct.font_size = 16.0 ext = ct.text_extents text # create the drag image surface = Cairo::ImageSurface.new Cairo::Format::ARGB32, ext.width, ext.height * 1.5 cc = Cairo::Context.new surface cc.set_source_rgba 1.0, 1.0, 1.0, 0.0 cc.paint cc.set_source_rgb 0.0, 0.0, 0.0 cc.move_to 0, ext.height cc.font_size = 16.0 cc.show_text text cc.stroke # remove this, if we switch to a newer ruby-gtk version dependency, and keep the from_surface call pixbuf = nil if ([2, 2, 2] <=> Gtk::BINDING_VERSION) < 1 pixbuf = Gdk::Pixbuf.from_surface surface, 0, 0, ext.width, ext.height * 1.5 else surface.flush pixbuf = Gdk::Pixbuf.new surface.data, Gdk::Pixbuf::ColorSpace::RGB, true, 8, ext.width, ext.height, ext.width * 4 end context.set_icon :pixbuf => pixbuf, :hot_x => ext.width / 2.0, :hot_y => ext.height end