diff --git a/lib/wx/doc/dc_overlay.rb b/lib/wx/doc/dc_overlay.rb new file mode 100644 index 00000000..3e6ee82c --- /dev/null +++ b/lib/wx/doc/dc_overlay.rb @@ -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 diff --git a/rakelib/lib/director/derived_dc.rb b/rakelib/lib/director/derived_dc.rb index f6f2602d..9f217557 100644 --- a/rakelib/lib/director/derived_dc.rb +++ b/rakelib/lib/director/derived_dc.rb @@ -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 @@ -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 @@ -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' @@ -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 @@ -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' @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/rakelib/lib/specs/interfaces.rb b/rakelib/lib/specs/interfaces.rb index e56ba944..fac2ef7b 100644 --- a/rakelib/lib/specs/interfaces.rb +++ b/rakelib/lib/specs/interfaces.rb @@ -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|