Viewport.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /******************************************************************************/
  2. #include "stdafx.h"
  3. namespace EE{
  4. /******************************************************************************/
  5. void Viewport::zero()
  6. {
  7. rect_color.zero();
  8. draw_func=null;
  9. fov_mode=FOV_Y;
  10. fov=0;
  11. from=0;
  12. range=0;
  13. }
  14. void Viewport::reset()
  15. {
  16. fov_mode=D.viewFovMode();
  17. fov =D.viewFov ();
  18. from =D.viewFrom ();
  19. range =D.viewRange ();
  20. }
  21. Viewport::Viewport() {zero();}
  22. Viewport& Viewport::del()
  23. {
  24. super::del(); zero(); return T;
  25. }
  26. Viewport& Viewport::create(void (*draw)(Viewport&), Ptr user)
  27. {
  28. del();
  29. _type =GO_VIEWPORT;
  30. _visible =true;
  31. T.user =user;
  32. T.draw_func =draw;
  33. _rect.max.x= 0.3f;
  34. _rect.min.y=-0.3f;
  35. rect_color=Gui.borderColor();
  36. reset();
  37. return T;
  38. }
  39. Viewport& Viewport::create(C Viewport &src)
  40. {
  41. if(this!=&src)
  42. {
  43. if(!src.is())del();else
  44. {
  45. copyParams(src);
  46. _type =GO_VIEWPORT;
  47. rect_color=src.rect_color;
  48. fov_mode =src.fov_mode;
  49. fov =src.fov;
  50. from =src.from;
  51. range =src.range;
  52. draw_func =src.draw_func;
  53. }
  54. }
  55. return T;
  56. }
  57. /******************************************************************************/
  58. void Viewport::setDisplayView()C
  59. {
  60. D.view(screenRect(), from, range, fov, fov_mode);
  61. }
  62. /******************************************************************************/
  63. GuiObj* Viewport::test(C GuiPC &gpc, C Vec2 &pos, GuiObj* &mouse_wheel)
  64. {
  65. if(GuiObj *go=super::test(gpc, pos, mouse_wheel))
  66. {
  67. mouse_wheel=this;
  68. return go;
  69. }
  70. return null;
  71. }
  72. void Viewport::draw(C GuiPC &gpc)
  73. {
  74. if(visible() && gpc.visible)
  75. {
  76. Rect r=rect()+gpc.offset;
  77. if(draw_func && (r&Rect(gpc.clip).extend(-D.pixelToScreenSize().x, -D.pixelToScreenSize().y)).valid())
  78. {
  79. Display::ViewportSettings temp_view; temp_view.get();
  80. Camera temp_cam=ActiveCam;
  81. D.view(r, from, range, fov, fov_mode).clip(gpc.clip); draw_func(T);
  82. temp_view.set(); temp_cam.set();
  83. }
  84. if(rect_color.a)
  85. {
  86. D.clip(gpc.clip);
  87. r.draw(rect_color, false);
  88. }
  89. }
  90. }
  91. /******************************************************************************/
  92. Bool Viewport::save(File &f, CChar *path)C
  93. {
  94. if(super::save(f, path))
  95. {
  96. f.cmpUIntV(1); // version
  97. f<<rect_color;
  98. return f.ok();
  99. }
  100. return false;
  101. }
  102. Bool Viewport::load(File &f, CChar *path)
  103. {
  104. del(); if(super::load(f, path))switch(f.decUIntV()) // version
  105. {
  106. case 1:
  107. {
  108. _type=GO_VIEWPORT;
  109. f>>rect_color;
  110. if(f.ok()){reset(); return true;}
  111. }break;
  112. case 0:
  113. {
  114. _type=GO_VIEWPORT;
  115. f>>rect_color; Swap(rect_color.r, rect_color.b);
  116. if(f.ok()){reset(); return true;}
  117. }break;
  118. }
  119. del(); return false;
  120. }
  121. /******************************************************************************/
  122. }
  123. /******************************************************************************/