beetlebug▾
/

ztk::game view

Fits the game into a toplevel with its zoom, or gives the options of the fit.

ztk::game view ?PATH?
ztk::game view ?PATH? ?-size {W H}? ?-fit MODE? ?-orientation ORIENTATION? ?-fullscreen BOOLEAN?

Description

In this stage the view is a toplevel: PATH, or . by default. The fit sets wm attributes PATH -zoom and puts the game in the middle with the padding of the toplevel, inside the insets of tk insets. It runs again after each <<Insets>> and each <Configure> of the toplevel. The origin and the size of the game are the frame of the zones of the actions. A widget of its own for the view comes with the sprite layer in stage 2.

With no option, gives the options as a dict.

Options

OptionTypeDefaultDescription
-sizelistemptyThe logical size of the game: a width and a height, or empty for the requested size of the content.
-fitstringnoneHow the game fills the room: letterbox, fill, integer, or none.
-orientationstringemptyThe orientation of the screen of a phone: landscape, portrait, or any.
-fullscreenboolean0With 1, the toplevel fills the screen.

-size

The logical size of the game: a width and a height, or empty for the requested size of the content.

A game that changes its layout with the shape of the window, such as a panel under the game in a tall window, leaves it empty.

% ztk::game view . -size {320 180}
> dict get [ztk::game view] -size
320 180
% ztk::game view . -size {0 10}
bad size "0 10": must be a list of a width and a height from 1 to 16384
-errorcode ZTK GAME SIZE

-fit

How the game fills the room: letterbox, fill, integer, or none.

letterbox takes the largest zoom at which the game fits. integer takes that zoom down to a whole number, at least 1, for pixel art. fill takes the smallest zoom at which the game covers the room. none keeps a zoom of 1. The zoom stays from 0.5 to 4.

% wm geometry . 400x300
> canvas .c -width 200 -height 100 -highlightthickness 0
> pack .c
> update
> ztk::game view . -size {} -fit letterbox
> wm attributes . -zoom
2.0
% ztk::game view . -fit wide
bad fit "wide": must be letterbox, fill, integer, or none
-errorcode ZTK GAME FIT wide

-orientation

The orientation of the screen of a phone: landscape, portrait, or any.

Sets wm attributes PATH -orientation. A desktop keeps the value with no effect.

% ztk::game view . -orientation landscape
> dict get [ztk::game view] -orientation
landscape
% ztk::game view . -orientation up
bad orientation "up": must be landscape, portrait, or any
-errorcode ZTK GAME ORIENTATION up

-fullscreen

With 1, the toplevel fills the screen.

Sets wm attributes PATH -fullscreen.

% ztk::game view . -fullscreen 0
> dict get [ztk::game view] -fullscreen
0
% ztk::game view . -fullscreen maybe
expected boolean value but got "maybe"
-errorcode TCL VALUE NUMBER

Returns

An empty string, or the options as a dict.

Examples

% ztk::game view
-size {} -fit none -orientation {} -fullscreen 0

Errors

% ztk::game view .nosuch
bad window path name ".nosuch"
-errorcode TK LOOKUP WINDOW .nosuch

% ztk::game view . -zoom 2
bad option "-zoom": must be -fit, -fullscreen, -orientation, or -size
-errorcode TCL LOOKUP OPTION -zoom

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztk 1.0.0-beta.7