AIR - set size of NativeWindow to include system chrome
Asked Answered
F

3

6

How do you find out the size of the system chrome so that I can specify the window size to achieve the stage size I want?

If my main window is set at 800 x 600 (stage), and I create a second window as below, it will be smaller.

public function Main():void 
{
    var windowOptions:NativeWindowInitOptions = new NativeWindowInitOptions();
    windowOptions.systemChrome = NativeWindowSystemChrome.STANDARD;
    windowOptions.type = NativeWindowType.NORMAL;
    var newWindow:NativeWindow = new NativeWindow( windowOptions );
    newWindow.width = 800;
    newWindow.height = 600;
    newWindow.stage.scaleMode = StageScaleMode.NO_SCALE;
    newWindow.stage.align = StageAlign.TOP_LEFT;
    newWindow.activate();

}

I assume you increase both newWindow.width = 800; and newWindow.height = 600;to account for the chrome, but how do you find this value?

Fabricant answered 19/1, 2012 at 16:27 Comment(0)
S
5

you can calculate the size of the chrome by substracting the windows size (that include the chrome) with the inner size (that exclude the chrome).

From the width help of NativeWindows :

The dimensions reported for a native window include any system window chrome that is displayed. The width of the usable display area inside a window is available from the Stage.stageWidth property.

So the inner size can be obtained with stage object ( stage.stageWidth and stage.stageHeight: )

hence :

var chromeWidth=newWindow.width-newWindow.stage.stageWidth;
var chromeHeight=newWindow.height-newWindow.stage.stageHeight;
Snailpaced answered 19/1, 2012 at 19:10 Comment(0)
E
0

When creating ActionScript projects with NO_SCALE the stage.stageHeight and stage.stageWidth cannot be used to calculate chrome in the main application window as they do not resize to conform to the inner width. You must reference the main window stage.

To find the main windows inner stage height and width you can use the stage.nativeWindow.stage references stageHeight and stageWidth properties which gives inner width.

e.g. for a 1280x720 desired inner size:

// width stage.nativeWindow.width = 1280 + (stage.nativeWindow.width -
stage.nativeWindow.stage.stageWidth);

// height stage.nativeWindow.height = 720 + (stage.nativeWindow.height
- stage.nativeWindow.stage.stageHeight);
Excommunicative answered 20/9, 2012 at 16:13 Comment(0)
T
0

For reference, as I feel the other answers aren't clear enough. To set a new window to the desired dimensions:

// first set the desired window dimensions to set the (smaller) stage dimensions:
newWindow.width = 1024;
newWindow.height = 768;

// then reset the window dimensions and add chrome dimensions:
newWindow.width = 1024 + (1024 - newWindow.stage.stageWidth);
newWindow.height = 768 + (768 - newWindow.stage.stageHeight);   
Terrijo answered 6/5, 2015 at 19:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.