G4P (GUI for Processing) 4.3.9
A set of GUI controls for your Processing sketch.
Loading...
Searching...
No Matches
g4p_controls.GStick Class Reference
Inheritance diagram for g4p_controls.GStick:

Public Member Functions

void draw ()
 
int getMode ()
 
int getPosition ()
 
int getStickX ()
 
int getStickY ()
 
 GStick (PApplet theApplet, float p0, float p1, float p2, float p3)
 
void mouseEvent (MouseEvent event)
 
void setMode (int m)
 
- Public Member Functions inherited from g4p_controls.GAbstractControl
void addControl (GAbstractControl c)
 
void addControl (GAbstractControl c, float x, float y)
 
void addControl (GAbstractControl c, float x, float y, float angle)
 
void addControls (GAbstractControl... controls)
 
void addEventHandler (Object obj, String methodName)
 
void dispose ()
 
void draw ()
 
void forceBufferUpdate ()
 
 GAbstractControl (PApplet theApplet)
 
 GAbstractControl (PApplet theApplet, float p0, float p1)
 
 GAbstractControl (PApplet theApplet, float p0, float p1, float p2, float p3)
 
int getAlpha ()
 
int getCursorOver ()
 
float getCX ()
 
float getCY ()
 
float getHeight ()
 
int getLocalColorScheme ()
 
PApplet getPApplet ()
 
GAbstractControl getParent ()
 
PGraphics getSnapshot ()
 
GToolTip getTip ()
 
float getWidth ()
 
float getX ()
 
float getY ()
 
boolean hasFocus ()
 
boolean isDragging ()
 
boolean isEnabled ()
 
boolean isOpaque ()
 
boolean isVisible ()
 
void keyEvent (KeyEvent e)
 
void mouseEvent (MouseEvent event)
 
void moveTo (float px, float py)
 
void moveTo (float px, float py, GControlMode mode)
 
void post ()
 
void pre ()
 
void removeTip ()
 
boolean saveSnapshot ()
 
boolean saveSnapshot (String filename)
 
void setAlpha (int alpha)
 
void setAlpha (int alpha, boolean includeChildren)
 
void setCursorOver (int cursorOver)
 
void setEnabled (boolean enable)
 
void setFocus (boolean focus)
 
void setLocalColor (int colorNo, int color)
 
void setLocalColorScheme (int cs)
 
void setLocalColorScheme (int cs, boolean includeChildren)
 
void setOpaque (boolean opaque)
 
void setRotation (float angle)
 
void setRotation (float angle, GControlMode mode)
 
void setTip (GToolTip tt, float dx, float dy)
 
void setTip (GToolTip tt, GAlign ax, GAlign ay, float gap)
 
void setTip (String text, float dx, float dy)
 
void setTip (String text, GAlign ax, GAlign ay, float gap)
 
void setTipDisplayTime (long msecs)
 
void setTipHorz (boolean level)
 
void setTipText (String text)
 
void setVisible (boolean visible)
 
String toString ()
 

Protected Member Functions

float calcStickAngle (float px, float py)
 
int getPositionFromAngle (float a)
 
void updateBuffer ()
 
- Protected Member Functions inherited from g4p_controls.GAbstractControl
void addControlImpl (GAbstractControl c, float x, float y, float angle)
 
void addToParent (GAbstractControl p)
 
void calcTransformedOrigin (float px, float py)
 
void createEventHandler (Object handlerObj, String methodName, Class[] param_classes, String[] param_names)
 
void drawChildren ()
 
void fireEvent (Object... objects)
 
int focusObjectZ ()
 
PGraphics getBuffer ()
 
int getCurrHotSpot ()
 
AffineTransform getTransform (AffineTransform aff)
 
void hideTip ()
 
boolean isAvailable ()
 
boolean isDisplayable (int ascii)
 
boolean isSuitableForGroupControl (GAbstractControl control)
 
void loseFocus (GAbstractControl grabber)
 
void makeBuffer ()
 
void manageToolTip ()
 
void resize (int w, int h)
 
void setAvailable (boolean avail)
 
void setTextRenderingHints (Graphics2D g2d, int hint)
 
void setZ (int parentZ)
 
void showTip ()
 
void takeFocus ()
 
void updateBuffer ()
 
int whichHotSpot (float px, float py)
 

Protected Attributes

float actionRad
 
float actionRadLimit
 
float gripRad
 
final float ledHeight
 
float ledRingRad
 
final float ledWidth
 
int mode = X4
 
int position = -1
 
float rodLength = 0
 
float rodRad
 
int status = OFF_CONTROL
 
float stickAngle
 
- Protected Attributes inherited from g4p_controls.GAbstractControl
boolean allowChildren = true
 
boolean allowToolTips = true
 
int alphaLevel = G4P.globalAlpha
 
PGraphicsJava2D buffer = null
 
boolean bufferInvalid = true
 
LinkedList< GAbstractControlchildren = null
 
int currSpot = -1
 
int cursorOver = HAND
 
float cx
 
float cy
 
boolean dragging = false
 
Method eventHandlerMethod = null
 
String eventHandlerMethodName
 
Object eventHandlerObject = null
 
float halfHeight
 
float halfWidth
 
float height
 
HotSpot[] hotspots = null
 
int lastSpot = -1
 
int localColorScheme = G4P.globalColorScheme
 
boolean opaque = false
 
float ox
 
float oy
 
Color[] palette = null
 
GAbstractControl parent = null
 
int registeredMethods = 0
 
float rotAngle
 
double[] temp = new double[2]
 
GToolTip tip = null
 
float width
 
PApplet winApp
 
float x
 
float y
 
int z = Z_STICKY
 

Static Protected Attributes

static final int ACTIONRING = 5
 
static final int BACK = 6
 
static final int BORDERS = 0
 
static final int LED_ACTIVE = 14
 
static final int LED_INACTIVE = 1
 
static final int OUTERRING = 6
 
static final int[] posMap = new int[] { 0x01, 0x07, 0x04, 0x1c, 0x10, 0x70, 0x40, 0xc1 }
 
static final int[] posX = new int[] { 1, 1, 0, -1, -1, -1, 0, 1 }
 
static final int[] posY = new int[] { 0, 1, 1, 1, 0, -1, -1, -1 }
 
static final float RAD22_5 = PApplet.radians(22.5f)
 
static final float RAD45 = PApplet.radians(45)
 
static final float RAD90 = PApplet.radians(90)
 
static final int ROD = 1
 
static final int STICK = 0
 
static final int STICK_TOP = 3
 
static final int STICK_TOP_DRAG = 15
 
static final int STICK_TOP_OVER = 11
 
static final int STICK_TOP_PRESS = 14
 
- Static Protected Attributes inherited from g4p_controls.GAbstractControl
static float epsilon = 0.001f
 

Additional Inherited Members

- Public Attributes inherited from g4p_controls.GAbstractControl
String tag = ""
 
int tagNo
 
- Public Attributes inherited from g4p_controls.GConstants
int ALPHA_BLOCK = 128
 
int ALPHA_PICK = 48
 
TextAttribute BACKGROUND = TextAttribute.BACKGROUND
 
int BLUE_SCHEME = 6
 
int BOLD = Font.BOLD
 
int CANCEL = JOptionPane.CANCEL_OPTION
 
int CLOSE_WINDOW = 0x00000f02
 
int CLOSED = JOptionPane.CLOSED_OPTION
 
int CTRL_ANGULAR = 0x00000501
 
int CTRL_HORIZONTAL = 0x00000502
 
int CTRL_VERTICAL = 0x00000503
 
int CYAN_SCHEME = 5
 
int DECIMAL = 1
 
char END = java.awt.event.KeyEvent.VK_END
 
int ERROR_MESSAGE = JOptionPane.ERROR_MESSAGE
 
int EXIT_APP = 0x00000f01
 
int EXPONENT = 2
 
TextAttribute FAMILY = TextAttribute.FAMILY
 
TextAttribute FOREGROUND = TextAttribute.FOREGROUND
 
int FORWARD = 1
 
int GOLD_SCHEME = 7
 
int GREEN_SCHEME = 1
 
int HIDE_WINDOW = 0x00000f04
 
char HOME = java.awt.event.KeyEvent.VK_HOME
 
int INFO_MESSAGE = JOptionPane.INFORMATION_MESSAGE
 
int INTEGER = 0
 
int ITALIC = Font.ITALIC
 
int KEEP_OPEN = 0x00000f03
 
int NO = JOptionPane.NO_OPTION
 
int OK = JOptionPane.OK_OPTION
 
int OK_CANCEL = JOptionPane.OK_CANCEL_OPTION
 
int ORANGE_SCHEME = 4
 
int ORIENT_LEFT = -1
 
int ORIENT_RIGHT = 1
 
int ORIENT_TRACK = 0
 
int PLAIN = Font.PLAIN
 
int PLAIN_MESSAGE = JOptionPane.PLAIN_MESSAGE
 
TextAttribute POSTURE = TextAttribute.POSTURE
 
Float POSTURE_OBLIQUE = new Float(0.20f)
 
Float POSTURE_REGULAR = new Float(0.0f)
 
int PURPLE_SCHEME = 3
 
int QUERY_MESSAGE = JOptionPane.QUESTION_MESSAGE
 
int RED_SCHEME = 0
 
int REVERSE = -1
 
int SCHEME_10 = 10
 
int SCHEME_11 = 11
 
int SCHEME_12 = 12
 
int SCHEME_13 = 13
 
int SCHEME_14 = 14
 
int SCHEME_15 = 15
 
int SCHEME_8 = 8
 
int SCHEME_9 = 9
 
int SCROLLBARS_AUTOHIDE = 0x1000
 
int SCROLLBARS_BOTH = 0x0003
 
int SCROLLBARS_HORIZONTAL_ONLY = 0x0002
 
int SCROLLBARS_NONE = 0x0000
 
int SCROLLBARS_VERTICAL_ONLY = 0x0001
 
TextAttribute SIZE = TextAttribute.SIZE
 
TextAttribute STRIKETHROUGH = TextAttribute.STRIKETHROUGH
 
Boolean STRIKETHROUGH_OFF = new Boolean(false)
 
Boolean STRIKETHROUGH_ON = new Boolean(true)
 
TextAttribute SUPERSCRIPT = TextAttribute.SUPERSCRIPT
 
Integer SUPERSCRIPT_OFF = new Integer(0)
 
Integer SUPERSCRIPT_SUB = new Integer(-1)
 
Integer SUPERSCRIPT_SUPER = new Integer(1)
 
int UNDEFINED = Integer.MAX_VALUE
 
int USER_COL_SCHEME = 0x00010102
 
int WARN_MESSAGE = JOptionPane.WARNING_MESSAGE
 
TextAttribute WEIGHT = TextAttribute.WEIGHT
 
Float WEIGHT_BOLD = new Float(2.0f)
 
Float WEIGHT_DEMIBOLD = new Float(1.75f)
 
Float WEIGHT_DEMILIGHT = new Float(0.875f)
 
Float WEIGHT_EXTRA_LIGHT = new Float(0.5f)
 
Float WEIGHT_EXTRABOLD = new Float(2.5f)
 
Float WEIGHT_HEAVY = new Float(2.25f)
 
Float WEIGHT_LIGHT = new Float(0.75f)
 
Float WEIGHT_MEDIUM = new Float(1.5f)
 
Float WEIGHT_REGULAR = new Float(1.0f)
 
Float WEIGHT_SEMIBOLD = new Float(1.25f)
 
Float WEIGHT_ULTRABOLD = new Float(2.75f)
 
TextAttribute WIDTH = TextAttribute.WIDTH
 
Float WIDTH_CONDENSED = new Float(0.75f)
 
Float WIDTH_EXTENDED = new Float(1.5f)
 
Float WIDTH_REGULAR = new Float(1.0f)
 
Float WIDTH_SEMI_CONDENSED = new Float(0.875f)
 
Float WIDTH_SEMI_EXTENDED = new Float(1.25f)
 
int X4 = 1
 
int X8 = 2
 
int YELLOW_SCHEME = 2
 
int YES = JOptionPane.YES_OPTION
 
int YES_NO = JOptionPane.YES_NO_OPTION
 
int YES_NO_CANCEL = JOptionPane.YES_NO_CANCEL_OPTION
 

Detailed Description

This control simulates a digital joystick and is designed to give more intuitive control in game scenarios where you might use the keyboard e.g. WASD keys for movement.

The joystick has two modes - in the default mode the joystick just responds to movement in 4 directions (left,right, up and down) the second mode allows for diagonals so recognises 8 directions.

As in a real joystick you have a dead zone near the centre which does not generate signals, thus avoiding jitter. This area is shown graphically.

The direction of the joystick is represented by an integer in the range 0-7 and -1 when in the dead zone.

    5   6   7
     \  |  /
      \ | /
  4 --- + --- 0         + is the dea zone so -1
      / | \
     /  |  \
    3   2   1


As well as the direction there are two useful methods to decode these into X and Y directions -

getStickX()

and

getStickY()

which give the values.

X= -1   0   +1 
     \  |  /  -1
      \ | /
    --- + ---  0
      / | \
     /  |  \
          Y=  +1


The stick will auto-center when released.

The minimum size for this control is 40x40 pixels and this is enforced when the control is created. If necessary the width and/or height the rectangle will be increased to 40pixels.

Author
Peter Lager

Constructor & Destructor Documentation

◆ GStick()

g4p_controls.GStick.GStick ( PApplet  theApplet,
float  p0,
float  p1,
float  p2,
float  p3 
)

Create the stick inside the specified rectangle.

Parameters
theAppletthe main sketch or GWindow control for this control
p0x position based on control mode
p1y position based on control mode
p2x position or width based on control mode
p3y position or height based on control mode

Member Function Documentation

◆ calcStickAngle()

float g4p_controls.GStick.calcStickAngle ( float  px,
float  py 
)
protected

Calculate the angle to the knob centre making sure it is in the range 0-360

Parameters
pxrelative to centre
pyrelative to centre
Returns
the angle made by the stick

◆ draw()

void g4p_controls.GStick.draw ( )

Reimplemented from g4p_controls.GAbstractControl.

◆ getMode()

int g4p_controls.GStick.getMode ( )
Returns
the current stick mode

◆ getPosition()

int g4p_controls.GStick.getPosition ( )

Returns the current position of the stick based on

    5   6   7
     \  |  /
      \ | /
  4 --- + --- 0         + is the dead zone so -1
      / | \
     /  |  \
    3   2   1


Returns
current stick direction

◆ getPositionFromAngle()

int g4p_controls.GStick.getPositionFromAngle ( float  a)
protected

Calculate the position (mode dependent) from an angle in the range 0-2PI

Parameters
athe angle 0-2PI
Returns
direction (0-7)

◆ getStickX()

int g4p_controls.GStick.getStickX ( )

Get the X position of the stick from

  • X= -1   0   +1 
         \  |  /  -1
          \ | /
        --- + ---  0
          / | \
         /  |  \
              Y=  +1
    


Returns
the X value (-1, 0 or 1)

◆ getStickY()

int g4p_controls.GStick.getStickY ( )

Get the Y position of the stick from

  • X= -1   0   +1 
         \  |  /  -1
          \ | /
        --- + ---  0
          / | \
         /  |  \
              Y=  +1
    


Returns
the Y value (-1, 0 or 1)

◆ mouseEvent()

void g4p_controls.GStick.mouseEvent ( MouseEvent  event)

Reimplemented from g4p_controls.GAbstractControl.

◆ setMode()

void g4p_controls.GStick.setMode ( int  m)

Sets the stick mode to either 4 or 8 directions.
If the mode parameter should be either G4P.X4 or G4P.X8 any other value will be silently ignored

Parameters
mthe new mode

◆ updateBuffer()

void g4p_controls.GStick.updateBuffer ( )
protected

Reimplemented from g4p_controls.GAbstractControl.