de.matthiasmann.twl
Class FPSCounter

java.lang.Object
  extended by de.matthiasmann.twl.Widget
      extended by de.matthiasmann.twl.TextWidget
          extended by de.matthiasmann.twl.Label
              extended by de.matthiasmann.twl.FPSCounter

public class FPSCounter
extends Label

A simple FPS counter.

Measures the time required to render a specified number of frames (default 100) using System.nanoTime and displays the frame rate:

1e9 * framesToCount / elapsedNanoseconds 

This widget does not generate garbage while measuring and displaying the frame rate.

See Also:
System.nanoTime()

Nested Class Summary
 
Nested classes/interfaces inherited from class de.matthiasmann.twl.Label
Label.CallbackReason
 
Nested classes/interfaces inherited from class de.matthiasmann.twl.Widget
Widget.OffscreenMouseAdjustments, Widget.RenderOffscreen
 
Field Summary
 
Fields inherited from class de.matthiasmann.twl.TextWidget
STATE_HOVER, STATE_TEXT_CHANGED, STATE_TEXT_SELECTION
 
Fields inherited from class de.matthiasmann.twl.Widget
STATE_DISABLED, STATE_HAS_FOCUSED_CHILD, STATE_HAS_OPEN_POPUPS, STATE_KEYBOARD_FOCUS
 
Constructor Summary
FPSCounter()
          Creates the FPS counter with 3 integer digits and 2 decimal digits
FPSCounter(int numIntegerDigits, int numDecimalDigits)
          Creates the FPS counter with the given number of integer and decimal digits
 
Method Summary
 int getFramesToCount()
           
protected  void paintWidget(GUI gui)
          Called by Widget.paint(de.matthiasmann.twl.GUI) after painting the background and before painting all children.
 void setFramesToCount(int framesToCount)
          Specified how many frames to count to compute the FPS.
 
Methods inherited from class de.matthiasmann.twl.Label
addCallback, applyTheme, applyThemeLabel, doCallback, getLabelFor, getMinHeight, getMinWidth, getText, getTooltipContent, handleClick, handleEvent, isAutoSize, removeCallback, requestKeyboardFocus, setAutoSize, setFont, setLabelFor, setText
 
Methods inherited from class de.matthiasmann.twl.TextWidget
applyThemeTextWidget, computeRelativeCursorPositionX, computeRelativeCursorPositionX, computeTextHeight, computeTextWidth, computeTextX, computeTextY, destroy, getAlignment, getCharSequence, getFont, getNumTextLines, getPreferredInnerHeight, getPreferredInnerWidth, handleMouseHover, hasText, isCache, isMultilineText, paintLabelText, paintTextAt, paintWithSelection, paintWithSelection, setAlignment, setCache, setCharSequence
 
Methods inherited from class de.matthiasmann.twl.Widget
add, addActionMapping, addPropertyChangeListener, addPropertyChangeListener, adjustSize, afterAddToGUI, allChildrenRemoved, applyThemeBackground, applyThemeBorder, applyThemeInputMap, applyThemeMaxSize, applyThemeMinSize, applyThemeMouseCursor, applyThemeOffscreenExtra, applyThemeOverlay, applyThemeTooltip, beforeRemoveFromGUI, borderChanged, canAcceptKeyboardFocus, childAdded, childInvalidateLayout, childRemoved, childVisibilityChanged, computeSize, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, focusFirstChild, focusLastChild, focusNextChild, focusPrevChild, getActionMap, getAnimationState, getBackground, getBorderBottom, getBorderHorizontal, getBorderLeft, getBorderRight, getBorderTop, getBorderVertical, getBottom, getChild, getChildAt, getChildIndex, getGUI, getHeight, getInnerBottom, getInnerHeight, getInnerRight, getInnerWidth, getInnerX, getInnerY, getInputMap, getKeyboardFocusOrder, getMaxHeight, getMaxWidth, getMouseCursor, getMouseCursor, getNumChildren, getOffscreenExtraBottom, getOffscreenExtraLeft, getOffscreenExtraRight, getOffscreenExtraTop, getOrCreateActionMap, getOverlay, getParent, getPreferredHeight, getPreferredWidth, getRenderOffscreen, getRight, getRootWidget, getTheme, getThemePath, getThemeTooltipContent, getTintAnimator, getTooltipContentAt, getWidgetAt, getWidth, getX, getY, giveupKeyboardFocus, handleKeyStrokeAction, hasKeyboardFocus, hasOpenPopups, hasSharedAnimationState, insertChild, invalidateLayout, invalidateLayoutLocally, isAbsoluteTheme, isClip, isDepthFocusTraversal, isEnabled, isFocusKeyEnabled, isInside, isLocallyEnabled, isMouseInside, isVisible, keyboardFocusChildChanged, keyboardFocusGained, keyboardFocusGained, keyboardFocusLost, layout, layoutChildFullInnerArea, layoutChildrenFullInnerArea, moveChild, paint, paintBackground, paintChild, paintChildren, paintDragOverlay, paintOverlay, positionChanged, reapplyTheme, removeAllChildren, removeChild, removeChild, removePropertyChangeListener, removePropertyChangeListener, requestKeyboardFocus, resetTooltip, setActionMap, setBackground, setBorderSize, setBorderSize, setBorderSize, setBorderSize, setCanAcceptKeyboardFocus, setClip, setDepthFocusTraversal, setEnabled, setFocusKeyEnabled, setInnerSize, setInputMap, setMaxSize, setMinSize, setMouseCursor, setOffscreenExtra, setOffscreenExtra, setOverlay, setPosition, setRenderOffscreen, setSize, setTheme, setTintAnimator, setTooltipContent, setVisible, sizeChanged, updateTintAnimation, updateTooltip, validateLayout, widgetDisabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FPSCounter

public FPSCounter(int numIntegerDigits,
                  int numDecimalDigits)
Creates the FPS counter with the given number of integer and decimal digits

Parameters:
numIntegerDigits - number of integer digits - must be >= 2
numDecimalDigits - number of decimal digits - must be >= 0

FPSCounter

public FPSCounter()
Creates the FPS counter with 3 integer digits and 2 decimal digits

See Also:
FPSCounter(int, int)
Method Detail

getFramesToCount

public int getFramesToCount()

setFramesToCount

public void setFramesToCount(int framesToCount)
Specified how many frames to count to compute the FPS. Larger values result in a more accurate result and slower update.

Parameters:
framesToCount - the number of frames to count

paintWidget

protected void paintWidget(GUI gui)
Description copied from class: Widget
Called by Widget.paint(de.matthiasmann.twl.GUI) after painting the background and before painting all children.

This should be overwritten instead of paint if normal themeable painting is desired by the subclass.

The default implementation does nothing.

Overrides:
paintWidget in class TextWidget
Parameters:
gui - the GUI object - it's the same as getGUI()