Skip to content

Commit

Permalink
Merge pull request #280 from mcorino/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mcorino authored May 14, 2024
2 parents c937509 + eeaf81d commit f5e4241
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 43 deletions.
12 changes: 9 additions & 3 deletions lib/wx/core/paintdc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 2 additions & 11 deletions lib/wx/doc/memory_dc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions lib/wx/doc/window.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
44 changes: 23 additions & 21 deletions rakelib/lib/director/derived_dc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down
12 changes: 9 additions & 3 deletions rakelib/lib/director/window.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion samples/html/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion samples/propgrid/propgrid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion samples/propgrid/propgrid_minimal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit f5e4241

Please sign in to comment.