diff --git a/lib/wx/core/paintdc.rb b/lib/wx/core/paintdc.rb index 07800add..0421bb84 100644 --- a/lib/wx/core/paintdc.rb +++ b/lib/wx/core/paintdc.rb @@ -6,10 +6,16 @@ # Copyright 2004-2007, wxRuby development team # released under the MIT-like wxRuby2 license -class Wx::PaintDC +module Wx + + class PaintDC + + def self.draw_on(win, &block) + win.paint(&block) if block + end - def self.draw_on(win, &block) - win.paint(&block) if block end + AutoBufferedPaintDC = PaintDC.has_native_double_buffer ? Wx::PaintDC : Wx::BufferedPaintDC + end diff --git a/lib/wx/doc/memory_dc.rb b/lib/wx/doc/memory_dc.rb index 9895a3cb..5eed3ccf 100644 --- a/lib/wx/doc/memory_dc.rb +++ b/lib/wx/doc/memory_dc.rb @@ -66,16 +66,7 @@ def self.draw_on(*arg) end end - class AutoBufferedPaintDC < Wx::BufferedPaintDC - - # Creates a Buffered DC and passes that to the given block to draw on. - # Destroys the DC after the block returns. - # Pass a pointer to the window on which you wish to paint. - # @note In wxRuby this method mostly exists to be consistent with the other DC classes. It is however recommended to use Wx::Window#paint_buffered instead. - # @param [Wx::Window] win The underlying window; everything drawn to this object will be flushed to this window when this object is destroyed. - # @yieldparam [Wx::AutoBufferedPaintDC] dc - def self.draw_on(win, &block) end - - end + # This constant is set to either Wx::PaintDC if the platform supports native double buffering or Wx::BufferedPaintDC otherwise. + AutoBufferedPaintDC = _ end diff --git a/lib/wx/doc/window.rb b/lib/wx/doc/window.rb index e707fbe7..c49d91e0 100644 --- a/lib/wx/doc/window.rb +++ b/lib/wx/doc/window.rb @@ -47,9 +47,10 @@ def raise_window; end # @return [::Object] result from block def paint; end - # Similar to #paint but this time creates a Wx::AutoBufferedPaintDC when called + # Similar to #paint but this time creates a buffered paint DC (which will be either a 'regular' Wx::PaintDC if + # the platform natively supports double buffering or a Wx::BufferedPaintDC otherwise) when called # from an evt_paint handler and a Wx::ClientDC otherwise. - # @yieldparam [Wx::AutoBufferedPaintDC,Wx::ClientDC] dc dc to paint on + # @yieldparam [Wx::PaintDC,Wx::BufferedPaintDC,Wx::ClientDC] dc dc to paint on # @return [::Object] result from block def paint_buffered; end diff --git a/rakelib/lib/director/derived_dc.rb b/rakelib/lib/director/derived_dc.rb index 51e0b5a7..79f194e8 100644 --- a/rakelib/lib/director/derived_dc.rb +++ b/rakelib/lib/director/derived_dc.rb @@ -67,17 +67,35 @@ def setup when 'wxPaintDC' spec.make_abstract 'wxPaintDC' spec.ignore 'wxPaintDC::wxPaintDC' + spec.add_header_code <<~__HEREDOC + // we need this static method here because we do not want SWIG to parse the preprocessor + // statements (#if/#else/#endif) which it does in %extend blocks + #include "wx/dcbuffer.h" + static VALUE do_check_native_double_buffer() + { + #if wxALWAYS_NATIVE_DOUBLE_BUFFER + return Qtrue; + #else + return Qfalse; + #endif + } + __HEREDOC + spec.add_extend_code 'wxPaintDC', <<~__HEREDOC + #include "wx/dcbuffer.h" + static VALUE has_native_double_buffer() + { + return do_check_native_double_buffer(); + } + __HEREDOC when 'wxMemoryDC' - spec.items << 'wxBufferedDC' << 'wxBufferedPaintDC' << 'wxAutoBufferedPaintDC' - spec.gc_as_untracked %w[wxBufferedDC wxBufferedPaintDC wxAutoBufferedPaintDC] + spec.items << 'wxBufferedDC' << 'wxBufferedPaintDC' + spec.gc_as_untracked %w[wxBufferedDC wxBufferedPaintDC] spec.make_abstract 'wxMemoryDC' spec.make_abstract 'wxBufferedDC' spec.make_abstract 'wxBufferedPaintDC' - spec.make_abstract 'wxAutoBufferedPaintDC' spec.ignore 'wxMemoryDC::wxMemoryDC', 'wxBufferedDC::wxBufferedDC', - 'wxBufferedPaintDC::wxBufferedPaintDC', - 'wxAutoBufferedPaintDC::wxAutoBufferedPaintDC' + 'wxBufferedPaintDC::wxBufferedPaintDC' # like all DC's these should best always be a temporary stack objects # we do not allow creation in Ruby but rather provide a class # method for block execution on a temp dc @@ -199,22 +217,6 @@ def setup return rc; } __HEREDOC - spec.add_extend_code 'wxAutoBufferedPaintDC', <<~__HEREDOC - static VALUE draw_on(wxWindow* tgt) - { - if (!wxRuby_IsAppRunning()) - rb_raise(rb_eRuntimeError, "A running Wx::App is required."); - VALUE rc = Qnil; - if (rb_block_given_p ()) - { - wxAutoBufferedPaintDC dc(tgt); - wxAutoBufferedPaintDC* dc_ptr = &dc; - VALUE rb_dc = SWIG_NewPointerObj(SWIG_as_voidptr(dc_ptr), SWIGTYPE_p_wxAutoBufferedPaintDC, 0); - rc = rb_yield(rb_dc); - } - return rc; - } - __HEREDOC when 'wxMirrorDC' spec.make_abstract 'wxMirrorDC' spec.ignore 'wxMirrorDC::wxMirrorDC' diff --git a/rakelib/lib/director/window.rb b/rakelib/lib/director/window.rb index 41cf0ef1..dc979e2c 100644 --- a/rakelib/lib/director/window.rb +++ b/rakelib/lib/director/window.rb @@ -150,9 +150,15 @@ def setup static VALUE do_paint_buffered(wxWindow* ptr) { VALUE rc = Qnil; - wxAutoBufferedPaintDC dc(ptr); - wxAutoBufferedPaintDC* ptr_dc = &dc; - VALUE r_class = rb_const_get(mWxCore, rb_intern("AutoBufferedPaintDC")); + #if wxALWAYS_NATIVE_DOUBLE_BUFFER + wxPaintDC dc(ptr); + wxPaintDC* ptr_dc = &dc; + VALUE r_class = rb_const_get(mWxCore, rb_intern("PaintDC")); + #else + wxBufferedPaintDC dc(ptr); + wxBufferedPaintDC* ptr_dc = &dc; + VALUE r_class = rb_const_get(mWxCore, rb_intern("BufferedPaintDC")); + #endif 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); diff --git a/samples/html/html.rb b/samples/html/html.rb index 02c4807e..f292425d 100644 --- a/samples/html/html.rb +++ b/samples/html/html.rb @@ -106,7 +106,7 @@ def setup_panel @html_win.set_related_frame(self, 'HTML : %s') @html_win.set_related_status_bar(1) - @html_win.load_file('samples/html/test.htm') + @html_win.load_file(File.join(__dir__, 'test.htm')) text = Wx::TextCtrl.new(panel, Wx::ID_ANY, "", Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, diff --git a/samples/propgrid/propgrid.rb b/samples/propgrid/propgrid.rb index 60dc9b1c..5c758bb2 100644 --- a/samples/propgrid/propgrid.rb +++ b/samples/propgrid/propgrid.rb @@ -609,7 +609,7 @@ def initialize(title, pos, size) menuHelp.append(ID::ABOUT, '&About', 'Show about dialog') if Wx::PLATFORM == 'WXOSX' - Wx.get_app.mac_about_menu_itemid = ID::ABOUT + Wx::App.mac_about_menu_itemid = ID::ABOUT end menuTools1.append(ID::APPENDPROP, 'Append New Property') diff --git a/samples/propgrid/propgrid_minimal.rb b/samples/propgrid/propgrid_minimal.rb index 12527cf6..02dcee7f 100644 --- a/samples/propgrid/propgrid_minimal.rb +++ b/samples/propgrid/propgrid_minimal.rb @@ -88,7 +88,7 @@ def self.display_minimal_frame(parent = nil) if (!defined? WxRuby::Sample) || (WxRuby::Sample.loading_sample && WxRuby::Sample.loading_sample != __FILE__) - module MinimalSample + module PropGridMinimalSample include WxRuby::Sample if defined? WxRuby::Sample