Desktop.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /******************************************************************************/
  2. #include "stdafx.h"
  3. namespace EE{
  4. /******************************************************************************/
  5. GuiPC::GuiPC(Desktop &desktop)
  6. {
  7. visible=(Gui.desktop()==&desktop);
  8. enabled=(Gui.desktop()==&desktop && desktop.enabled());
  9. offset.zero();
  10. client_rect=clip=desktop.rect();
  11. }
  12. /******************************************************************************/
  13. void Desktop::zero()
  14. {
  15. }
  16. Desktop::Desktop() {zero(); create();}
  17. Desktop& Desktop::del()
  18. {
  19. _children.del();
  20. super::del(); zero(); return T;
  21. }
  22. Desktop& Desktop::create()
  23. {
  24. del();
  25. _type =GO_DESKTOP;
  26. _visible=true;
  27. _rect =D.rect();
  28. return T;
  29. }
  30. Desktop& Desktop::create(C Desktop &src)
  31. {
  32. if(this!=&src)
  33. {
  34. if(!src.is())del();else
  35. {
  36. _children.del();
  37. copyParams(src);
  38. _type=GO_DESKTOP;
  39. }
  40. }
  41. return T;
  42. }
  43. /******************************************************************************/
  44. void Desktop::addChild(GuiObj &child)
  45. {
  46. _children.add(child, T);
  47. }
  48. void Desktop::removeChild(GuiObj &child)
  49. {
  50. _children.remove(child);
  51. }
  52. /******************************************************************************/
  53. GuiObj* Desktop::test(C Vec2 &pos, GuiObj* &mouse_wheel)
  54. {
  55. GuiPC gpc(T);
  56. mouse_wheel=this;
  57. // test overlay textline
  58. Vec2 offset; if(Gui.desktop()==this)if(TextLine *tl=Gui.overlayTextLine(offset))
  59. {
  60. GuiPC gpc2=gpc; gpc2.offset=offset; if(GuiObj *go=tl->test(gpc2, pos, mouse_wheel))return go;
  61. if(Cuts(pos, Rect(-D.w(), tl->rect().min.y+offset.y, D.w(), tl->rect().max.y+offset.y)))return tl;
  62. }
  63. // test children
  64. if(GuiObj *go=_children.test(gpc, pos, mouse_wheel))return go;
  65. // test self
  66. if(CutsEps(pos, rect()))return this; // use EPS version to make sure that for example Mouse Position will cut the Desktop despite numerical precision issues
  67. return null;
  68. }
  69. void Desktop::update()
  70. {
  71. GuiPC gpc(T); if(gpc.enabled)_children.update(gpc);
  72. }
  73. void Desktop::draw()
  74. {
  75. if(visible())
  76. {
  77. // draw children
  78. GuiPC gpc(T); _children.draw(gpc);
  79. // draw overlay textline
  80. Vec2 offset; if(Gui.desktop()==this)if(TextLine *tl=Gui.overlayTextLine(offset)) // don't use "Gui._overlay_textline" because offset can change during textline's window resize
  81. {
  82. D.clip(gpc.clip); Rect(-D.w(), tl->rect().min.y+offset.y, D.w(), tl->rect().max.y+offset.y).extend(0.01f).drawShaded(Color(0, 0, 0, 128), TRANSPARENT, 0.01f);
  83. GuiPC gpc2=gpc; gpc2.offset=offset; tl->draw(gpc2);
  84. }
  85. }
  86. }
  87. /******************************************************************************/
  88. }
  89. /******************************************************************************/