Initial source commit
This commit is contained in:
commit
f1384c11ee
335 changed files with 52715 additions and 0 deletions
31
minorGems/ui/GUIComponent.h
Normal file
31
minorGems/ui/GUIComponent.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Modification History
|
||||
*
|
||||
* 2001-September-15 Jason Rohrer
|
||||
* Created.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef GUI_COMPONENT_INCLUDED
|
||||
#define GUI_COMPONENT_INCLUDED
|
||||
|
||||
|
||||
#include "minorGems/ui/GUIComponent.h"
|
||||
|
||||
|
||||
/**
|
||||
* An generic superclass for all gui components.
|
||||
* Allows for easy event source determination during event passing.
|
||||
*
|
||||
* @author Jason Rohrer
|
||||
*/
|
||||
class GUIComponent {
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
77
minorGems/ui/Keyboard.h
Normal file
77
minorGems/ui/Keyboard.h
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Modification History
|
||||
*
|
||||
* 2000-December-7 Jason Rohrer
|
||||
* Created.
|
||||
*
|
||||
* 2000-December-8 Jason Rohrer
|
||||
* Changed so that key state functions take a string instead of
|
||||
* an integer vkey code.
|
||||
*
|
||||
* 2006-June-26 Jason Rohrer
|
||||
* Added function to get events that are waiting in the queue.
|
||||
*/
|
||||
|
||||
#ifndef KEYBOARD_INCLUDED
|
||||
#define KEYBOARD_INCLUDED
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Interface for accessing keyboard input.
|
||||
*
|
||||
* Note:
|
||||
* Certain implementations may require a ScreenGraphics object to
|
||||
* be constructed before accessing the keyboard (i.e., to give the
|
||||
* keyboard input a context).
|
||||
*/
|
||||
class Keyboard {
|
||||
|
||||
public:
|
||||
|
||||
/*
|
||||
* Key descriptions:
|
||||
*
|
||||
* For the standard ascii characters, pass in the string containing
|
||||
* the lower case character, for example, "a" for the character A.
|
||||
*
|
||||
* For other keys, the descriptors have not been defined yet.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Gets whether a key is down.
|
||||
*
|
||||
* @param inKeyDescription string describing the queried key.
|
||||
*
|
||||
* @return true if key represented by given key code is down.
|
||||
*/
|
||||
//char getKeyDown( int vKeyCode );
|
||||
char getKeyDown( const char *inKeyDescription );
|
||||
|
||||
|
||||
/**
|
||||
* Gets whether a key is up.
|
||||
*
|
||||
* @param inKeyDescription string describing the queried key.
|
||||
*
|
||||
* @return true if key represented by given key code is up.
|
||||
*/
|
||||
//char getKeyUp( int vKeyCode );
|
||||
char getKeyUp( const char *inKeyDescription );
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the next keyboard event.
|
||||
*
|
||||
* @return the ASCII encoding of the pressed key, or -1 if no
|
||||
* keyboard events are waiting.
|
||||
*/
|
||||
int getKeyPressedEvent();
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
97
minorGems/ui/Mouse.h
Normal file
97
minorGems/ui/Mouse.h
Normal file
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* Modification History
|
||||
*
|
||||
* 2000-November-28 Jason Rohrer
|
||||
* Created.
|
||||
*/
|
||||
|
||||
#ifndef MOUSE_INCLUDED
|
||||
#define MOUSE_INCLUDED
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Interface for accessing mouse input.
|
||||
*
|
||||
* Note:
|
||||
* Certain implementations may require a ScreenGraphics object to
|
||||
* be constructed before accessing the mouse (i.e., to give the
|
||||
* mouse coordinates a context).
|
||||
*/
|
||||
class Mouse {
|
||||
|
||||
public:
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a Mouse.
|
||||
*
|
||||
* @param inNumButtons the number of buttons on the mouse that should
|
||||
* be monitored. Default = 1.
|
||||
*/
|
||||
Mouse( int inNumButtons );
|
||||
|
||||
~Mouse();
|
||||
|
||||
|
||||
/**
|
||||
* Gets the location of the mouse.
|
||||
*
|
||||
* @param outX pointer to location where x component will be returned.
|
||||
* @param outY pointer to location where y component will be returned.
|
||||
*/
|
||||
void getLocation( int *outX, int *outY );
|
||||
|
||||
|
||||
/**
|
||||
* Gets whether the main mouse button is down.
|
||||
*
|
||||
* @return true if the main mouse button is down.
|
||||
*/
|
||||
char isButtonDown();
|
||||
|
||||
|
||||
/**
|
||||
* Gets whether a specified mouse button is down.
|
||||
*
|
||||
* @param inButtonNumber the number of the button to check for
|
||||
* (0 is the main mouse button).
|
||||
*
|
||||
* @return true if the specified mouse button is down.
|
||||
*/
|
||||
char isButtonDown( int inButtonNumber );
|
||||
|
||||
|
||||
private:
|
||||
int mXLocation;
|
||||
int mYLocation;
|
||||
|
||||
int mNumButtons;
|
||||
|
||||
// array of booleans that represent the current
|
||||
// (or last known) state of each button
|
||||
char *mButtonDown;
|
||||
};
|
||||
|
||||
|
||||
|
||||
inline Mouse::Mouse( int inNumButtons = 1 )
|
||||
: mNumButtons( inNumButtons ),
|
||||
mButtonDown( new char[inNumButtons] ) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline Mouse::~Mouse() {
|
||||
delete [] mButtonDown;
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline char Mouse::isButtonDown() {
|
||||
return isButtonDown( 0 );
|
||||
}
|
||||
|
||||
|
||||
#endif
|
131
minorGems/ui/Plot.cpp
Normal file
131
minorGems/ui/Plot.cpp
Normal file
|
@ -0,0 +1,131 @@
|
|||
// Jason Rohrer
|
||||
// Plot.cpp
|
||||
|
||||
/**
|
||||
*
|
||||
* Scrolling Plot Gui element implementation
|
||||
*
|
||||
*
|
||||
* Created 11-7-99
|
||||
* Mods:
|
||||
* Jason Rohrer 11-8-99 Changed to use GraphicBuffer object as screen buffer
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "Plot.h"
|
||||
|
||||
|
||||
Plot::Plot( int x, int y, int w, int h, Color bordC, Color bC, Color lnC ) {
|
||||
|
||||
startX = x;
|
||||
startY = y;
|
||||
wide = w;
|
||||
high = h;
|
||||
|
||||
innerWide = wide - 2*borderWide;
|
||||
innerHigh = high - 2*borderWide;
|
||||
|
||||
|
||||
borderC = bordC;
|
||||
bgC = bC;
|
||||
lineC = lnC;
|
||||
|
||||
|
||||
imageMap = new unsigned long[high * wide];
|
||||
|
||||
mapYOffset = new int[high];
|
||||
|
||||
// precalc y offsets into 2d image map
|
||||
for( int y=0; y<high; y++ ) {
|
||||
mapYOffset[y] = y*wide;
|
||||
}
|
||||
|
||||
// prepare image map
|
||||
for( int y=0; y<high; y++ ) {
|
||||
int yContrib = mapYOffset[y];
|
||||
|
||||
for( int x=0; x<wide; x++ ) {
|
||||
|
||||
if( y<borderWide || x<borderWide || y>high-borderWide-1 || x>wide-borderWide-1 ) {
|
||||
imageMap[ yContrib + x ] = borderC.composite; // border
|
||||
}
|
||||
else {
|
||||
imageMap[ yContrib + x ] = bgC.composite; // background
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
plotVals = new float[innerWide];
|
||||
|
||||
for( int i=0; i<innerWide; i++ ) {
|
||||
plotVals[i] = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Plot::~Plot() {
|
||||
delete [] imageMap;
|
||||
delete [] mapYOffset;
|
||||
delete [] plotVals;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Plot::addPoint( float p ) {
|
||||
|
||||
// scroll plot vals
|
||||
//memmove( (void *)plotVals, (void *)(&(plotVals[1])), sizeof(float) * innerWide );
|
||||
for( int i=0; i<innerWide-1; i++ ) {
|
||||
plotVals[i] = plotVals[i+1];
|
||||
}
|
||||
|
||||
|
||||
// add new
|
||||
plotVals[innerWide-1] = p;
|
||||
|
||||
|
||||
float largest = 0;
|
||||
// find largest
|
||||
for( int i=0; i<innerWide; i++ ) {
|
||||
if( largest < plotVals[i] ) {
|
||||
largest = plotVals[i];
|
||||
}
|
||||
}
|
||||
|
||||
float invLargest = 1;
|
||||
|
||||
if( largest > 0) {
|
||||
invLargest = 1/largest;
|
||||
}
|
||||
|
||||
|
||||
// fill plot with bg color
|
||||
for( int y=borderWide; y<high-borderWide; y++ ) {
|
||||
int yContrib = mapYOffset[y];
|
||||
for( int x=borderWide; x<wide-borderWide; x++ ) {
|
||||
imageMap[ yContrib + x ] = bgC.composite; // background
|
||||
}
|
||||
}
|
||||
|
||||
// now plot line
|
||||
for( int x=borderWide; x<wide-borderWide; x++ ) {
|
||||
|
||||
int y = (int)(plotVals[x-borderWide] * invLargest * innerHigh);
|
||||
y = innerHigh - y;
|
||||
if( y > innerHigh + borderWide ) y = innerHigh + borderWide -1;
|
||||
if( y < borderWide ) y = borderWide;
|
||||
|
||||
imageMap[ mapYOffset[y] + x ] = lineC.composite; // line
|
||||
}
|
||||
|
||||
|
||||
/* for( int x=0; x<innerWide; x++) {
|
||||
int y = innerHigh - (int)(plotVals[x] * innerHigh);
|
||||
imageMap[ mapYOffset[y] + x ] = lineC.composite;
|
||||
}
|
||||
*/
|
||||
}
|
83
minorGems/ui/Plot.h
Normal file
83
minorGems/ui/Plot.h
Normal file
|
@ -0,0 +1,83 @@
|
|||
// Jason Rohrer
|
||||
// Plot.h
|
||||
|
||||
/**
|
||||
*
|
||||
* Scrolling Plot Gui element
|
||||
*
|
||||
*
|
||||
* Created 11-7-99
|
||||
* Mods:
|
||||
* Jason Rohrer 11-8-99 Changed to use GraphicBuffer object as screen buffer
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef PLOT_INCLUDED
|
||||
#define PLOT_INCLUDED
|
||||
|
||||
|
||||
#include <string.h>
|
||||
#include "Color.h"
|
||||
#include "GraphicBuffer.h"
|
||||
|
||||
class Plot {
|
||||
|
||||
public:
|
||||
// construct a plot in a specific location with
|
||||
// specific border, background, and line colors
|
||||
Plot( int x, int y, int w, int h, Color bordC, Color bC, Color lnC );
|
||||
~Plot();
|
||||
|
||||
// add a point to the right of plot, cause plot to scroll left
|
||||
void addPoint( float p );
|
||||
|
||||
// draw plot into a graphic buffer
|
||||
void draw( GraphicBuffer &buff );
|
||||
|
||||
// erase plot from buffer
|
||||
void erase( GraphicBuffer &buff, Color &bgColor );
|
||||
|
||||
private:
|
||||
|
||||
unsigned long *imageMap;
|
||||
|
||||
int startX;
|
||||
int startY;
|
||||
int high;
|
||||
int wide;
|
||||
|
||||
int innerHigh; // width and heigth of area inside borders
|
||||
int innerWide;
|
||||
|
||||
int *mapYOffset;
|
||||
|
||||
Color borderC; // color of border
|
||||
Color bgC; // color of progress bar max
|
||||
|
||||
Color lineC; // color of plot line
|
||||
|
||||
|
||||
|
||||
static const int borderWide = 2;
|
||||
|
||||
|
||||
float *plotVals; // values of plot line
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
inline void Plot::draw( GraphicBuffer &buff ) {
|
||||
buff.drawImage(imageMap, mapYOffset, startX, startY, wide, high);
|
||||
}
|
||||
|
||||
inline void Plot::erase( GraphicBuffer &buff, Color &bgColor ) {
|
||||
buff.eraseImage(startX, startY, wide, high, bgColor);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
122
minorGems/ui/ProgressBar.cpp
Normal file
122
minorGems/ui/ProgressBar.cpp
Normal file
|
@ -0,0 +1,122 @@
|
|||
// Jason Rohrer
|
||||
// ProgressBar.cpp
|
||||
|
||||
/**
|
||||
*
|
||||
* ProgressBar Gui element implementation
|
||||
*
|
||||
*
|
||||
* Created 11-6-99
|
||||
* Mods:
|
||||
* Jason Rohrer 11-8-99 Changed to use GraphicBuffer object as screen buffer
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "ProgressBar.h"
|
||||
|
||||
|
||||
ProgressBar::ProgressBar(int x, int y, int w, int h, Color bordC, Color hC, Color tipC) {
|
||||
|
||||
startX = x;
|
||||
startY = y;
|
||||
wide = w;
|
||||
high = h;
|
||||
|
||||
barWide = wide - 2*borderWide;
|
||||
barHigh = high - 2*borderWide;
|
||||
|
||||
|
||||
borderC = bordC;
|
||||
highC = hC;
|
||||
barTipC = tipC;
|
||||
|
||||
|
||||
imageMap = new unsigned long[high * wide];
|
||||
|
||||
mapYOffset = new int[high];
|
||||
|
||||
// precalc y offsets into 2d image map
|
||||
for( int y=0; y<high; y++ ) {
|
||||
mapYOffset[y] = y*wide;
|
||||
}
|
||||
|
||||
// prepare image map
|
||||
for( int y=0; y<high; y++ ) {
|
||||
int yContrib = mapYOffset[y];
|
||||
|
||||
for( int x=0; x<wide; x++ ) {
|
||||
|
||||
if( y<borderWide || x<borderWide || y>high-borderWide-1 || x>wide-borderWide-1 ) {
|
||||
imageMap[ yContrib + x ] = borderC.composite; // border
|
||||
}
|
||||
else {
|
||||
imageMap[ yContrib + x ] = 0xFF000000; // black inside
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
lastProgress = 0;
|
||||
}
|
||||
|
||||
|
||||
ProgressBar::~ProgressBar() {
|
||||
delete [] imageMap;
|
||||
delete [] mapYOffset;
|
||||
}
|
||||
|
||||
|
||||
void ProgressBar::setProgress(float fractionFull) {
|
||||
|
||||
if( fractionFull < 0) fractionFull = 0;
|
||||
if( fractionFull > 1) fractionFull = 1;
|
||||
|
||||
if( fractionFull < lastProgress ) { // decreasing proress, erase part of bar
|
||||
|
||||
|
||||
int deleteXStart = (int)((fractionFull) * barWide + borderWide);
|
||||
|
||||
int deleteXEnd = (int)((lastProgress) * barWide + borderWide);
|
||||
|
||||
|
||||
for( int y=borderWide; y<high-borderWide; y++ ) {
|
||||
|
||||
int yContrib = mapYOffset[y];
|
||||
|
||||
for( int x=deleteXStart; x<=deleteXEnd; x++ ) {
|
||||
imageMap[ yContrib + x ] = 0xFF000000; // erase to black
|
||||
}
|
||||
// color bar tip
|
||||
imageMap[yContrib + deleteXStart] = barTipC.composite;
|
||||
}
|
||||
}
|
||||
else if( fractionFull > lastProgress) { //progress has increased
|
||||
|
||||
int addXStart = (int)((lastProgress) * barWide + borderWide);
|
||||
int addXEnd = (int)((fractionFull) * barWide + borderWide);
|
||||
|
||||
float weight = lastProgress;
|
||||
float deltaWeight = (fractionFull - lastProgress) / (addXEnd - addXStart);
|
||||
|
||||
for( int x=addXStart; x<addXEnd; x++) {
|
||||
// weighted color
|
||||
unsigned long thisColor = highC.getWeightedComposite(weight);
|
||||
weight += deltaWeight;
|
||||
for( int y=borderWide; y<high-borderWide; y++) {
|
||||
imageMap[mapYOffset[y] + x] = thisColor;
|
||||
}
|
||||
}
|
||||
// color bar tip
|
||||
for( int y=borderWide; y<high-borderWide; y++) {
|
||||
imageMap[mapYOffset[y] + addXEnd] = barTipC.composite;
|
||||
}
|
||||
}
|
||||
|
||||
lastProgress = fractionFull;
|
||||
}
|
||||
|
||||
|
||||
|
75
minorGems/ui/ProgressBar.h
Normal file
75
minorGems/ui/ProgressBar.h
Normal file
|
@ -0,0 +1,75 @@
|
|||
// Jason Rohrer
|
||||
// ProgressBar.h
|
||||
|
||||
/**
|
||||
*
|
||||
* ProgressBar Gui element
|
||||
*
|
||||
*
|
||||
* Created 11-6-99
|
||||
* Mods:
|
||||
* Jason Rohrer 11-8-99 Changed to use GraphicBuffer object as screen buffer
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef PROGRESS_BAR_INCLUDED
|
||||
#define PROGRESS_BAR_INCLUDED
|
||||
|
||||
#include "Color.h"
|
||||
#include "GraphicBuffer.h"
|
||||
|
||||
class ProgressBar {
|
||||
|
||||
public:
|
||||
// construct a progress bar in a specific location with
|
||||
// specific border and maximum colors
|
||||
ProgressBar( int x, int y, int w, int h, Color bordC, Color hC, Color tipC );
|
||||
~ProgressBar();
|
||||
|
||||
void setProgress( float fractionFull );
|
||||
|
||||
// draw progress bar into a graphic buffer
|
||||
void draw( GraphicBuffer &buff );
|
||||
|
||||
// erase progress bar from buffer
|
||||
void erase( GraphicBuffer &buff, Color &bgColor );
|
||||
|
||||
private:
|
||||
|
||||
unsigned long *imageMap;
|
||||
|
||||
int startX;
|
||||
int startY;
|
||||
int high;
|
||||
int wide;
|
||||
|
||||
int barHigh; // width and heigth of area inside borders
|
||||
int barWide;
|
||||
|
||||
int *mapYOffset;
|
||||
|
||||
Color borderC; // color of border
|
||||
Color highC; // color of progress bar max
|
||||
|
||||
Color barTipC;
|
||||
|
||||
static const int borderWide = 2;
|
||||
|
||||
float lastProgress; // fraction of last progress
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
inline void ProgressBar::draw( GraphicBuffer &buff ) {
|
||||
buff.drawImage(imageMap, mapYOffset, startX, startY, wide, high);
|
||||
}
|
||||
|
||||
inline void ProgressBar::erase( GraphicBuffer &buff, Color &bgColor ) {
|
||||
buff.eraseImage(startX, startY, wide, high, bgColor);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
15
minorGems/ui/SetMouse.h
Normal file
15
minorGems/ui/SetMouse.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
// Jason Rohrer
|
||||
// SetMouse.h
|
||||
|
||||
/**
|
||||
*
|
||||
* Interface for force-setting mouse cursor position
|
||||
*
|
||||
* Created 1-14-2000
|
||||
* Mods:
|
||||
* Jason Rohrer 1-18-2000 Added capture and release mouse functions to help Win32
|
||||
*/
|
||||
|
||||
void SetMouse( int x, int y);
|
||||
void CaptureMouse();
|
||||
void ReleaseMouse();
|
40
minorGems/ui/SetMouseMac.cpp
Normal file
40
minorGems/ui/SetMouseMac.cpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
// Jason Rohrer
|
||||
// SetMouseMac.cpp
|
||||
|
||||
/**
|
||||
*
|
||||
* implementation of SetMouse on Mac
|
||||
* This uses a hack that may not be supported in later OSs (e.g., OSX)
|
||||
*
|
||||
* Created 1-14-2000
|
||||
* Mods:
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include <MacTypes.h>
|
||||
#include "SetMouse.h"
|
||||
|
||||
void SetMouse (int x, int y) {
|
||||
Point base;
|
||||
// This routine donated to MacMAME by John Stiles
|
||||
// Picked up for RadiosGL from the Mac GLQuake site
|
||||
Point *RawMouse = (Point*) 0x82C;
|
||||
Point *MTemp = (Point*) 0x828;
|
||||
Ptr CrsrNew = (Ptr) 0x8CE;
|
||||
Ptr CrsrCouple = (Ptr) 0x8CF;
|
||||
|
||||
base.v = y;
|
||||
base.h = x;
|
||||
LocalToGlobal(&base);
|
||||
|
||||
*RawMouse = base;
|
||||
*MTemp = base;
|
||||
*CrsrNew = *CrsrCouple;
|
||||
}
|
||||
|
||||
// do nothing, these are needed in windows only
|
||||
void CaptureMouse() {
|
||||
}
|
||||
void ReleaseMouse() {
|
||||
}
|
50
minorGems/ui/SetMouseWin32.cpp
Normal file
50
minorGems/ui/SetMouseWin32.cpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
// Jason Rohrer
|
||||
// SetMouseWin32.cpp
|
||||
|
||||
/**
|
||||
*
|
||||
* implementation of SetMouse on Win32
|
||||
* This uses an "official" os feature (unlike the hacked mac version
|
||||
*
|
||||
* Created 1-16-2000
|
||||
* Mods:
|
||||
* Jason Rohrer 1-18-2000 Added conversion from client to screen coords.
|
||||
* GLUT tracks mouse motion relative to window
|
||||
* Windows can only set the cursor position using
|
||||
* screen coordinates.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include <winuser.h>
|
||||
|
||||
#include "SetMouse.h"
|
||||
|
||||
char captured = false;
|
||||
|
||||
void SetMouse( int x, int y ) {
|
||||
|
||||
POINT p;
|
||||
p.x = x;
|
||||
p.y = y;
|
||||
|
||||
HWND window = GetActiveWindow();
|
||||
|
||||
ClientToScreen( window, &p );
|
||||
|
||||
SetCursorPos( p.x, p.y );
|
||||
|
||||
//SetCursorPos( x, y );
|
||||
|
||||
}
|
||||
|
||||
|
||||
// send all mouse movements to our window, even those outside the border
|
||||
void CaptureMouse() {
|
||||
HWND window = GetActiveWindow();
|
||||
SetCapture( window );
|
||||
}
|
||||
|
||||
void ReleaseMouse() {
|
||||
ReleaseCapture();
|
||||
}
|
54
minorGems/ui/event/ActionListener.h
Normal file
54
minorGems/ui/event/ActionListener.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Modification History
|
||||
*
|
||||
* 2001-September-15 Jason Rohrer
|
||||
* Created.
|
||||
*
|
||||
* 2006-July-3 Jason Rohrer
|
||||
* Fixed warnings.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ACTION_LISTENER_INCLUDED
|
||||
#define ACTION_LISTENER_INCLUDED
|
||||
|
||||
|
||||
#include "minorGems/ui/GUIComponent.h"
|
||||
|
||||
|
||||
/**
|
||||
* An interface for a class that can handle a GUI action.
|
||||
*
|
||||
* @author Jason Rohrer
|
||||
*/
|
||||
class ActionListener {
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
virtual ~ActionListener();
|
||||
|
||||
|
||||
/**
|
||||
* Tells this class that an action has been performed.
|
||||
*
|
||||
* @param inTarget the GUI component on which the action
|
||||
* is being performed.
|
||||
*/
|
||||
virtual void actionPerformed( GUIComponent *inTarget ) = 0;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
inline ActionListener::~ActionListener() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
143
minorGems/ui/event/ActionListenerList.h
Normal file
143
minorGems/ui/event/ActionListenerList.h
Normal file
|
@ -0,0 +1,143 @@
|
|||
/*
|
||||
* Modification History
|
||||
*
|
||||
* 2001-September-15 Jason Rohrer
|
||||
* Created.
|
||||
*
|
||||
* 2001-September-17 Jason Rohrer
|
||||
* Fixed a missing include.
|
||||
*
|
||||
* 2006-July-3 Jason Rohrer
|
||||
* Fixed warnings.
|
||||
*
|
||||
* 2009-December-22 Jason Rohrer
|
||||
* New SimpleVector delete call.
|
||||
*
|
||||
* 2010-May-19 Jason Rohrer
|
||||
* Added call to check if a listener is on the list.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ACTION_LISTENER_LIST_INCLUDED
|
||||
#define ACTION_LISTENER_LIST_INCLUDED
|
||||
|
||||
|
||||
#include "ActionListener.h"
|
||||
#include "minorGems/ui/GUIComponent.h"
|
||||
#include "minorGems/util/SimpleVector.h"
|
||||
|
||||
|
||||
/**
|
||||
* A utility class to be subclassed by classes needing
|
||||
* to handle a list of action listeners.
|
||||
*
|
||||
* @author Jason Rohrer
|
||||
*/
|
||||
class ActionListenerList : protected SimpleVector<ActionListener*> {
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
virtual ~ActionListenerList();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Adds an action listener.
|
||||
*
|
||||
* @param inListener the listener to add. Must
|
||||
* be destroyed by caller after this class has been destroyed.
|
||||
*/
|
||||
virtual void addActionListener( ActionListener *inListener );
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Removes an action listener.
|
||||
*
|
||||
* @param inListener the listener to remove. Must
|
||||
* be destroyed by caller.
|
||||
*/
|
||||
virtual void removeActionListener( ActionListener *inListener );
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Checks if action listener added
|
||||
*
|
||||
* @param inListener the listener to look for. Must
|
||||
* be destroyed by caller.
|
||||
*
|
||||
* @return true iff listener is on the list
|
||||
*/
|
||||
virtual char isListening( ActionListener *inListener );
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Tells all registered listeners that an action has been
|
||||
* performed.
|
||||
*
|
||||
* @param inTarget the GUI component on which the action
|
||||
* is being performed.
|
||||
*/
|
||||
virtual void fireActionPerformed( GUIComponent *inTarget );
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
inline ActionListenerList::~ActionListenerList() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline void ActionListenerList::addActionListener(
|
||||
ActionListener *inListener ) {
|
||||
|
||||
push_back( inListener );
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline void ActionListenerList::removeActionListener(
|
||||
ActionListener *inListener ) {
|
||||
|
||||
deleteElementEqualTo( inListener );
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline char ActionListenerList::isListening(
|
||||
ActionListener *inListener ) {
|
||||
|
||||
int index = getElementIndex( inListener );
|
||||
|
||||
if( index == -1 ) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline void ActionListenerList::fireActionPerformed( GUIComponent *inTarget ) {
|
||||
for( int i=0; i<size(); i++ ) {
|
||||
ActionListener *listener = *( getElement( i ) );
|
||||
listener->actionPerformed( inTarget );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
180
minorGems/ui/linux/KeyboardLinux.cpp
Normal file
180
minorGems/ui/linux/KeyboardLinux.cpp
Normal file
|
@ -0,0 +1,180 @@
|
|||
/*
|
||||
* Modification History
|
||||
*
|
||||
* 2000-December-7 Jason Rohrer
|
||||
* Created.
|
||||
*
|
||||
* 2000-December-8 Jason Rohrer
|
||||
* Changed so that key state functions take a string instead of
|
||||
* an integer vkey code.
|
||||
*
|
||||
* 2001-May-2 Jason Rohrer
|
||||
* Changed to use more standard SDL include location.
|
||||
*
|
||||
* 2006-June-26 Jason Rohrer
|
||||
* Added function to get events that are waiting in the queue.
|
||||
*/
|
||||
|
||||
#include "minorGems/ui/Keyboard.h"
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* Note: Linux implementation:
|
||||
* Requires that a ScreenGraphics be constructed before accessing the keyboard.
|
||||
*/
|
||||
|
||||
// prototypes:
|
||||
|
||||
/**
|
||||
* Maps an ascii string description of a key, such as "a", to an SDL keycode.
|
||||
*
|
||||
* @param inKeyDescription an ascii description of a key.
|
||||
*
|
||||
* @return the SDL keycode.
|
||||
*/
|
||||
int getKeyCode( const char *inKeyDescription );
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Maps a keycode to an ascii character.
|
||||
*
|
||||
* @param inSDLKeycode the keycode.
|
||||
*
|
||||
* @return the ascii character, or -1 if the keycode is not mappable to ascii.
|
||||
*/
|
||||
int getKeyASCII( int inSDLKeycode );
|
||||
|
||||
|
||||
|
||||
|
||||
#define M_KEY SDLK_m
|
||||
#define N_KEY SDLK_n
|
||||
|
||||
#define S_KEY SDLK_s
|
||||
|
||||
#define Q_KEY SDLK_q
|
||||
|
||||
#define L_KEY SDLK_l
|
||||
|
||||
#define R_KEY SDLK_r
|
||||
|
||||
#define T_KEY SDLK_t
|
||||
|
||||
|
||||
|
||||
//char Keyboard::getKeyDown( int vKeyCode ) {
|
||||
char Keyboard::getKeyDown( const char *inKeyDescription ) {
|
||||
SDL_PumpEvents();
|
||||
Uint8 *keys;
|
||||
keys = SDL_GetKeyState( NULL );
|
||||
return keys[ getKeyCode( inKeyDescription ) ] == SDL_PRESSED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//char Keyboard::getKeyUp( int vKeyCode ) {
|
||||
char Keyboard::getKeyUp( const char *inKeyDescription ) {
|
||||
SDL_PumpEvents();
|
||||
Uint8 *keys;
|
||||
keys = SDL_GetKeyState( NULL );
|
||||
return keys[ getKeyCode( inKeyDescription ) ] == SDL_RELEASED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int Keyboard::getKeyPressedEvent() {
|
||||
|
||||
SDL_Event event;
|
||||
|
||||
if( SDL_PollEvent( &event ) ) {
|
||||
switch( event.type ) {
|
||||
case SDL_KEYDOWN:
|
||||
return getKeyASCII( event.key.keysym.sym );
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int getKeyCode( const char *inKeyDescription ) {
|
||||
|
||||
// note that strcmp functions return 0 if strings match
|
||||
|
||||
if( !strcasecmp( inKeyDescription, "m" ) ) {
|
||||
return SDLK_m;
|
||||
}
|
||||
else if( !strcasecmp( inKeyDescription, "n" ) ) {
|
||||
return SDLK_n;
|
||||
}
|
||||
else if( !strcasecmp( inKeyDescription, "s" ) ) {
|
||||
return SDLK_s;
|
||||
}
|
||||
else if( !strcasecmp( inKeyDescription, "q" ) ) {
|
||||
return SDLK_q;
|
||||
}
|
||||
else if( !strcasecmp( inKeyDescription, "l" ) ) {
|
||||
return SDLK_l;
|
||||
}
|
||||
else if( !strcasecmp( inKeyDescription, "r" ) ) {
|
||||
return SDLK_r;
|
||||
}
|
||||
else if( !strcasecmp( inKeyDescription, "t" ) ) {
|
||||
return SDLK_t;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int getKeyASCII( int inSDLKeycode ) {
|
||||
switch( inSDLKeycode ) {
|
||||
case SDLK_m:
|
||||
return 'm';
|
||||
break;
|
||||
case SDLK_n:
|
||||
return 'n';
|
||||
break;
|
||||
case SDLK_s:
|
||||
return 's';
|
||||
break;
|
||||
case SDLK_q:
|
||||
return 'a';
|
||||
break;
|
||||
case SDLK_l:
|
||||
return 'l';
|
||||
break;
|
||||
case SDLK_r:
|
||||
return 'r';
|
||||
break;
|
||||
case SDLK_t:
|
||||
return 't';
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
#define M_KEY SDLK_m
|
||||
#define N_KEY SDLK_n
|
||||
|
||||
#define S_KEY SDLK_s
|
||||
|
||||
#define Q_KEY SDLK_q
|
||||
|
||||
#define L_KEY SDLK_l
|
||||
|
||||
#define R_KEY SDLK_r
|
||||
|
||||
#define T_KEY SDLK_t
|
||||
*/
|
73
minorGems/ui/linux/MouseLinux.cpp
Normal file
73
minorGems/ui/linux/MouseLinux.cpp
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Modification History
|
||||
*
|
||||
* 2000-November-28 Jason Rohrer
|
||||
* Created.
|
||||
*
|
||||
* 2001-May-2 Jason Rohrer
|
||||
* Changed to use more standard SDL include location.
|
||||
*/
|
||||
|
||||
#include "minorGems/ui/Mouse.h"
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
|
||||
/**
|
||||
* Note: Linux implementation:
|
||||
* Requires that a ScreenGraphics be constructed before accessing the mouse.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
void Mouse::getLocation( int *outX, int *outY ) {
|
||||
SDL_PumpEvents();
|
||||
SDL_GetMouseState( outX, outY );
|
||||
/*
|
||||
SDL_PumpEvents( void );
|
||||
|
||||
int numEventsToGet = 99;
|
||||
|
||||
SDL_Event *events = new SDL_Event[numEventsToGet];
|
||||
|
||||
// get events from the queue
|
||||
int numEventsRetrieved = SDL_PeepEvents( events, numEventsToGet,
|
||||
SDL_GETEVENT, SDL_MOUSEMOTIONMASK );
|
||||
|
||||
// for mouse motion, we only care about the last event
|
||||
SDL_Event lastEvent = events[ numEventsRetrieved - 1 ];
|
||||
|
||||
delete [] events;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
char Mouse::isButtonDown( int inButtonNumber ) {
|
||||
SDL_PumpEvents();
|
||||
|
||||
int x, y;
|
||||
|
||||
Uint8 buttonState = SDL_GetMouseState( &x, &y );
|
||||
|
||||
if( inButtonNumber == 0 ) {
|
||||
return( buttonState & SDL_BUTTON_LMASK );
|
||||
}
|
||||
|
||||
if( mNumButtons >=3 ) {
|
||||
// if we care about 3 buttons, then count the middle button
|
||||
// as button 1
|
||||
if( inButtonNumber == 1 ) {
|
||||
return( buttonState & SDL_BUTTON_MMASK );
|
||||
}
|
||||
if( inButtonNumber == 2 ) {
|
||||
return( buttonState & SDL_BUTTON_RMASK );
|
||||
}
|
||||
}
|
||||
else {
|
||||
// we care about 2 or fewer buttons
|
||||
if( inButtonNumber == 1 ) {
|
||||
return( buttonState & SDL_BUTTON_RMASK );
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue