KCL: Windowing Classes

From Spheriki

Jump to: navigation, search

The KCL (Kamatsu's Class Library) includes a set of objects that handle basic window drawing functions, as well as message prompts, within the kclWindowClasses.js file.

The following classes are included:

  • Window - Ultimate Superclass
    is inherited by:
    • ImageWindow - Window containing an image
    • TextWindow - Window containing text
      is inherited by:
      • MessageWindow - RPG-style message prompt.


Contents

Window Class

The window class is rarely used of itself, but rather provides a superclass from which other windows can inherit.

Defining

To create a new Window instance, use:

var myWindow = new Window(x,y,w,h,windowstyle);

where:

  • x,y (optional) - initial coordinates of the window
  • w,h (optional) - initial dimensions of the window
  • windowstyle (optional) - Windowstyle to use. Defaults to Game.windowStyle.

Properties

  • background (rw) - This is a KCL background property. Default is BACKGROUND_NONE. It controls what is blitted to screen before the element is blitted. can be one of the following values:
    • BACKGROUND_NONE - Nothing is blitted by the object beforehand.
    • BACKGROUND_RENDERMAP - RenderMap() is called by the object before blitting.
    • An Image or Surface to blit as a background.
  • x,y (rw) - Coordinates of the window
  • w,h (rw) - Dimensions of the window
  • style (rw) - Windowstyle to use. Defaults to Game.windowStyle.
  • margin (rw) - Margin of the window to it's bounding box. Useful for spacing in scenes.
  • opacity (rw) - Value of 0 - 255 determining the opacity of window blitting.
  • visible (rw) - Whether or not to blit the window when .redraw() is called.
  • animInc (rw) - The rate of change (per frame) for the show/hide animations.
  • animSpeed (rw) - The fps for the show/hide animations.
  • introAnim (rw) - Animation to use for when the window is shown. While others can be defined, this defaults to either:
    • WINDOWANIM_GROW - Make the window unfold from its center
    • WINDOWANIM_FADE - Fading animation
    • WINDOWANIM_NONE - Do not animate the window
  • outtroAnim (rw) - Animation to use for when the window is hidden. While others can be defined, this defaults to either:
    • WINDOWANIM_GROW - Make the window collapse to its center
    • WINDOWANIM_FADE - Fading animation
    • WINDOWANIM_NONE - Do not animate the window
  • flipScreen (rw) - Boolean value specifying whether or not to call FlipScreen(); when .update() is called.
  • preRender (rw) - First class function (i.e, a function passed as an object) that is called before the window is drawn.
  • postRender (rw) - First class function (i.e, a function passed as an object) that is called after the window is drawn.

Example of preRender and postRender

var a = new Window();
a.preRender = function () {
 // Do some stuff
}
a.postRender = function () {
 // Do some other stuff
}

Methods

Common Methods

Window.show()

Shows the window, displaying any animation specified in the .introAnim property via a call to the internal .runAnim() function.

This will set the visible property of the instance to true and make it display when .update() is called.


Window.hide()

Shows the window, displaying any animation specified in the .outtroAnim property via a call to the internal .runAnim() method.

This will set the visible property of the instance to false and make it not be drawn when .update() is called.


Window.update()

The primary operation of the update() function is threefold:

  • Draw the background (via a call to the internal .drawBackground() method), then call the .preRender if supplied.
  • Draw the window at the specified opacity.
  • Call the .postRender function if supplied, and, if .flipScreen is true, call sphere's FlipScreen()

Mostly Internal Methods

Window.runAnim(animName,reverse)

Executes an animation.


Parameters:

  • animName - Animation to use:
    • WINDOWANIM_GROW
    • WINDOWANIM_FADE
    • (user defined ones)
  • reverse - Boolean value specifying if the animation is to be reversed (i.e an outtro).

Note: The .preRender and .postRender properties are called while redraws in animations run.

Window.drawBackground()

Draws the background based on the .background property.

Window.redraw()

Draws the window at specified opacity with specified margin to bounding box.

Window.initialize()

Initializes particular window properties for animations. Called before .runAnim()

TextWindow Class (inherits from Window)

Defining

Properties

Methods

ImageWindow Class (inherits from Window)

Defining

To create a new Window instance, use:

var myWindow = new ImageWindow(image,imageAlignment,x,y,w,h,windowstyle);

where:

  • image - Image or surface to use within the window.
  • imageAlignment - A KCL alignment property. Can be one of the following:
    • ALIGNMENT_TOPLEFT
    • ALIGNMENT_TOPRIGHT
    • ALIGNMENT_TOPCENTER
    • ALIGNMENT_BOTTOMLEFT
    • ALIGNMENT_BOTTOMRIGHT
    • ALIGNMENT_BOTTOMCENTER
    • ALIGNMENT_MIDDLELEFT
    • ALIGNMENT_MIDDLERIGHT
    • ALIGNMENT_MIDDLECENTER
  • x,y (optional) - initial coordinates of the window
  • w,h (optional) - initial dimensions of the window
  • windowstyle (optional) - Windowstyle to use. Defaults to Game.windowStyle.


Properties

This class includes all the properties inherited from the Window class, as well as the following properties:
  • image (rw) - The Image or Surface displayed within the window.
  • imageLeftPadding, imageRightPadding, imageTopPadding, imageBottomPadding (rw) - Padding in pixels from the window border to the image.
  • imageOpacity (rw) - Opacity (0-255) with which to blit the image.
  • imageAlignment (rw) - A KCL alignment property. Can be one of the following:
    • ALIGNMENT_TOPLEFT
    • ALIGNMENT_TOPRIGHT
    • ALIGNMENT_TOPCENTER
    • ALIGNMENT_BOTTOMLEFT
    • ALIGNMENT_BOTTOMRIGHT
    • ALIGNMENT_BOTTOMCENTER
    • ALIGNMENT_MIDDLELEFT
    • ALIGNMENT_MIDDLERIGHT
    • ALIGNMENT_MIDDLECENTER
  • imageVisible (rw) - Boolean value that determines whether or not the image is drawn within the window.

Methods

This class includes all the methods inherited from the Window Class, and does not include any additional methods.

MessageWindow Class (inherits from TextWindow)

Defining

Properties

Method

Example

Personal tools