D3D GUI Interface

Posts 115 of 16 · Page 1 of 2
D3D GUI Interface
Currently, I'm developing a GUI editor in C++ using DirectX, and I've created a couple of classes some people may find useful. Soon, I will be releasing the whole project, but at the moment, you may find these objects I've created useful. I'm not going to bother explaining it until I've completed the GUI editor, when I do finish it though, there will be an indepth description of all the methods and how to use the GUIEditer to compile GUIs and how to use the GUIReader library(which I will be creating) that you can use to read and display the GUIs created with the GUIEditor. Please note the below code isn't finished nor cleaned up. There are some parts were I was really lazzy and defined variabled that are constant over and over in the Render methods.

Form.h
[highlight=cpp]#pragma once

#include "stdafx.h"
#include <windows.h>
#include "d3d9.h"
#include "d3dx9.h"
#include "Button.h"
class Form {
private:
LPDIRECT3DSURFACE9 surface;
LPD3DXFONT d3dFont;
char caption[100];
int buttonCount;
bool visible;
D3DCOLOR bgrColor;
D3DCOLOR capColor;
RECT destRect;
RECT capBounds;

public:
Button* childButtons[100]; //You sure as hell shouldn't ever need more then 100 buttons..
Form(LPDIRECT3DDEVICE9 d3dDev, D3DCOLOR srcBgrColor, D3DCOLOR srcCapColor, RECT srcDestRect, char *srcCaption, bool vis);
void AddButton(Button *btn);
bool isVisible();
int Save(char* path);
void Render(LPDIRECT3DDEVICE9 d3dDev, LPDIRECT3DSURFACE9 destSurface);
void SetVisible(bool vis);

};[/highlight]Form.cpp
[highlight=cpp]
#include "stdafx.h"
#include "Form.h"
Form::Form(LPDIRECT3DDEVICE9 d3dDev, D3DCOLOR srcBgrColor, D3DCOLOR srcCapColor, RECT srcDestRect, char* srcCaption, bool vis)
{
strcpy(caption, srcCaption);
visible = vis;
buttonCount = 0;

destRect = RECT(srcDestRect);
capBounds = RECT(destRect);
capBounds.left = 0;
capBounds.top = 0;
capBounds.bottom = 20;

//REWRITE BELOW METHOD


D3DXCreateFont( d3dDev, 12, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH | FF_DONTCARE, TEXT("Arial"), &d3dFont );

d3dDev->CreateOffscreenPlainSurface(srcDestRect.right - srcDestRect.left, srcDestRect.bottom - srcDestRect.top,
D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &surface, NULL);

bgrColor = srcBgrColor;
capColor = srcCapColor;
}
void Form::AddButton(Button *btn) {
childButtons[buttonCount] = btn;
buttonCount++;
}
bool Form::isVisible()
{
return visible;
}
int Form::Save(char* path) {
//This is gunna be a hell of a method :X
return 1;
}

void Form::Render(LPDIRECT3DDEVICE9 d3dDev, LPDIRECT3DSURFACE9 d3dSurface) {
if(!visible)
return;

RECT capRendLoc = RECT(capBounds);
capRendLoc.left += destRect.left + 20;
capRendLoc.top += destRect.top + 3;
capRendLoc.right = capRendLoc.left + (10 * strlen(caption));
capRendLoc.bottom = capRendLoc.top + 10;

d3dDev->ColorFill(surface, NULL, bgrColor);
d3dDev->ColorFill(surface, &capBounds, capColor);

for(int i = 0; i < buttonCount; i++)
childButtons[i]->Render(d3dDev, surface, destRect);

d3dDev->StretchRect(surface, NULL, d3dSurface, &destRect, D3DTEXF_NONE);
d3dFont->DrawTextA(NULL, caption, -1, &capRendLoc, 0, D3DCOLOR_XRGB(0,0,0));


}

void Form::SetVisible(bool vis) {
visible = vis;
}
[/highlight]Button.h
[highlight=cpp]
#pragma once
#include "stdafx.h"
#include "d3d9.h"
#include "d3dx9.h"
#include "windows.h"


class Button {
private:
void (*methodToExecute)();
char caption[100]; //You shouldn't have a captions larger then 100 characters, but if you do Feel free to change this.
bool visible;
RECT destRect;
LPD3DXFONT d3dFont;
LPDIRECT3DSURFACE9 surface;
public:
Button(LPDIRECT3DDEVICE9 d3dDev, void *srcMethodToExecute, char* caption, int x, int y, bool vis);
void Button::SetCaption(char* srcCaption);
bool isVisible();
void SetVisible(bool vis);
void SetRect(RECT &newRect);
void Render(LPDIRECT3DDEVICE9 d3dDev, LPDIRECT3DSURFACE9 d3dSurface, RECT frmRect);
};
[/highlight]
button.cpp

[highlight=cpp]
#include "stdafx.h"
#include "Button.h"
#include "rectTools.h"
#include <windows.h>
#define _CRT_SECURE_NO_WARNINGS
Button::Button(LPDIRECT3DDEVICE9 d3dDev, void *srcMethodToExecute, char* srcCaption, int x, int y, bool vis) {

strncpy(caption, srcCaption, sizeof(caption));
this->visible = vis;
destRect.top = y;
destRect.left = x;
destRect.right = destRect.left + strlen(caption) * 10;
destRect.bottom = destRect.top + 20;



D3DXCreateFont( d3dDev, 12, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH | FF_DONTCARE, TEXT("Arial"), &d3dFont );

HRESULT res = d3dDev->CreateOffscreenPlainSurface(destRect.right, destRect.bottom, D3DFMT_X8R8G8B8,
D3DPOOL_DEFAULT, &surface, NULL);

methodToExecute = (void (__cdecl *)())srcMethodToExecute;
}

void Button::SetRect(RECT &newRect) {
destRect = RECT(newRect);
}

void Button::SetVisible(bool vis) {
visible = vis;
}

void Button::Render(LPDIRECT3DDEVICE9 d3dDev, LPDIRECT3DSURFACE9 d3dSurface, RECT frmRect) {
if(!isVisible())
return;

POINT mPos;
D3DCOLOR btnColor = D3DCOLOR_XRGB(200,200,200);
GetCursorPos(&mPos);

RECT posTestRect(destRect);
posTestRect.left += frmRect.left;
posTestRect.top += frmRect.top;
posTestRect.right += frmRect.left;
posTestRect.bottom += frmRect.top;
if(isInRect(mPos, posTestRect)) {
btnColor = D3DCOLOR_XRGB(100,100,200);
if(GetAsyncKeyState(VK_LBUTTON) & 0x8000)
methodToExecute();
}


RECT btnRect = RECT(destRect);
btnRect.left += 2;
btnRect.right -= 2;
btnRect.top += 2;
btnRect.bottom -= 2;
d3dDev->ColorFill(d3dSurface, &destRect, D3DCOLOR_XRGB(0,0,0));
d3dDev->ColorFill(d3dSurface, &btnRect, btnColor);
}
bool Button::isVisible(){
return visible;
}
void Button::SetCaption(char* srcCaption) {
strncpy(caption, srcCaption, sizeof(caption));
}
[/highlight]
Thanks jetamay, I hope other people actually read this fucking thread.
Quote Originally Posted by jeremy6996 View Post
Thanks jetamay, I hope other people actually read this fucking thread.
Posting in your own thread?

Come on .
Quote Originally Posted by Synns View Post
Posting in your own thread?

Come on .
There the same people lol?
Is this like a menu?
u know, i always wanted to make a D3d GUI ^^
cheers helped alot
Can you tell me where I can find the rectTools.h file or class?
google, or use search at your pc
I need 101 buttons .
Just gimme the recttools file! I used google, but my google seems to fail! The file is NOT included in the directX sdk as far as I know. And he uses " instead of < and > to include it, so it must be a custom file! Please post it here!! i really need this
Quote Originally Posted by ultimate-tester View Post
Just gimme the recttools file! I used google, but my google seems to fail! The file is NOT included in the directX sdk as far as I know. And he uses " instead of < and > to include it, so it must be a custom file! Please post it here!! i really need this
<> means it's from the compiler's directives, "" means it from the project directive. Anyway, I updated this for my game engine, so I'll be posting that instead sometime next week. The rectTools is a source file I programmed myself. To be honest, this class wasn't really 100% completed, it will be next week and I'll post the whole thing.
could of been written better, but this is a nice share xD

going to work on a gui class with this one
Quote Originally Posted by ultimate-tester View Post
Just gimme the recttools file! I used google, but my google seems to fail! The file is NOT included in the directX sdk as far as I know. And he uses " instead of < and > to include it, so it must be a custom file! Please post it here!! i really need this
Try this

[php]

#ifndef MYRECTTOOLS_H
#define MYRECTTOOLS_H
#ifndef MAC_PLATFORM
#include "PIHeaders.h"
#endif

/**
* Function for Activation of Sign Tool
*/
extern ACCB1 void ACCB2 ActivateSignTool (void *clientData);

/**
* Function for Activation of SignExpert Tool
*/
//extern ACCB1 void ACCB2 ActivateSignExpertTool (void *clientData);

/**
* Sets up the Tool for SignMode
*/
extern void SetUpSignTool(void);


#endif /* MYRECTTOOLS_H */[/php]
Well yes, I know c++ That's why I asked you the file! LOOK:

#include "rectTools.h"

(between " and not <>
Posts 115 of 16 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

Need help?