This is Google's cache of http://www.gamedeception.net/archive/index.php?t-3580.html. It is a snapshot of the page as it appeared on Aug 7, 2013 12:15:20 GMT. The current page could have changed in the meantime. Learn more
Tip: To quickly find your search term on this page, press Ctrl+F or ⌘-F (Mac) and use the find bar.

Text-only version
 
*OpenGL GUI 2* [Archive] - GameDeception - A Development Site for Reverse Engineering

View Full Version : *OpenGL GUI 2*



Organner
06-04-2004, 01:42 PM
This code is better, please comment it :)

Credits:
gfreeman1 (drawing code)
panzer ( some ideas )
LanceVorgin (mouse)



/*
Put this code in ur opengl func. file
*/

extern Gui OGui;
float mainViewAngles[2];
POINT pt;

//Every 5 viewports or hudredraw
OGui.DrawGui();

//Every viewport
if(YOUR_GUI_ACTIVE)
{
GetCursorPos(&pt);
Settings.MouseX = (Settings.MouseX - (centerX - pt.x));
Settings.MouseY = (Settings.MouseY - (centerY - pt.y));
OGui.DrawGui();
pEngfuncs->SetViewAngles(mainViewAngles);
}
else
{
Settings.MouseX = centerX;
Settings.MouseY = centerY;
pEngfuncs->GetViewAngles(mainViewAngles);
}





//Gui.h

class Gui
{
public:
void DrawGui();
void InitMouse ();
void DrawPointer();
void DrawShadow( int x, int y, int width, int height, int reversed );
void DrawFrame( int x, int y, int width, int height, int r, int g, int b, int a );
};

class Windows
{
public:
void DrawBody( int number, int x, int y, int width, int height, int r, int g, int b, int a );
void DrawTitle( int number, int x, int y, int width, int height, int r, int g, int b, int a, char* title );
void DrawClosePoint( int number, int closeX, int closeY );
};

class Buttons
{
public:
void DrawButton( int number, int x, int y, int width, int height, int r, int g, int b, int a, char* label );
};


typedef struct{
char* title;
int x;
int y;
int height; // Wysokos
int width; // Szerokosc
int transparent;
int r;
int g;
int b;
int a;
int drawX;
int drawY;
int movepointX;
int movepointY;
int movepointHeight;
int movepointWidth;
int closepointX;
int closepointY;
int closepointHeight;
int closepointWidth;
bool active;
}gui_windows;

typedef struct{
int WindowsCount;
int ButtonsCount;
int InputsCount;
int FontWidth;
int FontHeight;
int MovePointHeight;
int ClosePointHeight;
int ClosePointWidth;
int TitleBarHeight;
int FreeSpace;
int ButtonPressed;
int WindowSelected;
int InputSelected;
int CorrectionX;
int CorrectionY;
int MouseX;
int MouseY;
}gui_settings;

extern gui_windows Window[10];
extern Gui OGui;
extern gui_settings Settings;

Organner
06-04-2004, 01:44 PM
// Gui.cpp
#include "Gui.h"

typedef struct{
char* label;
int x;
int y;
int height;
int width;
int transparent;
int r;
int g;
int b;
bool pressed;
bool active;
}gui_buttons;

typedef struct{
int x;
int y;
int height; // Wysokos
int width; // Szerokosc
bool selected;
}gui_inputs;

gui_windows Window[10];
gui_buttons Button[10];
gui_inputs Input[10];

gui_settings Settings;
POINT Mouse;

Gui OGui;
Windows OWindow;
Buttons OButton;
int ButtonCenterX = 0;
int ButtonCenterY = 0;
bool Once = true;

void Gui::InitMouse ()
{
GetCursorPos(&Mouse);

if(Settings.WindowSelected)
{
Window[Settings.WindowSelected].x = Settings.MouseX;
Window[Settings.WindowSelected].y = Settings.MouseY;
}
else if(Settings.InputSelected)
{
//InputMode(input_selected);
}

for(int temp = 0; temp < 10; temp++)
{
if((Settings.MouseY > Window[temp].closepointY && Settings.MouseY < Window[temp].closepointY + Window[temp].closepointHeight) && (Settings.MouseX > Window[temp].closepointX && Settings.MouseX < Window[temp].closepointX + Window[temp].closepointWidth))
{
Window[temp].active = false;
return;
}
else if((Settings.MouseY > Window[temp].movepointY && Settings.MouseY < Window[temp].movepointY + Window[temp].movepointHeight) && (Settings.MouseX > Window[temp].movepointX && Settings.MouseX < Window[temp].movepointX + Window[temp].movepointWidth))
{
Settings.WindowSelected = temp;
return;
}
else if((Settings.MouseY > Button[temp].y && Settings.MouseY < Button[temp].y + Button[temp].height) && (Settings.MouseX > Button[temp].x && Settings.MouseX < Button[temp].x + Button[temp].width))
{
Settings.ButtonPressed = temp;
return;
}
else if((Settings.MouseY > Input[temp].y && Settings.MouseY < Input[temp].y + Input[temp].height) && (Settings.MouseX > Input[temp].x && Settings.MouseX < Input[temp].x + Input[temp].width))
{
Settings.InputSelected = temp;
return;
}
}
}


void Gui::DrawFrame( int x, int y, int width, int height, int r, int g, int b, int a )
{
FillRGBA(x, y, 1, height, r, g, b, a);
FillRGBA(x, y, width, 1, r, g, b, a);
FillRGBA(x, y + height, width, 1, r, g, b, a);
FillRGBA(x + width, y, 1, height + 1, r, g, b, a);
}

void Gui::DrawShadow( int x, int y, int width, int height, int reversed )
{
if(reversed)
{
FillRGBA(x, y, 1, height + 1, 0, 0, 0, 255); // Frame
FillRGBA(x, y, width + 1, 1, 0, 0, 0, 255);
FillRGBA(x, y + height, width, 1, 140, 140, 140, 255);
FillRGBA(x + width, y, 1, height + 1, 140, 140, 104, 255);
}
else
{
FillRGBA(x, y, 1, height + 1, 120, 120, 120, 255);
FillRGBA(x, y, width + 1, 1, 120, 120, 120, 255);
FillRGBA(x, y + height, width, 1, 0, 0, 0, 255);
FillRGBA(x + width, y, 1, height + 1, 0, 0, 0, 255);
}
}

void DrawInput( int number, int x, int y, int width, int height )
{
FillRGBA(x, y, 1, height + 1, 0, 0, 0, 255);
FillRGBA(x, y, width + 1, 1, 0, 0, 0, 255);
FillRGBA(x, y + height, width, 1, 140, 140, 140, 255);
FillRGBA(x + width, y, 1, height + 1, 140, 140, 104, 255);

Input[number].x = x;
Input[number].y = y;
Input[number].width = width;
Input[number].height = height;
}


void Buttons::DrawButton( int number, int x, int y, int width, int height, int r, int g, int b, int a, char* label )
{
int LabelCount = strlen(label);

ButtonCenterX = x + (width / 2) - LabelCount*Settings.FontWidth;
ButtonCenterY = y + (height / 2) + Settings.FontHeight;

if(Settings.ButtonPressed == number)
{
PlaySound("C:\\Click.wav",NULL, SND_FILENAME|SND_ASYNC);
FillRGBA(x + 1, y + 1, width, height, r, g, b, a); //Draws button
OGui.DrawShadow(x + 1, y + 1, width, height, 1); // Draws Frame
DrawText(ButtonCenterX + 1, ButtonCenterY + 1, 255/255, 255/255, 255/255, label);
}
else if(Settings.ButtonPressed != number)
{
FillRGBA(x, y, width, height, r, g, b, a);
OGui.DrawShadow(x, y, width, height, 0);
DrawText(ButtonCenterX, ButtonCenterY, 255/255, 255/255, 255/255, label);
}

Button[number].x = x;
Button[number].y = y;
Button[number].width = width;
Button[number].height = height;
}

void Windows::DrawClosePoint( int number, int closeX, int closeY )
{
OGui.DrawFrame(closeX, closeY, 6, 6, 255, 255, 255, 255);
Window[number].closepointX = closeX;
Window[number].closepointY = closeY;
Window[number].closepointHeight = Settings.ClosePointHeight;
Window[number].closepointWidth = 6;
closeX = closeX + Window[number].closepointWidth/2;
closeY = closeY + Window[number].closepointHeight/2;
DrawX(3, closeX, closeY, 255, 255, 255, 255);
}

void Windows::DrawTitle( int number, int x, int y, int width, int height, int r, int g, int b, int a, char* title )
{
int TitleCount = strlen(title);
FillRGBA(x, y, width, height, r, g, b, a);
OGui.DrawShadow( x, y, width, height, 0 );
DrawText(x + (width/2) - (TitleCount/2)*Settings.FontWidth, y + (height/2) + Settings.FontHeight, 255/255, 255/255, 255/255, title);
DrawClosePoint(number, x + width - (Settings.ClosePointWidth + 3), y + (height/2) - Settings.ClosePointHeight/2);

Window[number].movepointX = x;
Window[number].movepointY = y;
Window[number].movepointHeight = height;
Window[number].movepointWidth = width;
}

void Windows::DrawBody( int number, int x, int y, int width, int height, int r, int g, int b, int a )
{
FillRGBA(x, y, width, height, r, g, b, a);
OGui.DrawShadow(x + 5, y + 5, width - 10, height - 10, 1);
OGui.DrawShadow(x, y, width, height, 0);
Window[number].drawX = x + 10;
Window[number].drawY = y + 15;
}


void Gui::DrawPointer( void )
{
int r = 0;
int g = 0;
int b = 255;
int a = 255;
FillRGBA(Settings.MouseX - 1 , Settings.MouseY - 1 , 1, 1, r, g, b, a);
FillRGBA(Settings.MouseX , Settings.MouseY - 1 , 1, 1, r, g, b, a);
FillRGBA(Settings.MouseX , Settings.MouseY + 10, 1, 1, r, g, b, a);
FillRGBA(Settings.MouseX + 1 , Settings.MouseY , 1, 1, r, g, b, a);
FillRGBA(Settings.MouseX + 1 , Settings.MouseY + 9 , 1, 1, r, g, b, a);
FillRGBA(Settings.MouseX + 2 , Settings.MouseY + 1 , 1, 1, r, g, b, a);
FillRGBA(Settings.MouseX + 2 , Settings.MouseY + 8 , 1, 1, r, g, b, a);
FillRGBA(Settings.MouseX + 3 , Settings.MouseY + 2 , 1, 1, r, g, b, a);
FillRGBA(Settings.MouseX + 3 , Settings.MouseY + 9 , 1, 1, r, g, b, a);
FillRGBA(Settings.MouseX + 4 , Settings.MouseY + 3 , 1, 1, r, g, b, a);
FillRGBA(Settings.MouseX + 4 , Settings.MouseY + 11, 1, 1, r, g, b, a);
FillRGBA(Settings.MouseX + 5 , Settings.MouseY + 4 , 1, 1, r, g, b, a);
FillRGBA(Settings.MouseX + 5 , Settings.MouseY + 7 , 1, 1, r, g, b, a);
FillRGBA(Settings.MouseX + 5 , Settings.MouseY + 13, 1, 1, r, g, b, a);
FillRGBA(Settings.MouseX + 6 , Settings.MouseY + 5 , 1, 1, r, g, b, a);
FillRGBA(Settings.MouseX + 6 , Settings.MouseY + 7 , 1, 1, r, g, b, a);
FillRGBA(Settings.MouseX + 6 , Settings.MouseY + 9 , 1, 1, r, g, b, a);
FillRGBA(Settings.MouseX + 6 , Settings.MouseY + 13, 1, 1, r, g, b, a);
FillRGBA(Settings.MouseX + 7 , Settings.MouseY + 6 , 1, 1, r, g, b, a);
FillRGBA(Settings.MouseX + 7 , Settings.MouseY + 11, 1, 1, r, g, b, a);
r = 255;
g = 0;
b = 0;
a = 100;
FillRGBA(Settings.MouseX , Settings.MouseY , 1, 1, r, g, b, a);
FillRGBA(Settings.MouseX + 1 , Settings.MouseY + 1 , 1, 1, r, g, b, a);
FillRGBA(Settings.MouseX + 2 , Settings.MouseY + 2 , 1, 1, r, g, b, a);
FillRGBA(Settings.MouseX + 3 , Settings.MouseY + 3 , 1, 1, r, g, b, a);
FillRGBA(Settings.MouseX + 4 , Settings.MouseY + 4 , 1, 1, r, g, b, a);
FillRGBA(Settings.MouseX + 5 , Settings.MouseY + 5 , 1, 1, r, g, b, a);
FillRGBA(Settings.MouseX + 5 , Settings.MouseY + 9 , 1, 1, r, g, b, a);
FillRGBA(Settings.MouseX + 6 , Settings.MouseY + 6 , 1, 1, r, g, b, a);
FillRGBA(Settings.MouseX + 6 , Settings.MouseY + 11, 1, 1, r, g, b, a);
}

...

Organner
06-04-2004, 01:45 PM
void Gui::DrawGui()
{
if(Once)
{
int ScreenX = 0;
int ScreenY = 0;

Settings.CorrectionX = ScreenX - 640;
Settings.CorrectionY = ScreenY - 480;

switch(ScreenX+ScreenY)
{
case 640+480:
Settings.FreeSpace = 2;
Settings.TitleBarHeight = 12;
Settings.FontHeight = 3;
Settings.FontWidth = 7;
Settings.ClosePointHeight = 6;
Settings.ClosePointWidth = 6;
break;
case 800+600:
Settings.FreeSpace = 2;
Settings.TitleBarHeight = 12;
Settings.FontHeight = 3;
Settings.FontWidth = 7;
Settings.ClosePointHeight = 6;
Settings.ClosePointWidth = 6;
break;
case 1024+768:
Settings.FreeSpace = 2;
Settings.TitleBarHeight = 12;
Settings.FontHeight = 3;
Settings.FontWidth = 7;
Settings.ClosePointHeight = 6;
Settings.ClosePointWidth = 6;
Settings.TitleBarHeight = Settings.TitleBarHeight + 5;
break;
default:
Settings.FreeSpace = 2;
Settings.TitleBarHeight = 12;
Settings.FontHeight = 3;
Settings.FontWidth = 7;
Settings.ClosePointHeight = 6;
Settings.ClosePointWidth = 6;
Settings.TitleBarHeight = Settings.TitleBarHeight + 5;
break;
}
Once = false;
}

if(UR_GUI_ACTIVE)
{
OGui.DrawPointer();

if( GetAsyncKeyState(VK_LBUTTON) )
{
OGui.InitMouse();
}
else if ( !GetAsyncKeyState(VK_LBUTTON) )
{
Settings.ButtonPressed = 0;
Settings.InputSelected = 0;
Settings.WindowSelected = 0;
}
}

for(int temp = 0; temp < 10; temp++)
{
if( Window[temp].active && strlen(Window[temp].title) )
{
Window[temp].r = 0;
Window[temp].g = 0;
Window[temp].b = 0;
Window[temp].a = 100;
OWindow.DrawTitle( temp, Window[temp].x, Window[temp].y, Window[temp].width, Settings.TitleBarHeight, Window[temp].r, Window[temp].g, Window[temp].b, Window[temp].a, Window[temp].title );
OWindow.DrawBody( temp, Window[temp].x, Window[temp].y + Settings.FreeSpace + Settings.TitleBarHeight, Window[temp].width, Window[temp].height, Window[temp].r, Window[temp].g, Window[temp].b, Window[temp].a );
}
}



This is no copy+paste code, u must have brain to get it working. Please credit ppl who helped me (look at credits), game-deception.com and me (Organner). Have Fun with ur own GUI.

(3 PARTS :/)

kream-
06-04-2004, 03:36 PM
wow thank for the new free source ^^ :)

Lance705
06-04-2004, 04:23 PM
Nice. Example SS?

De-Sire
06-04-2004, 05:16 PM
Nice work Organner :D

Organner
06-05-2004, 02:45 AM
http://games-cheats.net/organner/Screeny/Orgia%204/Gui6

LanceVorgin
06-05-2004, 03:42 AM
Better :) But still - go for each control is a class! Standard interfaces inherited for different controls -- from my old gui:



class CControl {
public:
virtual void Draw(bool bSelected);

virtual bool KeyEvent(int iKey, bool bDown, bool bRepeat);
virtual bool MouseEvent(int iBut, bool bDown);

void (*pfnCallback)(void);
protected:
CWindow* m_pParent;
};

class CButton : public CControl {
public:
char m_szText[BUTTON_MAX];

virtual void Draw(bool bSelected);

virtual bool MouseEvent(int iBut, bool bDown);

virtual bool GetDown();

private:
bool m_bPressed;
};

class CEditBox : public CControl {
public:
char m_szText[EDITBOX_MAX];

virtual void Draw(bool bSelected);

virtual bool KeyEvent(int iKey, bool bDown, bool bRepeat);
virtual bool MouseEvent(int iBut, bool bDown);

void (*pfnEnterCallback)();
void (*pfnTypeCallback)();
};

gfreeman1
06-05-2004, 12:05 PM
i'd have to agree with lance on this, using an OOP approach to a GUI will make it much easier for yourself, i started working on a generic opengl gui system myself, had a CBaseWindow class, from which all subsequent controls and windows would be derived, made things much easier to keep organized in my source.

xen
06-05-2004, 12:54 PM
Haha I seem to be thinking along the same lines as you guys, I never did finish this, maybe one day.



class CGuiTemplate
{
public:

CGuiTemplate(void) { }

CGuiTemplate(std::string sLabel, float fX, float fY, float fWidth, float fHeight, colorEntry *pNewColor)
{
setName(sLabel);
setCoords(fX,fY);
setDimensions(fWidth,fHeight);
setColor(pNewColor);
}

~CGuiTemplate(void) { }

inline void setCoords(float fX, float fY) { x = fX; y = fY; }
inline void setDimensions(float fWidth, float fHeight) { width = fWidth; height = fHeight; }
inline void setColor(colorEntry *pNewColor) { pColor = pNewColor; }
inline void setName(std::string sLabel) { sName = sLabel; }

inline void getCoords(float fX, float fY) { fX = x; fY = y; }
float getX() { return x; }
inline void getDimensions(float fWidth, float fHeight) { fWidth = width; fHeight = height; }
inline void getColor(colorEntry *pNewColor) { pNewColor = pColor; }

protected:

float x;
float y;
float width;
float height;

colorEntry *pColor;

std::string sName;
};

class CGuiWindow : public CGuiTemplate
{
public:

CGuiWindow(void) { }

CGuiWindow(std::string sLabel, float fX, float fY, float fWidth, float fHeight, colorEntry *pNewColor, int Type)
: CGuiTemplate(sLabel,fX,fY,fWidth,fHeight,pNewColor)
{
setType(Type);

addLog("fX %f x %f",fX,x);
}

~CGuiWindow(void) { }

inline void setType(int Type) { iType = Type; }

void registerElement(CGuiElement *pElement)
{
if(pElement == NULL) return;

elementStorage.push_back(pElement);
}

void draw(void);

protected:

std::vector<CGuiElement*> elementStorage;

int iType;
};

class CGuiElement : public CGuiTemplate
{
public:

CGuiElement(void) { }

CGuiElement(std::string sLabel,
float fX, float fY,
float fWidth, float fHeight,
CGuiWindow *pOwnerWindow,
colorEntry *pNewColor,
int Type,
void *pFunc) : CGuiTemplate(sLabel,fX,fY,fWidth,fHeight,pNewColor)
{

if(pOwnerWindow != NULL)
{
setParent(pOwnerWindow);

pParentWindow->registerElement(this);
}

setType(Type);
setAction(pFunc);
}

~CGuiElement(void) { }

inline void setParent(CGuiWindow *pOwnerWindow) { pParentWindow = pOwnerWindow; }
inline void setAction(void *pFunc) { pAction = pFunc; }
inline void setType(int Type) { iType = Type; }

void draw(void);

protected:

CGuiWindow *pParentWindow;

void *pAction;

int iType;
};

^B|!nG
06-25-2004, 03:43 AM
I've gotten this to compile fine but when I join a game and activate my menu, steam crashes. Here's my code:


void Draw() {
OGui.DrawGui();
}

void APIENTRY pglEnable(GLenum cap)
{
static bool Init = false;
if(!Init) {
BuildFont();
Init = true;
}
if(bDraw){ bDraw=false; Draw(); }
if(bEnable){
bEnable=false;
if(cvar.menu) {
//HookKBD();
GetCursorPos(&pt);
Settings.MouseX = (Settings.MouseX - (centerX - pt.x));
Settings.MouseY = (Settings.MouseY - (centerY - pt.y));
OGui.DrawGui();
pEngfuncs->SetViewAngles(mainViewAngles);
}
else {
Settings.MouseX = centerX;
Settings.MouseY = centerY;
pEngfuncs->GetViewAngles(mainViewAngles);
}
}
glEnable(cap);
}

void APIENTRY pglViewport(GLint x,GLint y,GLsizei width,GLsizei height)
{
iViewport_Count++;
if(iViewport_Count>=5){ bDraw=true; }
if(iViewport_Count==1){ bEnable=true; }
if(GetAsyncKeyState(VK_F1)&1==1) {
cvar.menu = !cvar.menu;
}
glViewport(x, y, width, height);
}

void APIENTRY pwglSwapBuffers(HDC HDC)
{
iViewport_Count=0;
owglSwapBuffers(HDC);
}

Any ideas?

P47R!CK
06-25-2004, 04:31 AM
ExitProcess(-1);

corntoegoblin
09-18-2004, 05:52 PM
i agree with pato that function would leebalize your gui

goozeman
09-27-2004, 06:44 PM
heleeb! gj ORGANNER. :evolved:

SpuN
09-27-2004, 07:18 PM
nice job ORGANNER

nice avatar gooze :)

Organner
09-28-2004, 12:48 AM
Now its old and very shitty :/

TuPLaD
12-26-2004, 07:33 PM
This code is better, please comment it :)

Credits:
gfreeman1 (drawing code)
panzer ( some ideas )
LanceVorgin (mouse)



/*
Put this code in ur opengl func. file
*/

extern Gui OGui;
float mainViewAngles[2];
POINT pt;

//Every 5 viewports or hudredraw
OGui.DrawGui();

//Every viewport
if(YOUR_GUI_ACTIVE)
{
GetCursorPos(&pt);
Settings.MouseX = (Settings.MouseX - (centerX - pt.x));
Settings.MouseY = (Settings.MouseY - (centerY - pt.y));
OGui.DrawGui();
pEngfuncs->SetViewAngles(mainViewAngles);
}
else
{
Settings.MouseX = centerX;
Settings.MouseY = centerY;
pEngfuncs->GetViewAngles(mainViewAngles);
}

are you sure i gotta put this all in def's ?

ikonz
05-15-2005, 03:15 AM
could you post a screenshot? thanks!

Sruh
05-18-2005, 04:43 AM
thats very nice :) thanks

cyclone02
10-13-2006, 12:20 PM
any screenshot would be really helpful(the current one doesnt work)