Skip to content

Commit

Permalink
add Wx::Overlay, Wx::DCOverlay and doc
Browse files Browse the repository at this point in the history
  • Loading branch information
mcorino committed Mar 30, 2024
1 parent 70611e0 commit 66b7b9f
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 10 deletions.
34 changes: 34 additions & 0 deletions lib/wx/doc/dc_overlay.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# :stopdoc:
# Copyright (c) 2023 M.J.N. Corino, The Netherlands
#
# This software is released under the MIT license.
# :startdoc:


module Wx

class DCOverlay < Wx::DC

private :initialize

# Connects this overlay to the corresponding drawing dc. If the overlay is not initialized yet, this call will do so.
# Creates a Wx::DCOverlay instance for to do that and passes the instance to the given block to use.
# Uses either the entire area of the drawing DC or the area specified.
# @overload draw_on(overlay, dc)
# @param [Wx::Overlay] overlay Overlay to connect
# @param [Wx::DC] dc Drawing DC
# @yieldparam [Wx::DCOverlay] ovl_dc DCOverlay instance to use
# @return [Object] result from block
# @overload draw_on(overlay, dc, x, y, width, height)
# @param [Wx::Overlay] overlay Overlay to connect
# @param [Wx::DC] dc Drawing DC
# @param [Integer] x topleft x coordinate of area to use
# @param [Integer] y topleft y coordinate of area to use
# @param [Integer] width width of area to use
# @param [Integer] height height of area to use
# @yieldparam [Wx::DCOverlay] ovl_dc DCOverlay instance to use
# @return [Object] result from block
def self.draw_on(*arg) end
end

end
55 changes: 45 additions & 10 deletions rakelib/lib/director/derived_dc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def setup
super
spec.disable_proxies
spec.gc_as_untracked spec.module_name
if spec.module_name == 'wxScreenDC'
case spec.module_name
when 'wxScreenDC'
spec.make_abstract 'wxScreenDC'
# as a ScreenDC should always be a temporary stack object
# we do not allow creation in Ruby but rather provide a class
Expand All @@ -41,7 +42,7 @@ def setup
spec.ignore 'wxScreenDC::StartDrawingOnTop',
'wxScreenDC::EndDrawingOnTop',
'wxScreenDC::wxScreenDC'
elsif spec.module_name == 'wxClientDC'
when 'wxClientDC'
spec.make_abstract 'wxClientDC'
spec.ignore 'wxClientDC::wxClientDC'
# as a ClientDC should best always be a temporary stack object
Expand All @@ -63,10 +64,10 @@ def setup
return rc;
}
__HEREDOC
elsif spec.module_name == 'wxPaintDC'
when 'wxPaintDC'
spec.make_abstract 'wxPaintDC'
spec.ignore 'wxPaintDC::wxPaintDC'
elsif spec.module_name == 'wxMemoryDC'
when 'wxMemoryDC'
spec.items << 'wxBufferedDC' << 'wxBufferedPaintDC' << 'wxAutoBufferedPaintDC'
spec.make_abstract 'wxMemoryDC'
spec.make_abstract 'wxBufferedDC'
Expand Down Expand Up @@ -213,7 +214,7 @@ def setup
return rc;
}
__HEREDOC
elsif spec.module_name == 'wxMirrorDC'
when 'wxMirrorDC'
spec.make_abstract 'wxMirrorDC'
spec.ignore 'wxMirrorDC::wxMirrorDC'
# as a MirrorDC should best always be a temporary stack object
Expand All @@ -235,7 +236,7 @@ def setup
return rc;
}
__HEREDOC
elsif spec.module_name == 'wxSVGFileDC'
when 'wxSVGFileDC'
spec.items.concat %w[wxSVGBitmapHandler wxSVGBitmapFileHandler wxSVGBitmapEmbedHandler]
spec.make_abstract 'wxSVGFileDC'
spec.ignore 'wxSVGFileDC::wxSVGFileDC'
Expand Down Expand Up @@ -272,7 +273,7 @@ def setup
'wxSVGFileDC::EndDoc',
'wxSVGFileDC::StartPage',
'wxSVGFileDC::EndPage'
elsif spec.module_name == 'wxGCDC'
when 'wxGCDC'
spec.make_abstract 'wxGCDC'
spec.ignore 'wxGCDC::wxGCDC'
# like all DC this should best always be a temporary stack object
Expand Down Expand Up @@ -357,7 +358,7 @@ def setup
}
__HEREDOC
spec.ignore 'wxGCDC::wxGCDC(const wxEnhMetaFileDC &)'
elsif spec.module_name == 'wxScaledDC'
when 'wxScaledDC'
spec.items.clear # wxRuby extension; no XML docs
spec.override_inheritance_chain('wxScaledDC', %w[wxDC wxObject])
# as there are no dependencies parsed from XML make sure we're initialized after Wx::DC
Expand Down Expand Up @@ -398,7 +399,7 @@ class wxScaledDC : public wxDC
wxScaledDC(wxDC& target, double scale);
};
__HEREDOC
elsif spec.module_name == 'wxPrinterDC'
when 'wxPrinterDC'
spec.make_abstract 'wxPrinterDC'
spec.ignore 'wxPrinterDC::wxPrinterDC'
# as a PrinterDC should best always be a temporary stack object
Expand All @@ -420,7 +421,7 @@ class wxScaledDC : public wxDC
return rc;
}
__HEREDOC
elsif spec.module_name == 'wxPostScriptDC'
when 'wxPostScriptDC'
spec.make_abstract 'wxPostScriptDC'
spec.ignore 'wxPostScriptDC::wxPostScriptDC'
# as a PostScriptDC should best always be a temporary stack object
Expand All @@ -442,6 +443,40 @@ class wxScaledDC : public wxDC
return rc;
}
__HEREDOC
when 'wxDCOverlay'
spec.items << 'wxOverlay'
spec.make_abstract 'wxDCOverlay'
spec.ignore 'wxDCOverlay::wxDCOverlay'
spec.add_extend_code 'wxDCOverlay', <<~__HEREDOC
static VALUE draw_on(wxOverlay &overlay, wxDC *dc)
{
if (!wxRuby_IsAppRunning())
rb_raise(rb_eRuntimeError, "A running Wx::App is required.");
VALUE rc = Qnil;
if (rb_block_given_p ())
{
wxDCOverlay ovl_dc(overlay, dc);
wxDCOverlay* ovl_dc_ptr = &ovl_dc;
VALUE rb_dc = SWIG_NewPointerObj(SWIG_as_voidptr(ovl_dc_ptr), SWIGTYPE_p_wxDCOverlay, 0);
rc = rb_yield(rb_dc);
}
return rc;
}
static VALUE draw_on(wxOverlay &overlay, wxDC *dc, int x, int y, int width, int height)
{
if (!wxRuby_IsAppRunning())
rb_raise(rb_eRuntimeError, "A running Wx::App is required.");
VALUE rc = Qnil;
if (rb_block_given_p ())
{
wxDCOverlay ovl_dc(overlay, dc, x, y, width, height);
wxDCOverlay* ovl_dc_ptr = &ovl_dc;
VALUE rb_dc = SWIG_NewPointerObj(SWIG_as_voidptr(ovl_dc_ptr), SWIGTYPE_p_wxDCOverlay, 0);
rc = rb_yield(rb_dc);
}
return rc;
}
__HEREDOC
else
# ctors of all other derived DC require a running App
spec.require_app spec.module_name
Expand Down
1 change: 1 addition & 0 deletions rakelib/lib/specs/interfaces.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ module WXRuby3
Director.Spec(pkg, 'wxPersistentObject', requirements: %w[USE_CONFIG])
Director.Spec(pkg, 'wxPersistentWindow', requirements: %w[USE_CONFIG])
Director.Spec(pkg, 'wxSecretStore', requirements: %w[USE_SECRETSTORE])
Director.Spec(pkg, 'wxDCOverlay', director: Director::DerivedDC)
}

Director.Package('Wx::PRT', 'USE_PRINTING_ARCHITECTURE') do |pkg|
Expand Down

0 comments on commit 66b7b9f

Please sign in to comment.