Skip to content
GhostglowDev edited this page Mar 21, 2024 · 2 revisions
local wnd = require "ghostutil.window"

See source code

Funfact: This is the biggest class in GhostUtil

This was not fun to make

For eases, check out FlxEase

Variables

  • defaultDimensions:Array<Int> =
{
    width = 1280, 
    height = 720
}
  • desktopDimensions:Array[Int] - Stores your desktop's width and height

Functions: Tweens

windowTweenX(tag:String, value:Float, duration:Float, ?ease:String) -> Void

Tweens the window's x position

  • tag: For pausing/resuming, cancelling and for onTweenCompleted()
  • value: The window's target x position
  • duration: The duration it takes to complete (in seconds)
  • ease: FlxEase

Example:

wnd.windowTweenX("windowx", 780, 3, "expoOut")

windowTweenY(tag:String, value:Float, duration:Float, ?ease:String) -> Void

Tweens the window's y Position

  • tag: For pausing/resuming, cancelling and for onTweenCompleted()
  • value: The window's target y position
  • duration: The duration it takes to complete (in seconds)
  • ease: FlxEase

Example:

wnd.windowTweenY("windowy", 525, 3, "expoOut")

windowTweenPosition(tag:String, value:Array<Float>|Float, duration:Float, ?ease:String) -> Void

Tweens the Application Y Position

  • tag: For pausing/resuming, cancelling and for onTweenCompleted()
  • value: The window's target y position. If the values are both the same, use Float instead.
  • duration: The duration it takes to complete (in seconds)
  • ease: FlxEase

Example:

-- {x: 100, y: 600}
wnd.windowTweenPosition("hello", {100, 600}, 3, "expoOut")

-- {x, y: 500}
wnd.windowTweenPosition("world", 500, 2, "expoOut")

tweenToCenter(tag:String, axis:String, duration:Float, ?ease:String) -> Void

Centers the window with tweens

  • tag: For pausing/resuming, cancelling and for onTweenCompleted()
  • axis: "xy", "x" or "y".
  • duration: The duration it takes to complete (in seconds)
  • ease: FlxEase

Example:

-- Centers the window on both axis
wnd.tweenToCenter("centerwindow", "xy", 3, "expoOut")

-- Centers the window only on the x axis
wnd.tweenToCenter("centerwindow", "x", 3, "expoOut")

tweenResizeTo(tag:String, dimensions:Array<Float>|Float, duration:Float, ?ease:String) -> Void

Tweens the Application size

  • tag: For pausing/resuming, cancelling and for onTweenCompleted()
  • dimensions: The width and height in table. If both values are the same, use Float instead.
  • duration: The duration it takes to complete (in seconds)
  • ease: FlxEase

Example:

-- Sets the window dimension to a 720x720px square
wnd.tweenResizeTo("windowsize", 720, 3, "expoOut")

-- Sets the window dimension to the default
wnd.tweenResizeTo("windowsize", {
    wnd.defaultDimensions.width,
    wnd.defaultDimensions.height
}, 3, "expoOut")

Pause / Resume / Cancel Tween

pauseTween(tag:String) -> Void

Pauses a tween that is currently active.

resumeTween(tag:String) -> Void

Resumes a tween that is currently paused.

cancelTween(tag:String) -> Void

Cancels a window tween.

  • tag: Window tween tag

Example:

function onCreatePost()
    wnd.windowTweenX("windowtest", wnd.desktopDimensions.width / 1.2, 8, "smootherStepInOut")
end

function onSongStart()
    wnd.pauseTween("windowtest")
end

function onStepHit()
    if curStep == 32 then
        wnd.resumeTween("windowtest")
    end
end

-- Plays a tween onCreatePost and pausing it onSongStart.
-- Resumes on step 32

Functions: General

close() -> Void

Closes the window

Example:

wnd.close()

setPosition(position:Array<Float>|Float) -> Void

Sets the window's position

  • position: The new position in a table. If both values are the same, use Float instead.

Example:

-- {x: 0, y: 100}
wnd.setPosition({0, 100})

-- {x, y: 10}
wnd.setPosition(10)

screenCenter(axis:String) -> Void

Centers the window

  • axis: "xy", "x" or "y".

Example:

wnd.screenCenter("xy")

resizeTo(dimensions:Array<Float>|Float) -> Void

Resizes the window to a certain height and width.

Self-explanatory. If both values are the same, use Float instead.

Example:

-- {width, height = 720}
wnd.resizeTo(720)

alert(title:String, message:String) -> Void

Creates a new window alert

  • title: Alert window's Title

  • message: Alert window's message

  • Use \n to create a new line

Example:

wnd.alert("Thank you", "Thanks for using GhostUtil! :D")

changeTitle(?title:String) -> Void

Changes the application title

  • title: Application title (When empty, it will set the title back to Friday Night Funkin': Psych Engine")

Example:

wnd.changeTitle("Friday Night Funkin': Testing Ghost's Utilities")

focus() -> Void

Focuses the current window.

Example:

Should be self-explanatory

createWindow(windowName:String, ?attributes:Array<Dynamic>, ?closeOnDestroy:Bool = true) -> Void

Creates a new window

  • windowName: Used for accessing the new window in runHaxeCode.
  • attributes: The attributes for the new window. (All values are optional)
{
    position:Array<Float>,
    dimensions:Array<Float>,
    title:String,
    resizable:Bool, 
    minimized:Bool, 
    maximized:Bool, 
    fullscreen:Bool
    borderless:Bool,
    alwaysOnTop:Bool  
}
  • closeOnDestroy: Should the window close when you exit the song, die, etc.

Example:

function onCreatePost()
    wnd.createWindow("bob", {
        {100, 100}, -- x, y
        {720, 720}, -- width, height
        "hi im bob" -- title
        -- unnecessary values are not included
    });
end

setProperty(variable:String, value:Dynamic) -> Void

setProperty(), for window.

  • variable: The name of the window property
  • value: New value

Variables:

  • borderless (Bool)
  • height (Float)
  • width (Float)
  • x (Float)
  • y (Float)
  • fullscreen (Bool)
  • title (String)
  • resizable / canResize (Bool)

Example:

wnd.setProperty("borderless", true)

getProperty(variable:String) -> Dynamic

getProperty(), for window.

  • variable: The name of the window property to fetch

Variables:

  • borderless (Bool)
  • height (Float)
  • width (Float)
  • x (Float)
  • y (Float)
  • fullscreen (Bool)
  • title (String)
  • resizable / canResize (Bool)

Example:

wnd.getProperty("x")
Clone this wiki locally