About Windows
This is a part of the nuclear plugin documentation.
Some of the marked functions are available in a shortened form in AGK-Basic version. In general, this concerns those functions where the parameters could also be passed as
nk_vec2 or
nk_rect.
Others of these marked functions return only a Memblock-ID. This is then converted with the corresponding AppGameKit function in a UDT.
Function overview (Plugin - .DLL/.SO)
- Integer WindowBegin(title as String, posx as Float, posy as Float, width as Float, height as Float, flags as Integer)
- Integer WindowBegIntegeritled(name as String, title as String, posx as Float, posy as Float, width as Float, height as Float, flags as Integer)
- WindowEnd()
- WindowStore(slot as Integer, name as String)
- Integer WindowGetPosition()
- Integer WindowGetSize()
- Float WindowGetWidth()
- Float WindowGetHeight()
- Integer WindowGetContentRegion()
- Integer WindowGetContentRegionMin()
- Integer WindowGetContentRegionMax()
- Integer WindowGetContentRegionSize()
- WindowStoreCanvas(slot as Integer)
- Integer WindowGetScroll()
- Integer WindowHasFocus()
- Integer WindowIsCollapsed(name as String)
- Integer WindowIsClosed(name as String)
- Integer WindowIsHidden(name as String)
- Integer WindowIsActive(name as String)
- Integer WindowIsHovered()
- Integer WindowIsAnyHovered()
- Integer WindowIsAnyActive()
- WindowStorePanel(slot as Integer)
- Integer WindowGetPanel()
- Integer WindowGetPanelBounds()
- Integer WindowGetBounds()
- Float WindowGetBoundX()
- Float WindowGetBoundY()
- Float WindowGetBoundWidth()
- Float WindowGetBoundHeight()
- Float WindowGetContentRegionX()
- Float WindowGetContentRegionY()
- Float WindowGetContentRegionWidth()
- Float WindowGetContentRegionHeight()
- WindowSetBounds(name as String, x as Float, y as Float, w as Float, h as Float)
- WindowSetPosition(name as String, x as Float, y as Float)
- WindowSetSize(name as String, x as Float, y as Float)
- WindowSetFocus(name as String)
- WindowSetScroll(x as Integer, y as Integer)
- WindowClose(name as String)
- WindowCollapse(name as String , state as Integer)
- WindowCollapseIf(name as String , state as Integer, cond as Integer)
- WindowShow(name as String , state as Integer)
- WindowShowIf(name as String , Integer state as , cond as Integer)
Parameter (Plugin)
- name
Gives a name to a window. Used to identify different windows. Also outside a WindowBegin() and WindowEnd() command.
- title
This is the title to be displayed. If the title stands alone without the parameter name, then the title is also the name.
- posx, posy
Position of a Windows.
- width, height
Size of a Windows.
- flags
Flags for a window. Affects the look, behavior and functionality of a window.
- slot
Is used as a workaround for the use of pointers. Some functions like the Draw/Stroke commands require such a 'slot' to access the pointer internally.
- scrollx, scrolly
Specifies the scroll offset.
- state
Describes a status - On or Off (1 or 0 / nk_true or nk_false).
- cond
Condition that must be complied with in order to actually perform the state change.
flags
NK_WINDOW_BORDER
NK_WINDOW_MOVABLE
NK_WINDOW_SCALABLE
NK_WINDOW_CLOSABLE
NK_WINDOW_MINIMIZABLE
NK_WINDOW_NO_SCROLLBAR
NK_WINDOW_TITLE
NK_WINDOW_SCROLL_AUTO_HIDE
NK_WINDOW_BACKGROUND
NK_WINDOW_SCALE_LEFT
NK_WINDOW_NO_INPUT
NK_WINDOW_PRIVATE
NK_WINDOW_DYNAMIC
NK_WINDOW_ROM
NK_WINDOW_NOT_INTERACTIVE
NK_WINDOW_HIDDEN
NK_WINDOW_CLOSED
NK_WINDOW_MINIMIZED
NK_WINDOW_REMOVE_ROM
Function overview (AGK-Basic - .AGC)
- nk_rect nkWindowGetBounds()
- nk_vec2 nkWindowGetSize()
- nk_vec2 nkWindowGetPosition()
- nk_rect nkWindowGetContentRegion()
- nk_vec2 nkWindowGetContentRegionMin()
- nk_vec2 nkWindowGetContentRegionMax()
- nk_vec2 nkWindowGetContentRegionSize()
- nk_rect nkWindowGetPanelBounds()
- nk_vec2 nkWindowGetScroll()
- nkWindowSetBounds(name as string as , bounds as nk_rect)
- nkWindowSetPosition(name as string as , position as nk_vec2)
- nkWindowSetSize(name as string as , size as nk_vec2)
- nkWindowSetScroll(name as string as , scroll as nk_vec2)
Parameter (AGK-Basic)
- name
Gives a name to a window. Used to identify different windows. Also outside a WindowBegin() and WindowEnd() command.
- bounds
Position and size of a window
- position
Position of a window
- size
Size of a window
- scroll
Specifies the scroll offset.
A description of the most important functions can be found
here on the nuclear page. I think you can match the corresponding functions.
There are three functions which are not described because they were created by me as work around.
This concerns the functions:
WindowStore(slot as Integer, name as String)
WindowStoreCanvas(slot as Integer)
WindowStorePanel(slot as Integer)
These functions simply store the pointers from the window, panel or canvas in an array. Other functions can then access this pointer.
WindowStore and WindowStorePanel are probably not necessary. I leave them in case there is a later use for them.
WindowStoreCanvas was used in the extended demo. This was necessary to write directly into the command buffer. For example if you want to write circles and lines directly into the command buffer.
The functions FillCircle, StrokeLine, DrawImage ect. finally use this pointer/slot.
Table of contents————Next topic (About Layout & Groups)
And now again a small example.
#import_plugin Nuklear as nk
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Nuklear Window" )
SetWindowSize( 640, 480, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 640, 480 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 0, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
#insert "../Nuklear.agc"
// basic nuklear initialization
nkInit()
global boolean as string[1] = ["false","true"]
global collapse as integer = NK_MAXIMIZED
global window_open as integer = 1
do
// pass agk inputs to nuklear
nk.HandleInput()
// check if the window should be displayed
if window_open = 1
// show our window
if nk.WindowBegin("Window", 160, 50, 320, 240, NK_WINDOW_BORDER||NK_WINDOW_MOVABLE||NK_WINDOW_TITLE||NK_WINDOW_SCALABLE||NK_WINDOW_MINIMIZABLE||NK_WINDOW_CLOSABLE)
window_bounds as nk_rect
window_bounds = nkWindowGetBounds()
nk.LayoutRowDynamic(20,1)
nk.Label("window position:"+str(window_bounds.x)+","+str(window_bounds.y), NK_TEXT_LEFT)
nk.Label("window size:"+str(window_bounds.w)+","+str(window_bounds.h), NK_TEXT_LEFT)
nk.Label("window has focus:"+boolean[nk.WindowHasFocus()], NK_TEXT_LEFT)
nk.Label("window is hovered:"+boolean[nk.WindowIsHovered()], NK_TEXT_LEFT)
nk.Label("window is active:"+boolean[nk.WindowIsActive("Window")], NK_TEXT_LEFT)
endif
nk.WindowEnd()
endif
// get new collapse state
if nk.WindowIsCollapsed("Window")
collapse = NK_MINIMIZED
else
collapse = NK_MAXIMIZED
endif
// check if our window was closed
window_open = nk.WindowIsClosed("Window") = 0
// F1 - toggle the collape state
if GetRawKeyPressed(112)
collapse = 1 - collapse
nk.WindowCollapse("Window", collapse)
endif
// F2 - bring back a closed window
if GetRawKeyPressed(113) and window_open = 0 then window_open = 1
nkSync()
loop