[perl-Gtk3] Add overrides for Gtk3::Gdk::RGBA
- From: Torsten SchÃnfeld <tsch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [perl-Gtk3] Add overrides for Gtk3::Gdk::RGBA
- Date: Thu, 24 Jan 2013 00:21:42 +0000 (UTC)
commit 607f2ef3d8092e5eb189553b5636f983fb48408f
Author: Torsten SchÃnfeld <kaffeetisch gmx de>
Date: Sun Aug 26 20:08:09 2012 +0200
Add overrides for Gtk3::Gdk::RGBA
NEWS | 1 +
dist.ini | 2 +-
lib/Gtk3.pm | 32 ++++++++++++++++++++++++++++++++
t/overrides.t | 24 +++++++++++++++++++++++-
4 files changed, 57 insertions(+), 2 deletions(-)
---
diff --git a/NEWS b/NEWS
index af7bd87..406faa4 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@
* Add overrides for Gtk3::RecentChooserDialog.
* Add overrides for Gtk3::TextBuffer.
* Add an override for Gtk3::main_level.
+* Add overrides for Gtk3::Gdk::RGBA.
* Add Gtk3::EVENT_PROPAGATE and Gtk3::EVENT_STOP.
* Test that no double-frees occur for custom Gtk3::Widget subclasses.
diff --git a/dist.ini b/dist.ini
index 5ce243b..6f4639a 100644
--- a/dist.ini
+++ b/dist.ini
@@ -18,7 +18,7 @@ copyright_year = 2011
Carp = 0 ; core
Exporter = 0 ; core
Cairo::GObject = 1.000
-Glib::Object::Introspection = 0.013_001 ; FIXME
+Glib::Object::Introspection = 0.013_001 ; FIXME: 0.014
[NextRelease]
filename = NEWS
diff --git a/lib/Gtk3.pm b/lib/Gtk3.pm
index bba6137..442c9e4 100644
--- a/lib/Gtk3.pm
+++ b/lib/Gtk3.pm
@@ -1085,6 +1085,38 @@ sub Gtk3::Window::new {
# Gdk
+sub Gtk3::Gdk::RGBA::new {
+ my ($class, @rest) = @_;
+ # Handle Gtk3::Gdk::RGBA->new (r, g, b, a) specially.
+ if (4 == @rest) {
+ my %data;
+ @data{qw/red green blue alpha/} = @rest;
+ return Glib::Boxed::new ($class, \%data);
+ }
+ # Fall back to Glib::Boxed::new.
+ return Glib::Boxed::new ($class, @rest);
+}
+
+sub Gtk3::Gdk::RGBA::parse {
+ my $have_instance;
+ {
+ local $@;
+ $have_instance = eval { $_[0]->isa ('Gtk3::Gdk::RGBA') };
+ }
+ # This needs to be switched around if/when
+ # <https://bugzilla.gnome.org/show_bug.cgi?id=682125> is fixed.
+ if ($have_instance) {
+ return Glib::Object::Introspection->invoke (
+ $_GDK_BASENAME, 'RGBA', 'parse', @_);
+ } else {
+ my $instance = Gtk3::Gdk::RGBA->new;
+ my $success = Glib::Object::Introspection->invoke (
+ $_GDK_BASENAME, 'RGBA', 'parse',
+ $instance, @_);
+ return $success ? $instance : undef;
+ }
+}
+
sub Gtk3::Gdk::Window::new {
my ($class, $parent, $attr, $attr_mask) = @_;
if (not defined $attr_mask) {
diff --git a/t/overrides.t b/t/overrides.t
index 5ced709..5e5877a 100644
--- a/t/overrides.t
+++ b/t/overrides.t
@@ -5,7 +5,7 @@ BEGIN { require './t/inc/setup.pl' };
use strict;
use warnings;
-plan tests => 98;
+plan tests => 108;
# Gtk3::CHECK_VERSION and check_version
{
@@ -337,6 +337,28 @@ __EOD__
isa_ok ($menubars[1], "Gtk3::MenuBar");
}
+# Gtk3::Gdk::RGBA
+{
+ my $rgba = Gtk3::Gdk::RGBA->new ({red => 0.0, green => 0.5, blue => 0.5, alpha => 0.5});
+ isa_ok ($rgba, 'Gtk3::Gdk::RGBA');
+ is ($rgba->red, 0.0);
+
+ $rgba = Gtk3::Gdk::RGBA->new (red => 0.5, green => 0.0, blue => 0.5, alpha => 0.5);
+ isa_ok ($rgba, 'Gtk3::Gdk::RGBA');
+ is ($rgba->green, 0.0);
+
+ $rgba = Gtk3::Gdk::RGBA->new (0.5, 0.5, 0.0, 0.5);
+ isa_ok ($rgba, 'Gtk3::Gdk::RGBA');
+ is ($rgba->blue, 0.0);
+
+ $rgba = Gtk3::Gdk::RGBA::parse ('rgba(0.5, 0.5, 0.5, 0.0)');
+ isa_ok ($rgba, 'Gtk3::Gdk::RGBA');
+ is ($rgba->alpha, 0.0);
+
+ ok ($rgba->parse ('rgba(0.5, 0.5, 0.5, 1.0)'));
+ is ($rgba->alpha, 1.0);
+}
+
# Gtk3::Gdk::Window::new
SKIP: {
# https://bugzilla.gnome.org/show_bug.cgi?id=670369
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]