Code:
#include "cMenu.h"
#include "textures.h"
#include <d3dx9.h>
D3DHOOK_API cMenu::cMenu(void) : UIHANDLE(sizeof(cMenu))
{
Name = "Topblast Menu Window v1.0";
X= Y = 30;
W = 250;
char process[512];
//GetModuleFileNameA(GetModuleHandle(0), process, sizeof(process));
//PathStripPathA(process);
GetWindowTextA(GetForegroundWindow(),process, sizeof(process));
wHandle = FindWindowA(0, process);
herebefore = false;
char* font = "Arial";
fTitle = new CD3DFont(font, 10, D3DFONT_BOLD);
fItem = new CD3DFont(font, 10);
m_pFont = new CD3DFont("Info", 10);
Tabs = new sTab[3];
}
D3DHOOK_API cMenu::cMenu(PCHAR name, short x, short y, short w, unsigned char maxTabs) : UIHANDLE(sizeof(cMenu))
{
Input = 0;
Name = name;
X= x;Y = y;
W = w;
herebefore = false;
char process[512];
//GetModuleFileNameA(GetModuleHandle(0), process, sizeof(process));
//PathStripPathA(process);
GetWindowTextA(GetForegroundWindow(),process, sizeof(process));
wHandle = FindWindowA(0, process);
char* font = "Arial";
fTitle = new CD3DFont(font, 10, D3DFONT_BOLD);
fItem = new CD3DFont(font, 10);
m_pFont = new CD3DFont("Info", 10);
Tabs = new sTab[maxTabs];
}
D3DHOOK_API cMenu::~cMenu(void)// : ~UIHANDLE()
{
// Clean up
for(BYTE i = 0; i < noTabs; i++)
{
if(this->Tabs)
{
for( BYTE e = 0; e < Tabs[i].noItems; e++ )
{
Tabs[i].Items[e].~sItem();
}
}
}
if(fTitle)
fTitle ->~CD3DFont();
if(fItem)
fItem ->~CD3DFont();
if(m_pFont)
m_pFont->~CD3DFont();
// then
memset(this, 0, sizeof(cMenu));
}
// Menu Starting Up Process
D3DHOOK_API void cMenu::AddTab(sTab tab)
{
this->Tabs[noTabs] = tab;
noTabs++;
}
// Input Controls
void cMenu::MouseHover( UIHANDLE* sender )
{
}
bool cMenu::isClicked()
{
if(Input->MouseButtonDown( DIMOUSE_LEFTBUTTON ))//GetAsyncKeyState(VK_LBUTTON))
{
if (this->release == true)
{
this->release = false;
return true;
}else{
return false;
}
}
this->release = true;
return false;
}
bool rig = false, lef = false;
void cMenu::KeyBoardNav()
{
if(Input->KeyPressed(DIK_HOME))
{
if(Input->KeyPressed(DIK_UP))
Y=Y-5;
else if(Input->KeyPressed(DIK_DOWN))
Y=Y+5;
if(Input->KeyPressed(DIK_LEFT))
this->X = X-5;
else if(Input->KeyPressed(DIK_RIGHT))
X= X+5;
}
else if(Input->KeyPressed(DIK_LSHIFT))
{
if(Input->KeyPressed(DIK_LEFT))
{
if (this->Selected != 0 && (!lef))
{
this->Selected=this->Selected -1;
}
lef = true;
}
else
lef = false;
if(Input->KeyPressed(DIK_RIGHT))
{
if (this->Selected < this->noTabs &&(!rig))
{
this->Selected=this->Selected +1;
if(this->Selected == this->noTabs)
this->Selected=this->Selected -1;
}
rig = true;
}
else
rig = false;
}
else
{
if (Input->KeyPressed(DIK_UP)&1)
{
Tabs[this->Selected].Selected--;
if (Tabs[this->Selected].Selected < 0) Tabs[this->Selected].Selected = Tabs[this->Selected].noItems-1;
}
else if (Input->KeyPressed(DIK_DOWN)&1)
{
Tabs[this->Selected].Selected++;
if (Tabs[this->Selected].Selected >= Tabs[this->Selected].noItems ) Tabs[this->Selected].Selected = 0;
}
else{
sTab & Tab = Tabs[this->Selected];
sItem& Item = Tab.Items[Tab.Selected];
if (Input->KeyPressed(DIK_LEFT)&1)
{
Item.Dec();
}
else if (Input->KeyPressed(DIK_RIGHT)&1)
{
Item.Inc();
}
}
}
}
// D3D Function
sVertex new_sVertex(DWORD x, DWORD y, DWORD color)
{
float fx = float(x);
float fy = float(y);
float fz = float(0);
float RHW = float(0);
sVertex ret = {fx,fy,fz,RHW, color};
return ret;
}
void sGRAPHICS::DrawBox(LPDIRECT3DDEVICE9 pDevice, DWORD x, DWORD y, DWORD w, DWORD h, DWORD color)
{
sVertex Veri[4] =
{
new_sVertex(x,y,color),
new_sVertex(x+w,y,color),
new_sVertex(x,y+h,color),
new_sVertex(x+w,y+h,color)
};
pDevice->SetFVF( sVertex::FVF_Flags );
pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,Veri,sizeof(sVertex));
}
void sGRAPHICS::DrawTexBox(LPDIRECT3DDEVICE9 pDevice,
LPDIRECT3DTEXTURE9 pTexture,
int x,
int y,
int w,
int h)
{
struct tVertex
{
float X, Y, Z, RHW;
float IU, IV;
enum FVF
{
FVF_Flags = (D3DFVF_XYZRHW | D3DFVF_TEX1)
};
};
tVertex Veri[4] =
{
{(float)x ,(float)y , 0.0f, 1.0f, 0.0f, 0.0f },
{(float)(x+w) ,(float)y , 0.0f, 1.0f, 1.0f, 0.0f },
{(float)x ,(float)(y+h) , 0.0f, 1.0f, 0.0f, 1.0f },
{(float)(x+w) ,(float)(y+h) , 0.0f, 1.0f, 1.0f, 1.0f },
};
pDevice->SetTexture( 0, pTexture );
//
// Credit mmbob for helping fixing the problem
//
pDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
pDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
pDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TEXTURE );
pDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
pDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE );
//
// Credit mmbob for helping fixing the problem
//
pDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE );
pDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
////////////////////////////////////
pDevice->SetRenderState( D3DRS_LIGHTING, FALSE);
pDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW);
pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
pDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
pDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_FALSE );
pDevice->SetRenderState( D3DRS_FOGENABLE, false );
pDevice->SetFVF( tVertex::FVF_Flags );
pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,Veri,sizeof(tVertex));
pDevice->SetTexture(0,0);
}
void cMenu::DrawTitleBar(LPDIRECT3DDEVICE9 pDevice)
{
DWORD BarColor = TitleBarColor;
if(Minimized)
BarColor = TitleBarInactiveColor;
// ToDO Mouse Move TitleBar
if (Input->IsEnable())
{
if(Input->IsMouseHere(X, Y, W-30, 24))
{
if (Input->MouseButtonDown( DIMOUSE_LEFTBUTTON ))
{
if(!herebefore)
{
bmp.x = Input->GetWindowsX() - X;
bmp.y = Input->GetWindowsY() - Y;
herebefore = true;
}
bX=X = short(Input->GetWindowsX() - bmp.x);
bY=Y = short(Input->GetWindowsY() - bmp.y);
}
else
herebefore=false;
}
if (herebefore)
{
X = short(Input->GetWindowsX() - bmp.x);
Y = short(Input->GetWindowsY() - bmp.y);
}
}
else
herebefore=false;
sVertex Veri[] =
{
new_sVertex(X+6,Y, BarColor),
new_sVertex(X+W-6,Y, BarColor),
new_sVertex(X+3,Y+2, BarColor),
new_sVertex(X+W-3,Y+2, BarColor),
new_sVertex(X+1,Y+4, BarColor),
new_sVertex(X+W-1,Y+4, BarColor),
new_sVertex(X,Y+6, BarColor),
new_sVertex(X+W,Y+6, BarColor),
new_sVertex(X,Y+24, BarColor),
new_sVertex(X+W,Y+24, BarColor),
};
DWORD color = MinButtonColor;
if (Input->IsMouseHere(X+W-30,Y+2, 20, 20) || Input->KeyPressed(DIK_LCONTROL))
{
if(this->isClicked())
Minimized=!Minimized;
color = MinButtonHighlightColor;
}
sVertex Min[] =
{
new_sVertex(X+W-30,Y+2, color),
new_sVertex(X+W-10,Y+2, color),
new_sVertex(X+W-30,Y+22,color),
new_sVertex(X+W-10,Y+22,color),
};
pDevice->SetFVF( sVertex::FVF_Flags );
pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,8,Veri,sizeof(sVertex));
pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,Min,sizeof(sVertex));
DrawBox(pDevice, X+W-26,Y+12,12, 2, 0xffffffff);
if(this->Name)
{
DWORD fcolor = 0xffffffff;
if (Minimized)
fcolor = 0xffcccccc;
fTitle->DrawText(float(X+10), float(Y+3), 0xffffffff, this->Name, D3DFONT_SHADOW);
}
}
void cMenu::DrawTabs(LPDIRECT3DDEVICE9 pDevice)
{
pDevice->SetTexture(0,0);
pDevice->SetRenderState(D3DRS_LIGHTING, false);
short width = (W-6) / noTabs;
for(unsigned char i = 0; i < this->noTabs; i++)
{
#pragma region Tab_D3D_Workup
H=0;
DWORD tabColor = TabInactiveColor;
if( Input->IsMouseHere(X+(width*i)-2, Y+30, width, 20) )
{
if(isClicked())
this->Selected = i;
tabColor = TabMouseActiveColor;
}
if(i == this->Selected)
tabColor = TabActiveColor;
sVertex TabBox[] =
{
new_sVertex(X+(width*i)+2 , Y+30, tabColor),
new_sVertex(X+(width*i)-2+width , Y+30, tabColor),
new_sVertex(X+(width*i)+2 , Y+50, tabColor),
new_sVertex(X+(width*i)+4+width , Y+50, tabColor),
};
pDevice->SetFVF( sVertex::FVF_Flags );
pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,TabBox,sizeof(sVertex));
fItem->DrawText(float(X+(width*i)+2+(width/2)),float(Y+33), 0xFFFFFFFF,Tabs[i].Name, D3DFONT_SHADOW | D3DFONT_CENTERED);
H += 250;
if(i != this->Selected) goto next;
#pragma endregion Tab_D3D_Workup
DrawBox(pDevice, X+5, Y+60,W-10, 160, 0x30888888);
while( Tabs[i].Selected < Tabs[i].scroll) Tabs[i].scroll--;
while( Tabs[i].Selected >= (Tabs[i].scroll+10)) Tabs[i].scroll++;
BYTE max =Tabs[i].noItems;
int scrolled = (int)Input->GetRelativeZ() /60;
if (Input->IsMouseHere(X+5, Y+60,W-10, 160))
{
Tabs[i].scroll -= scrolled;
if ((Tabs[i].scroll)>Tabs[i].noItems-10)
Tabs[i].scroll = Tabs[i].noItems-10;
if (Tabs[i].scroll < 0 )
Tabs[i].scroll = 0;
}
if ((Tabs[i].scroll+10)<max)
max = Tabs[i].scroll+10;
for( unsigned char e=Tabs[i].scroll ; e<max; e++)
{
DWORD itemColor = ItemFontColor;
if (Input->IsMouseHere(X+5, Y+65+(e*15-(Tabs[i].scroll*15)),200, 15))
{
Tabs[i].Selected = e;
if(isClicked())
{
Tabs[i].Items[e].ClickInc();
}
}
if (e== Tabs[i].Selected)
{
DrawBox(pDevice, X+5, Y+65+(e*15-(Tabs[i].scroll*15)), W-10, 15, 0x30454545);
itemColor = ItemSelectedFontColor;
}
fItem->DrawText(float( X+10), float(Y+65+(e*15-(Tabs[i].scroll*15))),itemColor, Tabs[i].Items[e].Name , D3DFONT_SHADOW | D3DFONT_FILTERED);
if(Tabs[i].Items[e].type == ITEM_NORMAL)
{
if(Tabs[i].Items[e].Options)
{
fItem->DrawText(float( X+W-10), float(Y+65+(e*15-(Tabs[i].scroll*15))),itemColor, Tabs[i].Items[e].Options[(Tabs[i].Items[e].GetValue())] , D3DFONT_SHADOW | D3DFONT_RIGHT | D3DFONT_FILTERED);
}
else
{
char val[0x10];
sprintf_s(val, "%d", Tabs[i].Items[e].GetValue());
fItem->DrawText(float( X+W-10), float(Y+65+(e*15-(Tabs[i].scroll*15))),itemColor, val , D3DFONT_SHADOW | D3DFONT_RIGHT | D3DFONT_FILTERED);
}
SIZE siz;
if (Tabs[i].Items[e].desc && e== Tabs[i].Selected)
{
m_pFont->GetTextExtent(Tabs[i].Items[e].desc, &siz);
DrawBox(pDevice, short( X+W+10), short(Y+65+(e*15-(Tabs[i].scroll*15))), short(siz.cx + 5), short(siz.cy +5), 0xF0484848);
m_pFont->DrawText(float( X+W+10),float(Y+65+(e*15-(Tabs[i].scroll*15))),0xFFFFFF00, Tabs[i].Items[e].desc,D3DFONT_SHADOW | D3DFONT_FILTERED);
}
}
else if (Tabs[i].Items[e].type == ITEM_TEXT)
{
fItem->DrawText(float( X+W-10), float(Y+65+(e*15-(Tabs[i].scroll*15))),itemColor, (char*)Tabs[i].Items[e].Options , D3DFONT_SHADOW | D3DFONT_RIGHT | D3DFONT_FILTERED);
}
else if (Tabs[i].Items[e].type == ITEM_COLOR)
{
DrawBox(pDevice, X+W-25, Y+65+(e*15-(Tabs[i].scroll*15)), 15, 15, Tabs[i].Items[e].GetColor() );
if (e== Tabs[i].Selected)
{
this->Draw(pDevice,(int)X+5, (int)Y+225,(int) W-10, (int)47);//this->DrawTexBox(pDevice, this->GetTex(), X+5, Y+225, W-10, 100);
if (Input->IsMouseHere((int)X+5, (int)Y+245, (int)W-10, 100))
{
if (GetAsyncKeyState(VK_LBUTTON))
{
if (Tabs[i].Items[e].Options)
*Tabs[i].Items[e].Options = (char*)GetColor((int)Input->GetWindowsX() -int(X+5), (int)Input->GetWindowsY() - int(Y+225));
}
}
}
}
}
next:
i = i;
}
}
D3DHOOK_API void cMenu::Show(LPDIRECT3DDEVICE9 pDevice)
{
if (m_pDevice != pDevice)
{
m_pDevice = pDevice;
D3DVIEWPORT9 vp;
pDevice->GetViewport(&vp);
Input = new CInput(vp.Height, vp.Width);
Input->UpdateDevice(pDevice);
if (fTitle != 0)
{
fTitle->InvalidateDeviceObjects();
fTitle->DeleteDeviceObjects();
}
fTitle->InitDeviceObjects(pDevice);
fTitle->RestoreDeviceObjects();
if (fItem != 0)
{
fItem->InvalidateDeviceObjects();
fItem->DeleteDeviceObjects();
}
fItem->InitDeviceObjects(pDevice);
fItem->RestoreDeviceObjects();
if (m_pFont != 0)
{
m_pFont->InvalidateDeviceObjects();
m_pFont->DeleteDeviceObjects();
}
m_pFont->InitDeviceObjects(pDevice);
m_pFont->RestoreDeviceObjects();
}
bX=X;
bY=Y;
bH=H+24;
bW=W;
if(Input->IsEnable())
{
Input->Update();
KeyBoardNav();
}
DrawTitleBar(pDevice);
if (Minimized) return;
sVertex Background[] =
{
new_sVertex(X,Y+24, 0xc0484848),
new_sVertex(X+W,Y+24, 0xc0484848),
new_sVertex(X,Y+24+H,0xc0484848),
new_sVertex(X+W,Y+24+H,0xc0484848),
};
pDevice->SetFVF( sVertex::FVF_Flags );
pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,Background,sizeof(sVertex));
DrawTabs(pDevice);
//TO do Keyboard Controls
}
void D3DColorSpectrum::Draw(LPDIRECT3DDEVICE9 pDevice, int x, int y, int _Width, int _Height)
{
Width = _Width;
Height = _Height;
for (DWORD i = 0; i < Width; i+=5)
{
for (DWORD j = 0; j < Height; j+=7)
{
if ((!((i+5) > Width) ) && !((j+7) > Height))
{
sVertex pixel[] =
{
new_sVertex(x+i,y+j, GetColor((int)i,(int)j)),
new_sVertex(x+i+5,y+j, GetColor((int)i+5,(int)j)),
new_sVertex(x+i,y+j+7, GetColor((int)i,(int)j+7)),
new_sVertex(x+i+5,y+j+7,GetColor((int)i+5,(int)j+7)),
};
pDevice->SetFVF( sVertex::FVF_Flags );
pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,pixel,sizeof(sVertex));
}
}
}
}
D3DCOLOR D3DColorSpectrum::HSLToRGB(float H, float S, float L)
{
float Q;
if (L < 0.5f)
Q = L * (S + 1.0f);
else
Q = L + S - (L * S);
float P = 2 * L - Q;
float RGBs[3];
RGBs[0] = H + (1.0f / 3.0f);
RGBs[1] = H;
RGBs[2] = H - (1.0f / 3.0f);
for (int i = 0; i < 3; ++i)
{
if (RGBs[i] < 0)
RGBs[i] += 1.0f;
if (RGBs[i] > 1)
RGBs[i] -= 1.0f;
if (RGBs[i] < (1.0f / 6.0f))
RGBs[i] = P + ((Q - P) * 6 * RGBs[i]);
else if (RGBs[i] < 0.5f)
RGBs[i] = Q;
else if (RGBs[i] < (2.0f / 3.0f))
RGBs[i] = P + ((Q - P) * 6 * ((2.0f / 3.0f) - RGBs[i]));
else
RGBs[i] = P;
}
return D3DCOLOR_XRGB(int(RGBs[0] * 255.0f), int(RGBs[1] * 255.0f), int(RGBs[2] * 255.0f));
}
D3DCOLOR D3DColorSpectrum::GetColor(int X, int Y)
{
float H = X * (1.0f / Width);
float S = 0.99f;
float L = 1.0f - Y * (1.0f / Height);
return HSLToRGB(H, S, L);
}
D3DHOOK_API void sTab::Show(LPDIRECT3DDEVICE9 pDevice)
{
#pragma region Reset
if (m_pDevice != pDevice)
{
D3DVIEWPORT9 vp;
m_pDevice = pDevice;
pDevice->GetViewport(&vp);
if (Input)
{
Input->~CInput();
Input=0;
}
Input = new CInput(vp.Height, vp.Width);
Input->Enable();
Input->UpdateDevice(pDevice);
if (m_pFont != 0)
{
m_pFont->InvalidateDeviceObjects();
m_pFont->DeleteDeviceObjects();
}
m_pFont->InitDeviceObjects(pDevice);
m_pFont->RestoreDeviceObjects();
}
Input->Update();
#pragma endregion Reset
#pragma region Tab_D3D_Workup
SIZE siz;
m_pFont->GetTextExtent(Name, &siz);
sVertex TabBox[] =
{
new_sVertex(bX , bY , 0x44FFFFFF),
new_sVertex(bX+2+siz.cx , bY , 0x44FFFFFF),
new_sVertex(bX , bY+30, 0x44FFFFFF),
new_sVertex(bX+6+siz.cx , bY+30, 0x44FFFFFF),
};
pDevice->SetFVF( sVertex::FVF_Flags );
pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,TabBox,sizeof(sVertex));
m_pFont->DrawText(float(bX+2+(float(siz.cx)/2)),float(bY+2), 0xFFFFFFFF,this->Name, D3DFONT_SHADOW | D3DFONT_CENTERED);
#pragma endregion Tab_D3D_Workup
#pragma region DRAW _CALCULATION
for (BYTE i = 0, e = 0; i < noItems, e < noHandles; i++, e++)
{
if(this->Items[i].type == ITEM_NORMAL)
{
DWORD itemColor = ItemFontColor;
if (Input->IsMouseHere(bX+5, bY+65+(i*15-(this->scroll*15)),200, 15))
{
this->Selected = i;
if(Input->MouseButtonDown(DIMOUSE_LEFTBUTTON))
this->Items[i].ClickInc();
}
if (i== this->Selected)
{
DrawBox(pDevice, bX+5, bY+65+(i*15-(this->scroll*15)), bW-10, 15, 0x30454545);
itemColor = ItemSelectedFontColor;
}
m_pFont->DrawText(float( bX+10), float(bY+65+(i*15-(this->scroll*15))),itemColor, this->Items[i].Name , D3DFONT_SHADOW);
if(this->Items[i].Options)
{
m_pFont->DrawText(float( bX+bW), float(bY+65+(i*15-(this->scroll*15))),itemColor, this->Items[i].Options[(this->Items[i].GetValue())] , D3DFONT_SHADOW | D3DFONT_RIGHT);
}
else
{
char val[0x10];
sprintf_s(val, "%d", this->Items[i].GetValue());
m_pFont->DrawText(float( bX+bW-10), float(bY+65+(i*15-(this->scroll*15))),itemColor, val , D3DFONT_SHADOW | D3DFONT_RIGHT);
}
SIZE siz;
if (this->Items[i].desc && i== this->Selected)
{
m_pFont->GetTextExtent(this->Items[i].desc, &siz);
DrawBox(pDevice, bX, short(bY+bH), short(siz.cx + 5), short(siz.cy +5), 0x90484848);
m_pFont->DrawText(float(bX+5),float(bY+bH+3),0xFFFFFF00, this->Items[i].desc,D3DFONT_SHADOW);
}
}
else
{
{
DWORD x1 = bX,
y1 = bY + 30,
w1 = bW,
h1 = bH-30;
sVertex Veri[4] =
{
new_sVertex(x1,y1,0x44FFFFFF),
new_sVertex(x1+w1,y1,0x90000000),
new_sVertex(x1,y1+h1,0x90000000),
new_sVertex(x1+w1,y1+h1,0x90000000)
};
pDevice->SetFVF( sVertex::FVF_Flags );
pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,Veri,sizeof(sVertex));
}
DWORD x1 = bX+10,
y1 = DWORD(bY+35+(i*25-(this->scroll*15))),
w1 = bW-20,
h1 = 25;
if (!Input->IsMouseHere(x1, y1, w1, h1))
{
sVertex Veri[4] =
{
new_sVertex(x1,y1,0x44FFFFFF),
new_sVertex(x1+w1,y1,0x44999999),
new_sVertex(x1,y1+h1,0x44999999),
new_sVertex(x1+w1,y1+h1,0x44999999)
};
pDevice->SetFVF( sVertex::FVF_Flags );
pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,Veri,sizeof(sVertex));
}
else
{
sVertex Veri[4] =
{
new_sVertex(x1,y1,0x44FFFFFF),
new_sVertex(x1+w1,y1,0x55999999),
new_sVertex(x1,y1+h1,0x55999999),
new_sVertex(x1+w1,y1+h1,0x55999999)
};
pDevice->SetFVF( sVertex::FVF_Flags );
pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,Veri,sizeof(sVertex));
if (Input->MouseButtonDown(DIMOUSE_LEFTBUTTON))
{
if(!this->handles[e]->Running)
{
Explorer.StartUI(&this->handles[e]);
this->noHandles--;
this->handles[this->noHandles] = 0;
}
}
}
m_pFont->DrawText(float( x1), float(y1),0xffffffff, this->handles[i]->Name , D3DFONT_SHADOW);
}
}
#pragma endregion _CALCULATION
}
D3DHOOK_API explorer::explorer() : UIHANDLE(sizeof(explorer))
{
Name = "Blast OS";
Input = 0;
//startMenu->AddItem(("Shot Gun Gpread") , 0 , 0 , "WHAT IS THIS?");
m_pFont = new CD3DFont("Arial", 9);
butInfo = (UIHANDLE**)malloc(4*10);
for (int i = 0; i < 10; i++)
butInfo[i] = new UIHANDLE();
startInfo = (UIHANDLE**)malloc(4*10);
for (int i = 0; i < 10; i++)
startInfo[i] = new UIHANDLE();
trackIds = new DWORD[10];
}
D3DHOOK_API void explorer::Show(LPDIRECT3DDEVICE9 pDevice)
{
if(!init)
{
startMenu = new sTab("bOS");
startMenu->bX = 0;
startMenu->bY = 500;
startMenu->bW = 200;
startMenu->bH = 300;
for (BYTE i = 0; i < startItems; i++)
{
startMenu->AddButton(&startInfo[i]);
}
Menu = true;
init = true;
}
static bool update = false;
pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ZERO);
pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_SRCCOLOR);
pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
pDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
pDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
pDevice->SetRenderState( D3DRS_ALPHAREF, 0x08 );
pDevice->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL );
pDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW );
pDevice->SetRenderState( D3DRS_STENCILENABLE, FALSE );
pDevice->SetRenderState( D3DRS_CLIPPING, TRUE );
pDevice->SetRenderState( D3DRS_CLIPPLANEENABLE, FALSE );
pDevice->SetRenderState( D3DRS_VERTEXBLEND, D3DVBF_DISABLE );
pDevice->SetRenderState( D3DRS_INDEXEDVERTEXBLENDENABLE, FALSE );
D3DVIEWPORT9 vp;
if (m_pDevice != pDevice)
{
m_pDevice = pDevice;
pDevice->GetViewport(&vp);
scLength = vp.Height;
scWidth = vp.Width;
if (Input)
{
Input->~CInput();
Input=0;
}
Input = new CInput(scLength, scWidth);
Input->Enable();
Input->UpdateDevice(pDevice);
if (m_pFont != 0)
{
m_pFont->InvalidateDeviceObjects();
m_pFont->DeleteDeviceObjects();
}
m_pFont->InitDeviceObjects(pDevice);
m_pFont->RestoreDeviceObjects();
if (startTex != 0)
{
startTex->Release();
startTex = NULL;
}
HRESULT hr;
hr=D3DXCreateTextureFromResource(pDevice,
NULL,
MAKEINTRESOURCE(IDB_PNG1),
&startTex);
if(FAILED(hr))
{
if(FAILED(D3DXCreateTextureFromFileInMemory(pDevice, &myFile, sizeof(myFile), &startTex)))
MessageBoxA(0, "Texture Creation Fail", 0, 0);
}
}
DWORD size = DWORD(scWidth* 0.05) + 2;
{
DWORD x1 = 0,
y1 = scLength - DWORD(scLength* 0.05),
w1 = scWidth,
h1 = DWORD(scLength* 0.05);
sVertex Veri[4] =
{
new_sVertex(x1,y1,0xc0FF0000),
new_sVertex(x1+w1,y1,0xc0FF0000),
new_sVertex(x1,y1+h1,0xc0000000),
new_sVertex(x1+w1,y1+h1,0xc0000000)
};
pDevice->SetFVF( sVertex::FVF_Flags );
pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,Veri,sizeof(sVertex));
}
// DrawBox(pDevice, 0, scLength - DWORD(scLength* 0.05), scWidth, DWORD(scLength* 0.05), 0xFFff0000);
for (char i = 0; i < noButtons; i++)
{
if(noButtons > 0)
{
butInfo[i]->Running = true;
if(!butInfo[i]->Minimized)
{
if (i == this->Selected)
{
if (butInfo[i]->Input)
butInfo[i]->Input->Enable();
}
else
{
if (butInfo[i]->Input)
{
butInfo[i]->Input->Disable();
if(butInfo[Selected]->Minimized)
Selected = i;
if(butInfo[i]->ObjectsInterset(*butInfo[Selected]))
{
butInfo[i]->Input->Enable();
if (Input->MouseButtonDown(DIMOUSE_LEFTBUTTON))
{
butInfo[Selected]->Input->Disable();
Selected = i;
Menu = false;
}
}
}
DWORD x = butInfo[i]->bX ,
y = butInfo[i]->bY,
w = butInfo[i]->bW ,
h = butInfo[i]->bH;
sVertex Veri[4] =
{
new_sVertex(x,y,0x66FFFFFF),
new_sVertex(x+w,y,0x66000000),
new_sVertex(x,y+h,0x66000000),
new_sVertex(x+w,y+h,0x66000000)
};
pDevice->SetFVF( sVertex::FVF_Flags );
pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,Veri,sizeof(sVertex));
butInfo[i]->Show(pDevice);
pDevice->SetFVF( sVertex::FVF_Flags );
pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,Veri,sizeof(sVertex));
}
}
SIZE tsize;
m_pFont->GetTextExtent(butInfo[i]->Name, &tsize);
static DWORD tWidth=0;
DWORD x = (size)+(i*(tWidth+6)),
y = scLength - DWORD(scLength* 0.05);
tWidth= tsize.cx;
DWORD w = tWidth+4,
h = DWORD(scLength* 0.05);
if (i == Selected && !butInfo[i]->Minimized)
{
sVertex Veri[4] =
{
new_sVertex(x,y,0x30FFFFFF),
new_sVertex(x+w,y,0x99FFFFFF),
new_sVertex(x,y+h,0x99FFFFFF),
new_sVertex(x+w,y+h,0x99FFFFFF)
};
pDevice->SetFVF( sVertex::FVF_Flags );
pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,Veri,sizeof(sVertex));
// DrawBox(pDevice, (size)+(i*(tWidth+6)), scLength - DWORD(scLength* 0.05), tWidth+4, DWORD(scLength* 0.05), 0x9900FFFF);
}
else if((i!= Selected || butInfo[Selected]->Minimized ) && Input->IsMouseHere((size)+(i*(tWidth+6)),scLength - DWORD(scLength* 0.05),tWidth+4, DWORD(scLength* 0.05)))
{
/* DWORD x = (size)+(i*(tWidth+6)),
y = scLength - DWORD(scLength* 0.05),
w = tWidth+4,
h = DWORD(scLength* 0.05);*/
sVertex Veri[4] =
{
new_sVertex(x,y,0x66FFFFFF),
new_sVertex(x+w,y,0x66FFFFFF),
new_sVertex(x,y+h,0x66000000),
new_sVertex(x+w,y+h,0x66000000)
};
pDevice->SetFVF( sVertex::FVF_Flags );
pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,Veri,sizeof(sVertex));
// DrawBox(pDevice, (size)+(i*(tWidth+6)), scLength - DWORD(scLength* 0.05), tWidth+4, DWORD(scLength* 0.05), 0x6644FFFF);
if (Input->MouseButtonDown(DIMOUSE_LEFTBUTTON))
{
butInfo[i]->Input->Enable();
butInfo[i]->Minimized = false;
butInfo[Selected]->Input->Disable();
Selected = i;
}
}
else
{/*
DWORD x = (size)+(i*(tWidth+6)),
y = scLength - DWORD(scLength* 0.05),
w = tWidth+4,
h = DWORD(scLength* 0.05);*/
sVertex Veri[4] =
{
new_sVertex(x,y,0x44FFFFFF),
new_sVertex(x+w,y,0x44FFFFFF),
new_sVertex(x,y+h,0x44000000),
new_sVertex(x+w,y+h,0x44000000)
};
pDevice->SetFVF( sVertex::FVF_Flags );
pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,Veri,sizeof(sVertex));
// DrawBox(pDevice, (size)+(i*(tWidth+6)), scLength - DWORD(scLength* 0.05), tWidth+4, DWORD(scLength* 0.05), 0x4400FFFF);
}
if(noButtons != 0 && butInfo && butInfo[i])
m_pFont->DrawText(float(x + 2 ), float(y)+ float(scLength* 0.05)/2.0f,0xffffffff, butInfo[i]->Name, D3DFONT_SHADOW );
if( !update)
{
if( Input->IsMouseHere(size+i*(tWidth+6),scLength - DWORD(scLength* 0.05),tWidth+4, DWORD(scLength* 0.05) ) )
{
if (Input->MouseButtonDown(DIMOUSE_RIGHTBUTTON))
{
if (!update)
{
butInfo[i]->Running = false;
Selected = 0;
for (BYTE I = i; I < noButtons; I++)
{
if( (I+1) < noButtons)
{
butInfo[I] = butInfo[I+1];
Selected = i+1;
}
else if (I == i && noButtons == 1 )
{
butInfo[I] = 0;
butInfo[0] = 0;
noButtons = 0;
update = true;
break;
return;
}
else if ( i-1 < 0)
Selected = 0;
else
Selected = i-1;
}
noButtons --;
update = true;
}
else
update = false;
}
else
update = false;
}
}
else if (!Input->IsMouseHere(size+i*(tWidth+6),scLength - DWORD(scLength* 0.05),tWidth+4, DWORD(scLength* 0.05))
|| !Input->MouseButtonDown(DIMOUSE_RIGHTBUTTON))
update = false;
//size+= tWidth+6;
Input->Update();
}
}
DWORD x = 0,
y = scLength - DWORD(scLength* 0.05),
w = DWORD(scWidth* 0.05),
h = DWORD(scLength* 0.05);
if (Input->IsMouseHere(x, y, w, h))
{
sVertex Veri[4] =
{
new_sVertex(x,y,0x44FFFFFF),
new_sVertex(x+w,y,0x40ffffff),
new_sVertex(x,y+h,0x40ffffff),
new_sVertex(x+w,y+h,0x40ffffff)
};
pDevice->SetFVF( sVertex::FVF_Flags );
pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,Veri,sizeof(sVertex));
DrawTexBox(pDevice, startTex, x, y, w, h);
if (Input->MouseButtonDown(DIMOUSE_LEFTBUTTON))
{
Menu =true;
// StartUI((UIHANDLE**)&startMenu);
}
}
else
{
sVertex Veri[4] =
{
new_sVertex(x,y,0x44FFFFFF),
new_sVertex(x+w,y,0x44FFFFFF),
new_sVertex(x,y+h,0x90000000),
new_sVertex(x+w,y+h,0x90000000)
};
pDevice->SetFVF( sVertex::FVF_Flags );
pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,Veri,sizeof(sVertex));
DrawTexBox(pDevice, startTex, x, y, w, h);
}
if(noButtons > 0 && butInfo && butInfo[Selected])
{
if(butInfo[Selected]->Input)
butInfo[Selected]->Input->Enable();
butInfo[Selected]->Show(pDevice);
DWORD x2 = butInfo[Selected]->bX ,
y2 = butInfo[Selected]->bY,
w2 = butInfo[Selected]->bW ,
h2 = butInfo[Selected]->bH;
sVertex Veri[4] =
{
new_sVertex(x2,y2,0x34FFFFFF),
new_sVertex(x2+w2,y2,0x34000000),
new_sVertex(x2,y2+h2,0x34000000),
new_sVertex(x2+w2,y2+h2,0x34000000)
};
pDevice->SetFVF( sVertex::FVF_Flags );
pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,Veri,sizeof(sVertex));
}
if (Menu)
{
startMenu->bX = 0;
startMenu->bY = DWORD(scLength - float(scLength* 0.45));
startMenu->bW = DWORD(scLength* 0.20);
startMenu->bH = DWORD((scLength -startMenu->bY) - float(scLength* 0.05));
startMenu->Show(pDevice);
}
// DrawBox(pDevice, 0, scLength - DWORD(scLength* 0.05), DWORD(scLength* 0.05), DWORD(scLength* 0.05), 0xF4FfFFFF);
}
D3DHOOK_API void explorer::StartUI(UIHANDLE** obj)
{
if( obj != 0)
{
butInfo[noButtons] = *obj;
AddToStartMenu(obj);
Selected = noButtons;
noButtons++;
}
}
D3DHOOK_API void explorer::AddToStartMenu(UIHANDLE** obj)
{
if( obj != 0)
{
startInfo[startItems] = (*obj);
startItems++;
if (init)
{
startMenu->AddButton(obj);
}
}
}