Component View

Table of contents
  1. Introduction
  2. Properties
    1. Event handler
      1. Mouse movement events
      2. Mouse interaction events
      3. Key events
      4. Drag events
  3. Functions

Introduction

ComponentView is the abstract baseclass of all framework /components. It defines important fields and functions that are necessary to visualize inheriting /components. Most fields come as a pair of attribute and observable property.

Properties

posX: Double/posXProperty: DoubleProperty: The horizontal position.

posY: Double/posYProperty: DoubleProperty: The vertical position.

width: Double/widthProperty: DoubleProperty: The width.

height: Double/heightProperty: DoubleProperty: The height.

scaleX: Double/scaleXProperty: DoubleProperty: The horizontal scale

scaleY: Double/scaleYProperty: DoubleProperty: The vertical scale

scale: Double: Scale of this component. Setter sets both scaleX and scaleY. Getter returns scale if scaleX == scaleY or throws an IllegalStateException if scaleX and scaleY differ.

rotation: Double/rotationProperty: DoubleProperty: Rotation of this component in degrees. Between 0 (incl.) and 360 (excl.).

visual: Visual/visualProperty: Property<Visual>: The current Visual. Read more about Visuals here.

opacity: Double/opacityProperty: DoubleProperty: The current opacity. Must be in range 0.0 to 1.0. 0.0 corresponds to 0% opacity, where 1.0 corresponds to 100% opacity.

isVisible/isVisibleProperty: BooleanProperty: Visibility of this component. Visible /components may still be opaque due to opacity property.

Note that invisible /components no longer trigger mouse click events, /components with opacity = 0.0 still do.

isDisabled: Boolean/isDisabledProperty: BooleanProperty:Controls if user input events cause input functions of this component to get invoked

isFocusable: Boolean/isFocusableProperty: BooleanProperty: Controls whether this component is focusable or not.

name: String: Name field only for debugging purposes. Has no effect on rendering. Use this to label /components for easier debugging and printing

parent: ComponentView?: The parent of this ComponentView. Its value is null if the component is not contained in any GameComponentContainer, LayoutView, or a Scene. If the component has been added directly to a scene, parent is equal to the scene’s RootComponent.

Event handler

Event handlers et called by the framework if the associated event happened. Handlers can be assigned like attribute values. To remove a handler assign null. Read more about this topic here.

Mouse movement events

onMouseEntered: ((MouseEvent) -> Unit)?: Gets invoked when the mouse enters this component.

onMouseExited: ((MouseEvent) -> Unit)?: Gets invoked when the mouse leaves this component.

Mouse interaction events

onMousePressed: ((MouseEvent) -> Unit)?:Gets invoked when the mouse is pressed inside this component.

onMouseReleased: ((MouseEvent) -> Unit)?:Gets invoked when the mouse is released inside this component.

onMouseClicked: ((MouseEvent) -> Unit)?:Gets invoked when the mouse is clicked, i.e. pressed and released, inside this component.

Note: The MouseEvent’s button attribute always contains the mouse button.

Key events

onKeyPressed: ((KeyEvent) -> Unit)?:Gets invoked when a keyboard key is pressed while this component has focus.

onKeyReleased: ((KeyEvent) -> Unit)?:Gets invoked when a keyboard key is released while this component has focus.

onKeyTyped: ((KeyEvent) -> Unit)?:Gets invoked when a keyboard key is typed, i.e. pressed and released, while this component has focus.

Note: The KeyEvent always contains the key combination.

Drag events

Read more about drag and drop here

onDragGestureEntered: ((DragEvent) -> Unit)?: Gets invoked with a DragEvent containing the dragged component when the mouse enters this component while dragging.

onDragGestureExited: ((DragEvent) -> Unit)?: Gets invoked with a DragEvent containing the dragged component when the mouse leaves this component while dragging.

onDragDropped: ((DragEvent) -> Unit)?: Gets invoked with a DragEvent containing the dragged component after a successful drag and drop gesture.

dropAcceptor: ((DragEvent) -> Boolean)?: Gets invoked when a dragged component was released inside this component. Implement this function in such a way that it returns true if this component accepts the drop of the given component, passed with the DragEvent,, or false if a drop is not valid. The dragged component will snap back if all available drop targets return false. It is advised not to modify the Scene or its children in this function. The modification, for example adding the component to a container should be done in onDragDropped as this function only gets invoked if this dropAccessor returns true.

Functions

reposition(posX: Number, posY: Number): Repositions this component to the specified coordinates. To move it with an animation refer to the MovementAnimation tutorial here.

offset(offsetX: Number, offsetY: Number): Moves this component by relative offset. To move it with an animation refer to the MovementAnimation tutorial here.

rotate(degrees: Number): Rotates this component by the given number of degrees. To rotate it with an animation refer to the RotationAnimation tutorial here.

resize(width: Number, height: Number): Resizes this component to the specified dimensions.

scale(scalar: Number): Scales this component by given scalar.

scaleX(scalar: Number): Scales this component’s width by given scalar.

scaleY(scalar: Number): Scales this component’s height by given scalar.

removeFromParent(): ComponentView: Removes this component from its parent. Returns the former parent. Throws an IllegalStateException if the parent was null, i.e. this component was not contained in any scene.