™️ Welcome And SwiftGamerz ™️™️[-] The User Has Not IN SwiftGamerz Please Register.[-] Existing expected to log in first.[-] Many Public Hacks In Our Forum[-] Register for your User. (There are More Applications).Thankz ~ ~ For ALL SwiftGamerz


 
PortalHomeFAQCalendarMemberlistRegisterLog in

Share | 
 

 Jetamay's D3D Form Class

View previous topic View next topic Go down 
AuthorMessage
avatar
___RJ___
Moderator
Moderator

Posts : 15
Join date : 2012-01-18
Age : 26
Location : Cebu

PostSubject: Jetamay's D3D Form Class   Fri Jan 27, 2012 4:55 pm

Quote :
A class programmed by me(Jetamay) to render and manage forms in a D3D environment. When you make use of this class, Credit By Jetamay.

Download + Project information & license :
-d3d-gui-creator/

Library can be downloaded in attachments. The header is here :
[php]#pragma once
#include "d3d9.h"
#include "d3dx9.h"


#define CONTROL_APPEND_TEXT 0x00000001
#define CONTROL_SET_TEXT 0x00000002
#define CONTROL_GET_TEXT 0x00000003
#define CONTROL_BUTTON_PRESS 0x00000004
#define GAME_ROOTDIR(pCharBuffer, len) GetCurrentDirectoryA(len, pCharBuffer)

typedef void (*FORMCALLBACK)(DWORD command, DWORD param1, DWORD param2); //P1 form name, p2 command
enum ControlType{Textbox = 1, Button = 2, Caption = 3, Password = 4};

struct Control {
RECT bounds; //LEAVE NULL ON INIT, SET WHEN RENDERED;
DWORD Command;

char name[300];
char text[300];
bool enabled;
int x, y;
int type;
};
class CForm {
private:
int hoverControlIndex, activeControlIndex;
int x, y, mouseX, mouseY;
int numControls;

Control controls[100];
LPDIRECT3DTEXTURE9 formTexture;
LPD3DXFONT d3dFont;

void SetText(int index, char* source);
void AppendText(int index, char* text);

bool NameInUse(char* name);
char* GetText(int index);
int GetControlIndex(char* name);
FORMCALLBACK formCallback;
public:
char name[300];
CForm(FORMCALLBACK callback, char* objName, int formX, int formY, char* bgrLocalDir, LPDIRECT3DDEVICE9 d3ddev, LPD3DXFONT font);
int CreateControl(char* name, char* text, int type, float x, float y, DWORD Command = 0, bool enabled = true);
void ProcessMouse(POINT* mousePos, bool leftDown);
void ProcessKey(char key);
void Callback(DWORD Command, DWORD param1, DWORD param2);
void MoveBy(int x, int y);
void MoveTo(int posX, int posY);
void Render(LPD3DXSPRITE d3dSprite);
void Update();
~CForm();
};[/php]Class Information :

CForm(Constructor)
Parameters

callback :
Pointer to callback method, read more in callback methods section
objName :
Parameter is useless without the CFormManager class, which will be posted in a couple hours. Use to name the form object, set to NULL if you're not using a method to manage numerous forms, or plan to use a different system to identify them.
formX :
Form's default X position to render all controls and the form itself. Control structure contains offset X cords to this number. Thus the X cords in the Control structure are relative to the form's X position.
formY :
Form's default Y position to render all controls and the form itself. Control structure contains offset Y cords to this number. Thus the Y cords in the Control structure are relative to the form's Y position.
bgrLocalDir :
Pointer to a string which is null terminated. This string is used to load the background of the form. This only works locally. E.X, if the executable is placed in C:\program\program.exe and you pass "\\background.png" the class will load the image at C:\Program\Background.png. Be sure to include the \ character.
d3ddev :
A pointer to an initialized D3D Device.
font :
A pointer to a d3d font interface.

Description :
This is the constructor for the CForm class. It will initialize the private members needed to create controls and render the form. This must be called.

CreateControl
Parameters

name :
Controls name. You use this to modify it's properties using the built in callback. Refer to Callback information section.
text :
Text of Control. This can be the caption of a button, label, or default text in a textbox & password textbox.
type :
Refer to the ControlType enumerator defined in the CForm header. Specifies which kind of control you wish to create it as.
x :
Controls x position which is relative to the forms X position.
y :
Controls y position which is relative to the forms y position.
Command :
DWORD that specified the controls command code, read callback section for more information on this parameter.

Enabled :
Useless without CGUIManager class. More description on this paremeter will be posted at later time. For now ignore, and allow the compile set it to true, or set it to true yourself.

Description :
Creates a desired control for the form. This form will then be rendered when the render method within the class is called.

ProcessKey
Parameters

key :
Key which was pressed to be processed. '%' character will cause a deletion of the last character.

Description :
Processes a given key. This can cause several actions to occur depending on the active control. It may sometimes be ignored.

Callback
Parameters

Read callback section of this post for information on these parameters.
Description :
Read callback section of this post for information on these parameters.

MoveBy
Parameters

x :
Amount to change X coordination by.
y :
Amount to change Y coordination by.

Description :
Moves forms XY coordinations by a desired amount.

MoveTo
Parameters

x :
Set X coordination.
y :
Set Y coordination.

Description :
Moves forms XY coordinations to a desired position.
Render
Parameters

d3dSprite :
Pointer to initialized sprite interface.
Description :
Renders form.
Update
Ignore, useless without CGUIManager.

Callback Methods
A callback method has three parameters, the first is generally the command or the name of an object. Here's an example callback I write that should explain everything you need to know about them.
Form Init :
[php] mainForm = new CForm(FormCallback, "Form1",0,0, "FormDatatexturesdefaultForm.PNG", pd3ddev, d3dFont);
mainForm->CreateControl("cap1", "Login Window", Caption, 5, 5, 0);
mainForm->CreateControl("cap2", "Username:", Caption, 100, 80, 0);
mainForm->CreateControl("cap3", "Password:", Caption, 100, 110, 0);
mainForm->CreateControl("txtUsername", "Insert Username", Textbox, 170, 80, 0);
mainForm->CreateControl("txtPassword", "Insert Password", Password, 170, 110, 0);
mainForm->CreateControl("btnSubmit", "Submit", Button, 230, 130, BTN_SUBMIT);
mainForm->CreateControl("btnTwo", "Quit", Button, 300, 130, BTN_QUIT);
[/php]Callback :
[php]
void FormCallback(DWORD command, DWORD p1, DWORD p2) {
if(command == CONTROL_BUTTON_PRESS) {
if(!strcmp(mainForm->name, (char*)p1)) {
switch(p2) {
case BTN_QUIT:
tinit();
break;
case BTN_SUBMIT:
break;
}
}

}
}[/php]

Built-in callback :
[php]
Callback(DWORD Command, DWORD param1, DWORD param2) {
switch(Command) {
case CONTROL_APPEND_TEXT:
AppendText(GetControlIndex((char*)param1), (char*) param2);
break;
case CONTROL_GET_TEXT:
memcpy((void*)param2,
(void*)GetText(GetControlIndex((char*)param1)),
4);
break;
case CONTROL_SET_TEXT:
SetText(GetControlIndex((char*)param1), (char*) param2);
break;
case CONTROL_BUTTON_PRESS:
formCallback(CONTROL_BUTTON_PRESS, (DWORD)this->name, (DWORD)param1);
break;
}
}

[/php]


Post Here ___RJ___

Credit By Jetamay's
Back to top Go down
 

Jetamay's D3D Form Class

View previous topic View next topic Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
 :: FORUM LEARN/TEACH :: Direct3Device D3D-