Skip to content

Commit

Permalink
Use "surface" not "drawable"
Browse files Browse the repository at this point in the history
Because GTK 4 uses "surface".
  • Loading branch information
kou committed Sep 15, 2024
1 parent 884f81e commit 1ba996f
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 27 deletions.
10 changes: 5 additions & 5 deletions lib/rabbit/cursor-manager.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2006-2015 Kouhei Sutou <[email protected]>
# Copyright (C) 2006-2024 Sutou Kouhei <[email protected]>
#
# 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
Expand Down Expand Up @@ -39,17 +39,17 @@ def keep(name)
@stocks[name].push(@current)
end

def restore(drawable, name)
def restore(surface, name)
if name.nil?
type = @current
else
type = @stocks[name].pop
end
drawable.cursor = type_to_cursor(type)
surface.cursor = type_to_cursor(type)
end

def update(drawable, type)
drawable.cursor = type_to_cursor(type)
def update(surface, type)
surface.cursor = type_to_cursor(type)
end

private
Expand Down
9 changes: 8 additions & 1 deletion lib/rabbit/gtk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ def call(*args, &block)
end
end

class ApplicationWindow
class Widget
# For GTK 3
unless method_defined?(:surface)
def native
self
end
end

# GTK 4 renames Gdk::Window to Gdk::Surface
unless method_defined?(:surface)
alias_method :surface, :window
Expand Down
10 changes: 5 additions & 5 deletions lib/rabbit/renderer/display/base.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2006-2019 Kouhei Sutou <[email protected]>
# Copyright (C) 2006-2024 Sutou Kouhei <[email protected]>
#
# 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
Expand All @@ -25,7 +25,7 @@ module Base
include HookHandler

def initialize(*args, &block)
@drawable = nil
@surface = nil
@size = nil
@size_dirty = true
super
Expand Down Expand Up @@ -154,9 +154,9 @@ def draw_slide(slide, simulation)
end

private
def set_drawable(drawable)
@drawable = drawable
set_default_size(@drawable.width, @drawable.height)
def set_surface(surface)
@surface = surface
set_default_size(@surface.width, @surface.height)
end

def set_default_size(w, h)
Expand Down
20 changes: 18 additions & 2 deletions lib/rabbit/renderer/display/cursor.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# Copyright (C) 2004-2024 Sutou Kouhei <[email protected]>
#
# 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 "rabbit/cursor-manager"

module Rabbit
Expand All @@ -19,13 +35,13 @@ def keep_cursor(name)
end

def restore_cursor(name)
@cursor_manager.restore(@drawable, name)
@cursor_manager.restore(@surface, name)
end

def update_cursor(cursor_type, update_current_cursor=false)
@cursor_manager.current = cursor_type if update_current_cursor
cursor_type = :pencil if @graffiti_mode
@cursor_manager.update(@drawable, cursor_type)
@cursor_manager.update(@surface, cursor_type)
end
end
end
Expand Down
30 changes: 23 additions & 7 deletions lib/rabbit/renderer/display/drawing-area-base.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# Copyright (C) 2004-2024 Sutou Kouhei <[email protected]>
#
# 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 "rabbit/renderer/display/drawing-area-primitive"
require "rabbit/renderer/display/menu"
require "rabbit/renderer/display/progress"
Expand Down Expand Up @@ -289,7 +305,7 @@ def set_motion_notify_event
end

def paint(color_name)
context = @drawable.create_cairo_context
context = @surface.create_cairo_context
context.set_source_rgba(*Color.parse(color_name).to_a)
context.paint
end
Expand All @@ -313,9 +329,9 @@ def draw_current_slide_pixbuf(pixbuf)
width, height = pixbuf.width, pixbuf.height
x = @adjustment_x * width
y = @adjustment_y * height
@drawable.draw_pixbuf(@foreground, pixbuf,
x, y, 0, 0, width, height,
Gdk::RGB::DITHER_NORMAL, 0, 0)
@surface.draw_pixbuf(@foreground, pixbuf,
x, y, 0, 0, width, height,
Gdk::RGB::DITHER_NORMAL, 0, 0)
if @adjustment_x != 0 or @adjustment_y != 0
draw_next_slide
end
Expand Down Expand Up @@ -353,9 +369,9 @@ def draw_next_slide_pixbuf(pixbuf)
src_height = -adjustment_height
end

@drawable.draw_pixbuf(@foreground, pixbuf, src_x, src_y,
dest_x, dest_y, src_width, src_height,
Gdk::RGB::DITHER_NORMAL, 0, 0)
@surface.draw_pixbuf(@foreground, pixbuf, src_x, src_y,
dest_x, dest_y, src_width, src_height,
Gdk::RGB::DITHER_NORMAL, 0, 0)
end

def configured_after(widget, event)
Expand Down
8 changes: 4 additions & 4 deletions lib/rabbit/renderer/display/drawing-area-primitive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def set_map
end

def mapped(widget)
set_drawable(widget.window)
set_surface(widget.native.surface)
end

def set_draw
Expand Down Expand Up @@ -199,8 +199,8 @@ def set_configure_event
end

def configured(x, y, w, h)
@real_width = @drawable.width
@real_height = @drawable.height
@real_width = @surface.width
@real_height = @surface.height
@size_dirty = true
end

Expand All @@ -225,7 +225,7 @@ def set_configure_event_after

def configured_after(widget, event)
update_size(event.width, event.height)
reload_theme if @drawable
reload_theme if @surface
end

def reload_theme(&callback)
Expand Down
18 changes: 17 additions & 1 deletion lib/rabbit/renderer/display/gesture.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# Copyright (C) 2006-2024 Sutou Kouhei <[email protected]>
#
# 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 "rabbit/gesture/handler"

module Rabbit
Expand Down Expand Up @@ -49,7 +65,7 @@ def init_gesture
first_move = !@gesture.moved?
handled = @gesture.button_motion(event.x, event.y, width, height)
queue_draw if handled or first_move
init_renderer(@drawable)
init_renderer(@surface)
@gesture.draw_last_locus(self)
finish_renderer
true
Expand Down
20 changes: 18 additions & 2 deletions lib/rabbit/renderer/engine/cairo.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# Copyright (C) 2005-2024 Sutou Kouhei <[email protected]>
#
# 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 "cairo"
require "stringio"

Expand Down Expand Up @@ -25,8 +41,8 @@ def background_image=(pixbuf)
pixbuf
end

def init_renderer(drawable)
init_context(drawable.create_cairo_context)
def init_renderer(surface)
init_context(surface.create_cairo_context)
end

def finish_renderer
Expand Down

0 comments on commit 1ba996f

Please sign in to comment.