00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00035 #ifndef _SO3_WIDGET_H_
00036 #define _SO3_WIDGET_H_
00037
00038 #include "../SCOLBasic/SO3Prerequisites.h"
00039 #include "../SCOLBasic/SO3DataScol.h"
00040 #include "../SO3Material/SO3Material.h"
00041 #include "../SO3Renderer/SO3ViewPort.h"
00042 #include "../SO3Utils/SO3Point.h"
00043 #include "OgrePanelOverlayElement.h"
00044
00045 namespace SO3
00046 {
00047
00050 class _SO3_Export SWidget : public SData,
00051 public Ogre::ManualResourceLoader
00052 {
00053 public:
00054 friend SWidgetManager;
00055 struct WidgetScriptFunction
00056 {
00057 std::string function;
00058 std::vector<std::string> arguments;
00059 };
00060 protected:
00061 std::string baseResourceName;
00062 int leftPos;
00063 int topPos;
00064 unsigned short width;
00065 unsigned short height;
00066 unsigned short textureWidth;
00067 unsigned short textureHeight;
00068 SScene* scene;
00069 SViewPort* viewport;
00070 Ogre::TexturePtr renderingTexture;
00071 bool forceRenderingUpdate;
00072 float transparentTresholdColor;
00073 private:
00074 const bool isOverlayed;
00075 const bool is2DRect;
00076 std::string type;
00077 bool compensateNPOT;
00078 std::string originalTextureName;
00079 Ogre::TextureUnitState* originalTextureUnit;
00080 Ogre::Pass* originalMaterialPass;
00081 Ogre::SceneBlendFactor originalSceneBlendFactorSource;
00082 Ogre::SceneBlendFactor originalSceneBlendFactorDest;
00083 Ogre::LayerBlendModeEx originalTextureUnitBlendMode;
00084 Ogre::FilterOptions originalTextureUnitMinFiltering;
00085 Ogre::FilterOptions originalTextureUnitMagFiltering;
00086 Ogre::FilterOptions originalTextureUnitMipFiltering;
00087 bool originalMaterialDepthWrite;
00088 bool originalMaterialDepthCheck;
00089 Ogre::Overlay* ogreOverlay;
00090 Ogre::PanelOverlayElement* ogreOverlayPanel;
00091 Ogre::Rectangle2D* ogre2dRect;
00092 Ogre::SceneNode* ogre2dNode;
00093 Ogre::MaterialPtr ogreOverlayMaterial;
00094 SMaterial* originalMaterial;
00095 unsigned int zOrder;
00096 bool topOnFocus;
00097 bool isPriorized;
00098 bool mouseIsOver;
00099 Ogre::TextureUnitState* renderingTextureUnit;
00100 float opacity;
00101 bool isTransparent;
00102 bool mouseEnable;
00103 bool keyboardEnable;
00104 bool transparentIgnorePixels;
00105
00106 public:
00110 SWidget(SScene* targetScene, std::string widgetName, int xPos, int yPos, unsigned short widgetWidth, unsigned short widgetHeight, SViewPort* targetViewport, unsigned int widgetZOrder, std::string widgetType);
00111
00115 SWidget(SScene* targetScene, std::string widgetName, int xPos, int yPos, unsigned short widgetWidth, unsigned short widgetHeight, SViewPort* targetViewport, std::string widgetType);
00116
00120 SWidget(SScene* targetScene, std::string widgetName, unsigned short widgetWidth, unsigned short widgetHeight, SMaterial* targetMaterial, unsigned short targetTechnique, unsigned short targetPass, unsigned short targetTextureUnit, std::string widgetType);
00121
00125 ~SWidget();
00126
00129 SScene* GetParentScene();
00130
00133 std::string GetType();
00134
00137 unsigned short GetWidth();
00138
00141 unsigned short GetHeight();
00142
00145 SPoint<unsigned short> GetSize();
00146
00149 void SetSize(unsigned short newWidth, unsigned short newHeight);
00150
00153 void SetSize(SPoint<unsigned short> newSize);
00154
00158 SPoint<int> GetPosition();
00159
00163 void SetPosition(int xPos, int yPos);
00164
00168 void SetPosition(const SPoint<int>& newPosition);
00169
00173 void Move(const SPoint<int>& relativeMove);
00174
00180 virtual void InjectMouseMove(int xPos, int yPos, MouseButtonId button)=0;
00181
00187 virtual void InjectMouseWheel(int scrollX, int scrollY, int relativeScroll)=0;
00188
00195 virtual void InjectMouseDown(int xPos, int yPos, MouseButtonId button)=0;
00196
00203 virtual void InjectMouseUp(int xPos, int yPos, MouseButtonId button)=0;
00204
00207 virtual void InjectKeyEvent(UINT msg, WindowHandle hwnd, WPARAM wParam, LPARAM lParam)=0;
00208
00211 virtual void InjectTextEvent(std::string utf8)=0;
00212
00219 void Show(bool fade=false, unsigned short fadeDurationMS=300);
00220
00227 void Hide(bool fade=false, unsigned short fadeDurationMS=300);
00228
00232 bool GetVisible();
00233
00237 void SetTransparency(bool enableTransparency);
00238
00242 bool GetTransparency();
00243
00247 void SetOpacity(float widgetOpacity);
00248
00252 float GetOpacity();
00253
00257 void SetIgnoreTransparentPixels(bool widgetIgnoreTransparentPixels, float tresholdColor=0.0f);
00258
00262 bool GetIgnoreTransparentPixels();
00263
00267 float GetIgnoreTransparentPixelsTreshold();
00268
00272 virtual void LoadURL(const std::string& url)=0;
00273
00278 virtual void LoadFile(const std::string& file)=0;
00279
00283 void SetZOrder(unsigned short newWidgetOrder);
00284
00288 unsigned short GetZOrder();
00289
00293 void TakeFocus();
00294
00298 bool HasFocus();
00299
00303 void SetKeyboardEnable(bool enableKeyboardOnWidget);
00304
00308 bool GetKeyboardEnable();
00309
00313 void SetMouseEnable(bool enableMouseOnWidget);
00314
00318 bool GetMouseEnable();
00319
00322 bool GetMouseOver();
00323
00327 void SetForeground(bool enableWidgetForeground);
00328
00332 bool GetForeground();
00333
00337 void SetTopOnFocus(bool enableWidgetTopOnFocus);
00338
00342 bool GetTopOnFocus();
00343
00347 virtual void RunScriptFunction(std::string functionName, std::vector<std::string> argumentList)=0;
00348
00352 virtual void loadResource(Ogre::Resource* resource);
00353
00357 virtual int GetPixelUnder(int posX, int posY)=0;
00358 protected:
00361 bool IsCompensateNPOT() const;
00362
00366 std::string CheckUrl(const std::string& url);
00367
00371 virtual void SetFocusImpl(bool focusOnWidget)=0;
00372
00375 virtual void SetTransparencyImpl(bool enableTransparency)=0;
00376
00379 virtual void SetKeyboardEnableImpl(bool enableKeyboardOnWidget)=0;
00380
00384 virtual void SetMouseEnableImpl(bool enableMouseOnWidget)=0;
00385
00388 virtual void SetSizeImpl(unsigned short newWidth, unsigned short newHeight)=0;
00389 private:
00393 SWidget();
00394
00398 void StandardConstructor(SScene* targetScene, int xPos, int yPos, unsigned short widgetWidth, unsigned short widgetHeight, unsigned int widgetZOrder, SViewPort* targetViewport, std::string widgetType);
00399
00404 void _SetOgreOverlayZOrder(unsigned short overlayZOrder);
00405
00409 void CreateTexture();
00410
00414 void DestroyTexture();
00415
00419 void CreateMaterial();
00420
00424 void DestroyMaterial();
00425
00428 void ApplyMaterialParameters(Ogre::Pass* materialPassToModify, Ogre::TextureUnitState* materialTextureUnitToModify);
00429
00433 void CreateOverlay();
00434
00438 void DestroyOverlay();
00439
00443 void Create2D();
00444
00448 void Destroy2D();
00449 };
00450
00451 }
00452
00453 #endif