Jump to content
IElite

Repaint on resize in TW3CustomGameApplication?

Recommended Posts

How do I repaint or call the PaintView method again, when the application has resized in a TW3CustomGameApplication ?

 

I am using the GameView.Width and GameView.Height properties to determine the dimensions of a lot of things in my app. When the applications size changes, I need to redraw

 

Doesn't look like there is a Resize event to override.

 

Questions

 

1.) How to trap the resize event?

 

2.) How to repaint?

 

 

Share this post


Link to post
Share on other sites

Resize for canvas under HTML5 is very different from ordinary DIV based components.

First of all, altering the width/height of the container does not change the canvas-content size. The fact is that both the canvas.width and container.width must have the same value.

 

Hence, some events are abstracted, because the application will resize whenever it is needed.

 

What you can do is add an event manually with W3_AddEvent() from SmartCl.System.pas

 

The syntax is:

procedure w3_AddEvent(a_tagRef: THandle; a_eventName: String; a_callback: TProcedureRef; a_useCapture: boolean = true);

 

 

So you can use it as such:

w3_addevent(self.handle,'resize', procedure ()
  begin
    self.invalidate
  end, true);

if you are adding this to the constructor, you may want to wait until the DOM is ready:

self.Handle.ReadyExecute( procedure ()
  begin
    w3_addevent(self.handle,'resize', procedure ()
    begin
      self.invalidate
    end, true);
  end;

The ReadyExecute() adds a watcher to the handle, and when the handle is valid (the DOM is ready and the element created) it will execute a section of code. So now you can safely place this in the constructor without getting errors or strange behavior.

 

Note: You may want to use Beginupdate + AddToComponentState([csSized]) + EndUpdate around the invalidate call, since that will force a recursive refresh if you are mixing with normal controls on the same container.

Share this post


Link to post
Share on other sites

So, then if a user resizes their browser, or rotates their device, there is no event like Resize to respond to this change in size?

 

 

I am not using any controls on the container. I am simply using the canvas to draw out my playing board. I however would like to adjust the board according to the browser or device resizing.

 

thanx

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×