Jump to content


Repaint on resize in TW3CustomGameApplication?

  • Please log in to reply
2 replies to this topic

#1 ielite

  • Members
  • 701 posts

Posted 05 January 2016 - 02:49 AM

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.




1.) How to trap the resize event?


2.) How to repaint?



#2 Cipher Diaz

Cipher Diaz
  • Administrators
  • 313 posts

Posted 05 January 2016 - 09:07 PM

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 ()
  end, true);

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

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

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.

#3 ielite

  • Members
  • 701 posts

Posted 06 January 2016 - 03:15 AM

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.



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users