![]() |
Multimedia »
DirectX »
General
Intermediate
A DirectX WrapperBy arussellA DirectX Wrapper |
VC6Win2K, WinXP, Win2003, DirectX, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

Unzip the project in any directory of your choosing. The main workspace can be opened using the "DXSmithLib.dsw" workspace. The program requires at least DirectX 7.0 to compile and run.
[editor's note--the programs have been compiled and run successfully using VS6 on a Win2K machine with DirectX 9.0 SDK installed]
DXSmith is a wrapper around Microsoft's DirectX graphic libraries. The current version wraps the Direct Draw 2D graphics, I/O, sound, and music for DX7. No 3D functions are wrapped or used. The DXSmith wrapper provides a set of higher level functions that are easier to use and learn than the DirectX API. DXSmith makes it easier for beginners to use DirectX. DirectX is a very flexible API, but that very flexibility also makes it fairly complicated. DXSmith also provides tools to create and draw animated sprites, and simple GUI's without using MFC calls. A number of GDI calls are also wrapped to provide higher level functions like lines, circles, text, and pie sections. DXSmith also provides "resource management". Place all your data files in a sub-directory, or libraries in the sub-directory and the resource manager will load, unload, and track the resources in memory.
DXSmith provides everything for the amateur game programmer to get started with DirectX.
int
GetLastError(CString *errStr); Return the last error code and string set
by a CgsdxIO() function. GSDX_OK is returned if no
errors have yet occurred.
errStr: the last error string is copied to this.
RETURNS: Last error code.
DWORD
GetINI(LPCSTR pSectionName, LPCSTR pKeyName, LPCSTR \
pDefault, char
*pReturnedString, DWORD sizeRetStr, LPCSTR pFileName);
Read text data from a normal text INI file.
pSectionName |
name of the section to read the data from. Do not include the "[ ]" in the section name. |
pKeyName |
name of the key within the section to read. |
pDefault |
value to return if the section or key is not found. |
pReturnedString |
string to copy the requested value to from the INI file. |
sizeRetStr |
length of pReturnedString. If the length of the data exceeds sizeRetStr it will be truncated. |
pFileName |
name of the INI file to read from. If the filename includes a path (detected by searching for the back-slash "\" character) the resource paths are not searched. If the filename has no path, then the currently registered resource paths are searched for the INI file. |
RETURNS: Length of the string copied to pReturnedString.
Example:
char str[90]; GetINI("main_section", "one_key", "default_value", str, 90, "foobar.ini");
DWORD
GetINI(LPCSTR pSectionName, LPCSTR pKeyName, long \
defaultValue, long
*pReturnedLong, LPCSTR pFileName);
Read integer data from a normal text INI file. Attempts to convert the text to an integer.
pSectionName |
name of the section to read the data from. Do not include the "[ ]" in the section name. |
pKeyName |
name of the key within the section to read. |
pDefault |
value to return if the section or key is not found. |
pReturnedLong |
integer to copy the requested value to from the INI file. |
pFileName |
name of the INI file to read from. If the filename includes a path (detected by searching for the back-slash "\" character) the resource paths are not searched. If the filename has no path, then the currently registered resource paths are searched for the INI file. |
RETURNS: Length of the string representing the integer copied to
pReturnedLong.
Example:
long val; GetINI("main_section", "one_key", 999, &val, "foobar.ini");
int SetINI(LPCSTR pSectionName, LPCSTR pKeyName, LPCSTR pString, LPCSTR pFileName);
Write text data to a normal text INI file.
pSectionName |
name of the section to write the data to. Do not include the "[ ]" in the section name. |
pKeyName |
name of the key within the section to set. |
pString |
value to set the key to. |
pFileName |
name of the INI file to write to. If the filename includes a path (detected by searching for the back-slash "\" character) the resource paths are not searched. If the filename has no path, then the currently registered resource paths are searched for the INI file. |
RETURNS: Non-zero on success.
Example:
SetINI("main_section", "one_key", "key_value", "foobar.ini");
int
SetINI(LPCSTR pSectionName, LPCSTR pKeyName, long value, LPCSTR
pFileName);
Write integer data to a normal text INI file. Converts the integer to text.
pSectionName |
name of the section to write the data to. Do not include the "[ ]" in the section name. |
pKeyName |
name of the key within the section to set. |
value |
value to set the key to. |
pFileName |
name of the INI file to write to. If the filename includes a path (detected by searching for the back-slash "\" character) the resource paths are not searched. If the filename has no path, then the currently registered resource paths are searched for the INI file. |
RETURNS: Non-zero on success.
Example:
SetINI("main_section", "one_key", 1234, "foobar.ini");
int Blit(RECT *pDest, gsdxBitmap_t *pSrc, int transparent=1, HDC
hdc=NULL);
Draw a bitmap to the off-screen buffer. Call Flip() to display
the current off-screen buffer. Use pDest to set the size and location of the
bitmap. By changing the destination size you can scale the bitmap to any desired
size. Clipping is supported. If clipping is disabled be sure that
pDest does not exceed the off-screen buffer's boundaries.
| pDest | the destination position and size of the bitmap to be blitted. Note that the (right - left) equals the width, not the width -1, and (bottom - top) equals the height. |
| pScr | source bitmap, loaded by LoadBitpmap(). Transparent--if
non-zero then all pixels matching the top-left pixel are transparent.
Transparency not supported in GDI mode. |
| hdc | if not NULL the specified hdc is used instead of the default full-screen hdc. |
RETURNS: Zero on success. A GSDX_ERROR_ code on failure.
int Blit(POINT *pDest, gsdxBitmap_t *src, int transparent=1, HDC
hdc=NULL);
Draw a bitmap to the off-screen buffer. Call Flip() to display
the current off-screen buffer. Use pDest to set location of the
bitmap. The bitmap is displayed at its original size. If clipping is disabled be
sure that blitted bitmap does not exceed the off-screen buffer's boundaries.
| pDest | the destination position of the bitmap to be blitted. |
| pScr | source bitmap, loaded by LoadBitpmap().
Transparent--if non-zero then all pixels matching the top-left pixel are
transparent. Not supported in GDI mode. |
| hdc | if not NULL the specified hdc is used instead of the default full-screen hdc. |
RETURNS: Zero on success. A GSDX_ERROR_ code on failure.
DWORD CgsdxIO::ConvertRGB(DWORD rgb);
Line(), Ellipse(), PieFill()). Should be used for any DirectX
function that takes a color parameter (Blit()). Only valid for
full-screen modes, and requires that InitGraphics() be called
previously.int EnableClipping(int enable=1);
SetClipping() before enabling
clipping.int EllipseFill(int left, int top, int right, int bottom, DWORD colour,
HDC hdc);
int Flip(void);
Flip() to display it.inline gsdxMode_t *GetGraphicModeInfo(int index);
GetModes()
before calling this function. Use GetNumGraphicModes() to get the
number of detected graphics modes.typedef struct { int width, height; // size of logical screen int colorBits; // color depth } gsdxMode_t;RETURNS: Zero on success. A GSDX_ERROR_ code on failure.
int GetModes(void);
GetGraphicModeInfo() and
GetNumGraphicModes() can be called to get information on all
supported graphics modes.inline int GetNumGraphicModes(void);
GetModes() before calling this
function.int InitGraphics(int width, int height, int colorDepth, DWORD
options);
GetModes() and
GetGraphicsModeInfo() to detect support widths, heights, and color
depths. If the GDI mode is selected the current video mode is NOT changed, and
no buffers are prepared.
This function must be called before any other graphics function is called.
| width | width of the screen in pixels. |
| height | height of the screen in pixels. |
| colorDepth | number of bits per pixel. |
| options | full-screen or GDI. If full screen the GDSX_CONSOLE_MODE option must also be used if the exe if a console application. |
| GSDX_FULL_SCREEN | Exclusive full screen mode with double buffering. |
| GSDX_WINDOWED_GDI | Retain the current video mode. (NOTE: some functions will not be supported or have reduced function). |
| GSDX_CONSOLE_MODE | Only use with the full screen option if the exe is a console application. Failing to use this option with console applications will cause the application to crash. |
RETURNS: Zero on success. A GSDX_ERROR_ code on failure.
int IsMode(int width, int height, int colorDepth);
Returns non-zero if the specified video mode is supported in full-screen mode.
| width | width in pixels of mode to check. |
| height | height in pixels of mode to check. |
| colorDepth | colorDepth, in bits, of mode to check. |
RETURNS: Non-zero if the specified video mode is support, zero if the mode is not supported.
int Line(int x0, int y0, int x1, int y1, int width, DWORD
colour);
Draw line from (x0, y0) to (x1, y1) using the width and color specified. Note that the value passed to color depends on the pixel format of the selected mode.
| x0 | starting X position |
| y0 | starting Y position |
| x1 | ending X position |
| y1 | ending Y position |
| width | width of the line in pixels |
| colour | colour of the line. Note that same value of colour will give different colours on the screen depending on the current video mode and pixel format for that mode. |
RETURNS: Zero on success. A GSDX_ERROR_ code on failure.
gsdxBitmap_t *LoadBitmap(LPCSTR pFileName, RECT *pRect);
Load a bitmap from a file and prepare it to be blitted for the currently
selected video mode. InitResource() must be called first.
If the image is already loaded the currently loaded image is used for the bitmap. One image can have many bitmaps stored on it. Each bitmap will point to the area of the main image containing its region.
The returned bitmap must be `deleted' when the bitmap is no longer
required. This only deletes this particular bitmap (which includes a
pointer to the main source image), NOT the main source image in memory. Call
UnLoadAllBitmaps() to unload all the main source images.
| pFileName | name of the bitmap to be loaded. The resource paths and libraries are searched if there is no path included in the name. Currently only BMP format files are supported, and must have the .bmp file extenstion. |
| pRect | if NULL the returned bitmap is the whole source image. If pRect is not NULL and right and bottom are not zero then it defines the region of the source image to return as the bitmap. This enables multiple bitmaps to be stored in one image file. If pREct is not NULL, but right and bottom are zero then pRect is filled in with the size of the whole source image. |
RETURNS: Pointer to the loaded bitmap.
int PieFill(int left, int top, int right, int bottom, \
int x1, int
y1, int x2, int y2, DWORD colour,HDC hdc=NULL);
int RectFill(RECT *rect, DWORD color, HDC hdc=NULL);
Draw a solid filled rectangle. Note that the same value of color will give
different colors on screen depending on the current video mode's pixel format.
Use ConvertRGB() to change an RGB() value to a video
mode specific value. This function may be faster than Line() for
vertical and horizontal lines.
| rect | defines the rectangular region to be filled. |
| color | colour of the filled rectangle. Note that the same value of color will give different colours on screen depending on the current video mode's pixel format. |
RETURNS: Zero on success. A GSDX_ERROR_ code on failure.
int SetBlitOptions(DWORD optionFlags);
int SetClipping(RECT *pClipRect, int numRects=1);
Define multiple clipping regions. Use EnableClipping() after
calling this function to enable the defined clipping regions. All
Blits() and RectFills() that fall outside of the
defined regions will be clipped (not displayed). A second call to
SetClipping() deletes the previous clipping regions and sets up the
new regions.
| pClipRects | array of RECTS, each of which defines one clipping region. |
| numRects | number of RECTS in pClipRects. |
RETURNS: Zero on success. A GSDX_ERROR_ code on failure.
Example:
RECT *clips, r; clips=new RECT[2]; clips[0].right=900; clips[0].left=100; clips[0].top=100; clips[0].bottom=500; clips[1].right=90; clips[1].left=0; clips[1].top=0; clips[1].bottom=90; SetClipping(clips, 2); r.left=100; r.right=900; r.top=100; r.bottom=500; SetClipping(&r); // default 1 rect EnableClipping(); // default ON
int UnLoadAllBitmaps(void);
int DrawText(HFONT font, int x, int y, DWORD fore, DWORD back,
\
LPCSTR s, SIZE *size=NULL, HDC hdc=NULL);
int
DrawText(HFONT font, int x, int y, DWORD fore, DWORD back, \
LPCSTR s, int
len, SIZE *size, HDC hdc);
int DrawText(HFONT font, int x, int y, DWORD fore, DWORD back, char
\
a, SIZE *size, HDC hdc);
Draw text on the screen using the specified font, colour, and position.
| font | if NULL, use the default font. If not NULL it must be a font created
by CreateFont(). |
| x, y | position on the screen of the top left pixel of the text. |
| fore | colour of the text. Note that the same value of colour will display different colours depending on the pixel format of the current video mode. |
| back | background colour. Use GSDX_TRANSPARENT_TEXT for a transparent background. |
| s | if using the version without `len' s is a null terminated string. If len is specified then s is at least len long. |
| len | length of the string s. |
| size | if not NULL it is filled with the region that the text was drawn to. |
| hdc | if not NULL it over-rides the default full-screen hdc. |
RETURNS:
Zero on success. A GSDX_ERROR_ code on failure.
int DeleteFont(HFONT font);
CreateFont().HFONT CreateFont(int height, int weight, int proportional=1, int
serif=1);
Create a font to be used with DrawText().
| height | logical height of the font. Not quite the same as pixels. |
| weight | how `thick' the font is. 0 is `don't care' and the default will be used. Must be between 0 and 1000. |
| proportional | set to non-zero for a proportional font (each letter is a different width), or zero for a fixed-width font (each letter is the same width). Generally, proportional fonts look nicer. |
| serif | set to non-zero for a serif font, zero for a non-serif font. Serif fonts have the little bars at the letters ends (eg Times), and non-serif lack these little bars (eg Arial). |
These MS defined values can be used:
| FW_THIN | 100 |
| FW_EXTRALIGHT | 200 |
| FW_LIGHT | 300 |
| FW_NORMAL | 400 |
| FW_MEDIUM | 500 |
| FW_SEMIBOLD | 600 |
| FW_BOLD | 700 |
| FW_EXTRABOLD | 800 |
| FW_HEAVY | 900 |
RETURNS: A pointer to a font that can be used with
DrawText().
Example:
HFONT font=NULL; font=CreateFont(24, FW_MEDIUM, 0, 1); DrawText(font, 10, 100, RGB(255, 0,0), 0, "Hi World"); DeleteFont(font);
int GetTextSize(HFONT font, char *s, SIZE *size, HDC
hdc=NULL);
HFONT font; SIZE size; Font=CreateFont(24, 300, 1,1); GetTextSize(font, "hi world", &size);
int UnLoadAllFonts(void);
CreateFont().int AddResourcePath(LPCSTR path);
AddResourcePath()AddResourcePath("file:///c://data//maps//">c:\\data\\maps\\");
int GetFullResourcePath(LPCSTR pName, char *fullPath);
Search for pName in the resource directories, and return its full-path in fullPath if found.
| pName | name of the file to find. Do not include any path, do include the extension. |
| fullPath | the full path and filename will be copied to fullPath if the file is found. Be sure fullPath is long enough for the longest legal path and filename. |
RETURNS:
Zero on success. A GSDX_ERROR_ code on failure.
Example:
char path[MAX_PATH = 1]; GetFullResourcePath("foo.map", path);path will be set to something like: c:\data\foo.map
void * GetResource(DWORD index);
LoadResource()long index; Mapt_t *map1, *map1_alias; map1=LoadResource("foo.map", &index); map1_alias=GetResource(index);
int InitResource(DWORD options);
LoadBitmap() and
LoadSound() also requires that this be called as they use the
resource functions. Does not depend on InitGraphics(). Default
paths are added: exe_path\data, and cd_drive:\data where exe_path is the path
that the exe ran from. cd_drive is the drive letter for any cd drive
detected.InitResource()C:\myexe\data
E:\data
F:\data
options: not defined, set to zero.
RETURNS: Zero on success. A
GSDX_ERROR_ code on failure.
void * LoadResource(LPCSTR pName, DWORD *pIndex=NULL, DWORD
*pSize=NULL);
Load a file into memory. The resource paths are searched for the file.
Libraries in the resource paths are also searched. The last `good' path or
library is searched first - always call LoadResource() on files in
the same directory in batches if possible. If the file is already loaded its
count is increased and the existing pointer is returned.
| pName | name of file to load into memory. |
| pIndex | pointer to a DOWRD to return the INDEX in. Can be used by
GetResource() to quickly get a pointer to a previously loaded
resource. Using GetResource() is MUCH faster than calling
LoadResource(). |
| pSize | pointer to a DWORD to hold the size, in bytes, of the file loaded into memory. |
RETURNS: NULL on error, a pointer to the loaded file if OK. Call
GetLastError() to get detailed error information.
Example:
Map_t *map; DWORD index, size; map=LoadResource("foo.map"); map=LoadResource("foo.map", &index, &size);
int UnLoadAllResources(void);
int UnLoadResource(LPCSTR pName);
int UnLoadResource(DWORD index);
Decrement a resource count, and unloads from memory it if its count reaches zero.
| pName | name of a previously loaded resource without a path. |
| index | index of a resource as returned by
LoadResource() |
RETURNS: Zero on success. A GSDX_ERROR_ code on failure.
int InitSound(DWORD options, WORD bits=8, WORD rate=22050);
Initializes sound and music. InitSound() MUST be called first.
No sound or music functions will work until InitSound is
called.
| options | not defined, use zero. |
| bits | sample size for digital sound. |
| rate | sampling rate for digital sound. |
NOTES: For best performance all digital sounds should be created using the
same bits and rate value which should be set correctly when InitSound() is
called.
RETURNS: Zero on success. A GSDX_ERROR_ code on failure.
int LoadSound(LPCSTR pName, DWORD *pID);
Pre-Load a sound so that it can be played by Playsound().
InitResource() must be called before this is called.
| pName | name of the WAV file to pre-load. The resource paths and libraries are searched. |
| pID | the ID of the sound is copied to pID and is used to play the sound
using PlaySound(). |
RETURNS: Zero on success. A GSDX_ERROR_ code on failure.
int PlayMusic(LPCSTR pName, int loop=1);
Load and play a MIDI song. If a song is playing, it will be stopped and unloaded before the next is started.
| pName | name of the MID file to play. The resource paths are searched, but libraries cannot be used to store MIDI songs. If pName is NULL the current song is stopped and unloaded. |
| loop | set to non-zero to loop forever. |
RETURNS: Zero on success. A GSDX_ERROR_ code on failure.
int PlaySound(DWORD id, int loop=0, int pan=0, int
pan_speed=0);
Plays a previously loaded sound.
| id | id value set by LoadSound(). |
| loop | set to non-zero to loop forever. Set to -1 to stop a currently playing sound. Does not unload the sound if it is stopped. |
| pan | not implemented, set to zero. |
| pan_speed | not implemented, set to zero. |
RETURNS: Zero on success. A GSDX_ERROR_ code on failure.
int UnLoadAllSounds(void);
LoadSound() after
UnLoadAllSounds() is called before it can be played
again.int AcquireAllDevices(void);
WndProc() function for
the WM_ACTIVATE message.DWORD GetAutoRepeat(void);
DWORD GetAutoRepeatStart(void);
int GetCapState(void);
gsdxEvent_t * GetEvent(gsdxEvent_t *pEvent=NULL);
InitIO() must be
called with the events desired turned on. If a gsdxEvent_t pointer is passed in
then the oldest event is copied to it.Joystick:
Mouse:
Please see the definition of gsdxEvent_t for details on the data returned in
an event.
pEvent: pointer to gsdxEvent_t to hold the event
information.
RETURNS: NULL if no event is ready, or no event passed in.
Returns a pointer to pEvent if an event is available.
DWORD GetIoMode(void);
Return the current I/O mode. A bitmask containing these options:
| GSDX_IO_WANT_MOUSE_EVENTS |
| GSDX_IO_WANT_KEY_EVENTS |
| GSDX_IO_WANT_JOYSTICK_EVENTS |
| GSDX_IO_KEY_AUTO_REPEAT |
| GSDX_IO_WANT_ALL_EVENTS |
int GetJoystickInfo(gsdxJoystickInfo_t *pJinfo, int
index=0);
Return information about the detected joysticks.
| pJinfo | pointer to structure to hold the information for the selected joystick. |
| index | index number of the joystick to get information on. Joysticks index start at zero (0). |
Use GetNumberOfJoysticks() to get the maximum index.
// joystick enumeration information typedef struct { int num_buttons; // joy buttons int num_axis; // x, y, throttle, rudder etc... int num_povs; // number of pov devices, eg a 'hat' } gsdxJoystickInfo_t;RETURNS: Zero on success. A GSDX_ERROR_ code on failure.
int GetJoystickState(gsdxJoystickState_t *pState, int
index=0);
Return the current state of the selected joystick, that is, the current X, Y throttle, etc. values.
| pState | pointer to structure to hold the selected joysticks state. |
| index | index to select joystick, indexes start at zero. |
// current joystick state typedef struct { int x, y, z; // z is throttle on MS sidewinder int rx, ry, rz; // three 'rudders' rz is used by MS sidewinder int pov[GSDX_MAX_POV]; // multiple pov's DWORD buttons; // 32 buttons, if a bit is set the button is DOWN } gsdxJoystickState_t;Example:
gsdxJoystickState_t joyState; char temp[100], *t1; DWORD mask; GetEvent(NULL); GetJoyStickState(&joyState); // check the first 10 buttons t1=temp; for ( mask=1,i=0; i < 10; i++, mask<<=1 ) { if ( (mask & joyState.buttons) ) *t1='*'; else *t1=' '; t1++; }RETURNS: Zero on success. A GSDX_ERROR_ code on failure.
inline int GetNumberOfJoysticks(void);
int GetNumState(void);
int GetMouseInfo(gsdxMouseInfo_t *pMinfo);
typedef struct { int num_buttons; // left, right, wheel button, other buttons int num_axis; // X Y are 2 axis, wheel mouse adds a third axis. } gsdxMouseInfo_t;RETURNS: Zero on success. A GSDX_ERROR_ code on failure.
int GetMouseState(gsdxMouseState_t *pState);
// current mouse state typedef struct { int x, y, z; // wheel is z, current value for each of these int dx, dy, dz; // wheel is z, change in each value since last call DWORD buttons; // if a bit is set the button is down. int max_x, max_y, max_z; // Max_x and max_y // default to the screen resolution in pixels. } gsdxMouseState_t;RETURNS: Zero on success. A GSDX_ERROR_ code on failure.
int GetScrollState(void);
int InitIO(DWORD options=GSDX_IO_WANT_ALL_EVENTS);
InitGraphics() MUST be
called before InitIO() is called.options: controls the type of events generated by GetEvent().
Use a logical OR to combine the desired events.
| GSDX_IO_WANT_MOUSE_EVENTS |
| GSDX_IO_WANT_KEY_EVENTS |
| GSDX_IO_WANT_JOYSTICK_EVENTS |
| GSDX_IO_KEY_AUTO_REPEAT |
| GSDX_IO_WANT_ALL_EVENTS |
RETURNS: Zero on success. A GSDX_ERROR_ code on failure.
int IsKeyDown(DWORD index);
if ( IsKeyDown(DIK_ESCAPE) ) printf("ESC is pressed\n");All supported DIK codes (not all keyboards have all these keys):
DIK_TAB
DIK_Q
DIK_W
DIK_E
DIK_R
DIK_T
DIK_Y
DIK_U
DIK_I
DIK_O
DIK_P
DIK_LBRACKET
DIK_RBRACKET
DIK_RETURN
DIK_LCONTROL
DIK_A
DIK_S
DIK_D
DIK_F
DIK_G
DIK_H
DIK_J
DIK_K
DIK_L
DIK_SEMICOLON
DIK_APOSTROPHE
DIK_GRAVE
DIK_LSHIFT
DIK_BACKSLASH
DIK_Z
DIK_X
DIK_C
DIK_V
DIK_B
DIK_N
DIK_M
DIK_COMMA
DIK_PERIOD
DIK_SLASH
DIK_RSHIFT
DIK_MULTIPLY
DIK_LMENU
DIK_SPACE
DIK_CAPITAL
DIK_F1
DIK_F2
DIK_F3
DIK_F4
DIK_F5
DIK_F6
DIK_F7
DIK_F8
DIK_F9
DIK_F10
DIK_NUMLOCK
DIK_SCROLL
DIK_NUMPAD7
DIK_NUMPAD8
DIK_NUMPAD9
DIK_SUBTRACT
DIK_NUMPAD4
DIK_NUMPAD5
DIK_NUMPAD6
DIK_ADD
DIK_NUMPAD1
DIK_NUMPAD2
DIK_NUMPAD3
DIK_NUMPAD0
DIK_DECIMAL
DIK_OEM_102
DIK_F11
DIK_F12
DIK_F13
DIK_F14
DIK_F15
DIK_KANA
DIK_ABNT_C1
DIK_CONVERT
DIK_NOCONVERT
DIK_YEN
DIK_ABNT_C2
DIK_NUMPADEQUALS
DIK_PREVTRACK
DIK_AT
DIK_COLON
DIK_UNDERLINE
DIK_KANJI
DIK_STOP
DIK_AX
DIK_UNLABELED
DIK_NEXTTRACK
DIK_NUMPADENTER
DIK_RCONTROL
DIK_MUTE
DIK_CALCULATOR
DIK_PLAYPAUSE
DIK_MEDIASTOP
DIK_VOLUMEDOWN
DIK_VOLUMEUP
DIK_WEBHOME
DIK_NUMPADCOMMA
DIK_DIVIDE
DIK_SYSRQ
DIK_RMENU
DIK_PAUSE
DIK_HOME
DIK_UP
DIK_PRIOR
DIK_LEFT
DIK_RIGHT
DIK_END
DIK_DOWN
DIK_NEXT
DIK_INSERT
DIK_DELETE
DIK_LWIN
DIK_RWIN
DIK_APPS
DIK_POWER
DIK_SLEEP
DIK_WAKE
DIK_WEBSEARCH
DIK_WEBFAVORITES
DIK_WEBREFRESH
DIK_WEBSTOP
DIK_WEBFORWARD
DIK_WEBBACK
DIK_MYCOMPUTER
DIK_MAIL
DIK_MEDIASELECT
void SetAutoRepeat(DWORD rep);
Set the keyboard auto-repeat rate in milliseconds.
void SetAutoRepeatStart(DWORD rep);
void SetIoMode(DWORD ioMode);
Set the i/o mode. Use these values:
| GSDX_IO_WANT_MOUSE_EVENTS |
| GSDX_IO_WANT_KEY_EVENTS |
| GSDX_IO_WANT_JOYSTICK_EVENTS |
| GSDX_IO_KEY_AUTO_REPEAT |
| GSDX_IO_WANT_ALL_EVENTS (includes auto-repeat) |
Example:
DWORD currMode; // turn off keyboard autorepeat currMode=GetIoMode(); currMode&=~ GSDX_IO_KEY_AUTO_REPEAT; SetIoMode(currMode); // and turn it back on currMode=GetIoMode(); currMode|= GSDX_IO_KEY_AUTO_REPEAT; SetIoMode(currMode);
GuiLib provides functions that display and use simple graphical user interfaces suitable for use with games without using any MFC or win32 calls. Use GUIEdit to create GUI panels. Multiple panels can be loaded, but only the last loaded panel is active and returns events.
CGui::CGui(CgsdxIO *dx);
if ( dx.InitResource(0) ) return 0; if ( dx.InitGraphics(640, 480, 32, GSDX_FULL_SCREEN, g_hInst, g_hMainWnd) ) return 0; if ( dx.InitSound() ) return 0; if ( dx.InitIO() ) return 0; CGui gui(&dx);
CGui::~CGui();
On exit the current gui panel is unloaded.
See testgui for an example of using the gui lib.
int gui_load_gadget(char *fname);
int gui_load_gadget(BYTE *buff);
Load a new gui panel, and prepare it for use. Makes it the active panel (loads onto tail of panel list)
| fname | name of the gui panel to load. The dx resource loader is used to locate the file. |
| buff | pointer to a memory buffer holding a raw gui panel file. |
RETURNS: zero if no errors.
void gui_pop_gadget(void)
void gui_unload_gadget(gui_list_t *gui_list);
gui_pop_gadget() is used to free the last gadget.
int gui_unload_all_gadgets()
void gui_load_mouse(char *mouse_name);
void gui_hide_mouse(void);
void gui_show_mouse(void);
int gui_do_gadget(gsdxEvent_t *event);
event: pointer an event to return any user i/o in. The event type will
indicate if it is a gui event, or other type of user i/o. The ID will indicate
which gadget was used if it is a gui event.
RETURNS: non-zero if the user
generated any events.
Example:
typedef struct { HFONT font; int frame_count; DWORD last_time, elapsed; int paused; int done; char msg[MSGLEN+1]; CGui *m_pGui; } TestInfo_t; TestInfo_t tt; int DoTestLogic(CgsdxIO *dx) { gsdxEvent_t event; if ( tt.paused ) return tt.done; if ( tt.m_pGui->gui_do_gadget(&event) ) { if ( event.type == GSDX_IO_TYPE_GUI) { switch ( event.event.gui.type ) { case GUI_BUTTON: sprintf(tt.msg, "Button id %d clicked", event.event.gui.id); break; case GUI_RADIO: sprintf(tt.msg, "Radio id %d clicked, active = %d", event.event.gui.id, event.event.gui.parm1); break; case GUI_SLIDER: sprintf(tt.msg, "Slider id %d height = %d", event.event.gui.id, event.event.gui.parm1); break; case GUI_STRING_INPUT: sprintf(tt.msg, "Input id %d", event.event.gui.id); break; case GUI_PLIST: sprintf(tt.msg, "Plist id %d cursor item = %d", event.event.gui.id, event.event.gui.parm1); break; } } if ( dx->IsKeyDown(DIK_ESCAPE) ) tt.done=1; } return tt.done; }
void gui_draw_gadget(void);
int DoTestDraw(CgsdxIO *dx) { int err=0; char temp[128]; if ( tt.paused ) return 0; dx->RectFill(NULL, 0); // fill screen black tt.m_pGui->gui_draw_gadget(); // draw some text tt.frame_count++; if ( tt.frame_count > 100 ) { tt.elapsed=timeGetTime() - tt.last_time; tt.last_time=timeGetTime(); tt.frame_count=0; } sprintf(temp, "frameRate: %04d", tt.elapsed/10); dx->DrawText(tt.font, 1,1, RGB(0,255,0), 0, temp); dx->DrawText(tt.font, 150,1, RGB(0,255,0), 0, tt.msg); tt.m_pGui->gui_draw_mouse(); dx->Flip(); return err; }
void CGui::gui_draw_all_gadgets()
GuiEdit is a visual editor for creating gui panels that can be used with the GUI lib. Gadgets can be added, deleted, copied, moved, resized, and the details edited. Use TestGui to display and test your gui panels under fullscreen mode. The TestGui source code also is a good example of using a gui panel created with GUIEdit.
This version of GuiEdit supports lists, buttons, radio buttons, text, and sliders.
NOTE! Use ID's higher than 99 for the gadgets you create to avoid conflicts with system created gadgets.
SpriteLib provides simple functions to load and display sprites created with SpriteEdit. A sprite is a collection of small bitmaps that are animated, eg bitmaps for a walking character.
CSprite(CgsdxIO *dx);
int DrawSprite(int index, int x, int y)
RETURNS: zero if no error, non-zero if error.
int IncrementSprite(int sprite_index, int direction);
| sprite_index | index of sprite to increment. |
| direction | set to greater than zero for the next frame, set to less than zero for the previous frame. Will wrap the frame to the beginning/end if max/min frame is exceeded. |
RETURNS: zero if no error, non-zero if error.
int AnimateSpriteBank(void);
int FreeSpriteBank(void);
int LoadSpriteBank(char *fname);
int LoadSpriteBank(BYTE *buff);
| Fname | name of a spritebank file. Uses the DX resource functions, thus
requires that InitResources() has been called. |
| buff | pointer to memory holding a valid spritebank file image. |
RETURNS: zero if no error, non-zero if error.
int GetWidest(int index);
int GetHighest(int index);
inline void SetHDC(HDC hdc);
inline void SetSpriteBank(spriteBank_t *bank);
inline spriteBank_t *GetSpriteBank(void);
inline DWORD GetDrawMode(void);
inline void SetDrawMode(DWORD mode);
inline RECT *GetCollisionRect(int index);
inline spriteFrame_t *GetCurrentFrame(int index);
Get a pointer to the internal data for the current frame of the sprite
indicated by index. Allows any value of the current frame to be
changed.
See spritelib.h for details of the structure.
inline int GetCurrentFrameNum(int index);
inline int GetNumAttachPoints(int index);
inline int GetNumFrames(int index);
inline POINT *GetAttachPoints(int index, int
indexAttach);
| Index | sprite index; |
| IndexAttach | index of the attach point to get for the current frame. |
inline POINT *GetAttachPoints(int index);
inline DWORD GetID(int index);
inline void SetID(int index, DWORD id);
inline DWORD GetDelay(int index);
inline void SetDelay(int index, DWORD delay);
inline int GetDX(int index);
inline int GetDY(int index);
inline DWORD GetChangeMode(int index);
inline void SetChangeMode(int index, DWORD mode);
inline void SetDX(int index, int dx);
inline void SetDY(int index, int dy);
inline int GetNumSprites(void);
A sprite is a small graphic that can be moved across (animated) on the
screen. Each sprite is made up of multiple frames that can be animated also.
SpriteEdit allows you to load a bitmap, and select regions of the bitmap to be
the frames of a sprite. Multiple sprites can be made from a single bitmap, and
multiple bitmaps can be loaded into one "spritebank".
In general:
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 18 Jul 2003 Editor: Marc Clifton |
Copyright 2003 by arussell Everything else Copyright © CodeProject, 1999-2009 Web18 | Advertise on the Code Project |