From: "Daniel P. Zepeda" Date: 2003-01-15T04:06:15+09:00 Subject: Re: FXRuby problem on Windows On Wed, 15 Jan 2003 02:14:55 +0900 Lyle Johnson wrote: > Daniel P. Zepeda wrote: > > > I've cut down a larger program to this test case that shows a > > problem on windows. When I run this on my Linux box, I get an > > application window with some colored boxes and the string "Hi > > There, (I'm on my way, I'm making it) in it. When I run this same > > program on my Windows box, I get Zip, nada, at first a gray > > window, then a transparent one if I minimize thenmaximize the > > window. Some debugging statements show that onPaint *is* getting > > called. Can anyone tell me what the problem is here? > > > > I haven't had a chance to look at this under Windows yet, but I think I > see what's wrong; you need to call FXDC#end to "flush" out the drawing > commands that you're making. The fact that it *happens* to work under > Linux is just a coincidence. You were absolutely correct. After changing the code as you suggested, it works fine on both platforms. Thanks! > > Device contexts (i.e. FXDCWindow instances) are just supposed to be > temporary objects, not things that you hang on to for the life of a > program. They are most often constructed and torn down within a > SEL_PAINT handler, although there are some other times you might need to > use them (for some examples, see the scribble.rb example program). The documentation shows this as well. The reason I created the Device Contexts and kept them around for the life of the application is that I was using them to do crude animations. I figured (with no real basis) that setting up/tearing down Device Contexts every 10 milliseconds or so was wasteful and that just setting them up once and using them throughout the application would make the program run better. Am I wrong? Given that I want to use the Device Context every 10 milliseconds, doing crude animation, do you still recommend that I set up/tear down the Device Contexts each time, that is, for the example below, run the onPaint example below every 10 ms with a slightly different @image each time? Thanks for your stellar help Lyle. Here is the refactored code for those that might benefit from it: #!/usr/bin/env ruby require 'fox' require 'fox/colors' include Fox class DcProb < FXMainWindow def initialize(app) super(app, "Show Drawing Context Problem", nil, nil, DECOR_ALL, 0, 0, 400, 300) @canvas = FXCanvas.new(self, nil, 0 , (FRAME_SUNKEN| FRAME_THICK|LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_TOP|LAYOUT_LEFT),0,0,400,3 00) @canvas.connect(SEL_PAINT, method(:onPaint)) @image = FXImage.new(app, nil, IMAGE_SHMI|IMAGE_SHMP) @font= FXFont.new(app, "arial", 12, FONTWEIGHT_BOLD) end def create super @font.create @image.create setupImage show(PLACEMENT_SCREEN) end def onPaint( sender, sel, event ) sdc = FXDCWindow.new( @canvas ) sdc.drawImage( @image, 0,0 ) sdc.end end def setupImage canvasWidth = @canvas.getWidth canvasHeight = @canvas.getHeight @image.resize( canvasWidth, canvasHeight ) idc = FXDCWindow.new( @image ) step = 5 0.step(50, step ) { |y| 0.step(50, step ) { |x| idc.setForeground(FXRGB( rand(255), rand(255), rand(255))) idc.fillRectangle( x,y, x + canvasHeight, y + canvasWidth ) } } idc.fillRectangle( 50,50, canvasWidth, canvasHeight ) idc.setForeground(FXColor::Black) idc.setTextFont( @font ) idc.drawText( 60,80, "Hi There, (I'm on my way I'm making it!)") idc.end end end if __FILE__ == $0 application = FXApp.new("DcProb", "zepeda-zone.net") application.init(ARGV) DcProb.new(application) application.create application.run end > > > Hope this helps, > > Lyle > -- "Daniel P. Zepeda" (Remove commas for address)