lib/rabbit/renderer/display/clutter-embed.rb in rabbit-2.2.1 vs lib/rabbit/renderer/display/clutter-embed.rb in rabbit-3.0.0
- old
+ new
@@ -1,8 +1,23 @@
-require 'clutter_gtk'
-require 'clutter_cairo'
+# Copyright (C) 2008-2019 Kouhei Sutou <kou@cozmixng.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+require "clutter-gtk"
+
require "rabbit/utils"
require "rabbit/renderer/engine"
require "rabbit/renderer/display/base"
require 'rabbit/renderer/display/cursor'
require "rabbit/renderer/display/progress"
@@ -16,23 +31,21 @@
require "rabbit/renderer/display/info"
require "rabbit/renderer/display/spotlight"
require "rabbit/renderer/display/magnifier"
module Rabbit
- add_gui_init_proc do
- Clutter::Gtk.init
- end
-
module Renderer
module Display
class ClutterEmbed
class << self
def priority
0
end
end
+ include Renderer::Engine::Cairo
+
include Base
include Cursor
include Menu
include Graffiti
@@ -44,12 +57,10 @@
include ButtonHandler
include Info
include Spotlight
include Magnifier
- include Renderer::Engine::Cairo
-
attr_accessor :filename
def initialize(canvas)
@recreate_id = nil
@need_reload_theme = false
super
@@ -59,10 +70,17 @@
def widget
@embed
end
+ def redraw
+ actor = current_actor
+ # TODO: We need more work for periodical redraw
+ actor.content.invalidate if actor
+ widget.queue_draw
+ end
+
def clear_slide
super
redraw
end
@@ -88,10 +106,11 @@
old_actor = retrieve_actor(old_index)
old_actor.hide if old_actor
actor = retrieve_actor(index)
if actor and !hiding?
+ actor.content.set_size(actor.width, actor.height)
actor.show
actor.raise_top
if old_actor
transition = @canvas.slides[index].transition
transition_method = "transition_#{transition}"
@@ -105,10 +124,11 @@
def post_move_in_slide(old_index, index)
actor = retrieve_actor(nil, old_index)
actor.hide if actor
actor = retrieve_actor(nil, index)
if actor and !hiding?
+ actor.content.set_size(actor.width, actor.height)
actor.show
actor.raise_top
end
end
@@ -244,16 +264,16 @@
@x_dpi = ScreenInfo.screen_x_resolution
@y_dpi = ScreenInfo.screen_y_resolution
end
def init_clutter_embed
- @embed = Clutter::GtkEmbed.new
+ @embed = ClutterGtk::Embed.new
@embed.can_focus = true
@stage = @embed.stage
reset_stage_color
set_map
- set_expose_event
+ set_draw
set_configure_event_after
event_mask = Gdk::EventMask::BUTTON_PRESS_MASK
event_mask |= Gdk::EventMask::BUTTON_RELEASE_MASK
event_mask |= Gdk::EventMask::BUTTON1_MOTION_MASK
@@ -294,12 +314,12 @@
set_drawable(widget.window)
false
end
end
- def set_expose_event
- @embed.signal_connect("expose-event") do |widget, event|
+ def set_draw
+ @embed.signal_connect("draw") do |widget, context|
reload_source
false
end
end
@@ -313,10 +333,13 @@
configured_after(widget, event)
end
end
def configured_after(widget, event)
+ @real_width = event.width
+ @real_height = event.height
+ @size_dirty = true
reload_theme if @drawable
false
end
def set_motion_notify_event
@@ -413,13 +436,13 @@
@embed.signal_connect("scroll_event") do |widget, event|
handled = call_hook_procs(@scroll_hook_procs, event)
unless handled
handled = true
case event.direction
- when Gdk::EventScroll::Direction::UP
+ when Gdk::ScrollDirection::UP
@canvas.activate("PreviousSlide")
- when Gdk::EventScroll::Direction::DOWN
+ when Gdk::ScrollDirection::DOWN
@canvas.activate("NextSlide")
else
handled = false
end
end
@@ -429,12 +452,17 @@
def retrieve_actor(index=nil, index_in_slide=nil)
index ||= index || @canvas.current_index
slide_actors = @actors[index]
return nil if slide_actors.nil?
- slide = @canvas.slides[index]
- slide_actors[index_in_slide || slide.drawing_index]
+
+ if index_in_slide.nil?
+ slide = @canvas.slides[index]
+ return nil if slide.nil?
+ index_in_slide = slide.drawing_index
+ end
+ slide_actors[index_in_slide]
end
def current_actor
retrieve_actor
end
@@ -453,20 +481,26 @@
i = index || @canvas.current_index
slide_actors = @actors[i] || []
actor = slide_actors[index_in_slide]
slide = @canvas.slides[i]
if actor.nil?
- actor = Clutter::Cairo.new(width, height)
- context = actor.create
- init_context(context)
- draw_nth_slide(i, index_in_slide)
- finish_context
+ canvas = Clutter::Canvas.new
+ canvas.signal_connect(:draw, i, index_in_slide) do |_, context, _width, _height, _i, _index_in_slide|
+ init_context(context)
+ draw_nth_slide(_i, _index_in_slide)
+ finish_context
+ end
+ actor = Clutter::Actor.new
+ actor.instance_variable_set(:@c, canvas)
+ actor.content = canvas
+ actor.set_size(@real_width, @real_height)
@actors[i] ||= []
@actors[i][index_in_slide] = actor
- @stage.add(actor)
+ @stage.add_child(actor)
current_index_in_slide = index_in_slide == slide.drawing_index
if index.nil? and current_index_in_slide and !hiding?
+ canvas.set_size(@real_width, @real_height)
actor.show
actor.raise_top
Utils.process_pending_events_proc.call
else
actor.hide
@@ -490,22 +524,22 @@
have_next
end
end
def grab
- Gtk.grab_add(@embed)
+ @embed.grab_add
Gdk.pointer_grab(@embed.window, false,
Gdk::EventMask::BUTTON_PRESS_MASK |
Gdk::EventMask::BUTTON_RELEASE_MASK |
Gdk::EventMask::SCROLL_MASK |
Gdk::EventMask::POINTER_MOTION_MASK,
nil, nil,
- Gdk::Event::CURRENT_TIME)
+ Gdk::CURRENT_TIME)
end
def ungrab
- Gtk.grab_remove(@embed)
- Gdk.pointer_ungrab(Gdk::Event::CURRENT_TIME)
+ @embed.grab_remove
+ Gdk.pointer_ungrab(Gdk::CURRENT_TIME)
end
def pointer
window, x, y, mask = @embed.window.pointer
[x, y, mask]