net.ctdp.rfdynhud.widgets.base.widget
Class Widget

java.lang.Object
  extended by net.ctdp.rfdynhud.widgets.base.widget.Widget
All Implemented Interfaces:
java.lang.Cloneable, PropertiesKeeper
Direct Known Subclasses:
InternalWidget, NeedleMeterWidget, StatefulWidget

public abstract class Widget
extends java.lang.Object
implements java.lang.Cloneable, PropertiesKeeper

This is the base for all Widgets to be drawn on the HUD.
Any concrete extension must have a parameterless constructor.

Author:
Marvin Froehlich (CTDP)

Field Summary
static LogChannel LOG_CHANNEL
           
static int NEEDED_DATA_ALL
           
static int NEEDED_DATA_SCORING
           
static int NEEDED_DATA_TELEMETRY
           
 
Constructor Summary
protected Widget(WidgetSet widgetSet, WidgetPackage widgetPackage, float width, boolean widthPercent, float height, boolean heightPercent)
          Creates a new Widget.
protected Widget(WidgetSet widgetSet, WidgetPackage widgetPackage, float width, float height)
          Creates a new Widget.
 
Method Summary
protected  void addBackgroundPropertyToContainer(PropertiesContainer propsCont, boolean forceAll)
          Adds the background property to the container.
protected  void addBorderPropertyToContainer(PropertiesContainer propsCont, boolean forceAll)
          Adds the border property to the container.
protected  void addFontPropertiesToContainer(PropertiesContainer propsCont, boolean forceAll)
          Adds the font and font color properties to the container.
protected  void addPaddingPropertiesToContainer(PropertiesContainer propsCont, boolean forceAll)
          Adds the padding properties to the container.
protected  void addPositionAndSizePropertiesToContainer(PropertiesContainer propsCont, boolean forceAll)
          Adds the position and size properties to the PropertiesContainer.
protected  void addTypeAndNamePropertiesToContainer(PropertiesContainer propsCont, boolean forceAll)
          Adds the type and name properties to the PropertiesContainer.
protected  void addVisibilityPropertiesToContainer(PropertiesContainer propsCont, boolean forceAll)
          Adds the visibility properties to the PropertiesContainer.
 void afterConfigurationLoaded(WidgetsConfiguration widgetsConfig, LiveGameData gameData, boolean isEditorMode)
          This event is fired right after the WidgetsConfiguration has been (re-)loaded.
 void bake(boolean convertToPixels)
          Bakes effective position and size to variables, so that they don't need to be recalculated during runtime on each access.
 void beforeConfigurationCleared(WidgetsConfiguration widgetsConfig, LiveGameData gameData, boolean isEditorMode)
          This event is fired right before the WidgetsConfiguration is cleared.
protected  boolean canHaveBackground()
          Defines, if this Widget type can have a background.
protected  boolean canHaveBorder()
          Defines, if this Widget type can have a border.
protected  boolean checkForChanges(LiveGameData gameData, boolean isEditorMode, TextureImage2D texture, int width, int height)
          Checks, if the Widget needs any changes before it is drawn.
 boolean clearBackgroundRegion(TextureImage2D texture, int offsetX, int offsetY, int localX, int localY, int width, int height, boolean markDirty, Rect2i dirtyRect)
          Clears the given part of the Widget area with the current background.
 void clearRegion(TextureImage2D texture, int offsetX, int offsetY)
          Clears the region on the texture, that is covered by this Widget.
protected  void clearRegion(TextureImage2D texture, int offsetX, int offsetY, int width, int height)
           
 Widget clone()
           
protected  boolean cloneProperty(Property src, Property trg)
          Clones the value of the src property to the trg property.
protected  void debug(java.lang.Object... data)
          Logs data to the plugin's log file.
protected  void debugCS(java.lang.Object... data)
          Logs data to the plugin's log file.
protected  void drawBackground(LiveGameData gameData, boolean isEditorMode, TextureImage2D texture, int offsetX, int offsetY, int width, int height, boolean isRoot)
          You can use this method to directly draw static content onto your Widget's background.
protected  void drawBorder(boolean isEditorMode, BorderWrapper border, TextureImage2D texture, int offsetX, int offsetY, int width, int height)
           
 void drawWidget(Clock clock, boolean completeRedrawForced, LiveGameData gameData, boolean isEditorMode, TextureImage2D texture, boolean drawAtZero)
          This method invokes the parts of the actual drawing code for this Widget.
protected abstract  void drawWidget(Clock clock, boolean needsCompleteRedraw, LiveGameData gameData, boolean isEditorMode, TextureImage2D texture, int offsetX, int offsetY, int width, int height)
          This method must contain the actual drawing code for this Widget.
 void forceAndSetDirty(boolean mergedBackgroundToo)
          This simply calls forceCompleteRedraw(boolean), forceReinitialization() and setDirtyFlag().
 void forceCompleteRedraw(boolean mergedBackgroundToo)
          Forces a complete redraw on the next render.
 void forceReinitialization()
           
 int getAbsoluteOffsetX()
          Gets the absolute x-position relative to the configuration origin.
 int getAbsoluteOffsetY()
          Gets the absolute y-position relative to the configuration origin.
 boolean getAutoVisibility()
          Gets the automatically toggled visibility flag.
 WidgetBackground getBackground()
          Gets the Widget's background.
 BackgroundProperty getBackgroundProperty()
           
 BorderWrapper getBorder()
          Returns a BorderWrapper, that encapsulates the actual used border with convenience wrappers for the size getters.
protected  BorderProperty getBorderProperty()
           
 WidgetsConfiguration getConfiguration()
          Gets the WidgetsConfiguration, this Widget is a member of.
 java.lang.String getDefaultBorderValue(java.lang.String name)
          Gets the default value for the given border alias/name.
 java.lang.String getDefaultNamedColorValue(java.lang.String name)
          Gets the default value for the given named color.
 java.lang.String getDefaultNamedFontValue(java.lang.String name)
          Gets the default value for the given named font.
 boolean getDirtyFlag(boolean reset)
           
 java.lang.String getDocumentationSource()
           
protected  DrawnStringFactory getDrawnStringFactory()
          Gets the Widget's DrawnStringFactory.
 int getEffectiveHeight()
          Gets the result of getSize().getEffectiveHeight().
 int getEffectiveWidth()
          Gets the result of getSize().getEffectiveWidth().
protected  java.awt.Font getFont()
           
protected  java.awt.Color getFontColor()
          Gets the Widget's font color.
 ColorProperty getFontColorProperty()
           
 FontProperty getFontProperty()
           
protected  java.lang.String getInitialBackground()
          Gets the initial value for the background property.
 InnerSize getInnerSize()
          Gets the inner size of the Widget.
 InputAction[] getInputActions()
          Gets the InputActions, that can be bound with a Widget of this type.
 boolean getInputVisibility()
          Gets this Widget's visibility usually controlled by the ToggleWidgetVisibility InputAction.
 AbstractAssembledWidget getMasterWidget()
          If this Widget is part of an AbstractAssembledWidget, this master Widget is returned.
 int getMaxHeight(LiveGameData gameData, boolean isEditorMode)
          Gets the maximum height covered by this Widget.
 int getMaxWidth(LiveGameData gameData, boolean isEditorMode)
          Gets the maximum width covered by this Widget.
 int getMinHeight(LiveGameData gameData, boolean isEditorMode)
          Gets the minimum height for this Widget in pixels.
 int getMinWidth(LiveGameData gameData, boolean isEditorMode)
          Gets the minimum width for this Widget in pixels.
 java.lang.String getName()
          Gets this Widget's name.
 int getNeededData()
          Gets the data indicators for the data needed for this Widget to be drawn (bitmask).
protected  Widget getNewInstanceForClone()
           
 int getOffsetXToRootMasterWidget()
          Gets the x-offset relative to the master Widget.
 int getOffsetYToRootMasterWidget()
          Gets the y-offset relative to the master Widget.
protected  int getPaddingBottom()
           
protected  int getPaddingLeft()
           
protected  IntProperty getPaddingPropertyBottom()
           
protected  IntProperty getPaddingPropertyLeft()
           
protected  IntProperty getPaddingPropertyRight()
           
protected  IntProperty getPaddingPropertyTop()
           
protected  int getPaddingRight()
           
protected  int getPaddingTop()
           
 Position getPosition()
          Gets the Widget's position.
 void getProperties(PropertiesContainer propsCont, boolean forceAll)
          Puts all editable properties to the editor.
protected  void getPropertiesForParentGroup(PropertiesContainer propsCont, boolean forceAll)
          Puts all editable properties to the editor.
 java.util.Iterator<Property> getPropertiesIterator()
          Gets an Iterator to iterate all properties, defined in this class.
 Size getSize()
          Gets this Widget's size.
 TransformableTexture[] getSubTextures(LiveGameData gameData, boolean isEditorMode, int widgetInnerWidth, int widgetInnerHeight)
          Gets the TransformableTextures, that this Widget keeps.
 boolean getUpdatedVisibility()
          Gets this Widget's user visibility flag 2.
 WidgetController getWidgetController()
           
 WidgetPackage getWidgetPackage()
          Gets the package to group the Widget in the editor.
 WidgetSet getWidgetSet()
          Gets the WidgetSet this Widget belongs to.
 int getZIndex()
          Gets the Widget's z-index relative to other Widgets in the same configuration.
protected  boolean hasBorder()
          Gets whether this Widget has a border or not.
 boolean hasFixedSize()
          Gets, whether this Widget has a fixed (unmodifiable) size.
 boolean hasMasterCanvas(boolean isEditorMode)
          Returns true, if this Widget draws on the main texture, false otherwise.
protected  boolean hasText()
          Defines, if a Widget type (potentially) contains any text.
protected abstract  void initialize(LiveGameData gameData, boolean isEditorMode, DrawnStringFactory drawnStringFactory, TextureImage2D texture, int width, int height)
          This method is called once to initialized DrawnStrings used on this Widget.
protected abstract  void initSubTextures(LiveGameData gameData, boolean isEditorMode, int widgetInnerWidth, int widgetInnerHeight, SubTextureCollector collector)
          Gets the TransformableTextures, that this Widget keeps.
protected  boolean isFontAntiAliased()
           
 boolean isVisible()
          Gets this Widget's total visibility flag (getInputVisibility() && getAutoVisibility() && getUpdatedVisibility()).
 void loadProperty(PropertyLoader loader)
          Loads (and parses) a certain property from a config file.
protected  void log(LogLevel logLevel, java.lang.Object... data)
          Logs data to the plugin's log file.
protected  void log(java.lang.Object... data)
          Logs data to the plugin's log file.
protected  void logCS(LogLevel logLevel, java.lang.Object... data)
          Logs data to the plugin's log file.
protected  void logCS(java.lang.Object... data)
          Logs data to the plugin's log file.
protected  void onBackgroundChanged(boolean imageChanged, float deltaScaleX, float deltaScaleY)
          This method is invoked when the background has changed.
protected  java.lang.Boolean onBoundInputStateChanged(InputAction action, boolean state, int modifierMask, long when, LiveGameData gameData, boolean isEditorMode)
          This event is fired, when a bound input component has changed its state.
protected  void onCanvasSizeChanged()
           
protected  void onCompleteRedrawForced()
          This method is called when a complete redraw has been forced.
protected  void onDirtyFlagSet()
           
 void onGarageEntered(LiveGameData gameData, boolean isEditorMode)
          This method is called when a the car entered the garage.
 void onGarageExited(LiveGameData gameData, boolean isEditorMode)
          This method is called when a the car exited the garage.
 void onLapStarted(VehicleScoringInfo vsi, LiveGameData gameData, boolean isEditorMode)
          This method is called when a lap has been finished and a new one was started.
 void onNeededDataComplete(LiveGameData gameData, boolean isEditorMode)
          This method is called when the needed data is available in realtime mode.
 void onPitsEntered(LiveGameData gameData, boolean isEditorMode)
          This method is called when a the car entered the pits.
 void onPitsExited(LiveGameData gameData, boolean isEditorMode)
          This method is called when a the car exited the pits.
protected  void onPositionChanged(RelativePositioning oldPositioning, int oldX, int oldY, RelativePositioning newPositioning, int newX, int newY)
           
 void onPropertyChanged(Property property, java.lang.Object oldValue, java.lang.Object newValue)
          Invoked when a kept Property has changed.
 void onRealtimeEntered(LiveGameData gameData, boolean isEditorMode)
          This method is called when a the user entered realtime mode.
 void onRealtimeExited(LiveGameData gameData, boolean isEditorMode)
          This method is called when a the user exited realtime mode.
protected  void onReinitializationForced()
           
 void onScoringInfoUpdated(LiveGameData gameData, boolean isEditorMode)
          This method is called when ScoringInfo have been updated (done at 2Hz).
 void onSessionStarted(SessionType sessionType, LiveGameData gameData, boolean isEditorMode)
          This method is executed when a new session was started.
protected  void onSizeChanged(int oldWidth, int oldHeight, int newWidth, int newHeight)
           
 void onTrackChanged(java.lang.String trackname, LiveGameData gameData, boolean isEditorMode)
          This method is executed when a new track was loaded.
protected  java.lang.Boolean onVehicleControlChanged(VehicleScoringInfo viewedVSI, LiveGameData gameData, boolean isEditorMode)
          This method is called when either the player's vehicle control has changed or another vehicle is being viewed.
 void onVehicleSetupUpdated(LiveGameData gameData, boolean isEditorMode)
          This method is called when VehicleSetup has been updated.
protected  void onVisibilityChanged(boolean visible)
           
 void prepareForMenuItem()
          This method is called by the editor before it draws the Widget to a menu item.
 void saveProperties(PropertyWriter writer)
          Saves all settings to the config file.
 void setAllPosAndSizeToPercents()
           
 void setAllPosAndSizeToPixels()
           
 void setDirtyFlag()
           
 void setName(java.lang.String name)
          Sets this Widget's name.
protected  void setPadding(int top, int left, int right, int bottom)
          Sets padding for this Widget.
 void setWidgetController(WidgetController controller)
           
 void setZIndex(int zIndex)
          Sets the Widget's z-index relative to other Widgets in the same configuration.
protected  java.lang.Boolean updateVisibility(LiveGameData gameData, boolean isEditorMode)
          This method is called first by the rendering system each to check for visibility changes.
 boolean visibilityChangedSinceLastDraw()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG_CHANNEL

public static final LogChannel LOG_CHANNEL

NEEDED_DATA_TELEMETRY

public static final int NEEDED_DATA_TELEMETRY
See Also:
Constant Field Values

NEEDED_DATA_SCORING

public static final int NEEDED_DATA_SCORING
See Also:
Constant Field Values

NEEDED_DATA_ALL

public static final int NEEDED_DATA_ALL
See Also:
Constant Field Values
Constructor Detail

Widget

protected Widget(WidgetSet widgetSet,
                 WidgetPackage widgetPackage,
                 float width,
                 boolean widthPercent,
                 float height,
                 boolean heightPercent)
Creates a new Widget.

Parameters:
widgetSet - the WidgetSet this Widget belongs to
widgetPackage - the package in the editor
width - negative numbers for (screen_width - width)
widthPercent - width parameter treated as percents
height - negative numbers for (screen_height - height)
heightPercent - height parameter treated as percents

Widget

protected Widget(WidgetSet widgetSet,
                 WidgetPackage widgetPackage,
                 float width,
                 float height)
Creates a new Widget.

Parameters:
widgetSet - the WidgetSet this Widget belongs to
widgetPackage - the package in the editor
width - negative numbers for (screen_width - width)
height - negative numbers for (screen_height - height)
Method Detail

getInitialBackground

protected java.lang.String getInitialBackground()
Gets the initial value for the background property.

Returns:
the initial value for the background property.

onBackgroundChanged

protected void onBackgroundChanged(boolean imageChanged,
                                   float deltaScaleX,
                                   float deltaScaleY)
This method is invoked when the background has changed.

Parameters:
imageChanged - whether the image has changed
deltaScaleX - the x-scale factor in as a difference between the old background image and the new one or -1 of no background image was selected
deltaScaleY - the y-scale factor in as a difference between the old background image and the new one or -1 of no background image was selected

log

protected final void log(LogLevel logLevel,
                         java.lang.Object... data)
Logs data to the plugin's log file.

Parameters:
logLevel - the log level
data - the data to log

logCS

protected final void logCS(LogLevel logLevel,
                           java.lang.Object... data)
Logs data to the plugin's log file.

Parameters:
logLevel - the log level
data - the data to log (comma separated)

log

protected final void log(java.lang.Object... data)
Logs data to the plugin's log file.

Parameters:
data - the data to log

logCS

protected final void logCS(java.lang.Object... data)
Logs data to the plugin's log file.

Parameters:
data - the data to log (comma separated)

debug

protected final void debug(java.lang.Object... data)
Logs data to the plugin's log file.

Parameters:
data - the data to log

debugCS

protected final void debugCS(java.lang.Object... data)
Logs data to the plugin's log file.

Parameters:
data - the data to log (comma separated)

setWidgetController

public void setWidgetController(WidgetController controller)

getWidgetController

public final WidgetController getWidgetController()

onVisibilityChanged

protected void onVisibilityChanged(boolean visible)

onPropertyChanged

public void onPropertyChanged(Property property,
                              java.lang.Object oldValue,
                              java.lang.Object newValue)
Invoked when a kept Property has changed.

Specified by:
onPropertyChanged in interface PropertiesKeeper
Parameters:
property - the changed property
oldValue - the old value
newValue - the new value

onPositionChanged

protected void onPositionChanged(RelativePositioning oldPositioning,
                                 int oldX,
                                 int oldY,
                                 RelativePositioning newPositioning,
                                 int newX,
                                 int newY)
Parameters:
oldPositioning - the old value for the positioning
oldX - the old x
oldY - the old y
newPositioning - the new value for the positioning
newX - the new x
newY - the new y

onSizeChanged

protected void onSizeChanged(int oldWidth,
                             int oldHeight,
                             int newWidth,
                             int newHeight)
Parameters:
oldWidth - the old width
oldHeight - the old height
newWidth - the new width
newHeight - the new height

onCanvasSizeChanged

protected void onCanvasSizeChanged()

getWidgetSet

public final WidgetSet getWidgetSet()
Gets the WidgetSet this Widget belongs to.

Returns:
the WidgetSet this Widget belongs to.

getWidgetPackage

public final WidgetPackage getWidgetPackage()
Gets the package to group the Widget in the editor. This can be an null to be displayed in the root or a slash separated path.

Returns:
the package to group the Widget in the editor.

getDefaultBorderValue

public java.lang.String getDefaultBorderValue(java.lang.String name)
Gets the default value for the given border alias/name.

Parameters:
name - the border name to query
Returns:
the default value for the given border alias/name.

getDefaultNamedColorValue

public java.lang.String getDefaultNamedColorValue(java.lang.String name)
Gets the default value for the given named color.

Parameters:
name - the color name to query
Returns:
the default value for the given named color.

getDefaultNamedFontValue

public java.lang.String getDefaultNamedFontValue(java.lang.String name)
Gets the default value for the given named font.

Parameters:
name - the font name to query
Returns:
the default value for the given named font.

getConfiguration

public final WidgetsConfiguration getConfiguration()
Gets the WidgetsConfiguration, this Widget is a member of.

Returns:
the WidgetsConfiguration, this Widget is a member of.

getMasterWidget

public final AbstractAssembledWidget getMasterWidget()
If this Widget is part of an AbstractAssembledWidget, this master Widget is returned.

Returns:
the master AbstractAssembledWidget or null.

getInputActions

public InputAction[] getInputActions()
Gets the InputActions, that can be bound with a Widget of this type. "Override" this method to return your own custom actions.

Returns:
the InputActions, that can be bound with a Widget of this type.

initSubTextures

protected abstract void initSubTextures(LiveGameData gameData,
                                        boolean isEditorMode,
                                        int widgetInnerWidth,
                                        int widgetInnerHeight,
                                        SubTextureCollector collector)
Gets the TransformableTextures, that this Widget keeps.

Parameters:
gameData - the live game data
isEditorMode - rendering in the editor?
widgetInnerWidth - the total widget width excluding borders
widgetInnerHeight - the total widget height excluding borders
collector - the collector to collect all the sub textures

getSubTextures

public final TransformableTexture[] getSubTextures(LiveGameData gameData,
                                                   boolean isEditorMode,
                                                   int widgetInnerWidth,
                                                   int widgetInnerHeight)
Gets the TransformableTextures, that this Widget keeps.

Parameters:
gameData - the live game data
isEditorMode - rendering in the editor?
widgetInnerWidth - the total widget width excluding borders
widgetInnerHeight - the total widget height excluding borders
Returns:
the TransformableTextures, that this Widget keeps or null for no textures.

onDirtyFlagSet

protected void onDirtyFlagSet()

setDirtyFlag

public void setDirtyFlag()

getDirtyFlag

public final boolean getDirtyFlag(boolean reset)

onReinitializationForced

protected void onReinitializationForced()

forceReinitialization

public final void forceReinitialization()

setName

public void setName(java.lang.String name)
Sets this Widget's name.

Parameters:
name - the new name for this Widget

getName

public final java.lang.String getName()
Gets this Widget's name.

Returns:
this Widget's name.

getPosition

public final Position getPosition()
Gets the Widget's position.

Returns:
the Widget's position.

getOffsetXToRootMasterWidget

public final int getOffsetXToRootMasterWidget()
Gets the x-offset relative to the master Widget.

Returns:
the x-offset relative to the master Widget.

getOffsetYToRootMasterWidget

public final int getOffsetYToRootMasterWidget()
Gets the y-offset relative to the master Widget.

Returns:
the y-offset relative to the master Widget.

getAbsoluteOffsetX

public final int getAbsoluteOffsetX()
Gets the absolute x-position relative to the configuration origin.

Returns:
the absolute x-position relative to the configuration origin.

getAbsoluteOffsetY

public final int getAbsoluteOffsetY()
Gets the absolute y-position relative to the configuration origin.

Returns:
the absolute y-position relative to the configuration origin.

setZIndex

public void setZIndex(int zIndex)
Sets the Widget's z-index relative to other Widgets in the same configuration.

Parameters:
zIndex - the new z-index

getZIndex

public final int getZIndex()
Gets the Widget's z-index relative to other Widgets in the same configuration.

Returns:
the Widget's z-index relative to other Widgets in the same configuration.

hasFixedSize

public boolean hasFixedSize()
Gets, whether this Widget has a fixed (unmodifiable) size.

Returns:
whether this Widget has a fixed (unmodifiable) size.

getSize

public final Size getSize()
Gets this Widget's size.

Returns:
this Widget's width.

getInnerSize

public final InnerSize getInnerSize()
Gets the inner size of the Widget.

Returns:
the inner size of the Widget.

getEffectiveWidth

public final int getEffectiveWidth()
Gets the result of getSize().getEffectiveWidth().

Returns:
the result of getSize().getEffectiveWidth().

getEffectiveHeight

public final int getEffectiveHeight()
Gets the result of getSize().getEffectiveHeight().

Returns:
the result of getSize().getEffectiveHeight().

getMinWidth

public int getMinWidth(LiveGameData gameData,
                       boolean isEditorMode)
Gets the minimum width for this Widget in pixels.

Parameters:
gameData - the live game data
isEditorMode - rendering in the editor?
Returns:
the minimum width for this Widget in pixels.

getMinHeight

public int getMinHeight(LiveGameData gameData,
                        boolean isEditorMode)
Gets the minimum height for this Widget in pixels.

Parameters:
gameData - the live game data
isEditorMode - rendering in the editor?
Returns:
the minimum height for this Widget in pixels.

getMaxWidth

public int getMaxWidth(LiveGameData gameData,
                       boolean isEditorMode)
Gets the maximum width covered by this Widget. By default this method returns the result of getEffectiveWidth(gameResX). Override this method, if it will change its size during game play.

Parameters:
gameData - the live game data
isEditorMode - rendering in the editor?
Returns:
the maximum width covered by this Widget.

getMaxHeight

public int getMaxHeight(LiveGameData gameData,
                        boolean isEditorMode)
Gets the maximum height covered by this Widget. By default this method returns the result of getEffectiveHeight(gameResX). Override this method, if it will change its size during game play.

Parameters:
gameData - the live game data
isEditorMode - rendering in the editor?
Returns:
the maximum height covered by this Widget.

bake

public void bake(boolean convertToPixels)
Bakes effective position and size to variables, so that they don't need to be recalculated during runtime on each access.

Parameters:
convertToPixels - if true, all coordinates are converted to absolute pixels and positioned to TOP_LEFT.

setAllPosAndSizeToPercents

public void setAllPosAndSizeToPercents()

setAllPosAndSizeToPixels

public void setAllPosAndSizeToPixels()

getBackgroundProperty

public final BackgroundProperty getBackgroundProperty()

getBackground

public final WidgetBackground getBackground()
Gets the Widget's background.

Returns:
the Widget's background.

getFontProperty

public final FontProperty getFontProperty()

getFont

protected final java.awt.Font getFont()

isFontAntiAliased

protected final boolean isFontAntiAliased()

getFontColorProperty

public final ColorProperty getFontColorProperty()

getFontColor

protected final java.awt.Color getFontColor()
Gets the Widget's font color.

Returns:
the Widget's font color.

getPaddingPropertyTop

protected final IntProperty getPaddingPropertyTop()

getPaddingTop

protected final int getPaddingTop()

getPaddingPropertyLeft

protected final IntProperty getPaddingPropertyLeft()

getPaddingLeft

protected final int getPaddingLeft()

getPaddingPropertyRight

protected final IntProperty getPaddingPropertyRight()

getPaddingRight

protected final int getPaddingRight()

getPaddingPropertyBottom

protected final IntProperty getPaddingPropertyBottom()

getPaddingBottom

protected final int getPaddingBottom()

getBorderProperty

protected final BorderProperty getBorderProperty()

setPadding

protected final void setPadding(int top,
                                int left,
                                int right,
                                int bottom)
Sets padding for this Widget.

Parameters:
top - top padding value
left - left padding value
right - right padding value
bottom - bottom padding value

getBorder

public final BorderWrapper getBorder()
Returns a BorderWrapper, that encapsulates the actual used border with convenience wrappers for the size getters. The BorderWrapper instance is never null while the border can be null.

Returns:
a BorderWrapper for the used Border (never null).

onCompleteRedrawForced

protected void onCompleteRedrawForced()
This method is called when a complete redraw has been forced.


forceCompleteRedraw

public final void forceCompleteRedraw(boolean mergedBackgroundToo)
Forces a complete redraw on the next render.

Parameters:
mergedBackgroundToo - if true, the clear-background will be redrawn and the drawBackground(LiveGameData, boolean, TextureImage2D, int, int, int, int, boolean) methods will be called again.

forceAndSetDirty

public final void forceAndSetDirty(boolean mergedBackgroundToo)
This simply calls forceCompleteRedraw(boolean), forceReinitialization() and setDirtyFlag(). This method must be called after a value has been changed, that requires a reinitialization of all positioned strings, etc.

Parameters:
mergedBackgroundToo - whether to set merged background dirty, too

getInputVisibility

public final boolean getInputVisibility()
Gets this Widget's visibility usually controlled by the ToggleWidgetVisibility InputAction.
This flag is also restored when a different configurations is loaded unlike the others.

Returns:
this Widget's visibility flag.

getAutoVisibility

public final boolean getAutoVisibility()
Gets the automatically toggled visibility flag.

Returns:
this Widget's visibility flag.

getUpdatedVisibility

public final boolean getUpdatedVisibility()
Gets this Widget's user visibility flag 2. This is the one, you should toggle in your widget code.

Returns:
this Widget's visibility flag.

isVisible

public final boolean isVisible()
Gets this Widget's total visibility flag (getInputVisibility() && getAutoVisibility() && getUpdatedVisibility()).

Returns:
this Widget's visibility flag.

visibilityChangedSinceLastDraw

public final boolean visibilityChangedSinceLastDraw()

updateVisibility

protected java.lang.Boolean updateVisibility(LiveGameData gameData,
                                             boolean isEditorMode)
This method is called first by the rendering system each to check for visibility changes. This doesn't affect the visiblity toggled by the onBoundInputStateChanged(InputAction, boolean, int, long, LiveGameData, boolean) method. Automatic visiblity can also override the result.

Parameters:
gameData - the live game data
isEditorMode - true, if the Editor is used for rendering instead of rFactor
Returns:
true to set visible, false to set invisible, null for no change in visibility.
See Also:
getUpdatedVisibility()

getNeededData

public int getNeededData()
Gets the data indicators for the data needed for this Widget to be drawn (bitmask).

Returns:
the data indicators for the data needed for this Widget to be drawn.
See Also:
NEEDED_DATA_TELEMETRY, NEEDED_DATA_SCORING, NEEDED_DATA_SCORING

getDrawnStringFactory

protected final DrawnStringFactory getDrawnStringFactory()
Gets the Widget's DrawnStringFactory.

Returns:
the Widget's DrawnStringFactory.

afterConfigurationLoaded

public void afterConfigurationLoaded(WidgetsConfiguration widgetsConfig,
                                     LiveGameData gameData,
                                     boolean isEditorMode)
This event is fired right after the WidgetsConfiguration has been (re-)loaded.

Parameters:
widgetsConfig - the widgets configuration
gameData - the live game data
isEditorMode - true, if the Editor is used for rendering instead of rFactor

beforeConfigurationCleared

public void beforeConfigurationCleared(WidgetsConfiguration widgetsConfig,
                                       LiveGameData gameData,
                                       boolean isEditorMode)
This event is fired right before the WidgetsConfiguration is cleared.

Parameters:
widgetsConfig - the widgets configuration
gameData - the live game data
isEditorMode - true, if the Editor is used for rendering instead of rFactor

onTrackChanged

public void onTrackChanged(java.lang.String trackname,
                           LiveGameData gameData,
                           boolean isEditorMode)
This method is executed when a new track was loaded.

Parameters:
trackname - the current track's name
gameData - the live game data
isEditorMode - true, if the Editor is used for rendering instead of rFactor

onSessionStarted

public void onSessionStarted(SessionType sessionType,
                             LiveGameData gameData,
                             boolean isEditorMode)
This method is executed when a new session was started.

Parameters:
sessionType - the current session type
gameData - the live game data
isEditorMode - true, if the Editor is used for rendering instead of rFactor

onRealtimeEntered

public void onRealtimeEntered(LiveGameData gameData,
                              boolean isEditorMode)
This method is called when a the user entered realtime mode. If your Widget needs some data to be drawn correctly, consider using onNeededDataComplete(LiveGameData, boolean).

Parameters:
gameData - the live game data
isEditorMode - true, if the Editor is used for rendering instead of rFactor

onScoringInfoUpdated

public void onScoringInfoUpdated(LiveGameData gameData,
                                 boolean isEditorMode)
This method is called when ScoringInfo have been updated (done at 2Hz).

Parameters:
gameData - the live game data
isEditorMode - true, if the Editor is used for rendering instead of rFactor

onVehicleSetupUpdated

public void onVehicleSetupUpdated(LiveGameData gameData,
                                  boolean isEditorMode)
This method is called when VehicleSetup has been updated.

Parameters:
gameData - the live game data
isEditorMode - true, if the Editor is used for rendering instead of rFactor

onNeededDataComplete

public void onNeededDataComplete(LiveGameData gameData,
                                 boolean isEditorMode)
This method is called when the needed data is available in realtime mode.

Parameters:
gameData - the live game data
isEditorMode - true, if the Editor is used for rendering instead of rFactor

onPitsEntered

public void onPitsEntered(LiveGameData gameData,
                          boolean isEditorMode)
This method is called when a the car entered the pits.

Parameters:
gameData - the live game data
isEditorMode - true, if the Editor is used for rendering instead of rFactor

onGarageEntered

public void onGarageEntered(LiveGameData gameData,
                            boolean isEditorMode)
This method is called when a the car entered the garage.

Parameters:
gameData - the live game data
isEditorMode - true, if the Editor is used for rendering instead of rFactor

onGarageExited

public void onGarageExited(LiveGameData gameData,
                           boolean isEditorMode)
This method is called when a the car exited the garage.

Parameters:
gameData - the live game data
isEditorMode - true, if the Editor is used for rendering instead of rFactor

onPitsExited

public void onPitsExited(LiveGameData gameData,
                         boolean isEditorMode)
This method is called when a the car exited the pits.

Parameters:
gameData - the live game data
isEditorMode - true, if the Editor is used for rendering instead of rFactor

onRealtimeExited

public void onRealtimeExited(LiveGameData gameData,
                             boolean isEditorMode)
This method is called when a the user exited realtime mode.

Parameters:
gameData - the live game data
isEditorMode - true, if the Editor is used for rendering instead of rFactor

onVehicleControlChanged

protected java.lang.Boolean onVehicleControlChanged(VehicleScoringInfo viewedVSI,
                                                    LiveGameData gameData,
                                                    boolean isEditorMode)
This method is called when either the player's vehicle control has changed or another vehicle is being viewed.

Parameters:
viewedVSI - the currently viewed vehicle
gameData - the live game data
isEditorMode - true, if the Editor is used for rendering instead of rFactor
Returns:
true to set visible, false to set invisible, null for no change in visibility. This doesn't affect the visiblity toggled by the updateVisibility(LiveGameData, boolean) method or onBoundInputStateChanged(InputAction, boolean, int, long, LiveGameData, boolean) method.
See Also:
getAutoVisibility()

onLapStarted

public void onLapStarted(VehicleScoringInfo vsi,
                         LiveGameData gameData,
                         boolean isEditorMode)
This method is called when a lap has been finished and a new one was started.

Parameters:
vsi - the driver, who started the lap. If this is the leader and the session type is RACE, the whole race has moved on to the next lap.
gameData - the live game data
isEditorMode - true, if the Editor is used for rendering instead of rFactor

onBoundInputStateChanged

protected java.lang.Boolean onBoundInputStateChanged(InputAction action,
                                                     boolean state,
                                                     int modifierMask,
                                                     long when,
                                                     LiveGameData gameData,
                                                     boolean isEditorMode)
This event is fired, when a bound input component has changed its state.

Parameters:
action - the triggered action
state - the state of the input device component
modifierMask - see InputAction
when - the timestamp in nano seconds
gameData - the live game data
isEditorMode - true, if the Editor is used for rendering instead of rFactor
Returns:
true to set visible, false to set invisible, null for no change in visibility. This doesn't affect the visiblity toggled by the updateVisibility(LiveGameData, boolean) method. Automatic visiblity can also override the result.
See Also:
getInputVisibility()

hasMasterCanvas

public boolean hasMasterCanvas(boolean isEditorMode)
Returns true, if this Widget draws on the main texture, false otherwise.
Default is true.

Parameters:
isEditorMode - true, if the Editor is used for rendering instead of rFactor
Returns:
true, if this Widget draws on the main texture, false otherwise.

clearRegion

protected void clearRegion(TextureImage2D texture,
                           int offsetX,
                           int offsetY,
                           int width,
                           int height)

clearRegion

public final void clearRegion(TextureImage2D texture,
                              int offsetX,
                              int offsetY)
Clears the region on the texture, that is covered by this Widget.

Parameters:
texture - the texture image to draw on. Use TextureImage2D.getTextureCanvas() to retrieve the Texture2DCanvas for Graphics2D drawing.
offsetX - the x offset of the Widget on the drawing texture
offsetY - the y offset of the Widget on the drawing texture

clearBackgroundRegion

public boolean clearBackgroundRegion(TextureImage2D texture,
                                     int offsetX,
                                     int offsetY,
                                     int localX,
                                     int localY,
                                     int width,
                                     int height,
                                     boolean markDirty,
                                     Rect2i dirtyRect)
Clears the given part of the Widget area with the current background.

Parameters:
texture - the target texture
offsetX - the x offset of the Widget on the drawing texture
offsetY - the y offset of the Widget on the drawing texture
localX - the x coordinate of the upper left corner of the area to be cleared relative to the Widget's location
localY - the y coordinate of the upper left corner of the area to be cleared relative to the Widget's location
width - the width of the area to be cleared
height - the height of the area to be cleared
markDirty - if true, the pixel is marked dirty
dirtyRect - if non null, the dirty rect is written to this instance
Returns:
true, if this Widgets defines a background to clear with, false otherwise.

initialize

protected abstract void initialize(LiveGameData gameData,
                                   boolean isEditorMode,
                                   DrawnStringFactory drawnStringFactory,
                                   TextureImage2D texture,
                                   int width,
                                   int height)
This method is called once to initialized DrawnStrings used on this Widget.

Parameters:
gameData - the live game data
isEditorMode - true, if the Editor is used for rendering instead of rFactor
drawnStringFactory - a factory to get DrawnString instances from
texture - the texture image to draw on. Use TextureImage2D.getTextureCanvas() to retrieve the Texture2DCanvas for Graphics2D drawing.
width - the width on the texture
height - the height on the texture

checkForChanges

protected boolean checkForChanges(LiveGameData gameData,
                                  boolean isEditorMode,
                                  TextureImage2D texture,
                                  int width,
                                  int height)
Checks, if the Widget needs any changes before it is drawn. If true, drawBorder(boolean, BorderWrapper, TextureImage2D, int, int, int, int) and possibly drawBackground(LiveGameData, boolean, TextureImage2D, int, int, int, int, boolean) are (re-)invoked.
The original method is just an empty stub returning false.

Parameters:
gameData - the live game data
isEditorMode - true, if the Editor is used for rendering instead of rFactor
texture - the texture image to draw on. Use TextureImage2D.getTextureCanvas() to retrieve the Texture2DCanvas for Graphics2D drawing.
width - the width on the texture
height - the height on the texture
Returns:
true, if size has changed.

drawBorder

protected void drawBorder(boolean isEditorMode,
                          BorderWrapper border,
                          TextureImage2D texture,
                          int offsetX,
                          int offsetY,
                          int width,
                          int height)
Parameters:
isEditorMode - true, if the Editor is used for rendering instead of rFactor
border - the border
texture - the texture image to draw on. Use TextureImage2D.getTextureCanvas() to retrieve the Texture2DCanvas for Graphics2D drawing.
offsetX - the x-offset on the drawing texture
offsetY - the y offset on the drawing texture
width - the width of the area on the drawing texture
height - the height of the area on the drawing texture

drawBackground

protected void drawBackground(LiveGameData gameData,
                              boolean isEditorMode,
                              TextureImage2D texture,
                              int offsetX,
                              int offsetY,
                              int width,
                              int height,
                              boolean isRoot)
You can use this method to directly draw static content onto your Widget's background. Overriding this method makes the Widget use a background texture no matter, if the background is defined with a color only or an image.

Parameters:
gameData - the live game data
isEditorMode - true, if the Editor is used for rendering instead of rFactor
texture - the texture image to draw on. Use TextureImage2D.getTextureCanvas() to retrieve the Texture2DCanvas for Graphics2D drawing.
offsetX - the x-offset on the drawing texture
offsetY - the y offset on the drawing texture
width - the width of the area on the drawing texture
height - the height of the area on the drawing texture
isRoot - if this is true, you can possibly clear your stuff onto the texture instead of drawing it.

drawWidget

protected abstract void drawWidget(Clock clock,
                                   boolean needsCompleteRedraw,
                                   LiveGameData gameData,
                                   boolean isEditorMode,
                                   TextureImage2D texture,
                                   int offsetX,
                                   int offsetY,
                                   int width,
                                   int height)
This method must contain the actual drawing code for this Widget.

Parameters:
clock - this is a clock for very dynamic content, that needs smooth display. If 'needsCompleteRedraw' is true, clock1 is also true.
needsCompleteRedraw - whether this widget needs to be completely redrawn (true) or just the changed parts (false)
gameData - the live game data
isEditorMode - true, if the Editor is used for rendering instead of rFactor
texture - the texture image to draw on. Use TextureImage2D.getTextureCanvas() to retrieve the Texture2DCanvas for Graphics2D drawing.
offsetX - the x-offset on the texture
offsetY - the y-offset on the texture
width - the width on the texture
height - the height on the texture

drawWidget

public final void drawWidget(Clock clock,
                             boolean completeRedrawForced,
                             LiveGameData gameData,
                             boolean isEditorMode,
                             TextureImage2D texture,
                             boolean drawAtZero)
This method invokes the parts of the actual drawing code for this Widget.

Parameters:
clock - this is a clock for very dynamic content, that needs smooth display. If 'needsCompleteRedraw' is true, clock1 is also true.
completeRedrawForced - whether this widget needs to be completely redrawn (true) or just the changed parts (false)
gameData - the live game data
isEditorMode - true, if the Editor is used for rendering instead of rFactor
texture - the texture image to draw on. Use TextureImage2D.getTextureCanvas() to retrieve the Texture2DCanvas for Graphics2D drawing.
drawAtZero - draw at position 0,0?

saveProperties

public void saveProperties(PropertyWriter writer)
                    throws java.io.IOException
Saves all settings to the config file.

Specified by:
saveProperties in interface PropertiesKeeper
Parameters:
writer - the widgets configuration writer to write properties to
Throws:
java.io.IOException - if something went wrong

loadProperty

public void loadProperty(PropertyLoader loader)
Loads (and parses) a certain property from a config file.

Specified by:
loadProperty in interface PropertiesKeeper
Parameters:
loader - the property loader to load properties from

getPropertiesIterator

public java.util.Iterator<Property> getPropertiesIterator()
Gets an Iterator to iterate all properties, defined in this class.

Returns:
an Iterator to iterate all properties, defined in this class.

addTypeAndNamePropertiesToContainer

protected void addTypeAndNamePropertiesToContainer(PropertiesContainer propsCont,
                                                   boolean forceAll)
Adds the type and name properties to the PropertiesContainer.

Parameters:
propsCont - the container to add the properties to
forceAll - If true, all properties provided by this Widget must be added. If false, only the properties, that are relevant for the current Widget's situation have to be added, some can be ignored.

addVisibilityPropertiesToContainer

protected void addVisibilityPropertiesToContainer(PropertiesContainer propsCont,
                                                  boolean forceAll)
Adds the visibility properties to the PropertiesContainer.

Parameters:
propsCont - the container to add the properties to
forceAll - If true, all properties provided by this Widget must be added. If false, only the properties, that are relevant for the current Widget's situation have to be added, some can be ignored.

addPositionAndSizePropertiesToContainer

protected void addPositionAndSizePropertiesToContainer(PropertiesContainer propsCont,
                                                       boolean forceAll)
Adds the position and size properties to the PropertiesContainer.

Parameters:
propsCont - the container to add the properties to
forceAll - If true, all properties provided by this Widget must be added. If false, only the properties, that are relevant for the current Widget's situation have to be added, some can be ignored.

addBorderPropertyToContainer

protected void addBorderPropertyToContainer(PropertiesContainer propsCont,
                                            boolean forceAll)
Adds the border property to the container.

Parameters:
propsCont - the container to add the properties to
forceAll - If true, all properties provided by this Widget must be added. If false, only the properties, that are relevant for the current Widget's situation have to be added, some can be ignored.

addPaddingPropertiesToContainer

protected void addPaddingPropertiesToContainer(PropertiesContainer propsCont,
                                               boolean forceAll)
Adds the padding properties to the container.

Parameters:
propsCont - the container to add the properties to
forceAll - If true, all properties provided by this Widget must be added. If false, only the properties, that are relevant for the current Widget's situation have to be added, some can be ignored.

addBackgroundPropertyToContainer

protected void addBackgroundPropertyToContainer(PropertiesContainer propsCont,
                                                boolean forceAll)
Adds the background property to the container.

Parameters:
propsCont - the container to add the properties to
forceAll - If true, all properties provided by this Widget must be added. If false, only the properties, that are relevant for the current Widget's situation have to be added, some can be ignored.

addFontPropertiesToContainer

protected void addFontPropertiesToContainer(PropertiesContainer propsCont,
                                            boolean forceAll)
Adds the font and font color properties to the container.

Parameters:
propsCont - the container to add the properties to
forceAll - If true, all properties provided by this Widget must be added. If false, only the properties, that are relevant for the current Widget's situation have to be added, some can be ignored.

getPropertiesForParentGroup

protected void getPropertiesForParentGroup(PropertiesContainer propsCont,
                                           boolean forceAll)
Puts all editable properties to the editor.

Parameters:
propsCont - the container to add the properties to
forceAll - If true, all properties provided by this Widget must be added. If false, only the properties, that are relevant for the current Widget's situation have to be added, some can be ignored.

getProperties

public void getProperties(PropertiesContainer propsCont,
                          boolean forceAll)
Puts all editable properties to the editor.

Specified by:
getProperties in interface PropertiesKeeper
Parameters:
propsCont - the container to add the properties to
forceAll - If true, all properties provided by this PropertiesKeeper must be added. If false, only the properties, that are relevant for the current PropertiesKeeper's situation have to be added, some can be ignored.

getNewInstanceForClone

protected Widget getNewInstanceForClone()

cloneProperty

protected boolean cloneProperty(Property src,
                                Property trg)
Clones the value of the src property to the trg property. This method is invoked on the target Widget.

Parameters:
src -
trg -
Returns:
true, if the properties list needs to be refreshed, false otherwise.

clone

public Widget clone()
Overrides:
clone in class java.lang.Object

getDocumentationSource

public final java.lang.String getDocumentationSource()

canHaveBorder

protected boolean canHaveBorder()
Defines, if this Widget type can have a border.

Returns:
if this Widget type can have a border.

canHaveBackground

protected boolean canHaveBackground()
Defines, if this Widget type can have a background.

Returns:
if this Widget type can have a background.

hasBorder

protected final boolean hasBorder()
Gets whether this Widget has a border or not.

Returns:
whether this Widget has a border or not.

hasText

protected boolean hasText()
Defines, if a Widget type (potentially) contains any text. If false, the editor won't provide font or font-color selection. Should return a contant value.

Returns:
if this Widget can contain any text.

prepareForMenuItem

public void prepareForMenuItem()
This method is called by the editor before it draws the Widget to a menu item.