#include "stdafx.h" #include "d3dfont.h" #include "cGUI.h" #pragma warning( disable : 4244 ) void cRectMenu::FormPostReset( char *szFontType, DWORD dwFontSize, DWORD dwFontFlags, LPDIRECT3DDEVICE8 pDevice ) { text = new CD3DFont( szFontType, dwFontSize, dwFontFlags ); text->InitDeviceObjects( pDev ); text->RestoreDeviceObjects( ); } void cRectMenu::FormPreReset( ) { text->InvalidateDeviceObjects( ); text->DeleteDeviceObjects( ); text = NULL; } void cRectMenu::AddMainForm(float x, float y, float w, float h, DWORD dwOutlineColor, DWORD dwBGColor, char *Header = "") { Forms.X = x; Forms.Y = y; Forms.W = w; Forms.H = h; Forms.BorderColor = dwOutlineColor; Forms.BGColor = dwBGColor; Forms.Header = Header; } void cRectMenu::AddButton(bool Toggle, int max, int min, char* text, void *cvar, int key) { if(key == NULL) { Forms.FormButtons[ButtonNum].vKey = 0x0; } else { Forms.FormButtons[ButtonNum].vKey = key; } Forms.FormButtons[ButtonNum].Text = text; Forms.FormButtons[ButtonNum].Cvar = ( float* )cvar; Forms.FormButtons[ButtonNum].MaxClick = max; Forms.FormButtons[ButtonNum].MinClick = min; Forms.FormButtons[ButtonNum].IsToggle = Toggle; ButtonNum++; } #define DrawRect( x, y, w, h, c ) draw.FillRGBA( x, y, w, h, GetR( c ), GetG( c ), GetB( c ), GetA( c ), pDev ); #define DrawBorder( x, y, w, h, c ) draw.FillRGBA( x, y, w, 1, GetR( c ), GetG( c ), GetB( c ), GetA( c ), pDev ); /*top line*/ draw.FillRGBA( x, y, 1, h, GetR( c ), GetG( c ), GetB( c ), GetA( c ), pDev ); /*left line*/ draw.FillRGBA( x + w, y, 1, h, GetR( c ), GetG( c ), GetB( c ), GetA( c ), pDev ); /*right line*/ draw.FillRGBA( x, y + h, w, 1, GetR( c ), GetG( c ), GetB( c ), GetA( c ), pDev ); /*bottom line*/ void cRectMenu::DrawForm() { DrawRect(Forms.X, Forms.Y, Forms.W, Forms.H, Forms.BGColor); DrawRect(Forms.X, Forms.Y - 25, Forms.W, 20, Forms.BGColor); text->DrawText( Forms.X + 4, Forms.Y - 23, 0xFFFFFFFF, Forms.Header); DrawBorder(Forms.X, Forms.Y, Forms.W, Forms.H, FormBorderColor); DrawBorder(Forms.X, Forms.Y - 25, Forms.W, 20, FormBorderColor); for(int i = 0; i < this->ButtonNum; i++) { Ratio = ((20 * Forms.H) / (32 * (ButtonNum) )); TextOffset = Forms.Y + ( ( Ratio / 2 * 1.4) ) + (i * ( Ratio + ( Ratio / 2 ))); MathVar = Forms.Y + ( Ratio / 2 ) + (i * ( Ratio + ( Ratio / 2 ))); DrawRect( Forms.X + 15, MathVar, (Forms.W - 31), Ratio, ButtonBG ); DrawBorder( Forms.X + 15, MathVar, (Forms.W - 31), Ratio, ButtonBorder); if(Forms.FormButtons[i].IsToggle) { if( Forms.FormButtons[i].Cvar && *Forms.FormButtons[i].Cvar == 1 ) { text->DrawText( Forms.X + this->Ratio, TextOffset, 0xFF0000FF, Forms.FormButtons[i].Text); } else { text->DrawText( Forms.X + this->Ratio, TextOffset, White, Forms.FormButtons[i].Text); } } else { sprintf( theNum, "%s: %i", Forms.FormButtons[i].Text, Forms.FormButtons[i].ClickNum ); text->DrawText( Forms.X + Ratio, TextOffset, White, theNum ); } } } void cRectMenu::CheckButtonKeys( ) { for(int i = 0; i < this->ButtonNum; i++) { this->CheckClicks(Forms.X + this->Ratio, TextOffset, i); } } int cRectMenu::checkField(int x, int y, int w, int h) { POINT Cur; GetCursorPos(&Cur); if(Cur.x > x && Cur.x < x + w && Cur.y > y && Cur.y < y+h) { if(GetAsyncKeyState(VK_LBUTTON)&1) { return 1; } if(GetAsyncKeyState(VK_RBUTTON)&1) { return 2; } return 3; } return 0; } void cRectMenu::CheckClicks(int x, int y, int Item) { int iCheck = checkField(x, y, (Forms.W - 31), 10); if(Forms.FormButtons[Item].IsToggle) { if(iCheck == 1) { if(Forms.FormButtons[Item].Cvar) *Forms.FormButtons[Item].Cvar =! *Forms.FormButtons[Item].Cvar; } } else { if(iCheck == 1) { if(Forms.FormButtons[Item].ClickNum < Forms.FormButtons[Item].MaxClick)Forms.FormButtons[Item].ClickNum++; } else if(iCheck == 2) { if(Forms.FormButtons[Item].ClickNum > Forms.FormButtons[Item].MinClick)Forms.FormButtons[Item].ClickNum--; } } if(Forms.FormButtons[Item].IsToggle && Forms.FormButtons[Item].vKey != 0x0)//multival hotkey support can be added { if(GetAsyncKeyState(Forms.FormButtons[Item].vKey)&1) { *Forms.FormButtons[Item].Cvar =! *Forms.FormButtons[Item].Cvar; } } CheckDragAndResize(); } void cRectMenu::CheckDragAndResize() { POINT Cur; GetCursorPos(&Cur); int pSize = checkField(Forms.X + Forms.W - 10, Forms.Y + Forms.H - 10, 15, 15); if(pSize == 4) { Forms.W = (Cur.x - Forms.X); Forms.H = (Cur.y - Forms.Y); } //Add form drag code here... }