Advertisement
dcomicboy

ui.cpp

Apr 3rd, 2012
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.01 KB | None | 0 0
  1. /**********************************
  2. | Author : XForce |
  3. | Website : xforce.square7.ch |
  4. | |
  5. ***********************************/
  6.  
  7.  
  8. #include "stdafx.h"
  9.  
  10. #define WINDOW_NAME "SimpleSample"
  11.  
  12. using namespace std;
  13.  
  14. ID3DXFont *xfont = NULL;
  15. ID3DXFont *nfont = NULL;
  16. //bool initx = false;
  17. HHOOK MouseHook;
  18. HHOOK KeyboardHook;
  19.  
  20. RECT client;
  21.  
  22. bool mousedown;
  23. XGUI* ui;
  24. vector <XWindow> *windowsp;
  25. vector <XControl*> *controlsp;
  26. vector <XListBoxItem> *itemsp;
  27.  
  28. LPD3DXLINE g_pLine;
  29.  
  30.  
  31. #ifndef PI
  32. #define PI 3.14159265358979323846f
  33. #endif
  34.  
  35.  
  36. struct D3DVERTEX {float x, y, z, rhw; DWORD color;} vertices[4] = {{0,0,0,1.0f,0},{0,0,0,1.0f,0},{0,0,0,1.0f,0},{0,0,0,1.0f,0}};
  37.  
  38. void GradientRect(float x, float y, float height,float width, DWORD startCol, DWORD endCol, int orientation ,LPDIRECT3DDEVICE9 pDevice/*pD3dDev*/)
  39. {
  40.  
  41. vertices[0].x = x;
  42. vertices[0].y = y;
  43. vertices[0].color = startCol;
  44.  
  45. vertices[1].x = x+width;
  46. vertices[1].y = y;
  47. vertices[1].color = orientation == 1 ? endCol : startCol;
  48.  
  49. vertices[2].x = x;
  50. vertices[2].y = y+height;
  51. vertices[2].color = orientation == 1 ? startCol : endCol;
  52.  
  53. vertices[3].x = x+width;
  54. vertices[3].y = y+height;
  55. vertices[3].color = endCol;
  56.  
  57. pDevice->SetTexture(0, NULL);
  58. pDevice->SetRenderState(D3DRS_ALPHATESTENABLE, true);
  59. pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,true);
  60. pDevice->SetRenderState(D3DRS_ALPHAFUNC,D3DCMP_GREATEREQUAL);
  61. pDevice->SetRenderState(D3DRS_ALPHAREF,(DWORD)8);
  62. pDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);
  63. pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,vertices,sizeof(D3DVERTEX));
  64.  
  65.  
  66. //LPDIRECT3DVERTEXBUFFER9 pVertexObject = NULL;
  67. //void *pVertexBuffer = NULL;
  68. //if( !pVertexObject ) {
  69. // if(FAILED(pD3dDev->CreateVertexBuffer(sizeof(vertices), 0,
  70. // D3DFVF_XYZRHW|D3DFVF_DIFFUSE, D3DPOOL_DEFAULT, &pVertexObject, NULL)))
  71. // return;
  72. //}
  73. //if(FAILED(pVertexObject->Lock(0, sizeof(vertices), &pVertexBuffer, 0)))
  74. // return;
  75.  
  76. //memcpy( pVertexBuffer, vertices, sizeof(vertices) );
  77. //pVertexObject->Unlock();
  78.  
  79. //pD3dDev->SetStreamSource( 0, pVertexObject, 0, sizeof(D3DVERTEX) );
  80.  
  81. //pD3dDev->SetFVF( D3DFVF_XYZRHW|D3DFVF_DIFFUSE );
  82. //pD3dDev->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );
  83. //pVertexObject->Release();
  84. };
  85.  
  86. void DrawLine ( long Xa, long Ya, long Xb, long Yb, DWORD dwWidth, D3DCOLOR Color )
  87. {
  88. D3DXVECTOR2 vLine[ 2 ]; // Two points
  89. g_pLine->SetAntialias( 0 ); // To smooth edges
  90. g_pLine->SetGLLines( 1 );
  91. g_pLine->SetWidth( dwWidth ); // Width of the line
  92. g_pLine->Begin();
  93.  
  94. vLine[ 0 ][ 0 ] = Xa; // Set points into array
  95. vLine[ 0 ][ 1 ] = Ya;
  96. vLine[ 1 ][ 0 ] = Xb;
  97. vLine[ 1 ][ 1 ] = Yb;
  98.  
  99. g_pLine->Draw( vLine, 2, Color ); // Draw with Line, number of lines, and color
  100. g_pLine->End(); // finish
  101. };
  102.  
  103.  
  104.  
  105. void DrawRect ( long X, long Y, long W, long H, D3DCOLOR Color )
  106. {
  107. D3DXVECTOR2 vLine[ 2 ];
  108. g_pLine->SetWidth( W );
  109. g_pLine->SetAntialias( 0 );
  110. //g_pLine->SetGLLines( 1 );
  111.  
  112. g_pLine->SetWidth( W );
  113. g_pLine->Begin();
  114.  
  115. vLine[ 0 ][ 0 ] = X+W/2;
  116. vLine[ 0 ][ 1 ] = Y;
  117. vLine[ 1 ][ 0 ] = X+W/2;
  118. vLine[ 1 ][ 1 ] = Y+H;
  119.  
  120. g_pLine->Draw( vLine, 2, Color );
  121. g_pLine->End();
  122. };
  123.  
  124.  
  125. void FullRect(float x, float y, int width, int height, D3DCOLOR Color)
  126. {
  127. D3DXVECTOR2 vLine[2];
  128.  
  129. g_pLine->SetWidth( width );
  130. g_pLine->SetAntialias( false );
  131. g_pLine->SetGLLines( true );
  132.  
  133. vLine[0].x = x + (width/2);
  134. vLine[0].y = y;
  135. vLine[1].x = x + (width/2);
  136. vLine[1].y = y + height;
  137.  
  138. g_pLine->Begin( );
  139. g_pLine->Draw( vLine, 2, Color );
  140. g_pLine->End( );
  141. };
  142.  
  143.  
  144. void EmptyRect(float x,float y,int width,int height, int thickness, D3DCOLOR Color)
  145. {
  146. DrawLine(x,y,x+width,y,thickness,Color); // top side
  147. DrawLine(x,y,x,y+height,thickness,Color); // left side
  148. DrawLine(x,y+height,x+width,y+height,thickness,Color); // bottom side
  149. DrawLine(x+width,y,x+width,y+height,thickness,Color); // right side
  150. };
  151.  
  152.  
  153.  
  154. void GradientRect(int x, int y, int h, int w, DWORD color1, DWORD color2)
  155. {
  156. DWORD a1 = (color1>>24)&0xFF;
  157. DWORD r1 = (color1>>16)&0xFF;
  158. DWORD g1 = (color1>>8)&0xFF;
  159. DWORD b1 = (color1>>0)&0xFF;
  160. DWORD a2 = (color2>>24)&0xFF;
  161. DWORD r2 = (color2>>16)&0xFF;
  162. DWORD g2 = (color2>>8)&0xFF;
  163. DWORD b2 = (color2>>0)&0xFF;
  164. float aDif,rDif,gDif,bDif;
  165. aDif = ((float)a2-(float)a1)/h;
  166. rDif = ((float)r2-(float)r1)/h;
  167. gDif = ((float)g2-(int)g1)/h;
  168. bDif = ((float)b2-(float)b1)/h;
  169. DWORD DrawCol;
  170. for(int i = 0;i<h;i++)
  171. {
  172. DrawCol = (a1+(int)(aDif*i) << 24) | (r1+(int)(rDif * i) << 16) | (g1+(int)(gDif * i) << 8) | (b1+(int)(bDif*i));
  173. DrawRect(x,y+i,w,1,DrawCol);
  174. }
  175.  
  176. };
  177.  
  178.  
  179. void FullRectBordered(float x, float y, int width, int height, int borderThickness, D3DCOLOR fillColor, D3DCOLOR borderColor)
  180. {
  181. GradientRect(x,y,height,width,fillColor,borderColor);
  182. //FullRect(x,y,width,height,fillColor);
  183. EmptyRect(x,y,width,height,borderThickness,borderColor);
  184. };
  185.  
  186.  
  187. void DrawRectBordered( long X, long Y, long W, long H, D3DCOLOR Color,D3DCOLOR borderColor )
  188. {
  189. D3DXVECTOR2 vLine[ 2 ];
  190. g_pLine->SetWidth( W );
  191. g_pLine->SetAntialias( 0 );
  192. //g_pLine->SetGLLines( 1 );
  193.  
  194. g_pLine->SetWidth( W );
  195. g_pLine->Begin();
  196.  
  197. vLine[ 0 ][ 0 ] = X+W/2;
  198. vLine[ 0 ][ 1 ] = Y;
  199. vLine[ 1 ][ 0 ] = X+W/2;
  200. vLine[ 1 ][ 1 ] = Y+H;
  201.  
  202. g_pLine->Draw( vLine, 2, Color );
  203. g_pLine->End();
  204.  
  205.  
  206. DrawLine(X,Y,X,Y+H,1,borderColor);
  207.  
  208. DrawLine(X,Y,X+W,Y,1,borderColor);
  209.  
  210. DrawLine(X+W,Y,X + W,Y+H ,1,borderColor);
  211.  
  212. DrawLine(X ,Y+H,X+W+1,Y+H,1,borderColor);
  213. };
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221. int caltext(std::string textbuffer)
  222. {
  223. RECT r = {0, 0, 0, 0};
  224. char* pText = (char*)textbuffer.c_str();
  225. int len = strlen( pText );
  226. if( len == 0 )
  227. return 0;
  228.  
  229. char lastChar = pText[ len-1 ];
  230. if( lastChar == ' ' )
  231. pText[ len-1 ] = '_';
  232. xfont->DrawText( NULL, pText, -1, &r, DT_CALCRECT , 0xffffffff );
  233. pText[len-1] = lastChar;
  234. return r.right - r.left;
  235. }
  236. // Restore last character.return r.right - r.left;
  237. int caltexth(std::string textbuffer)
  238. {
  239. RECT r = {0, 0, 0, 0};
  240. char* pText = (char*)textbuffer.c_str();
  241. int len = strlen( pText );
  242. if( len == 0 )
  243. return 0;
  244.  
  245. char lastChar = pText[ len-1 ];
  246. if( lastChar == ' ' )
  247. pText[ len-1 ] = '_';
  248. xfont->DrawText( NULL, pText, -1, &r, DT_CALCRECT , 0xffffffff );
  249. pText[len-1] = lastChar;
  250. return r.bottom - r.top;
  251. }
  252. BYTE UnlockMouse[3] = {0xC2, 0x08, 0x00};
  253. BYTE LockMouse[3] = {0x8B,0xFF,0x55};
  254.  
  255.  
  256.  
  257. void Lockmouse(bool lock)
  258. {
  259. if(!lock)
  260. {
  261. HMODULE hMyMod = NULL;
  262. hMyMod = GetModuleHandle("USER32.dll");
  263.  
  264. if(hMyMod)
  265. {
  266. DWORD dwTemp = NULL;
  267. dwTemp = (DWORD)GetProcAddress(hMyMod, "SetCursorPos");
  268.  
  269. if(dwTemp)
  270. {
  271. DWORD dwProtect;
  272. VirtualProtect((void*)dwTemp, 3, PAGE_EXECUTE_READWRITE, &dwProtect);
  273. memcpy((void*)dwTemp, &UnlockMouse, 3);
  274. VirtualProtect((void*)dwTemp, 3, dwProtect, &dwProtect);
  275. }
  276. }
  277. }
  278. else
  279. {
  280. HMODULE hMyMod = NULL;
  281. hMyMod = GetModuleHandle("USER32.dll");
  282.  
  283. if(hMyMod)
  284. {
  285. DWORD dwTemp = NULL;
  286. dwTemp = (DWORD)GetProcAddress(hMyMod, "SetCursorPos");
  287.  
  288. if(dwTemp)
  289. {
  290. DWORD dwProtect;
  291. VirtualProtect((void*)dwTemp, 3, PAGE_EXECUTE_READWRITE, &dwProtect);
  292. memcpy((void*)dwTemp, &LockMouse, 3);
  293. VirtualProtect((void*)dwTemp, 3, dwProtect, &dwProtect);
  294. }
  295. }
  296. }
  297. }
  298.  
  299.  
  300. LRESULT CALLBACK KeyboardHookProc (int nCode, WPARAM wParam, LPARAM lParam)
  301. {
  302.  
  303.  
  304. if (nCode == HC_ACTION)
  305. {
  306.  
  307.  
  308. if ((nCode == HC_ACTION) &&
  309. ((wParam == WM_SYSKEYDOWN) ||
  310. (wParam == WM_KEYDOWN)
  311. )) {
  312. KBDLLHOOKSTRUCT* key = (KBDLLHOOKSTRUCT*)lParam;
  313.  
  314. if(key->vkCode == VK_INSERT)
  315. if(ui->disabled)
  316. {
  317. Lockmouse(false);
  318.  
  319. ShowCursor(true);
  320. ui->disabled = false;
  321. }else if( !ui->disabled)
  322. {
  323. Lockmouse(true);
  324. ui->disabled = true;
  325.  
  326. ShowCursor(false);
  327. }
  328. }
  329.  
  330.  
  331. for (vector<XControl*>::iterator control = controlsp->begin(); control != controlsp->end(); ++control) {
  332. XControl* cont;
  333. cont = *control._Ptr;
  334. if(cont->type == types::Textbox && cont->active == 1)
  335. {XTextBox* tb;
  336. tb = (XTextBox*)*control._Ptr;
  337. tb->HandleInput(nCode,wParam,lParam);break;}
  338. }
  339. }else return 0;
  340.  
  341.  
  342. return CallNextHookEx(KeyboardHook,
  343. nCode,wParam,lParam);
  344.  
  345. }
  346.  
  347. DWORD downtick;
  348. short zDelta;
  349.  
  350. LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam){
  351. if( nCode == 0 ) // means: nCode==HC_ACTION or nCode==HC_NOREMOVE
  352. {
  353.  
  354. //PMSLLHOOKSTRUCT k = (PMSLLHOOKSTRUCT)(lParam);
  355.  
  356. //MOUSEHOOKSTRUCT mhs = *(MOUSEHOOKSTRUCT*)lParam;
  357.  
  358. //GetCursorPos(&p);
  359. MOUSEHOOKSTRUCTEX* info = (MOUSEHOOKSTRUCTEX*)( lParam );
  360. POINT p;
  361. p=info->pt;
  362. ScreenToClient(FindWindow(NULL,/*"SimpleSample"*/WINDOW_NAME),&p);
  363. int xMetric = GetSystemMetrics(SM_CXVIRTUALSCREEN);
  364.  
  365. xMetric -= 100;
  366.  
  367. if(wParam == WM_LBUTTONDOWN)
  368. {
  369. //MessageBox(NULL,"Test","Test",0);
  370. for (vector<XControl*>::iterator cont = controlsp->begin(); cont != controlsp->end(); ++cont) {
  371.  
  372. XControl* control;
  373. control = *cont._Ptr;
  374. if(control->type == ::NumericUpDown)
  375. {
  376. XNumericUpDown* nud;
  377. nud = (XNumericUpDown*)*cont._Ptr;
  378. if(p.x <= nud->x + nud->window.x + 20 +2 && p.x > nud->x + nud->window.x -2 && p.y <= nud->y + nud->window.y +nud->h/4 + nud->h/2 + 2&& p.y > nud->y + nud->window.y +nud->h/4 -2)
  379. {
  380. if(nud->value - nud->step >= nud->min)
  381. {
  382. nud->value -= nud->step;
  383. nud->mouse = 1;
  384. }
  385. }
  386. if(p.x <= nud->x + nud->window.x +nud->w + 2 && p.x > nud->x + nud->window.x +nud->w -20 -2 && p.y <= nud->y + nud->window.y +nud->h/4 + nud->h/2 + 2&& p.y > nud->y + nud->window.y +nud->h/4 -2)
  387. {
  388. if(nud->value + nud->step <= nud->max)
  389. {
  390. nud->value += nud->step;
  391. nud->mouse = 2;
  392. }
  393. }
  394. //nud->x + nud->window.x , nud->y + nud->window.y + (nud->h/2)/2, 20 ,nud->h/2 +1
  395. }
  396. if(control->type == ::ListBox)
  397. {
  398. XListBox* ltb;
  399. ltb = (XListBox*)*cont._Ptr;
  400. if( p.x >= ltb->x +ltb->window.x + ltb->w -17 && p.y >= ltb->y +ltb->window.y + ltb->slidery && p.y <= ltb->y + ltb->window.y + (ltb->items.size() * 17) / ltb->h * 17 + ltb->slidery && p.x <= ltb->x +ltb->window.x + ltb->w)
  401. {ltb->slidermouse = 1;}
  402. }
  403. }
  404. downtick = GetTickCount();
  405. mousedown = true;
  406. }
  407. if(wParam == WM_LBUTTONUP)
  408. {
  409. mousedown = false;
  410. for (vector<XControl*>::iterator cont = controlsp->begin(); cont != controlsp->end(); ++cont) {
  411.  
  412. XControl* control;
  413. control = *cont._Ptr;
  414. switch(control->type)
  415. {
  416. case ::Button:
  417. XButton* btn;
  418. btn = (XButton*)*cont._Ptr;
  419. if(p.x <= btn->x + btn->w + btn->window.x && p.x > btn->x + btn->window.x && p.y <= btn->y + btn->h +btn->window.y && p.y > btn->y + btn->window.y)
  420. {
  421. /*std::stringstream ss (stringstream::in | stringstream::out);
  422. ss << p.x << " " << p.y << " " << btn->x << " " << btn->y << " " << btn->w << " " << btn->h;
  423. MessageBox(NULL,ss.str().c_str(),"Test",0); */
  424. mousedown = false;
  425. CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE)btn->clickevent, (LPVOID)btn, NULL, NULL);
  426. }
  427. break;
  428. case ::Textbox:
  429. XTextBox* tb;
  430. tb = (XTextBox*)*cont._Ptr;
  431. if(p.x <= tb->x + tb->w + tb->window.x && p.x > tb->x + tb->window.x && p.y <= tb->y + tb->h +tb->window.y && p.y > tb->y + tb->window.y)
  432. {
  433. /*std::stringstream ss (stringstream::in | stringstream::out);
  434. ss << p.x << " " << p.y << " " << tb->x << " " << tb->y << " " << tb->w << " " << tb->h;
  435. MessageBox(NULL,ss.str().c_str(),"Test",0); */
  436. tb->active = 1;
  437. }
  438. else
  439. tb->active = 0;
  440. break;
  441. case ::NumericUpDown:
  442. XNumericUpDown* nud;
  443. nud = (XNumericUpDown*)*cont._Ptr;
  444. nud->mouse = 0;
  445. /*if(p.x <= nud->x + nud->window.x + 20 +2 && p.x > nud->x + nud->window.x -2 && p.y <= nud->y + nud->window.y + nud->h/2 +2 && p.y > nud->y + nud->window.y +nud->h/4 -2)
  446. {nud->value += nud->step; nud->mouse = 1;}*/
  447. break;
  448. case ::ListBox:
  449. XListBox* ltb;
  450. ltb = (XListBox*)*cont._Ptr;
  451. int i = 0;
  452.  
  453. if(!ltb->slidermouse)
  454. {
  455. int n = 0;
  456. repeat:
  457. if(p.x <= ltb->x + ltb->w + ltb->window.x -17 && p.x > ltb->x + ltb->window.x && p.y <= ltb->y + ltb->window.y + n*17 +17 && p.y > ltb->y + ltb->window.y + n*17)
  458. {
  459. ltb->selected = n + ltb->out;
  460.  
  461. //break;
  462. }
  463. /*else
  464. {ltb->selected = -1;}*/
  465.  
  466. n++;
  467.  
  468. if(n*17+17 < ltb->h)
  469. goto repeat;
  470. if(p.x <= ltb->x + ltb->w + ltb->window.x -17)
  471. {
  472. for (vector<XListBoxItem>::iterator item = itemsp->begin(); item != itemsp->end(); ++item)
  473. {
  474. if(i == ltb->selected)
  475. item->selected = 1;
  476. else
  477. item->selected = 0;
  478. i++;
  479. }
  480. }
  481. }
  482. ltb->slidermouse = 0;
  483. break;
  484. }
  485. }
  486. }
  487.  
  488. }
  489.  
  490.  
  491.  
  492.  
  493. return CallNextHookEx(MouseHook,nCode,wParam,lParam);
  494. }
  495.  
  496.  
  497.  
  498. DWORD WINAPI hooks(LPVOID lpParm)
  499. {
  500. HINSTANCE hInstance = GetModuleHandle(NULL);
  501. if (!hInstance) hInstance = LoadLibrary((LPCSTR)lpParm);
  502. if (!hInstance) return 1;
  503.  
  504. //while(true)
  505. //{
  506. MouseHook = SetWindowsHookEx (
  507. WH_MOUSE_LL,
  508. (HOOKPROC)MouseHookProc,
  509. hInstance,
  510. NULL
  511. );
  512.  
  513.  
  514. KeyboardHook = SetWindowsHookEx (
  515. WH_KEYBOARD_LL,
  516. (HOOKPROC)KeyboardHookProc,
  517. hInstance,
  518. NULL
  519. );
  520.  
  521. //MessageLoop();
  522. MSG msg;
  523. //HACCEL hAccelTable;
  524. //hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_KEYBINDER));
  525. while (GetMessage(&msg, NULL, 0, 0))
  526. {
  527. TranslateMessage(&msg);
  528. DispatchMessage(&msg);
  529. }
  530.  
  531. UnhookWindowsHookEx(MouseHook);
  532. UnhookWindowsHookEx(KeyboardHook);
  533.  
  534. //}
  535.  
  536. return 0;
  537. }
  538.  
  539.  
  540. #define GR_GREEN2 D3DCOLOR_ARGB( 255, 120, 154,116 ),D3DCOLOR_ARGB( 255, 16, 102, 9 )
  541. #define GR_GREEN1 D3DCOLOR_ARGB( 255, 76, 135, 000 ),D3DCOLOR_ARGB( 255, 116, 205, 000 )
  542. #define GR_RED1 D3DCOLOR_ARGB( 255, 255, 000, 51 ),D3DCOLOR_ARGB( 255, 156, 000, 31 )
  543. #define GR_BTNDOWN D3DCOLOR_ARGB( 255,136, 109, 180 ),D3DCOLOR_ARGB( 255, 38,5, 75 )
  544. #define GR_BARB D3DCOLOR_ARGB( 255,48, 48, 48 ),D3DCOLOR_ARGB( 255, 17,17, 17 )
  545. #define GR_NUMB D3DCOLOR_ARGB( 255,60, 60, 60 ),D3DCOLOR_ARGB(90, 30,30,30 )
  546.  
  547.  
  548. #pragma region XControl
  549.  
  550.  
  551.  
  552. void XTextBox::HandleInput(int nCode, WPARAM wParam, LPARAM lParam)
  553. {
  554. //int tmp;
  555. //int spos;
  556. charw = caltext(" ");
  557.  
  558. KBDLLHOOKSTRUCT* key = (KBDLLHOOKSTRUCT*)lParam;
  559. if ((nCode == HC_ACTION) &&
  560. ((wParam == WM_SYSKEYDOWN) ||
  561. (wParam == WM_KEYDOWN)
  562. ))
  563. {
  564. BYTE keyState[256] = {0};
  565. WORD chars;
  566. GetKeyState(0);
  567.  
  568. GetKeyboardState(keyState);
  569. if(ToAscii(key->vkCode, key->scanCode,keyState, &chars, 0))
  570. {
  571.  
  572. if(key->vkCode == VK_DELETE)
  573. {
  574. //textbuffer.erase(caretPos+1,1);
  575. }
  576. else if((char)chars == '\b')
  577. {
  578. if(caretPos > 0)
  579. {
  580.  
  581.  
  582.  
  583. if(x +window.x+((caretPosScreen-1)*charw) >= x+window.x && ((showPosbegin <= 0) || (textbuffer.substr(showPosbegin,textbuffer.length()).length()*charw > this->w)))
  584. caretPosScreen -=1;
  585.  
  586.  
  587. if(showPosbegin > 0 && textbuffer.substr(showPosbegin,textbuffer.length()).length()*charw < this->w)
  588. showPosbegin -=1;
  589.  
  590.  
  591.  
  592.  
  593. if(caretPos-1 >= 0)
  594. {
  595. caretPos-=1;
  596. textbuffer.erase(caretPos,1);
  597. }
  598. else
  599. textbuffer.erase(caretPos-1,1);
  600.  
  601.  
  602.  
  603. //if(textbuffer.substr(showPosbegin,textbuffer.npos).length()*charw < this->w)
  604.  
  605.  
  606. }
  607. }
  608. else
  609. {
  610. textbuffer.insert(caretPos,1,(char)chars);
  611. if(x + window.x + ((caretPosScreen+2)*charw) < x +window.x + w)
  612. {caretPos +=1;caretPosScreen+=1;}
  613. else
  614. {caretPos+=1; showPosbegin +=1;}
  615. }
  616. }
  617.  
  618. if(key->vkCode == VK_RIGHT)
  619. {
  620. if(x + window.x + ((caretPosScreen)*charw) > x +window.x + w -charw -(charw/2))
  621. {
  622.  
  623. //if(showPosbegin < )
  624. if(caretPos < textbuffer.length())
  625. {showPosbegin +=1;caretPos+=1;}
  626. //control->x +control->window.x+(control->caretPos*8);
  627. }
  628. else
  629. {
  630. if(caretPos < textbuffer.length())
  631. {caretPos +=1;
  632. caretPosScreen +=1;}
  633. }
  634. }
  635.  
  636. if(key->vkCode == VK_LEFT)
  637. {
  638. if(x +window.x+((caretPosScreen-1)*charw) < x+window.x)
  639. {
  640.  
  641. if(showPosbegin > 0)
  642. {showPosbegin -=1; caretPos -=1;}//caretPos-=1;}
  643. }
  644. else
  645. {
  646. caretPosScreen -=1;
  647. caretPos -=1;
  648. }
  649.  
  650. }
  651. }
  652.  
  653. }
  654.  
  655. void XControl::Render(LPDIRECT3DDEVICE9 Device)
  656. {
  657.  
  658. std::string tmp;
  659. std::stringstream ss (stringstream::in | stringstream::out);
  660. switch(this->type)
  661. {
  662. case types::Textbox:
  663. XTextBox* tb;
  664. tb = (XTextBox*)this;
  665. tb->Render(Device);
  666. break;
  667. case types::Button:
  668. XButton* btn;
  669. btn = (XButton*)this;
  670. btn->Render(Device);
  671. break;
  672. }
  673. }
  674.  
  675. //void XControl::takeInput(char ch)
  676. //{
  677. //
  678. // MessageBox(NULL,(char*)ch,(char*)ch,0);
  679. // switch(ch)
  680. // {
  681. // case '\b': // backspace
  682. // {
  683. // if(caretPos>0)
  684. // {
  685. // textbuffer.erase(caretPos-1,1);
  686. // caretPos-=1;
  687. // }
  688. // }
  689. // break;
  690. //
  691. // case '\r': // return/enter
  692. // {
  693. // //prevCommands.push_back(command);
  694. //
  695. // //Send(command);
  696. //
  697. // textbuffer="";
  698. // caretPos=0;
  699. // //cmdCount=prevCommands.size();
  700. // //currCmd=cmdCount;
  701. // }
  702. // break;
  703. //
  704. // case '\t': // tab
  705. // {
  706. // /* if(cmdCount>0)
  707. // {
  708. // if(currCmd>0)
  709. // {
  710. // currCmd-=1;
  711. // command=prevCommands.at(currCmd);
  712. // caretPos=command.length();
  713. // }
  714. // else
  715. // {
  716. // currCmd=cmdCount-1;
  717. // command=prevCommands.at(currCmd);
  718. // caretPos=command.length();
  719. // }
  720. // }*/
  721. // }
  722. // break;
  723. //
  724. // default:
  725. //
  726. // textbuffer.insert(caretPos,1,ch);
  727. //
  728. // caretPos+=1;
  729. // break;
  730. // } // switch(ch)
  731. //}
  732.  
  733. #pragma endregion
  734.  
  735.  
  736.  
  737. #pragma region XNumeric
  738.  
  739. XNumericUpDown::XNumericUpDown()
  740. {
  741. this->max = 100.0f;
  742. this->min = 0.0f;
  743. this->step = 1.0f;
  744. }
  745.  
  746. XNumericUpDown::XNumericUpDown(int x,int y,int h,int w, std::string title,int id)
  747. {
  748. this->type = ::NumericUpDown;
  749. this->x = x;
  750. this->y = y;
  751. this->h = h;
  752. this->w = w;
  753. this->id = id;
  754. this->max = 100.0f;
  755. this->min = 0.1f;
  756. this->step = 0.1f;
  757. }
  758.  
  759. DWORD wtick;
  760.  
  761. void XNumericUpDown::Render(LPDIRECT3DDEVICE9 Device)
  762. {
  763. if(mousedown && downtick + 500 <= GetTickCount() && mouse == 1)
  764. {
  765. if(value - step >= min)
  766. value -= step;
  767. }
  768.  
  769. if(mousedown && downtick + 500 <= GetTickCount() && mouse == 2)
  770. {
  771. if(value + step <= max)
  772. value += step;
  773. }
  774.  
  775. std::stringstream ss (stringstream::in | stringstream::out);
  776. ss << value;
  777. RECT rctt;
  778. rctt.left = this->x +window.x;
  779. rctt.right = this->x +window.x+ this->w;
  780. rctt.top = this->y +window.y;
  781. rctt.bottom = this->y + window.y + this->h;
  782.  
  783. xfont->DrawText(NULL, ss.str().c_str(),-1,&rctt,DT_CENTER,D3DCOLOR_ARGB( 255, 255, 255, 0 ));
  784.  
  785. FullRectBordered(this->x + window.x , this->y +window.y + this->h/4 , 20 ,this->h/2 +1,2,GR_RED1);//,0,Device);
  786. rctt.left = this->x +window.x + 3;
  787. nfont->DrawText(NULL, "<<<",-1,&rctt,DT_LEFT | DT_VCENTER,D3DCOLOR_ARGB( 255, 255, 255, 255 ));
  788.  
  789.  
  790. FullRectBordered(this->x + window.x + this->w - 20, this->y +window.y + this->h/4 , 20 ,this->h/2 +1,2,GR_RED1);//,0,Device);
  791. rctt.right = this->x +window.x+ this->w - 3;
  792. nfont->DrawText(NULL, ">>>",-1,&rctt,DT_RIGHT | DT_VCENTER,D3DCOLOR_ARGB( 255, 255, 255, 255 ));
  793.  
  794. }
  795.  
  796. #pragma endregion
  797.  
  798. #pragma region XTextBox
  799.  
  800.  
  801. XTextBox::XTextBox()
  802. {
  803.  
  804. }
  805.  
  806.  
  807. XTextBox::XTextBox(int x,int y,int h,int w,int id)
  808. {
  809. this->type = ::Textbox;
  810. this->x = x;
  811. this->y = y;
  812. this->h = h;
  813. this->w = w;
  814. this->id = id;
  815. this->caretPos = 0;
  816. this->showPosbegin = 0;
  817. this->caretPosScreen = 0;
  818.  
  819. }
  820.  
  821.  
  822. void XTextBox::Render(LPDIRECT3DDEVICE9 Device)
  823. {
  824. DrawRectBordered(this->x +window.x , this->y +window.y,this->w, this->h,D3DCOLOR_ARGB( 155, 000, 000, 000 ),D3DCOLOR_ARGB( 255, 120, 154,116 ));
  825.  
  826. int length;
  827. RECT rctt;
  828. rctt.left = this->x +window.x +6;
  829. rctt.right = this->x +window.x+ this->w;
  830. rctt.top = this->y +window.y;
  831. rctt.bottom = this->y + window.y + this->h;
  832.  
  833. length = caltext(textbuffer);
  834. if(showPosbegin > 0)
  835.  
  836. {if(w == 0 || charw == 0){ MessageBox(NULL,"Es ist ein fehler aufgetreten\n bitte kontaktiere den entwickler","Error",MB_ICONEXCLAMATION | MB_OK); ExitProcess(0);}
  837. xfont->DrawText(NULL, textbuffer.substr(showPosbegin,(this->w/charw)).c_str(),-1,&rctt,0,D3DCOLOR_ARGB( 255, 255, 255, 0 ));}
  838. else
  839. xfont->DrawText(NULL,textbuffer.c_str(),-1,&rctt,0,D3DCOLOR_ARGB( 255, 255, 255, 0 ));
  840.  
  841. /*caretTick+=1;
  842. if ( caretTick >= 25)
  843. {
  844. caretTick=0;
  845. showCaret=!showCaret;
  846. } */
  847. if(ltick +750 <= GetTickCount() && active)
  848. {
  849. if(ltick + 1500 <= GetTickCount())
  850. ltick = GetTickCount();
  851. //caretPos = 8;
  852.  
  853. //if(this->x +window.x+((caretPos+1)*8) <= this->x +window.x + this->w)
  854. //{
  855. rctt.left = this->x +window.x+ (caretPosScreen*charw);
  856. //}
  857.  
  858. xfont->DrawText(NULL,"|",-1,&rctt,0,D3DCOLOR_ARGB( 255, 255, 255, 0 ));
  859. //Text(x+6+(caretPos*8),y+2,D3DCOLOR_ARGB( 255, 255, 165, 0 ),"|",pDevice);
  860. }
  861. //GradientRect(this->x +window.y , this->y +window.y, this->h,this->w,GR_GREEN2);
  862. }
  863.  
  864.  
  865. #pragma endregion
  866.  
  867.  
  868.  
  869. #pragma region XButton
  870.  
  871.  
  872. XButton::XButton()
  873. {
  874.  
  875. }
  876.  
  877.  
  878. XButton::XButton(int x,int y,int h,int w, std::string title,void (*func)(XButton* sender),int id)
  879. {
  880.  
  881. this->type = types::Button;
  882. this->x = x;
  883. this->y = y;
  884. this->h = h;
  885. this->w = w;
  886. this->title += title.c_str();
  887. this->id = id;
  888. this->clickevent = func;
  889. }
  890.  
  891. void XButton::Render(LPDIRECT3DDEVICE9 Device)
  892. {
  893. POINT p;
  894. GetCursorPos(&p);
  895. ScreenToClient(FindWindow(NULL,/*"SimpleSample"*/WINDOW_NAME),&p);
  896. if(mousedown && p.x <= this->x + this->w +window.x && p.x > this->x + window.x && p.y <= this->y + this->h +window.y && p.y > this->y + window.y)
  897. {
  898. GradientRect(this->x +window.x , this->y +window.y, this->h,this->w,GR_BTNDOWN);//,0,Device);
  899.  
  900. }
  901. else if(p.x <= this->x + this->w +window.x && p.x > this->x + window.x && p.y <= this->y + this->h +window.y && p.y > this->y + window.y)
  902. {
  903. GradientRect(this->x +window.x , this->y +window.y, this->h,this->w,GR_GREEN1);//,0,Device);
  904. }
  905. else
  906. {
  907. GradientRect(this->x +window.x , this->y +window.y, this->h,this->w,GR_GREEN2);//,0,Device);
  908. }
  909. RECT rct;
  910. rct.left = this->x + window.x;
  911. rct.top = this->y + window.y;
  912. rct.right = this->w +window.x +this->x;
  913. rct.bottom = this->h + window.y +this->y;
  914.  
  915. xfont->DrawText(NULL,this->title.c_str(),-1,&rct,DT_NOCLIP | DT_CENTER | DT_VCENTER ,D3DCOLOR_ARGB( 255, 255,255, 255 ));
  916. }
  917.  
  918. #pragma endregion
  919.  
  920.  
  921.  
  922. #pragma region XListBox
  923.  
  924.  
  925. XListBox::XListBox()
  926. {
  927. this->slidery = 0;
  928. };
  929.  
  930. XListBox::XListBox(int x,int y,int h,int w, std::string title,int id)
  931. {
  932. this->type = ::ListBox;
  933. this->x = x;
  934. this->y = y;
  935. this->h = h;
  936. this->w = w;
  937. this->id = id;
  938. this->title = title;
  939. for(int i = 0; i< 50;i++)
  940. {
  941. XListBoxItem item;
  942. item.name = "Test";
  943. item.name += i;
  944. item.selected = 0;
  945. //item.selected = i;
  946. items.push_back(item);
  947. }
  948. }
  949.  
  950. POINT oldp;
  951. void XListBox::Render(LPDIRECT3DDEVICE9 pDevice)
  952. {
  953.  
  954. itemsp = &items;
  955. int charh = caltexth("A");
  956. int sliderh =((float)items.size()*17 / (float)this->h);
  957. POINT p;
  958. GetCursorPos(&p);
  959. ScreenToClient(FindWindow(NULL,/*"SimpleSample"*/WINDOW_NAME),&p);
  960. DrawRectBordered(this->x +window.x , this->y +window.y,this->w, this->h,D3DCOLOR_ARGB( 155, 000, 000, 000 ),D3DCOLOR_ARGB( 255, 120, 154,116 ));
  961.  
  962.  
  963.  
  964. int n = 0;
  965. RECT rct;
  966. rct.left = this->x + window.x + 2;
  967. rct.top = this->y + window.y +2;
  968. rct.right = this->w +window.x +this->x;
  969. rct.bottom = this->h + window.y +this->y;
  970. int oldslidery;
  971. if(slidermouse == 1)
  972. {
  973.  
  974. //if(p.y > this->y + window.y && p.y < this->y + window.y + this->h)
  975. slidery = p.y -oldp.y + slidery;
  976.  
  977. if(sliderh + slidery > this->h)
  978. slidery = this->h -sliderh -1;
  979.  
  980. if(slidery < 0)
  981. slidery = 1;
  982.  
  983. oldslidery = slidery;
  984. }
  985.  
  986.  
  987. out = ((float)items.size() / (float)this->h) * slidery;
  988. RECT rctt;
  989. rctt.left = 250;
  990. rctt.top = 250;
  991. rctt.right = 10000;
  992. rctt.bottom =1000;
  993. stringstream ss (stringstream::in| stringstream::out);
  994. ss << sliderh;
  995. ss << " " << p.y << " " << zDelta;
  996. // xfont->DrawText(NULL,ss.str().c_str(),-1,&rctt,0,D3DCOLOR_ARGB( 255, 255,255, 255 ));
  997. GradientRect(this->x +window.x + this->w -15 , this->y +window.y + slidery, sliderh ,15,GR_BTNDOWN);//,0,Device);
  998.  
  999.  
  1000.  
  1001. //DrawRectBordered(this->x +window.x , this->y + window.y +2 + this->selected * 17 ,this->w -15, 17,D3DCOLOR_ARGB( 200, 255, 000, 000 ),D3DCOLOR_ARGB( 255, 120, 154,116 ));
  1002.  
  1003.  
  1004.  
  1005. for (vector<XListBoxItem>::iterator item = items.begin() + out; item != items.end(); ++item) {
  1006. rct.top = this->y + window.y +2 + n*17;
  1007. if(rct.top > rct.bottom)
  1008. break;
  1009.  
  1010.  
  1011. if(item->selected)
  1012. DrawRectBordered(this->x +window.x , this->y + window.y +2 + /*this->selected*/n * 17 ,this->w -17, 17,D3DCOLOR_ARGB( 200, 255, 000, 000 ),D3DCOLOR_ARGB( 255, 120, 154,116 ));
  1013.  
  1014. xfont->DrawText(NULL,item->name.c_str(),-1,&rct,0,D3DCOLOR_ARGB( 255, 255,255, 255 ));
  1015.  
  1016.  
  1017. n++;
  1018. }
  1019. //XListBoxItem item;
  1020. //item = this->GetSelectedItem();
  1021.  
  1022. //rct.top = this->h + window.x + 17;
  1023.  
  1024. //xfont->DrawText(NULL,item.name.c_str(),-1,&rct,0,D3DCOLOR_ARGB( 255, 255,255, 255 ));
  1025.  
  1026.  
  1027. if(sliderh + slidery +1 < this->h && p.y > this->y + window.y)
  1028. oldp = p;
  1029. //<∨∧>
  1030. }
  1031.  
  1032. void XListBox::RemoveItem(XListBoxItem item)
  1033. {
  1034. for (vector<XListBoxItem>::iterator itemb = items.begin() + out; itemb != items.end(); ++itemb) {
  1035. if(itemb->info == item.name && itemb->info == item.info)
  1036. {
  1037. items.erase(itemb);
  1038. }
  1039. }
  1040. }
  1041.  
  1042. void XListBox::AddItem(XListBoxItem item)
  1043. {
  1044. items.push_back(item);
  1045. }
  1046.  
  1047.  
  1048. XListBoxItem XListBox::GetSelectedItem()
  1049. {
  1050.  
  1051. XListBoxItem item;
  1052.  
  1053. for (vector<XListBoxItem>::iterator itemb = items.begin(); itemb != items.end(); ++itemb) {
  1054. if(itemb->selected == 1)
  1055. {
  1056. item = *itemb._Ptr;
  1057. return item;
  1058. }
  1059. }
  1060.  
  1061.  
  1062. item.name = "Nothing selected";
  1063. item.info = "Nothing";
  1064. item.selected = 1;
  1065. return item;
  1066. }
  1067.  
  1068. #pragma endregion
  1069.  
  1070. #pragma region XWindow
  1071.  
  1072. XWindow::XWindow()
  1073. {};
  1074.  
  1075.  
  1076. XWindow::XWindow(int x,int y,int h,int w, std::string title,int id)
  1077. {
  1078. this->x = x;
  1079. this->y = y;
  1080. this->h = h;
  1081. this->w = w;
  1082. this->id = id;
  1083. this->title += title.c_str();
  1084. this->state = WindowState::Normal;
  1085. controlsp = &controls;
  1086.  
  1087. }
  1088.  
  1089. DWORD tick;
  1090.  
  1091.  
  1092. void XWindow::Render(LPDIRECT3DDEVICE9 Device)
  1093. {
  1094.  
  1095. DrawRectBordered(this->x -1, this->y -1, this->w + 1,this->h + 1,D3DCOLOR_ARGB( 155, 000, 000, 000 ),D3DCOLOR_ARGB( 255, 000, 255, 000 ));
  1096. GradientRect(this->x , this->y, 20,this->w,GR_BARB);
  1097.  
  1098. //Rounded( this->x, this->y, this->w, 20, 2, D3DCOLOR_ARGB( 155, 255, 000, 000 ));
  1099. //Rounded( this->x , this->y + 20, this->w, this->h, 2, D3DCOLOR_ARGB( 155, 000, 000, 000 ));
  1100. RECT rct;
  1101. rct.left = this->x;
  1102. rct.top = this->y;
  1103. rct.right = 2000;
  1104. rct.bottom = 50;
  1105.  
  1106. xfont->DrawText(NULL,this->title.c_str(),-1,&rct,DT_NOCLIP,this->textcolor);
  1107. rct.top = this->y + this->h - 20;
  1108. rct.left = this->x + 5;
  1109. xfont->DrawText(NULL,"by XForce",-1,&rct,DT_NOCLIP,this->textcolor);
  1110. controlsp = &controls;
  1111.  
  1112.  
  1113. for (vector<XControl*>::iterator control = controls.begin(); control != controls.end(); ++control) {
  1114.  
  1115. XControl* cont;
  1116. cont = *control._Ptr;
  1117. cont->Render(Device);
  1118. //control->Render(Device);
  1119.  
  1120. }
  1121.  
  1122.  
  1123. }
  1124.  
  1125.  
  1126. void XWindow::AddControl(XControl* control)
  1127. {
  1128. /*control.window.x = this->x;
  1129. control.window.y = this->y;
  1130. control.caretPos = 0;
  1131. control.showPosbegin = 0;
  1132. control.caretPosScreen = 0;
  1133. controls.push_back(control);*/
  1134.  
  1135. control->window.x = this->x;
  1136. control->window.y = this->y;
  1137. controls.push_back(control);
  1138.  
  1139. controlsp = &controls;
  1140.  
  1141. }
  1142.  
  1143.  
  1144.  
  1145. void XWindow::RemoveControl(XControl* control)
  1146. {
  1147. for (vector<XControl*>::iterator controli = controls.begin(); controli < controls.end(); ++controli) {
  1148. XControl* cont;
  1149. cont = *controli._Ptr;
  1150. if(cont->id == control->id)
  1151. {controls.erase(controli);
  1152. return;
  1153. }
  1154. /*if(controli->id == control.id)
  1155. {controls.erase(controli);
  1156. return;
  1157. }*/
  1158. }
  1159. }
  1160.  
  1161. #pragma endregion
  1162.  
  1163.  
  1164.  
  1165.  
  1166.  
  1167. #pragma region XGUI
  1168.  
  1169. void XGUI::AddWindow(XWindow* window)
  1170. {
  1171. windows.push_back(window);
  1172. }
  1173.  
  1174.  
  1175.  
  1176. void XGUI::RemoveWindow(XWindow* window)
  1177. {
  1178.  
  1179.  
  1180. for (vector<XWindow*>::iterator windowi = windows.begin(); windowi != windows.end(); ++windowi) {
  1181. XWindow* wind;
  1182. wind = *windowi._Ptr;
  1183. if(wind->id == window->id)
  1184. {windows.erase(windowi);
  1185. return;}
  1186. }
  1187. }
  1188.  
  1189.  
  1190. void XGUI::Render(LPDIRECT3DDEVICE9 pDevice/*,D3DVIEWPORT9 viewport,ID3DXFont* xfont*/)
  1191. {
  1192. //SetCursorPos(50,50);
  1193. //ShowCursor(true);
  1194.  
  1195. if( !g_pLine )
  1196. D3DXCreateLine( pDevice, &g_pLine ); // Make sure to create before calling
  1197.  
  1198. if(!xfont)
  1199. D3DXCreateFont(pDevice, (UINT)20, 0, FW_NORMAL, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,CLEARTYPE_QUALITY , DEFAULT_PITCH | FF_DONTCARE, TEXT("Courier New"), &xfont);
  1200.  
  1201. if(!nfont)
  1202. D3DXCreateFont(pDevice, (UINT)15, 6, FW_NORMAL, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,CLEARTYPE_QUALITY , DEFAULT_PITCH | FF_DONTCARE, TEXT("Courier New"), &nfont);
  1203. if(!disabled)
  1204. {
  1205. XWindow* aw;
  1206. bool awb = false;
  1207. for (vector<XWindow*>::iterator window = windows.begin(); window != windows.end(); ++window) {
  1208. XWindow* wind;
  1209. wind = *window._Ptr;
  1210. if(wind->state == WindowState::Active)
  1211. {aw = wind; awb = true;}
  1212. else if(wind->state != WindowState::Hide)
  1213. wind->Render(pDevice);
  1214. }
  1215. if(awb)
  1216. aw->Render(pDevice);
  1217. }
  1218. }
  1219.  
  1220.  
  1221.  
  1222. XGUI::XGUI()
  1223. {
  1224.  
  1225.  
  1226.  
  1227. ui = this;
  1228. //ShowCursor(true);
  1229. this->disabled = true;
  1230. CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE)hooks, NULL, NULL, NULL);
  1231. }
  1232.  
  1233.  
  1234.  
  1235. void XGUI::Release()
  1236. {
  1237. //if(xfont)
  1238. SAFE_RELEASE(xfont);
  1239. SAFE_RELEASE(nfont);
  1240. SAFE_RELEASE(g_pLine);
  1241. }
  1242.  
  1243.  
  1244.  
  1245. #pragma endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement