Return to Snippet

Revision: 62740
at March 9, 2013 06:57 by xterminhate


Initial Code
// Xterminhate

#ifndef __C_GUI_WINDOW_H_INCLUDED__
#define __C_GUI_WINDOW_H_INCLUDED__

#include "IrrCompileConfig.h"
//#ifdef _IRR_COMPILE_WITH_GUI_

#include "IGUIWindow.h"
#include "IGUISkin.h"
#include "ICursorControl.h"

namespace irr
{
namespace gui
{
	//! Window button types
	enum EWINDOW_BUTTON_TYPE
	{
		//! close button
		EWBT_CLOSE,

		//! maximize button
		EWBT_MINIMIZE,

		//! pin button
		EWBT_PIN,

		//! user defined button
		EWBT_USER_DEFINED
	};
		//! Window Close behavior.
	//! Default is EWC_REMOVE
	enum EWINDOW_CLOSE
	{
		//! do nothing - window stays open
		EWC_IGNORE = 0,

		//! remove the gui element
		EWC_REMOVE = 1,

		//! call setVisible(false)
		EWC_HIDE = 2

	 	// next is 4
	};

	class IGUIButton;

	class CGUIAdvancedWindow : public IGUIElement //: public IGUIWindow
	{
	public:

	    //!
        struct buttoninfo
        {
            EWINDOW_BUTTON_TYPE Type;
            IGUISpriteBank* Sprite; //! Button Icon
            s32 SpriteIndex;    //! Button Icon
            bool VisibleWhenNormal; //! Button is visible when window is in normal state
            bool VisibleWhenBar; //! Button is visible when window is in bar state
            bool VisibleWhenMinimized; //! Button is visible when window is in minimized state
            s32 UserEventId; //! ID sent to user event receiver
            const wchar_t* Name; //! Button Text
            const wchar_t* ToolTipText; //! Button Tooltip Text
        };

		//! constructor
		CGUIAdvancedWindow(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle,
            const core::array<buttoninfo>& buttons, EWINDOW_CLOSE close, const core::position2di& minimized,
            ICursorControl* cursor = 0 );

		//! destructor
		virtual ~CGUIAdvancedWindow();

		//! called if an event happened.
		virtual bool OnEvent(const SEvent& event);

		//! update absolute position
		virtual void updateAbsolutePosition();

		//! draws the element and its children
		virtual void draw();

		//! Returns true if the window is minimized, false if not
		virtual bool isMinimized() const;

		//! Sets whether the window is minimized
		virtual void setMinimized(bool minimize);

		//! Sets whether the window is minimizable
		virtual void setMinimizable(bool allow);

		//! Returns true if the window is draggable, false if not
		virtual bool isDraggable() const;

		//! Sets whether the window is draggable
		virtual void setDraggable(bool draggable);

        //! Set if the window background will be drawn
        virtual void setDrawBackground(bool draw);

        //! Get if the window background will be drawn
        virtual bool getDrawBackground() const;

        //! Set if the window titlebar will be drawn
        //! Note: If the background is not drawn, then the titlebar is automatically also not drawn
        virtual void setDrawTitlebar(bool draw);

        //! Get if the window titlebar will be drawn
        virtual bool getDrawTitlebar() const;

		//! Returns the rectangle of the drawable area (without border and without titlebar)
		virtual core::rect<s32> getClientRect() const;

		//! Makes the tittle bar to blink
		///  Force = false ==> if window is minimized or bar
		///  Force = true ==> in any window state
		virtual void notify(bool force);

        virtual void OnPostRender(u32 timeMs);

	protected:

		void updateClientRect();
		void refreshSprites();

		//! Refresh button visibility and position according state (normal, bar, minimized)
        void refreshButtons(); //! ADDED

        //! Implementation of window close behavior
        void close(); //! ADDED

        //! Implementation of window draw with cursor lightning
        core::rect<s32> draw3DWindowBackgroundMouseLightning(IGUIElement* element,
				bool drawTitleBar, video::SColor titleBarColor,
				const core::rect<s32>& r,
				const core::rect<s32>* clip=0,
				core::rect<s32>* checkClientArea=0); //! ADDED

        //! Default skin management
        IGUISkin* Skin; //! ADDED
        IGUISpriteBank* DefaultSprites; //! ADDED
		video::SColor CurrentIconColor;

        //! Button management
        core::array<buttoninfo> ButtonInfo; //! ADDED
        core::array<core::rect<s32> > ButtonRectangles; //! ADDED
        core::array<IGUIButton*> Buttons;

		core::rect<s32> ClientRect;

		//! States and events management
		core::position2d<s32> DragStart;
		bool Dragging;
		bool IsDraggable;
        bool DrawBackground;
        bool DrawTitlebar;
		bool IsActive;
		bool IsMinimized;//! ADDED
		bool IsBar; //! ADDED
        bool IsMinimizable;//! ADDED

        //! Close button handling
        EWINDOW_CLOSE CloseHandling; //! ADDED

        //! Window position for each window state
        core::rect<s32> NormalRectangle; //! ADDED
        core::rect<s32> MinimizedRectangle; //! ADDED
        core::rect<s32> BarRectangle; //! ADDED

        //! Draw data
        bool UseGradient; /// ADDED clone Skin private member data
        ICursorControl* Cursor; //! ADDED

        //! Notification data
        bool IsNotifying; //! ADDED
        u32 NotifyTimer; //! ADDED
        bool NotifyState; //! ADDED
	};

} // end namespace gui
} // end namespace irr

//#endif // _IRR_COMPILE_WITH_GUI_

#endif

Initial URL


Initial Description
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.

Initial Title
CGUIAdvancedWindow.h

Initial Tags


Initial Language
C++