Board index FlightGear Development Canvas

Resizing a canvas

Canvas is FlightGear's new fully scriptable 2D drawing system that will allow you to easily create new instruments, HUDs and even GUI dialogs and custom GUI widgets, without having to write C++ code and without having to rebuild FlightGear.

Resizing a canvas

Postby kuifje09 » Thu Mar 13, 2014 10:23 pm

I am looking for a piece of code telling how I would resize a canvas.
This question I had before, and did not get it to a solution for me. despite some advice.
If I see some dialogs, then it is possible... but when I look in the airport.chooser ( menubar-location-choose_airport ) then I even do not see an eventmaneger for that goal. So where is it done. Maybe it is not the right example I took ? but same for the onboard-map.

The dialog/canvas I created as :
Code: Select all
Area.init = func (w,h) {
   me._Dialog=canvas.Window.new([w,h]);
   me._Canvas=me._Dialog.createCanvas()
                        .setColorBackground(0.5,0.5,0.5,me._Transp);


Just a little piece of the code, but this is now a fixed dialog/window.
I can drag it, no problem, but now I want to add the ctrl-button from the mouse in the routine to make it resizing.
Thus not using the default move behaviour. ( Is there a default resize ? don't think so. )
Lot of windows are resizeble, are these just PUI gui's which style I should not use...

When I look in the property tree, then I am puzzled. It is not only 1 set of x/y but a lot more and children not to forget...

I do understand, when resizing, there are some decicions to be made. Is just the canvas growing, but not the content.
Or is the content also growing...

Maby to much for me , If someone has a good example, it would help me much.
My goal is to resize the window, and not the content... Now I think about it, maby also the content.
I think it is very complex.
kuifje09
 
Posts: 596
Joined: Tue May 17, 2011 9:51 pm

Re: Resizing a canvas

Postby Hooray » Thu Mar 13, 2014 11:55 pm

Subject: kuifje09's FGPlot Development
TheTom wrote:
kuifje09 wrote in Wed Jul 24, 2013 11:48 pm:It becomes a bit more to live now, multiple instances are working as resizing is. But resizing is not how it should behave.

Please don't work on window resizing. I'm currently working on it and will include it in the canvas gui module, such that it will be enough to just set a single property for enabling resizing canvas windows. For correct resizing I think I will also need to do some changes to the C++ code to make it easier from Nasal.


Subject: kuifje09's FGPlot Development
Hooray wrote:kuije09, in case you're using git/next:
- "size" is now "content-size": https://gitorious.org/fg/fgdata/commit/ ... 2c43180496
- TheTom just implemented resizing support via a 'resize' flag: https://gitorious.org/~tomprogs/fg/toms ... 866239f4d2

Code: Select all
var dlg = canvas.Window.new([400,300], "dialog")
                              .set("resize", 1);



Subject: kuifje09's FGPlot Development
TheTom wrote:I've now pushed my changes to fgdata. Enter the following into the Nasal console to give it a try (You can drag the dialog around and resize/close it):
Code: Select all
canvas.Window.new([400,300], "dialog").set("resize", 1).createCanvas();


If the canvas is created using 'createCanvas', the canvas is automatically resized if the window is resized. To update the layout just listen on the canvas size properties and react accordingly.

Have a look at my canvas-gui-demo branch on how to use the new widgets:

Code: Select all
var dlg = canvas.Window.new([400,300], "dialog")
                       .set("resize", 1);

var my_canvas = dlg.createCanvas()
                   .set("background", canvas.style.getColor("bg_color"));

var root = my_canvas.createGroup();
var text =
  root.createChild("text")
      .setText("This could be used for building an 'Aircraft Help' dialog.\nYou can also #use it to play around with the new Canvas system :).")
      .setTranslation(10, 30)
      .setAlignment("left-top")
      .setFontSize(14)
      .setFont("LiberationFonts/LiberationSans-Regular.ttf")
      .set("max-width", 380)
      .set("fill", canvas.style.getColor("text_color"));

dlg.addWidget( canvas.gui.widgets.Button.new(root, style, {size: [64, 26]})
                                 .setText("Ok")
                                 .move(20,  250) );
dlg.addWidget( canvas.gui.widgets.Button.new(root, style, {size: [64, 26]})
                                 .setText("Apply")
                                 .move(100, 250) );
dlg.addWidget( canvas.gui.widgets.Button.new(root, style, {size: [64, 64]})
                                 .setText("Cancel")
                                 .move(180, 200) );
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Resizing a canvas

Postby kuifje09 » Fri Mar 14, 2014 11:58 am

:oops: I knew it was mentioned before, and just could not find it. I will read it over again. Thanks.
kuifje09
 
Posts: 596
Joined: Tue May 17, 2011 9:51 pm

Re: Resizing a canvas

Postby Hooray » Fri Mar 14, 2014 4:58 pm

those are threads/discussions that you started, i.e. answers in response to your own questions - I only searched for "canvas resize" :-)
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Resizing a canvas

Postby kuifje09 » Fri Mar 14, 2014 10:59 pm

Yep I know. Must have seen it, but never realized.

But I have it almost done now. Only thing , the lines in such resized window are also resized.
So line get thicker or thinner and some artifact jump in. But thats for later !
kuifje09
 
Posts: 596
Joined: Tue May 17, 2011 9:51 pm

Re: Resizing a canvas

Postby TheTom » Sat Mar 15, 2014 12:46 am

kuifje09 wrote in Fri Mar 14, 2014 10:59 pm:But I have it almost done now. Only thing , the lines in such resized window are also resized.

If you just set the resize flag, the size of the canvas and viewport should also be updated. This will let the lines stay at same size.
TheTom
 
Posts: 322
Joined: Sun Oct 09, 2011 11:20 am

Re: Resizing a canvas

Postby kuifje09 » Sat Mar 15, 2014 2:24 pm

Hi TheTom,

Yes, I can do so, but I don't want that extra border. So I need only to know a little more to keep the line thickness.
But depending on how you use my canvas, it can be done by the parent window, using this canvas, or I have to do it myself when the canvas with its own borderless window is running standalone.
But it will be solved later on ... i.e. use the canvas with "auto resize on" when used standalone.

EDIT: Right, without a title/name there is no border. But it also works a bit different then I expected...
kuifje09
 
Posts: 596
Joined: Tue May 17, 2011 9:51 pm


Return to Canvas

Who is online

Users browsing this forum: No registered users and 3 guests