LoginLogin
Might make SBS readonly: thread

Midori-OS: API DEF reference

Root / Submissions / [.]

Autz64Created:
This is a small reference page for Midori API. So you can continue the development without looking at the HELP app.

FUNCTIONS

General Usage

" APP_WINDOW_INIT()" Initializes data on the window array, to render a window with the given parameters. Returns the ID of the generated window. ARGUMENTS: UNIQUE: Boolean that handles "instances" of the app. If enabled, only one window can render the app, and any attempt to open the same app again will show a error: TYPE: type of window to draw. 1 renders a window with a banner and canvas. 0 renders a window similar to a tooltip (grey and no banner). FNAME$: Name of the DEF to execute. On each frame, this DEF will be called. Be sure it has the correct format with the correct parameters. NAME$: Name of the window app. Will appear on the banner of the window, if Type = 1. BANNERCOLOR: if TYPE equals 1, this sets the color of the banner. Any color code works. Use -1 to use the default color (blue). BCKCOLOR: if TYPE equals 1, this sets the color of the canvas. Any color code works. Use -1 to use the default color (white). POSX: Initial coordinate of the app on the X axis. When this function is executed, it will render the app on this given coordinate. POSY: Initial coordinate of the app on the Y axis. When this function is executed, it will render the app on this given coordinate. SIZEX: width in pixels of the app. If TYPE equals 1, it will set a minimun width which is determined by the length of NAME$. If the value is -1, it will render the app on fullscreen. SIZEY: height in pixels of the app. The minimum height is 32 pixels. If the value is -1, it will render the app on fullscreen.
ID=APP_WINDOW_INIT(TYPE,FNAME$,NAME$,BANNERCOLOR,BCKCOLOR,POSX,POSY,SIZEX,SIZEY)
Since the DEF returns the ID, you could manipulate that ID out of the DEF.
" APP_SIMPLE_INIT()" Similar to APP_WINDOW_INIT(), but with less arguments. The window app created with this command will appear with the following settings:
  • Type = 1.
  • Appears at X=50 and Y=50.
  • Width=100 and Height=50.
  • Default bannercolor and backcolor (Blue and White respectively).
If you want to programatically change these setting within the app, you can use Window Mutators for it. ARGUMENTS: FNAME$: Name of the DEF to execute. NAME$: Name of the window app. Will appear on the banner of the window. UNIQUE: Boolean that handles "instances" of the app. If enabled, only one window can render the app, and any attempt to open the same app again will show a error:
APP_SIMPLE_INIT(FNAME$,NAME$,UNIQUE)
Since v1.0.1
" APP_WINDOW_DESTROY" Deletes data from the window array based on the provided window ID. It also resets app globals to their default value. This do not resets custom globals. ARGUMENTS: ID: ID of the window to destroy.
APP_WINDOW_DESTROY ID
" APP_DRAG" Adds drag functionality to the window. The drag is done like any normal OS (hold left-click on the window banner, then move the cursor). This can (oddly) also be used with windows whose TYPE is 0. ARGUMENTS: ID: ID of the window to perform the drag. CRX: Cursor X coordinates. This is generated by GETPOINTERXY. CRX: Cursor Y coordinates. This is generated by GETPOINTERXY. STARTX: Start X coordinate of the window canvas. This is one of the parameters of template DEF. STARTY: Start Y coordinate of the window canvas. This is one of the parameters of template DEF. ENDX: End X coordinate of the window canvas. This is one of the parameters of template DEF.
APP_DRAG ID,CRX,CRY,STARTX,STARTY,ENDX
" APP_CLOSE_FUNC" Creates a hitbox at the top-right side of the window, which executes APP_WINDOW_DESTROY when clicked. This is commonly used with windows whose TYPE equals 1. ARGUMENTS: ID: ID of the window to close. CRX: Cursor X coordinates. This is generated by GETPOINTERXY. CRX: Cursor Y coordinates. This is generated by GETPOINTERXY. STARTY: Start Y coordinate of the window canvas. This is one of the parameters of template DEF. ENDX: End X coordinate of the window canvas. This is one of the parameters of template DEF.
APP_CLOSE_FUNC ID,CRX,CRY,STARTY,ENDX
"APP_MINIMIZE" Function similar to APP_CLOSE_FUNC, but suspends the program instead. A program suspended stop its execution at the very moment it was suspended, it does not executes on the background. ARGUMENTS: ID: WID of the window to close. CRX: Cursor X coordinates. This is generated by GETPOINTERXY. CRX: Cursor Y coordinates. This is generated by GETPOINTERXY. STARTY: Start Y coordinate of the window canvas. This is one of the parameters of template DEF. ENDX: End X coordinate of the window canvas. This is one of the parameters of template DEF.
APP_MINIMIZE WID, CRX, CRY, STARTY, ENDX
"ON_FOCUS()" Function that checks if the window is at the "focus" of the user. Returns TRUE if the window with the ID is on focus, FALSE otherwise. This is commonly used to avoid stuff like clicks through windows. See the Example below. ARGUMENTS: ID: ID of the window to check the focus.
A=ON_FOCUS(ID)
EXAMPLES:
IF ON_FOCUS(ID) && __ABTN2=#L THEN
 'Goes here if user clicks, ONLY if the window is on focus.
ENDIF
"GETKEY$()" Function that returns the pressed key from the keyboard. It works exactly as SmileBASIC's INKEY$() function. ARGUMENTS: none
A$=GETKEY$()
"ON_OPEN()" Function that returns TRUE on the first frame the app starts execution, and returns FALSE on the next subsequent frames the app is running. ARGUMENTS: ID: ID of the window.
A=ON_OPEN(ID)
EXAMPLES: TEMPLATE.PKG already has it. Is useful to initialize custom data:
IF ON_OPEN(WID) THEN
 FILL DEF_ARRAY,0 'Custom GLOBAL
ENDIF
"APP_WINDOW_INFO" Function that returns rendering information from a window based on the provided Window ID. ARGUMENTS: ID: ID of the window. RESULT: BNCL: Color of the Banner BNKCL: Color of the background POSX: Position of the window on the X axis. POSY: Position of the window on the X axis. SIZEX: Width of the window SIZEY: Height of the window TYPE: Type of window (1 or 0) If the window does not exist, all arguments returns -2.
APP_WINDOW_INFO WID OUT BNCL, BCKCL, POSX, POSY, SIZEX, SIZEY, TYPE
"IS_RUNNING()" Function that returns TRUE if there exist a window with the given Window ID. FALSE otherwise. ARGUMENTS: ID: ID of the window.
A=IS_RUNNING(WID)

Window Mutators

"SET_BACKCOLOR" Mutator to change the background color of a window programatically. ARGUMENTS: WID: ID of the window to change its color COL: Color code
SET_BACKCOLOR WID,COL
Since v1.0.1
"SET_BANNERCOLOR" Mutator to change the bannercolor of a window programatically. ARGUMENTS: WID: ID of the window to change its color COL: Color code
SET_BANNERCOLOR WID,COL
Since v1.0.1
"SET_SIZE" Mutator to change the width and height (in pixel unit) of a window app. ARGUMENTS: WID: ID of the window to change its color X: Width to apply to the window Y: Height to apply to the window
SET_SIZE WID,X,Y
Since v1.0.1

Utilities

"BTN_BOX()" Function that draws a button, and returns TRUE if the user clicks the button (BUTTON(3)). ARGUMENTS: X: Position on the X axis to place the button. Y: Position on the Y axis to place the button. W: Width of the button, in pixels. H: Height of the button, in pixels. PLACEHOLDER$: Text to draw inside the button. CRX: Cursor X coordinates. This is generated by GETPOINTERXY. CRY: Cursor Y coordinates. This is generated by GETPOINTERXY.
A=BTN_BOX(X,Y,W,H,PLACEHOLDER$,CRX,CRY)
EXAMPLES: Since BTN_BOX() returns TRUE when clicked, if you want to trigger an action it would be like this.
IF BTN_BOX(X,Y,W,H,PLACEHOLDER$,CRX,CRY) THEN
 'User clicked the button
ENDIF
"SPAWN_ALERT" Function that spawn an Alert window, showing the provided message and title. ARGUMENTS: WID: ID of the window that invoked the alert. TITLE$: Title of the Alert window. MESSAGE$: Message to show on the window.
SPAWN_ALERT WID, TITLE$, MESSAGE$
"SPAWN_TEXTFORM" Function that spawn a simple text form. The result of the form is stored at position 255 of the window that invoked the form. ARGUMENTS: WID: ID of the window that invoked the alert. PLACEHOLDER$: Text above the form that serves as a guide.
SPAWN_TEXTFORM WID, PLACEHOLDER$
EXAMPLES: When submitted, the text of the form is stored on position 255 of the window that invoked the form. For example, if the window that invoked the form is 5, the result will be stored on VARS_STR$[5,255]. To check if the form was submitted or not, just simply check if VARS_STR$[WID,255] has something:
IF LEN(VARS_STR$[WID,255]) THEN
 'User submitted the form
ENDIF

Cursor functions

"CURSOR_DEFAULT" Change the graphics of the cursor to its default graphic (pointer). ARGUMENTS: none
CURSOR_DEFAULT
"CURSOR_CLICKABLE" Change the graphics of the cursor to a pointing hand. Useful to indicate links and buttons. ARGUMENTS: none
CURSOR_CLICKABLE
"CURSOR_TEXT" Change the graphics of the cursor to a text selector. ARGUMENTS: none
CURSOR_TEXT
"GETPOINTERXY" Returns the XY coordinates of the cursor on screen. ARGUMENTS: none
GETPOINTERXY OUT X, Y

App globals

"VARS_NUM" Gets/sets information for the app to use outside the DEFs, this one holds numeric (either int of float). VARS_NUM is a 2D array which can be conveniently used by apps to store data. APP_WINDOW_DESTROY resets all the data from the window. Up to 256 slots can be used by a single app. ARGUMENTS: ID: ID of the window. SLOT: slot to set or get data from.
VARS_NUM[ID,SLOT]
EXAMPLES:
'Get data from slot 0
VAR L=VARS_NUM[ID,0]

'Set data to slot 0
VARS_NUM[ID,0]=L
"VARS_STR$" Gets/sets information for the app to use outside the DEFs, this one holds strings. VARS_STR$ is a 2D array which can be conveniently used by apps to store data. APP_WINDOW_DESTROY resets all the data from the window. Up to 256 slots can be used by a single app. ARGUMENTS: ID: ID of the window. SLOT: slot to set or get data from.
VARS_STR$[ID,SLOT]
EXAMPLES:
'Get data from slot 0
VAR D$=VARS_STR$[ID,0]

'Set data to slot 0
VARS_NUM$[ID,0]=D$
"VARS_ARRAY_ALLOC()" Allocates memory on the system to generate an array. Returns TRUE if the operation was successfull, FALSE if the memory could not be allocated. The array allocation should be used in conjuction with ON_OPEN(), since you need to allocate the array just one time. ARGUMENTS: ID: ID of the window. VNUM: VARS_NUM slot to use as a reference to the array. ARRAY: Type of array to initialize
VARS_ARRAY_ALLOC(ID,VNUM,ARRAY)
EXAMPLES:
DIM ARR[10,10]
IF VARS_ARRAY_ALLOC(WID,5,ARR) THEN
 'Memory allocated successfully, now we can retrieve the array anytime we want
ELSE
 GPUTCHR STARTX,STARTY,"The memory could not be allocated", #BLACK
ENDIF
Since v1.0.1
"VARS_ARRAY()" Retrieves the array allocated by the window app. ARGUMENTS: ID: ID of the window. VNUM: VARS_NUM slot that was used as a reference in VARS_ARRAY_ALLOC()
VARS_ARRAY(ID,VNUM)
EXAMPLES:
DIM D
D=VARS_ARRAY(WID,1)

'Now we can manipulate the array as we please.

INC D[0,0]

GPUTCHR STARTX,STARTY,STR$(D[0,0]),#BLACK

'There's no need to re-allocate the array once the app cycle ends
'The code above prints on each cycle:
'1,2,3,4,5,6,7,8,9...
Since v1.0.1

System globals

"__ABTN2" Variable that is used to get information from the buttons, regardless of the lag. EXAMPLES:
IF __ABTN2==#L THEN
 'Enters here if user clicks.
ENDIF
"__WINDOW_STYLE" Boolean that enables/disables Window Fast Draw. Window Fast Draw is a mode that draws windows on a minimalistic way with less instructions. Can improve perfomace by a bit.
"__WINDOW_SOUND" Boolean that enables/disables sounds when opening and closing apps.
"__KEYBOARD_SOUND" Boolean that enables/disables sounds when touching the keyboard.
"__STICKACTIVE" Boolean that enables/disables cursor movement with the left stick.
"__BCK_CL" Variable that handles the color of the background.
"__SYSTEMSHUT" Variable that tells Midori to shut down. Depending on the value, it can either shutdown or reset. EXAMPLES:
__SYSTEMSHUT=1 'Shutdown
__SYSTEMSHUT=2 'Restart
"__LC" Variable that holds the button ID that will act as Left Click.
"__RC" Variable that holds the button ID that will act as Right Click.
"__ENTER" Variable that holds the button ID that will act as Enter.
"__DEL" Variable that holds the button ID that will act as Delete.

No posts yet (will you be the first?)