Class: Wx::PaintEvent

Inherits:
Event show all
Defined in:
lib/wx/doc/gen/events.rb

Overview

A paint event is sent when a window’s contents needs to be repainted.

The handler of this event must create a PaintDC object and use it for painting the window contents. For example:

def on_paint(event)
    self.pain do |dc|
       draw_my_document(dc)
    end
  end

Notice that you must not create other kinds of DC (e.g. ClientDC or WindowDC) in EVT_PAINT handlers and also don’t create PaintDC outside of this event handlers. You can optimize painting by retrieving the rectangles that have been damaged and only repainting these. The rectangles are in terms of the client area, and are unscrolled, so you will need to do some calculations using the current view position to obtain logical, scrolled units. Here is an example of using the RegionIterator class:

# Called when window needs to be repainted.
  def on_paint(event)
    self.paint do |dc|
      # Find Out where the window has scrolled to
      vb_pt = get_view_start # Top left corner of client
    
      Wx::RegionIterator.for_region(get_update_region) do |region_it|
        region_it.each do |rct|
          # rct == Dimensions of client area to repaint in pixels
    
           # Repaint this rectangle
           ...some code...
        end
      end
    end
  end
Remark:

Please notice that in general it is impossible to change the drawing of a standard control (such as Button) and so you shouldn't attempt to handle paint events for them as even if it might work on some platforms, this is inherently not portable and won't work everywhere.

Events using this class

The following event-handler methods redirect the events to member method or handler blocks for PaintEvent events. Event handler methods:

Category: Events

See Also:

  • and Event Handling

Instance Method Summary collapse

Methods inherited from Event

#clone, #get_event_category, #get_event_object, #get_event_type, #get_id, #get_skipped, #get_timestamp, #is_command_event, #resume_propagation, #set_event_object, #set_event_type, #set_id, #set_timestamp, #should_propagate, #skip, #stop_propagation

Methods inherited from Object

#clone, #dup, #is_same_as, #un_share

Constructor Details

#initialize(window) ⇒ Wx::PaintEvent

Constructor for exclusive use of wxWidgets itself.

Note that the objects of this class can not be created from application code, they’re only created by the library itself. If you need a window to be repainted, use Window#refresh instead of trying to manually create an event of this class.

Parameters:



1506
# File 'lib/wx/doc/gen/events.rb', line 1506

def initialize(window) end