Posted By

xterminhate on 03/09/13


Tagged

CGUIAdvancedWindow


Versions (?)

CGUIAdvancedWindow.cpp


 / Published in: C++
 

A new custom GUI Element, based on the Irrlicht GUI Window, with these features : - Close behavior (nothing, remove, set visible false), - Configurable system buttons, - Minimize button, - Double click on minimized window maximizes it, - Restore button shows up when window is minimized, - Pinned button, to prevent moving the window, - Programmable user buttons, with attributes (show/hide for each window state) and user sprite bank, posting event catched by the user defined EventReceiver, - Double click on window bar hides window client area, - Window frame renderer using cursor coordinates as light source) and default/user skin. - Configurable minimized window position, - Flag preventing window minimizing, - Notification system, making the tittle bar to blink.

  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4.  
  5. #include "CGUIAdvancedWindow.h"
  6. //#ifdef _IRR_COMPILE_WITH_GUI_
  7.  
  8. #include "IGUISkin.h"
  9. #include "IGUIEnvironment.h"
  10. #include "IVideoDriver.h"
  11. #include "IGUIButton.h"
  12. #include "IGUIFont.h"
  13. #include "IGUIFontBitmap.h"
  14.  
  15. //#include<iostream> // DEBUG
  16.  
  17. namespace irr
  18. {
  19. namespace gui
  20. {
  21.  
  22. //! constructor
  23. CGUIAdvancedWindow::CGUIAdvancedWindow(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle,
  24. const core::array<buttoninfo>& buttons, EWINDOW_CLOSE close, const core::position2di& minimized, ICursorControl* cursor)
  25. : IGUIElement(EGUIET_WINDOW ,environment, parent, id, rectangle),
  26. Skin(environment->getSkin()), DefaultSprites(Skin->getSpriteBank()), CurrentIconColor(video::SColor(255,255,255,255)),
  27. ButtonInfo(buttons), ButtonRectangles(buttons.size()), Buttons(buttons.size()),
  28. Dragging(false), IsDraggable(true), DrawBackground(true), DrawTitlebar(true), IsActive(false), IsMinimized(false), IsBar(false),
  29. IsMinimizable(true), CloseHandling(close), NormalRectangle(rectangle),
  30. MinimizedRectangle(minimized,core::position2di(minimized.X+rectangle.getWidth(),minimized.Y+21)),
  31. BarRectangle(rectangle.UpperLeftCorner,core::position2di(rectangle.LowerRightCorner.X,rectangle.UpperLeftCorner.Y+21)),
  32. UseGradient((Skin->getType() == EGST_WINDOWS_METALLIC) || (Skin->getType() == EGST_BURNING_SKIN)), Cursor(cursor),
  33. IsNotifying(false), NotifyTimer(0), NotifyState(false)
  34. {
  35. #ifdef _DEBUG
  36. setDebugName("CGUIAdvancedWindow");
  37. #endif
  38. // create the buttons
  39. s32 buttonw = Skin->getSize(EGDS_WINDOW_BUTTON_WIDTH);
  40. s32 posx = RelativeRect.getWidth() - buttonw - 4;
  41. for (size_t index=0; index!=ButtonInfo.size(); ++index)
  42. {
  43. ButtonRectangles.push_back(core::rect<s32>(posx, 3, posx + buttonw, 3 + buttonw));
  44. posx -= buttonw + 2;
  45. switch(ButtonInfo[index].Type)
  46. {
  47. case EWBT_CLOSE:
  48. {
  49. Buttons.push_back(Environment->addButton(ButtonRectangles[index], this, -1,
  50. L"", Skin->getDefaultText(EGDT_WINDOW_CLOSE) ));
  51. }
  52. break;
  53. case EWBT_MINIMIZE:
  54. {
  55. Buttons.push_back(Environment->addButton(ButtonRectangles[index], this, -1,
  56. L"", Skin->getDefaultText(EGDT_WINDOW_MINIMIZE) ));
  57. }
  58. break;
  59. case EWBT_PIN:
  60. {
  61. Buttons.push_back(Environment->addButton(ButtonRectangles[index], this, -1,
  62. L"", L"Pin " )); /// \todo Skin lack of a pin button text. Must upgrade the Irrlicht source code.
  63. }
  64. break;
  65. case EWBT_USER_DEFINED:
  66. {
  67. Buttons.push_back(Environment->addButton(ButtonRectangles[index], this, ButtonInfo[index].UserEventId,
  68. ButtonInfo[index].Name, ButtonInfo[index].ToolTipText )); /// \todo Skin lack of a pin button text. Must upgrade the Irrlicht source code.
  69. }
  70. break;
  71. }
  72. Buttons[index]->setSubElement(true);
  73. Buttons[index]->setTabStop(false);
  74. Buttons[index]->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
  75. Buttons[index]->grab();
  76. }
  77. // this element is a tab group
  78. setTabGroup(true);
  79. setTabStop(true);
  80. setTabOrder(-1);
  81. // refresh all
  82. refreshSprites();
  83. refreshButtons();
  84. updateClientRect();
  85. }
  86.  
  87. //! destructor
  88. CGUIAdvancedWindow::~CGUIAdvancedWindow()
  89. {
  90. for (size_t index=0; index!=Buttons.size(); ++index)
  91. {
  92. Buttons[index]->drop();
  93. }
  94. }
  95.  
  96. void CGUIAdvancedWindow::refreshSprites()
  97. {
  98. CurrentIconColor = Skin->getColor(isEnabled() ? EGDC_WINDOW_SYMBOL : EGDC_GRAY_WINDOW_SYMBOL);
  99. for (size_t index=0; index!=Buttons.size(); ++index)
  100. {
  101. switch(ButtonInfo[index].Type)
  102. {
  103. case EWBT_CLOSE:
  104. {
  105. Buttons[index]->setSpriteBank(DefaultSprites);
  106. Buttons[index]->setSprite(EGBS_BUTTON_UP, Skin->getIcon(EGDI_WINDOW_CLOSE), CurrentIconColor);
  107. Buttons[index]->setSprite(EGBS_BUTTON_DOWN, Skin->getIcon(EGDI_WINDOW_CLOSE), CurrentIconColor);
  108. }
  109. break;
  110. case EWBT_MINIMIZE:
  111. {
  112. Buttons[index]->setSpriteBank(DefaultSprites);
  113. if (IsMinimized)
  114. {
  115. Buttons[index]->setSprite(EGBS_BUTTON_UP, Skin->getIcon(EGDI_WINDOW_RESTORE), CurrentIconColor);
  116. Buttons[index]->setSprite(EGBS_BUTTON_DOWN, Skin->getIcon(EGDI_WINDOW_RESTORE), CurrentIconColor);
  117. }
  118. else
  119. {
  120. Buttons[index]->setSprite(EGBS_BUTTON_UP, Skin->getIcon(EGDI_WINDOW_MINIMIZE), CurrentIconColor);
  121. Buttons[index]->setSprite(EGBS_BUTTON_DOWN, Skin->getIcon(EGDI_WINDOW_MINIMIZE), CurrentIconColor);
  122. }
  123. }
  124. break;
  125. case EWBT_PIN:
  126. {
  127. Buttons[index]->setSpriteBank(DefaultSprites);
  128. if (IsDraggable)
  129. {
  130. Buttons[index]->setSprite(EGBS_BUTTON_UP, Skin->getIcon(EGDI_RADIO_BUTTON_CHECKED), CurrentIconColor);
  131. Buttons[index]->setSprite(EGBS_BUTTON_DOWN, Skin->getIcon(EGDI_RADIO_BUTTON_CHECKED), CurrentIconColor);
  132. }
  133. else
  134. {
  135. Buttons[index]->setSprite(EGBS_BUTTON_UP, Skin->getIcon(EGDI_EXPAND), CurrentIconColor);
  136. Buttons[index]->setSprite(EGBS_BUTTON_DOWN, Skin->getIcon(EGDI_EXPAND), CurrentIconColor);
  137. }
  138. }
  139. break;
  140. case EWBT_USER_DEFINED:
  141. {
  142. Buttons[index]->setSpriteBank(ButtonInfo[index].Sprite);
  143. Buttons[index]->setSprite(EGBS_BUTTON_UP, ButtonInfo[index].SpriteIndex, CurrentIconColor);
  144. Buttons[index]->setSprite(EGBS_BUTTON_DOWN, ButtonInfo[index].SpriteIndex, CurrentIconColor);
  145. }
  146. break;
  147. }
  148. }
  149. }
  150.  
  151. void CGUIAdvancedWindow::refreshButtons()
  152. {
  153. u32 position = 0;
  154. for (size_t index=0; index!=Buttons.size(); ++index)
  155. {
  156. switch(ButtonInfo[index].Type)
  157. {
  158. case EWBT_CLOSE:
  159. case EWBT_PIN:
  160. case EWBT_USER_DEFINED:
  161. {
  162. if ( (ButtonInfo[index].VisibleWhenNormal && !IsMinimized && !IsBar )
  163. || (ButtonInfo[index].VisibleWhenMinimized && IsMinimized)
  164. || (ButtonInfo[index].VisibleWhenBar && IsBar && !IsMinimized) )
  165. {
  166. Buttons[index]->setVisible(true);
  167. Buttons[index]->setRelativePosition(ButtonRectangles[position++]);
  168. }
  169. else
  170. {
  171. Buttons[index]->setVisible(false);
  172. }
  173. }
  174. break;
  175. case EWBT_MINIMIZE:
  176. {
  177. Buttons[index]->setVisible(true);
  178. Buttons[index]->setRelativePosition(ButtonRectangles[position++]);
  179. }
  180. break;
  181. }
  182. }
  183. }
  184.  
  185. //! called if an event happened.
  186. bool CGUIAdvancedWindow::OnEvent(const SEvent& event)
  187. {
  188. if (isEnabled())
  189. {
  190. switch(event.EventType)
  191. {
  192. case EET_GUI_EVENT:
  193. if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST)
  194. {
  195. Dragging = false;
  196. IsActive = false;
  197. }
  198. else
  199. if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUSED)
  200. {
  201. if (Parent && ((event.GUIEvent.Caller == this) || isMyChild(event.GUIEvent.Caller)))
  202. {
  203. Parent->bringToFront(this);
  204. IsActive = true;
  205. }
  206. else
  207. {
  208. IsActive = false;
  209. }
  210. }
  211. else
  212. if (event.GUIEvent.EventType == EGET_BUTTON_CLICKED)
  213. {
  214. for (size_t index=0; index!=Buttons.size(); ++index)
  215. {
  216. if (Buttons[index]==event.GUIEvent.Caller)
  217. {
  218. switch(ButtonInfo[index].Type)
  219. {
  220. case EWBT_CLOSE:
  221. {
  222. if (Parent)
  223. {
  224. // send close event to parent
  225. SEvent e;
  226. e.EventType = EET_GUI_EVENT;
  227. e.GUIEvent.Caller = this;
  228. e.GUIEvent.Element = 0;
  229. e.GUIEvent.EventType = EGET_ELEMENT_CLOSED;
  230.  
  231. // if the event was not absorbed
  232. if (!Parent->OnEvent(e))
  233. close();
  234.  
  235. return true;
  236.  
  237. }
  238. else
  239. {
  240. close();
  241. return true;
  242. }
  243. }
  244. break;
  245. case EWBT_PIN:
  246. {
  247. IsDraggable = ! IsDraggable;
  248. }
  249. break;
  250. case EWBT_USER_DEFINED:
  251. {
  252. SEvent e;
  253. e.EventType = EET_GUI_EVENT;
  254. e.GUIEvent.Caller = Buttons[index];
  255. e.GUIEvent.Element = 0;
  256. e.GUIEvent.EventType = EGET_BUTTON_CLICKED;
  257. // send this event to the user event receiver
  258. Parent->OnEvent(e);
  259. }
  260. return true;
  261. case EWBT_MINIMIZE:
  262. {
  263. if (IsMinimized)
  264. {
  265. IsMinimized = false;
  266. if (IsBar)
  267. {
  268. setRelativePosition(BarRectangle);
  269. }
  270. else
  271. {
  272. setRelativePosition(NormalRectangle);
  273. }
  274. }
  275. else
  276. {
  277. IsMinimized = true;
  278. if (IsBar)
  279. {
  280. BarRectangle = getRelativePosition();
  281. }
  282. else
  283. {
  284. NormalRectangle = getRelativePosition();
  285. }
  286. setRelativePosition(MinimizedRectangle);
  287. }
  288. }
  289. break;
  290. }
  291. }
  292. }
  293. }
  294. break;
  295.  
  296. case EET_MOUSE_INPUT_EVENT:
  297. IsNotifying = false;
  298. switch(event.MouseInput.Event)
  299. {
  300. case EMIE_LMOUSE_DOUBLE_CLICK:
  301. {
  302. // do not process double click on buttons
  303. for (size_t index=0; index!=Buttons.size(); ++index)
  304. {
  305. if (Buttons[index]->isVisible() && Buttons[index]->getAbsolutePosition().isPointInside(core::position2di(event.MouseInput.X,event.MouseInput.Y)))
  306. return true;
  307. }
  308. if( IsMinimized )
  309. {
  310. IsMinimized = false;
  311. if(IsBar)
  312. {
  313. setRelativePosition(BarRectangle);
  314. }
  315. else
  316. {
  317. setRelativePosition(NormalRectangle);
  318. }
  319. }
  320. else if(IsBar)
  321. {
  322. IsBar = false;
  323. NormalRectangle = core::rect<s32>(
  324. getRelativePosition().UpperLeftCorner.X,
  325. getRelativePosition().UpperLeftCorner.Y,
  326. getRelativePosition().LowerRightCorner.X,
  327. getRelativePosition().UpperLeftCorner.Y+NormalRectangle.LowerRightCorner.Y-NormalRectangle.UpperLeftCorner.Y);
  328. setRelativePosition(NormalRectangle);
  329. }
  330. else
  331. {
  332. IsBar = true;
  333. NormalRectangle = getRelativePosition();
  334. BarRectangle = core::rect<s32>(NormalRectangle.UpperLeftCorner.X,NormalRectangle.UpperLeftCorner.Y,NormalRectangle.LowerRightCorner.X,NormalRectangle.UpperLeftCorner.Y+21);
  335. setRelativePosition(BarRectangle);
  336.  
  337. }
  338. }
  339. return true;
  340. case EMIE_LMOUSE_PRESSED_DOWN:
  341.  
  342. DragStart.X = event.MouseInput.X;
  343. DragStart.Y = event.MouseInput.Y;
  344. Dragging = IsDraggable;
  345. if (Parent)
  346. Parent->bringToFront(this);
  347. return true;
  348. case EMIE_LMOUSE_LEFT_UP:
  349. Dragging = false;
  350. return true;
  351. case EMIE_MOUSE_MOVED:
  352. if (!event.MouseInput.isLeftPressed())
  353. Dragging = false;
  354.  
  355. if (Dragging)
  356. {
  357. // gui window should not be dragged outside its parent
  358. if (Parent &&
  359. (event.MouseInput.X < Parent->getAbsolutePosition().UpperLeftCorner.X +1 ||
  360. event.MouseInput.Y < Parent->getAbsolutePosition().UpperLeftCorner.Y +1 ||
  361. event.MouseInput.X > Parent->getAbsolutePosition().LowerRightCorner.X -1 ||
  362. event.MouseInput.Y > Parent->getAbsolutePosition().LowerRightCorner.Y -1))
  363. return true;
  364.  
  365. move(core::position2d<s32>(event.MouseInput.X - DragStart.X, event.MouseInput.Y - DragStart.Y));
  366. DragStart.X = event.MouseInput.X;
  367. DragStart.Y = event.MouseInput.Y;
  368. return true;
  369. }
  370. break;
  371. default:
  372. break;
  373. }
  374. default:
  375. break;
  376. }
  377. }
  378.  
  379. return IGUIElement::OnEvent(event);
  380. }
  381.  
  382.  
  383. //! Updates the absolute position.
  384. void CGUIAdvancedWindow::updateAbsolutePosition()
  385. {
  386. IGUIElement::updateAbsolutePosition();
  387. }
  388.  
  389. //! draws the element and its children
  390. void CGUIAdvancedWindow::draw()
  391. {
  392. if (IsVisible)
  393. {
  394. // update each time because the skin is allowed to change this always.
  395. updateClientRect();
  396. refreshSprites();
  397. refreshButtons();
  398.  
  399. core::rect<s32> rect = AbsoluteRect;
  400.  
  401. // draw body fast
  402. if (DrawBackground)
  403. {
  404. rect = draw3DWindowBackgroundMouseLightning(this, DrawTitlebar,
  405. Skin->getColor( (IsActive&&IsDraggable) || (NotifyState&&IsNotifying) ? EGDC_ACTIVE_BORDER : EGDC_INACTIVE_BORDER),
  406. AbsoluteRect, &AbsoluteClippingRect);
  407.  
  408. if (DrawTitlebar && Text.size())
  409. {
  410. rect.UpperLeftCorner.X += Skin->getSize(EGDS_TITLEBARTEXT_DISTANCE_X);
  411. rect.UpperLeftCorner.Y += Skin->getSize(EGDS_TITLEBARTEXT_DISTANCE_Y);
  412. rect.LowerRightCorner.X -= Skin->getSize(EGDS_WINDOW_BUTTON_WIDTH) + 5;
  413.  
  414. IGUIFont* font = Skin->getFont(EGDF_WINDOW);
  415. if (font)
  416. {
  417. font->draw(Text.c_str(), rect,
  418. Skin->getColor( (IsActive&&IsDraggable) || (NotifyState&&IsNotifying) ? EGDC_ACTIVE_CAPTION:EGDC_INACTIVE_CAPTION),
  419. false, true, &AbsoluteClippingRect);
  420. }
  421. }
  422. }
  423. }
  424. IGUIElement::draw();
  425. }
  426.  
  427. void LightCoef( const core::rect<s32>& rect, const core::vector2df& center, const core::vector2df& light, f32* coef )
  428. {
  429. core::vector2df corner[4];
  430. corner[0] = (core::vector2df(rect.UpperLeftCorner.X,rect.UpperLeftCorner.Y)-center).normalize();
  431. corner[1] = (core::vector2df(rect.LowerRightCorner.X,rect.UpperLeftCorner.Y)-center).normalize();
  432. corner[2] = (core::vector2df(rect.UpperLeftCorner.X,rect.LowerRightCorner.Y)-center).normalize();
  433. corner[3] = (core::vector2df(rect.LowerRightCorner.X,rect.LowerRightCorner.Y)-center).normalize();
  434.  
  435. coef[0]= 0.5*corner[0].dotProduct(light)+0.5;
  436. coef[1]= 0.5*corner[1].dotProduct(light)+0.5;
  437. coef[2]= 0.5*corner[2].dotProduct(light)+0.5;
  438. coef[3]= 0.5*corner[3].dotProduct(light)+0.5;
  439. }
  440.  
  441. //void LightAlpha( const core::rect<s32>& rect, const core::vector2df& center, const core::vector2df& light,
  442. // const video::SColor& ocolor, video::SColor * color )
  443. //{
  444. // f32 coef[4];
  445. // LightCoef( rect, center, light, coef );
  446. // color[0] = video::SColor( ocolor.getAlpha()*(1-coef[0]), ocolor.getRed(), ocolor.getBlue(), ocolor.getGreen() );
  447. // color[1] = video::SColor( ocolor.getAlpha()*(1-coef[1]), ocolor.getRed(), ocolor.getBlue(), ocolor.getGreen() );
  448. // color[2] = video::SColor( ocolor.getAlpha()*(1-coef[2]), ocolor.getRed(), ocolor.getBlue(), ocolor.getGreen() );
  449. // color[3] = video::SColor( ocolor.getAlpha()*(1-coef[3]), ocolor.getRed(), ocolor.getBlue(), ocolor.getGreen() );
  450. //}
  451.  
  452. void LightInterpolate( const core::rect<s32>& rect, const core::vector2df& center, const core::vector2df& light,
  453. const video::SColor& ocolor, const video::SColor& colorTo, video::SColor * color )
  454. {
  455. f32 coef[4];
  456. LightCoef( rect, center, light, coef );
  457. color[0]=ocolor.getInterpolated(colorTo,coef[0]);
  458. color[1]=ocolor.getInterpolated(colorTo,coef[1]);
  459. color[2]=ocolor.getInterpolated(colorTo,coef[2]);
  460. color[3]=ocolor.getInterpolated(colorTo,coef[3]);
  461. }
  462.  
  463. //! draws a window background
  464. // return where to draw title bar text.
  465. core::rect<s32> CGUIAdvancedWindow::draw3DWindowBackgroundMouseLightning(IGUIElement* element,
  466. bool drawTitleBar, video::SColor titleBarColor,
  467. const core::rect<s32>& r,
  468. const core::rect<s32>* clip,
  469. core::rect<s32>* checkClientArea)
  470. {
  471. video::IVideoDriver* Driver = Environment->getVideoDriver();
  472. if (!Driver)
  473. {
  474. if ( checkClientArea )
  475. {
  476. *checkClientArea = r;
  477. }
  478. return r;
  479. }
  480.  
  481. core::rect<s32> rect = r;
  482.  
  483. /// init light algorithm
  484. core::vector2df center = core::vector2df(rect.getCenter().X,rect.getCenter().Y);
  485. core::vector2df light = core::vector2df(
  486. Cursor->getRelativePosition().X*Parent->getAbsolutePosition().getWidth()-center.X,
  487. Cursor->getRelativePosition().Y*Parent->getAbsolutePosition().getHeight()-center.Y
  488. ).normalize();
  489. video::SColor color[4];
  490.  
  491. // top border
  492. rect.UpperLeftCorner.X = r.UpperLeftCorner.X;
  493. rect.UpperLeftCorner.Y = r.UpperLeftCorner.Y;
  494. rect.LowerRightCorner.X = r.LowerRightCorner.X;
  495. rect.LowerRightCorner.Y = r.UpperLeftCorner.Y + 1;
  496. if ( !checkClientArea )
  497. {
  498. LightInterpolate(rect, center, light, Skin->getColor(EGDC_3D_HIGH_LIGHT), Skin->getColor(EGDC_3D_DARK_SHADOW), color);
  499. Driver->draw2DRectangle(
  500. rect,
  501. color[0],
  502. color[1],
  503. color[2],
  504. color[3],
  505. clip);
  506. }
  507. // inner top border
  508. rect.UpperLeftCorner.X = r.UpperLeftCorner.X + 1;
  509. rect.UpperLeftCorner.Y = r.UpperLeftCorner.Y + 1;
  510. rect.LowerRightCorner.X = r.LowerRightCorner.X - 1;
  511. rect.LowerRightCorner.Y = r.UpperLeftCorner.Y + 2;
  512. if ( !checkClientArea )
  513. {
  514. LightInterpolate(rect, center, light, Skin->getColor(EGDC_3D_FACE), Skin->getColor(EGDC_3D_SHADOW), color);
  515. Driver->draw2DRectangle(
  516. rect,
  517. color[0],
  518. color[1],
  519. color[2],
  520. color[3],
  521. clip);
  522. }
  523. // left border
  524. rect.UpperLeftCorner.X = r.UpperLeftCorner.X ;
  525. rect.UpperLeftCorner.Y = r.UpperLeftCorner.Y;
  526. rect.LowerRightCorner.X = r.UpperLeftCorner.X + 1;
  527. rect.LowerRightCorner.Y = r.LowerRightCorner.Y;
  528. if ( !checkClientArea )
  529. {
  530. LightInterpolate(rect, center, light, Skin->getColor(EGDC_3D_HIGH_LIGHT), Skin->getColor(EGDC_3D_DARK_SHADOW), color);
  531. Driver->draw2DRectangle(
  532. rect,
  533. color[0],
  534. color[1],
  535. color[2],
  536. color[3],
  537. clip);
  538. }
  539. // left border
  540. rect.UpperLeftCorner.X = r.UpperLeftCorner.X + 1;
  541. rect.UpperLeftCorner.Y = r.UpperLeftCorner.Y + 1;
  542. rect.LowerRightCorner.X = r.UpperLeftCorner.X + 2;
  543. rect.LowerRightCorner.Y = r.LowerRightCorner.Y - 1;
  544. if ( !checkClientArea )
  545. {
  546. LightInterpolate(rect, center, light, Skin->getColor(EGDC_3D_FACE), Skin->getColor(EGDC_3D_SHADOW), color);
  547. Driver->draw2DRectangle(
  548. rect,
  549. color[0],
  550. color[1],
  551. color[2],
  552. color[3],
  553. clip);
  554. }
  555. // right border dark outer line
  556. rect.UpperLeftCorner.X = r.LowerRightCorner.X - 1;
  557. rect.LowerRightCorner.X = r.LowerRightCorner.X;
  558. rect.UpperLeftCorner.Y = r.UpperLeftCorner.Y;
  559. rect.LowerRightCorner.Y = r.LowerRightCorner.Y;
  560. if ( !checkClientArea )
  561. {
  562. LightInterpolate(rect, center, light, Skin->getColor(EGDC_3D_HIGH_LIGHT), Skin->getColor(EGDC_3D_DARK_SHADOW), color);
  563. Driver->draw2DRectangle(
  564. rect,
  565. color[0],
  566. color[1],
  567. color[2],
  568. color[3],
  569. clip);
  570. }
  571.  
  572. // right border bright innner line
  573. rect.UpperLeftCorner.X -= 1;
  574. rect.LowerRightCorner.X -= 1;
  575. rect.UpperLeftCorner.Y += 1;
  576. rect.LowerRightCorner.Y -= 1;
  577. if ( !checkClientArea )
  578. {
  579. LightInterpolate(rect, center, light, Skin->getColor(EGDC_3D_FACE), Skin->getColor(EGDC_3D_SHADOW), color);
  580. Driver->draw2DRectangle(
  581. rect,
  582. color[0],
  583. color[1],
  584. color[2],
  585. color[3],
  586. clip);
  587. }
  588.  
  589. // bottom border dark outer line
  590. rect.UpperLeftCorner.X = r.UpperLeftCorner.X;
  591. rect.UpperLeftCorner.Y = r.LowerRightCorner.Y - 1;
  592. rect.LowerRightCorner.Y = r.LowerRightCorner.Y;
  593. rect.LowerRightCorner.X = r.LowerRightCorner.X;
  594. if ( !checkClientArea )
  595. {
  596. LightInterpolate(rect, center, light, Skin->getColor(EGDC_3D_HIGH_LIGHT), Skin->getColor(EGDC_3D_DARK_SHADOW), color);
  597. Driver->draw2DRectangle(
  598. rect,
  599. color[0],
  600. color[1],
  601. color[2],
  602. color[3],
  603. clip);
  604. }
  605.  
  606. // bottom border bright inner line
  607. rect.UpperLeftCorner.X += 1;
  608. rect.LowerRightCorner.X -= 1;
  609. rect.UpperLeftCorner.Y -= 1;
  610. rect.LowerRightCorner.Y -= 1;
  611. if ( !checkClientArea )
  612. {
  613. LightInterpolate(rect, center, light, Skin->getColor(EGDC_3D_FACE), Skin->getColor(EGDC_3D_SHADOW), color);
  614. Driver->draw2DRectangle(
  615. rect,
  616. color[0],
  617. color[1],
  618. color[2],
  619. color[3],
  620. clip);
  621. }
  622.  
  623. // client area for background
  624. rect = r;
  625. rect.UpperLeftCorner.X +=2;
  626. rect.UpperLeftCorner.Y +=2;
  627. rect.LowerRightCorner.X -= 2;
  628. rect.LowerRightCorner.Y -= 2;
  629. if (checkClientArea)
  630. {
  631. *checkClientArea = rect;
  632. }
  633.  
  634. if ( !checkClientArea )
  635. {
  636. if (!UseGradient)
  637. {
  638. Driver->draw2DRectangle(Skin->getColor(EGDC_3D_FACE), rect, clip);
  639. }
  640. else if ( Skin->getType() == EGST_BURNING_SKIN )
  641. {
  642. const video::SColor c1 = Skin->getColor(EGDC_WINDOW).getInterpolated ( 0xFFFFFFFF, 0.9f );
  643. const video::SColor c2 = Skin->getColor(EGDC_WINDOW).getInterpolated ( 0xFFFFFFFF, 0.8f );
  644.  
  645. Driver->draw2DRectangle(rect, c1, c1, c2, c2, clip);
  646. }
  647. else
  648. {
  649. video::SColor color[4];
  650. LightInterpolate(rect, center, light, Skin->getColor(EGDC_3D_FACE), Skin->getColor(EGDC_3D_SHADOW), color);
  651. Driver->draw2DRectangle(
  652. rect,
  653. color[0],
  654. color[1],
  655. color[2],
  656. color[3],
  657. clip);
  658. }
  659. }
  660.  
  661. // title bar
  662. rect = r;
  663. rect.UpperLeftCorner.X += 2;
  664. rect.UpperLeftCorner.Y += 2;
  665. rect.LowerRightCorner.X -= 2;
  666. rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + Skin->getSize(EGDS_WINDOW_BUTTON_WIDTH) + 2;
  667.  
  668. if (drawTitleBar )
  669. {
  670. if (checkClientArea)
  671. {
  672. (*checkClientArea).UpperLeftCorner.Y = rect.LowerRightCorner.Y;
  673. }
  674. else
  675. {
  676. // draw title bar
  677. //if (!UseGradient)
  678. // Driver->draw2DRectangle(titleBarColor, rect, clip);
  679. //else
  680. if ( Skin->getType() == EGST_BURNING_SKIN )
  681. {
  682. const video::SColor c = titleBarColor.getInterpolated( video::SColor(titleBarColor.getAlpha(),255,255,255), 0.8f);
  683. Driver->draw2DRectangle(rect, titleBarColor, titleBarColor, c, c, clip);
  684. }
  685. else
  686. {
  687. const video::SColor c = titleBarColor.getInterpolated(video::SColor(titleBarColor.getAlpha(),0,0,0), 0.2f);
  688. Driver->draw2DRectangle(rect, titleBarColor, c, titleBarColor, c, clip);
  689. }
  690. }
  691. }
  692.  
  693. return rect;
  694. }
  695.  
  696. //! Returns true if the window is draggable, false if not
  697. bool CGUIAdvancedWindow::isDraggable() const
  698. {
  699. return IsDraggable;
  700. }
  701.  
  702.  
  703. //! Sets whether the window is draggable
  704. void CGUIAdvancedWindow::setDraggable(bool draggable)
  705. {
  706. IsDraggable = draggable;
  707.  
  708. if (Dragging && !IsDraggable)
  709. Dragging = false;
  710. }
  711.  
  712. //! Set if the window background will be drawn
  713. void CGUIAdvancedWindow::setDrawBackground(bool draw)
  714. {
  715. DrawBackground = draw;
  716. }
  717.  
  718.  
  719. //! Get if the window background will be drawn
  720. bool CGUIAdvancedWindow::getDrawBackground() const
  721. {
  722. return DrawBackground;
  723. }
  724.  
  725. //! Set if the window titlebar will be drawn
  726. void CGUIAdvancedWindow::setDrawTitlebar(bool draw)
  727. {
  728. DrawTitlebar = draw;
  729. }
  730.  
  731.  
  732. //! Get if the window titlebar will be drawn
  733. bool CGUIAdvancedWindow::getDrawTitlebar() const
  734. {
  735. return DrawTitlebar;
  736. }
  737.  
  738. void CGUIAdvancedWindow::updateClientRect()
  739. {
  740. if (! DrawBackground )
  741. {
  742. ClientRect = core::rect<s32>(0,0, AbsoluteRect.getWidth(), AbsoluteRect.getHeight());
  743. return;
  744. }
  745. IGUISkin* skin = Environment->getSkin();
  746. skin->draw3DWindowBackground(this, DrawTitlebar,
  747. skin->getColor(IsActive&&IsDraggable ? EGDC_ACTIVE_BORDER : EGDC_INACTIVE_BORDER),
  748. AbsoluteRect, &AbsoluteClippingRect, &ClientRect);
  749. ClientRect -= AbsoluteRect.UpperLeftCorner;
  750. }
  751.  
  752.  
  753. //! Returns the rectangle of the drawable area (without border, without titlebar and without scrollbars)
  754. core::rect<s32> CGUIAdvancedWindow::getClientRect() const
  755. {
  756. return ClientRect;
  757. }
  758.  
  759. //! Implementation of window close behavior
  760. void CGUIAdvancedWindow::close()
  761. {
  762. switch(CloseHandling)
  763. {
  764. case EWC_IGNORE:
  765. break;
  766. case EWC_REMOVE:
  767. remove();
  768. break;
  769. case EWC_HIDE:
  770. setVisible(false);
  771. break;
  772. }
  773. }
  774.  
  775. void CGUIAdvancedWindow::notify(bool force)
  776. {
  777. if(IsBar || IsMinimized || force)
  778. {
  779. IsNotifying = true;
  780. NotifyState = true;
  781. NotifyTimer = 0;
  782. }
  783. }
  784.  
  785. void CGUIAdvancedWindow::OnPostRender(u32 timeMs)
  786. {
  787. if ( IsNotifying && NotifyTimer < timeMs)
  788. {
  789. NotifyTimer = timeMs + 1000;
  790. NotifyState = ! NotifyState;
  791. }
  792. IGUIElement::OnPostRender(timeMs);
  793. }
  794.  
  795. bool CGUIAdvancedWindow::isMinimized() const
  796. {
  797. return IsMinimized;
  798. }
  799.  
  800. void CGUIAdvancedWindow::setMinimized(bool minimize)
  801. {
  802. IsMinimized = minimize;
  803. }
  804.  
  805. void CGUIAdvancedWindow::setMinimizable(bool allow)
  806. {
  807. IsMinimizable = allow;
  808. }
  809.  
  810.  
  811. } // end namespace gui
  812. } // end namespace irr
  813.  
  814. //#endif // _IRR_COMPILE_WITH_GUI_

Report this snippet  

You need to login to post a comment.