Window.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /******************************************************************************/
  2. enum WIN_FLAG // Window Flags
  3. {
  4. WIN_MOVABLE =0x01, // movable
  5. WIN_RESIZABLE=0x02, // resizable
  6. };
  7. /******************************************************************************/
  8. const_mem_addr STRUCT(Window , GuiObj) // Gui Window !! must be stored in constant memory address !!
  9. //{
  10. Byte flag , // WIN_FLAG , default=WIN_MOVABLE
  11. resize_mask; // specifies which edges of the window can be resized, default=DIRF_RIGHT|DIRF_LEFT|DIRF_DOWN|DIRF_UP (used only if 'flag' has WIN_RESIZABLE enabled)
  12. Str title ; // title bar text, default=""
  13. Button button[3] ; // buttons : 0-minimize, 1-maximize, 2-close
  14. RippleFx *ripple ; // ripple effect , default=null
  15. // manage
  16. Window& del ( ); // delete
  17. Window& create( C Str &title=S); // create
  18. Window& create(C Rect &rect, C Str &title=S) {create(title).rect(rect); return T;} // create and set rectangle
  19. Window& create(C Window &src ); // create from 'src'
  20. // set / get
  21. Window& setTitle (C Str &title ); // set title bar text
  22. virtual Window& move (C Vec2 &delta ); // move by delta
  23. virtual Window& rect (C Rect &rect ); C Rect& rect ()C {return super::rect() ;} // set/get rectangle
  24. Window& maximize ( ); Bool maximized ()C; // set/get maximized state, this method will check if the Window rectangle covers the entire screen
  25. Window& level ( Int level ); Int level ()C {return _level ;} // set/get window level (windows with level 1 will always be drawn on top of level 0 windows), default=0
  26. Window& skin (C GuiSkinPtr &skin ); C GuiSkinPtr& skin ()C {return _skin ;} // set/get skin override, default=null (if set to null then current value of 'Gui.skin' is used), changing this value will automatically change the skin of the window buttons
  27. GuiSkin* getSkin ()C {return _skin ? _skin() : Gui.skin();} // get actual skin
  28. Window& barVisible( Bool visible); Bool barVisible ()C {return _bar_visible ;} // set/get title bar visibility, default=true
  29. Flt barHeight ()C; // get title bar height
  30. Flt highlightHover()C {return _lit_hover ;} // get current hover highlight (0..1)
  31. Flt highlightFocus()C {return _lit_focus ;} // get current focus highlight (0..1)
  32. Window& alpha ( Flt alpha ); Flt alpha ()C {return _alpha ;} // set/get custom window opacity controlled by the user (0..1)
  33. Flt fadeAlpha ()C {return _fade_alpha ;} // get current window opacity based on the fade effect (0..1)
  34. Flt finalAlpha ()C {return _final_alpha ;} // get final window opacity based on custom and fade alpha (0..1), this is "alpha()*fadeAlpha()"
  35. Flt clientWidth ()C {return _crect.w () ;} // get client width
  36. Flt clientHeight ()C {return _crect.h () ;} // get client height
  37. Vec2 clientSize ()C {return _crect.size() ;} // get client size
  38. Window& clientRect(C Rect &rect ); C Rect& clientRect ()C {return _crect ;} // set/get client rect
  39. virtual Rect sizeLimit ( )C {return Rect(0.045f, 0.045f, Max(4, D.w2()), Max(4, D.h2()));} // allowed size limits for the Window rectangle, you can override this method and return custom values, they will be used by 'rect' method
  40. virtual void extendedRect (Rect &rect )C; // get extended rectangle (including self and all child elements extending it visually)
  41. void defaultInnerPadding (Rect &padding )C; // get default inner padding
  42. void defaultInnerPaddingSize(Vec2 &padd_size)C; // get default inner padding size
  43. Vec2 defaultInnerPaddingSize( )C; // get default inner padding size
  44. Flt defaultBarHeight ( )C; // get default bar height
  45. Flt defaultBarTextWidth ( )C; // get default bar text width
  46. Flt defaultBarFullWidth ( )C; // get default bar full width including text and visible buttons
  47. // operations
  48. Bool showing ( )C; // if visible and not fading out
  49. Bool hiding ( )C; // if hidden or fading out
  50. virtual Window& fadeIn ( ) ; // fade in window
  51. virtual Window& fadeOut ( ) ; // fade out window
  52. virtual Window& fadeToggle( ) ; // toggle fading
  53. virtual Window& fade (Bool in) ; // set fading
  54. virtual Window& show ( ) ; // show
  55. virtual Window& hide ( ) ; // hide
  56. // main
  57. virtual GuiObj* test (C GuiPC &gpc, C Vec2 &pos, GuiObj* &mouse_wheel); // test if 'pos' screen position intersects with the object, by returning pointer to object or its children upon intersection and null in case no intersection, 'mouse_wheel' may be modified upon intersection either to the object or its children or null
  58. virtual void update(C GuiPC &gpc); // update object
  59. virtual void draw (C GuiPC &gpc); // draw object
  60. #if EE_PRIVATE
  61. Panel* getNormalPanel()C;
  62. void focusToggle(); // this method will activate the window if it's not at the top, otherwise it will hide it
  63. void zero();
  64. void addChild(GuiObj &child);
  65. void removeChild(GuiObj &child);
  66. void setParent();
  67. void setParams();
  68. void setButtons();
  69. void setRect();
  70. void setFinalAlpha();
  71. Bool active()C {return Gui.window ()==this && App.active();}
  72. Bool lit()C {return Gui.windowLit()==this;}
  73. #endif
  74. ~Window() {del();}
  75. Window();
  76. #if !EE_PRIVATE
  77. private:
  78. #endif
  79. Bool _bar_visible;
  80. Byte _fade_type, _resize;
  81. Int _level;
  82. Flt _alpha, _fade_alpha, _final_alpha, _lit_hover, _lit_focus;
  83. Rect _crect;
  84. GuiSkinPtr _skin;
  85. GuiObjChildren _children;
  86. protected:
  87. virtual Bool save(File &f, CChar *path=null)C;
  88. virtual Bool load(File &f, CChar *path=null) ;
  89. virtual void parentClientRectChanged(C Rect *old_client, C Rect *new_client);
  90. NO_COPY_CONSTRUCTOR(Window);
  91. };
  92. /******************************************************************************/
  93. STRUCT(ClosableWindow , Window) // Closable Window (automatically hides on Escape or Middle Mouse Button)
  94. //{
  95. virtual void update(C GuiPC &gpc);
  96. };
  97. /******************************************************************************/
  98. STRUCT(ModalWindow , Window) // Modal Window (draws half transparent black color on entire desktop below the window, after clicking the background the window fades out)
  99. //{
  100. virtual GuiObj* test(C GuiPC &gpc, C Vec2 &pos, GuiObj* &mouse_wheel);
  101. virtual void update(C GuiPC &gpc);
  102. virtual void draw(C GuiPC &gpc);
  103. private:
  104. GuiObj _background;
  105. };
  106. /******************************************************************************/
  107. STRUCT(Dialog , Window) // Dialog (has text and custom amount of buttons, creating it automatically sets the correct rectangles for the window and its children)
  108. //{
  109. struct Text2 : Text
  110. {
  111. virtual GuiObj* test(C GuiPC &gpc, C Vec2 &pos, GuiObj* &mouse_wheel);
  112. };
  113. Text2 text;
  114. Memx<Button> buttons;
  115. Dialog& create (C Str &title, C Str &text, C MemPtr<Str> &buttons, C TextStylePtr &text_style=null); // create with given parameters, this automatically calls 'set'
  116. Dialog& set (C Str &title, C Str &text, C MemPtr<Str> &buttons, C TextStylePtr &text_style=null); // adjust an already created Dialog with given parameters, this automatically calls 'autoSize'
  117. Dialog& autoSize(); // set window, text and buttons rectangles based on their values
  118. };
  119. /******************************************************************************/