Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #269

Merged
merged 9 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 36 additions & 28 deletions lib/wx/core/colour.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,45 @@
# Copyright 2004-2007, wxRuby development team
# released under the MIT-like wxRuby2 license

class Wx::Colour
# Redefine the initialize method so it raises an exception if an
# invalid colour value is given. This might be an unknown colour
# string (eg 'dark blue') or out-of-bounds integer values (<0 or >255)
wx_init = self.instance_method(:initialize)
define_method(:initialize) do | *args |
begin
wx_init.bind(self).call(*args)
# Invalid integer values raise SWIG 'no matching func'
rescue ArgumentError, TypeError
Kernel.raise ArgumentError, "Invalid colour values #{args.inspect}"
require_relative 'ext'

module Wx

Wx.add_delayed_constant(self, :TRANSPARENT_COLOUR, 'Wx::Colour.new(0, 0, 0, Wx::ALPHA_TRANSPARENT)') { Wx::Colour.new(0, 0, 0, Wx::ALPHA_TRANSPARENT) }

class Colour
# Redefine the initialize method so it raises an exception if an
# invalid colour value is given. This might be an unknown colour
# string (eg 'dark blue') or out-of-bounds integer values (<0 or >255)
wx_init = self.instance_method(:initialize)
define_method(:initialize) do | *args |
begin
wx_init.bind(self).call(*args)
# Invalid integer values raise SWIG 'no matching func'
rescue ArgumentError, TypeError
Kernel.raise ArgumentError, "Invalid colour values #{args.inspect}"
end
end
end

# Missing Standard colour
Wx::MAGENTA = new(255, 0, 255)

# Colours are equal to one another if they have the same red, green
# and blue intensity, and the same alpha
def ==(other)
case other
when Wx::Colour
[ self.red, self.green, self.blue, self.alpha ] ==
[ other.red, other.green, other.blue, other.alpha ]
else
false
# Missing Standard colour
Wx::MAGENTA = new(255, 0, 255)

# Colours are equal to one another if they have the same red, green
# and blue intensity, and the same alpha
def ==(other)
case other
when Wx::Colour
[ self.red, self.green, self.blue, self.alpha ] ==
[ other.red, other.green, other.blue, other.alpha ]
else
false
end
end
end

# More informative output for inspect etc
def to_s
"#<Wx::Colour: (#{red}, #{green}, #{blue} *#{alpha})>"
# More informative output for inspect etc
def to_s
"#<Wx::Colour: (#{red}, #{green}, #{blue} *#{alpha})>"
end
end

end
12 changes: 12 additions & 0 deletions lib/wx/doc/colour.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# :stopdoc:
# Copyright (c) 2023 M.J.N. Corino, The Netherlands
#
# This software is released under the MIT license.
# :startdoc:


module Wx

TRANSPARENT_COLOUR = Wx::Colour.new(0, 0, 0, Wx::ALPHA_TRANSPARENT)

end
11 changes: 10 additions & 1 deletion lib/wx/doc/gc_dc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class GCDC < Wx::DC

# Creates a Wx::GCDC instance for target and
# passes the instance to the given block to draw on.
# @overload draw_on()
# @yieldparam [Wx::GCDC] dc GCDC instance to draw on
# @return [Object] result from block
# @overload draw_on(dc)
# @param [Wx::WindowDC,Wx::MemoryDC] target DC to draw on
# @yieldparam [Wx::GCDC] dc GCDC instance to draw on
Expand All @@ -23,10 +26,16 @@ class GCDC < Wx::DC
# @return [Object] result from block
# @wxrb_require USE_PRINTING_ARCHITECTURE,WXMSW|WXOSX|USE_GTKPRINT
# @overload draw_on(gc)
# Note that the context will continue using the same font, pen and brush as before until #set_font, #set_pen
# or #set_brush is explicitly called to change them. This means that the code can use this wxDC-derived object
# to work using pens and brushes with alpha component, for example (which normally isn't supported by Wx::DC API),
# but it also means that the return values of #get_font, #get_pen and #get_brush won't really correspond to the
# actually used objects because they simply can't represent them anyhow. If you wish to avoid such discrepancy,
# you need to call the setter methods to bring Wx::DC and Wx::GraphicsContext font, pen and brush in sync with each other.
# @param [Wx::GraphicsContext] gc GraphicsContext to draw on
# @yieldparam [Wx::GCDC] dc GCDC instance to draw on
# @return [Object] result from block
def self.draw_on(arg) end
def self.draw_on(*arg) end
end

end
3 changes: 2 additions & 1 deletion rakelib/lib/director/dc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def setup
'wxDC::GetLogicalOrigin(wxCoord *,wxCoord *) const',
'wxDC::GetHandle'
]
spec.disable_proxies
spec.disable_proxies
spec.disown 'wxGraphicsContext *ctx'
spec.rename_for_ruby({
'GetDimensions' => 'wxDC::GetSize(wxCoord *, wxCoord *) const',
'GetDimensionsMM' => 'wxDC::GetSizeMM(wxCoord *, wxCoord *) const',
Expand Down
22 changes: 21 additions & 1 deletion rakelib/lib/director/derived_dc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def setup
spec.ignore 'wxPaintDC::wxPaintDC'
when 'wxMemoryDC'
spec.items << 'wxBufferedDC' << 'wxBufferedPaintDC' << 'wxAutoBufferedPaintDC'
spec.gc_as_untracked %w[wxBufferedDC wxBufferedPaintDC wxAutoBufferedPaintDC]
spec.make_abstract 'wxMemoryDC'
spec.make_abstract 'wxBufferedDC'
spec.make_abstract 'wxBufferedPaintDC'
Expand Down Expand Up @@ -302,6 +303,24 @@ def setup
__HEREDOC
end
spec.add_extend_code 'wxGCDC', <<~__HEREDOC
static VALUE draw_on()
{
if (!wxRuby_IsAppRunning())
rb_raise(rb_eRuntimeError, "A running Wx::App is required.");
VALUE rc = Qnil;
if (rb_block_given_p ())
{
// Somehow there seems to be a problem with the Ruby GCDC value
// being GC-ed unless we block GC for the duration of the block
// execution. Unclear why. We have similar code for other objects
// where this issue does not come up.
wxGCDC gc_dc;
wxGCDC* dc_ptr = &gc_dc;
VALUE rb_dc = SWIG_NewPointerObj(SWIG_as_voidptr(dc_ptr), SWIGTYPE_p_wxGCDC, 0);
rc = rb_yield(rb_dc);
}
return rc;
}
static VALUE draw_on(const wxWindowDC& dc)
{
if (!wxRuby_IsAppRunning())
Expand Down Expand Up @@ -356,7 +375,8 @@ def setup
}
return rc;
}
__HEREDOC
__HEREDOC
spec.disown 'wxGraphicsContext *gc'
spec.ignore 'wxGCDC::wxGCDC(const wxEnhMetaFileDC &)'
when 'wxScaledDC'
spec.items.clear # wxRuby extension; no XML docs
Expand Down
3 changes: 2 additions & 1 deletion rakelib/lib/director/graphics_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ def setup
'wxGraphicsContext::CreateFromNativeHDC',
'wxGraphicsContext::CreateFromUnknownDC',
'wxGraphicsContext::GetNativeContext',
'wxGraphicsContext::Create',
'wxGraphicsContext::Create(const wxEnhMetaFileDC &)',
'wxGraphicsContext::CreateMatrix(const wxAffineMatrix2DBase &) const',
'wxGraphicsContext::DrawLines(size_t, const wxPoint2DDouble *, wxPolygonFillMode)',
'wxGraphicsContext::StrokeLines(size_t, const wxPoint2DDouble *)',
'wxGraphicsContext::StrokeLines (size_t, const wxPoint2DDouble *, const wxPoint2DDouble *)'
spec.ignore_unless(Config::AnyOf.new('WXMSW', 'WXOSX', 'USE_GTKPRINT'), 'wxGraphicsContext::Create(const wxPrinterDC &)')
spec.new_object 'wxGraphicsContext::Create'
spec.add_header_code <<~__HEREDOC
// special free funcs are needed to clean up Dashes array if it has been
// set; wxWidgets does not do this automatically so will leak if not
Expand Down
1 change: 1 addition & 0 deletions rakelib/lib/director/graphics_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def setup
spec.ignore 'wxGraphicsRenderer::GetGDIPlusRenderer',
'wxGraphicsRenderer::GetDirect2DRenderer'
end
spec.new_object 'wxGraphicsRenderer::CreateContext'
# Deal with GraphicsMatrix#get method
spec.map_apply 'double *OUTPUT' => [ 'wxDouble *a', 'wxDouble *b',
'wxDouble *c', 'wxDouble *d',
Expand Down
9 changes: 2 additions & 7 deletions rakelib/lib/director/window.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,8 @@ def setup
{
VALUE rc = Qnil;
wxAutoBufferedPaintDC dc(ptr);
#if wxALWAYS_NATIVE_DOUBLE_BUFFER
wxPaintDC* ptr_dc = &dc;
VALUE r_class = rb_const_get(mWxCore, rb_intern("PaintDC"));
#else
wxMemoryDC* ptr_dc = &dc;
VALUE r_class = rb_const_get(mWxCore, rb_intern("MemoryDC"));
#endif
wxAutoBufferedPaintDC* ptr_dc = &dc;
VALUE r_class = rb_const_get(mWxCore, rb_intern("AutoBufferedPaintDC"));
swig_type_info* swig_type = wxRuby_GetSwigTypeForClass(r_class);
VALUE rb_dc = SWIG_NewPointerObj(SWIG_as_voidptr(ptr_dc), swig_type, 0);
rc = rb_yield(rb_dc);
Expand Down