Project

General

Profile

SO3Engine
SO3Widget.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
32#ifndef _SO3_WIDGET_H_
33#define _SO3_WIDGET_H_
34
37#include "SO3Utils/SO3Point.h"
38#include <OgreRectangle2D.h>
39#include <OgreOverlay.h>
40#include <OgreOverlaySystem.h>
41#include <OgreOverlayElement.h>
42#include <OgreOverlayManager.h>
43#include <OgrePanelOverlayElement.h>
44namespace SO3
45{
46
49class _SO3_Export SWidget : public SData,
50 public Ogre::ManualResourceLoader
51{
52public:
54 {
55 MONO = 0,
56 SBS = 1,
57 TB = 2,
58 BT = 3
59 };
60
62 {
63 public:
66
67 Ogre::SceneBlendFactor oSceneBlendingS;
68 Ogre::SceneBlendFactor oSceneBlendingD;
70 };
71
72public:
74protected:
75 std::string baseResourceName;
77 int topPos;
79 float topOffset;
80 unsigned short width;
81 unsigned short height;
82 unsigned short mTextureWidth;
83 unsigned short mTextureHeight;
87 Ogre::Viewport* currentViewport;
88 Ogre::TexturePtr renderingTexture;
92 Ogre::Vector2 xCoef;
93 Ogre::Vector2 yCoef;
94
95private:
96 const bool isOverlayed;
97 const bool is2DRect;
98 StereoMode mStereoMode;
99 float widthScale;
100 float heightScale;
101 std::string type;
102 Ogre::TextureUnitState* ogreTargetTextureUnit;
103 Ogre::Pass* ogreTargetMaterialPass;
104 Ogre::Overlay* ogreOverlay;
105 Ogre::PanelOverlayElement* ogreOverlayPanel;
106 Ogre::Rectangle2D* ogre2dRect;
107 Ogre::SceneNode* ogre2dNode;
108 Ogre::MaterialPtr ogreOverlayMaterial;
109 SMaterial* originalMaterial;
110 SMatData matData;
111 Ogre::MaterialPtr ogreTargetMaterial;
112 Ogre::TextureUnitState* ogreOriginalTextureUnit;
113 unsigned int zOrder;
114 bool topOnFocus;
115 bool isPriorized;
116 bool mouseIsOver;
117 std::vector<int> inputIndexes;
118 Ogre::TextureUnitState* renderingTextureUnit;
119 float opacity;
120 bool isTransparent;
121 bool mouseEnable;
122 bool keyboardEnable;
123 bool transparentIgnorePixels;
124 bool updateOnFocusOnly;
125 bool mVisible;
126
127public:
131 SWidget(SScene* targetScene, const std::string& widgetName, const int& xPos, const int& yPos, const unsigned short& widgetWidth, const unsigned short& widgetHeight, SViewPort* targetViewport, const unsigned int& widgetZOrder, const std::string& widgetType);
132
136 SWidget(SScene* targetScene, const std::string& widgetName, const int& xPos, const int& yPos, const unsigned short& widgetWidth, const unsigned short& widgetHeight, SViewPort* targetViewport, const std::string& widgetType);
137
141 SWidget(SScene* targetScene, const std::string& widgetName, const unsigned short& widgetWidth, const unsigned short& widgetHeight, SMaterial* targetMaterial, const unsigned short& targetTechnique, const unsigned short& targetPass, const unsigned short& targetTextureUnit, const std::string& widgetType);
142
146 virtual ~SWidget();
147
150 SScene* GetParentScene();
151
154 std::string GetType();
155
158 unsigned short GetWidth();
159
162 unsigned short GetHeight();
163
166 SPoint<unsigned short> GetSize();
167
170 void SetSize(const unsigned short& newWidth, const unsigned short& newHeight);
171
174 void SetSize(const SPoint<unsigned short>& newSize);
175
178 float GetTextureRatio();
179
182 void SetTextureRatio(const float& newRatio);
183
186 bool GetIsStereo();
187
190 void SetStereo(StereoMode state);
191
194 void SetStereoEye(bool isleft = true);
195
199 SPoint<int> GetPosition();
200
204 void SetPosition(const int& xPos, const int& yPos);
205
209 void SetPosition(const SPoint<int>& newPosition);
210
214 void Move(const SPoint<int>& relativeMove);
215
219 void SetCurrentViewport(Ogre::Viewport* vp);
220
224 void SetScale(const float width, const float height);
225
229 SPoint<float> GetScale();
230
234 void SetLeftOffset(const float left);
235
239 void SetTopOffset(const float top);
240
244 SPoint<int> GetRealPixelPosition();
245
249 SPoint<unsigned short> GetRealPixelSize();
250
256 virtual void InjectMouseMove(const int& xPos, const int& yPos, const MouseButtonId& button)=0;
257
263 virtual void InjectMouseWheel(const int& scrollX, const int& scrollY, const int& relativeScroll)=0;
264
271 virtual void InjectMouseDown(const int& xPos, const int& yPos, const MouseButtonId& button)=0;
272
279 virtual void InjectMouseUp(const int& xPos, const int& yPos, const MouseButtonId& button)=0;
280
287 virtual void InjectTouchAdd(const int& xPos, const int& yPos, const int& touchid) = 0;
288
293 virtual void InjectTouchRemove(const int& touchid) = 0;
294
303 virtual void InjectTouchUpdate(const int& xPos, const int& yPos, const int& vx, const int& vy, const int& touchid) = 0;
304
307 virtual void InjectKeyEvent(const UINT& msg, const ScolWindowHandle& hwnd, const WPARAM& wParam, const LPARAM& lParam) = 0;
308
311 virtual void InjectTextEvent(const std::string& utf8)=0;
312
319 void Show(const bool& fade=false, const unsigned short& fadeDurationMS=300);
320
327 void Hide(const bool& fade=false, const unsigned short& fadeDurationMS=300);
328
332 bool GetVisible();
333
337 void SetTransparency(const bool& enableTransparency);
338
342 bool GetTransparency();
343
347 void SetOpacity(const float& widgetOpacity);
348
352 float GetOpacity();
353
357 void SetIgnoreTransparentPixels(const bool& widgetIgnoreTransparentPixels, const float& tresholdColor=0.0f);
358
362 bool GetIgnoreTransparentPixels();
363
367 float GetIgnoreTransparentPixelsTreshold();
368
372 virtual void LoadURL(const std::string& url)=0;
373
378 virtual void LoadFile(const std::string& file)=0;
379
383 void SetZOrder(const unsigned short& newWidgetOrder);
384
388 unsigned short GetZOrder();
389
393 void TakeFocus();
394
398 void ReleaseFocus();
399
403 bool HasFocus();
404
408 void SetKeyboardEnable(const bool& enableKeyboardOnWidget);
409
413 bool GetKeyboardEnable();
414
418 void SetMouseEnable(const bool& enableMouseOnWidget);
419
423 bool GetMouseEnable();
424
427 bool GetMouseOver();
428
431 bool GetInputOver(int id);
432
435 void SetInputOver(int id, bool state);
436
440 void SetForeground(const bool& enableWidgetForeground);
441
445 bool GetForeground();
446
450 void SetTopOnFocus(const bool& enableWidgetTopOnFocus);
451
455 bool GetTopOnFocus();
456
460 virtual void RunScriptFunction(const std::string& functionName, const std::vector<std::string>& argumentList)=0;
461
465 virtual void loadResource(Ogre::Resource* resource);
466
470 virtual bool CheckPixelAlpha(const int& posX, const int& posY)=0;
471
474 bool GetUpdateOnFocusOnly();
475
478 void SetUpdateOnFocusOnly(const bool& activate);
479
482 bool GetIsOverlayed();
483
486 bool GetIs2DRect();
487
492 virtual HCURSOR GetCurrentMouseCursor();
493protected:
496 bool IsCompensateNPOT() const;
497
501 void CreateTexture(bool alpha = true);
502
506 std::string CheckUrl(const std::string& url);
507
511 virtual void SetFocusImpl(const bool& focusOnWidget)=0;
512
515 virtual void SetTransparencyImpl(const bool& enableTransparency)=0;
516
519 virtual void SetKeyboardEnableImpl(const bool& enableKeyboardOnWidget)=0;
520
524 virtual void SetMouseEnableImpl(const bool& enableMouseOnWidget)=0;
525
528 virtual void SetSizeImpl(const unsigned short& newWidth, const unsigned short& newHeight)=0;
529private:
533 SWidget();
534
538 void StandardConstructor(SScene* targetScene, const int& xPos, const int& yPos, const unsigned short& widgetWidth, const unsigned short& widgetHeight, const unsigned int& widgetZOrder, SViewPort* targetViewport, const std::string& widgetType);
539
544 void _SetOgreOverlayZOrder(const unsigned short& overlayZOrder);
545
549 void DestroyTexture();
550
554 void CreateMaterial();
555
559 void DestroyMaterial();
560
563 void ApplyMaterialParameters(Ogre::Pass* materialPassToModify, Ogre::TextureUnitState* materialTextureUnitToModify);
564
568 void CreateOverlay();
569
573 void DestroyOverlay();
574
578 void Create2D();
579
583 void Destroy2D();
584};
585
586}
587
588#endif
unsigned int UINT
Definition SO3Android.h:58
void * HCURSOR
Definition SO3Android.h:60
librairies include
Ogre::SceneBlendFactor oSceneBlendingD
Definition SO3Widget.h:68
Ogre::SceneBlendFactor oSceneBlendingS
Definition SO3Widget.h:67
virtual void LoadFile(const std::string &file)=0
virtual void InjectMouseDown(const int &xPos, const int &yPos, const MouseButtonId &button)=0
virtual void SetSizeImpl(const unsigned short &newWidth, const unsigned short &newHeight)=0
bool forceRenderingUpdate
Definition SO3Widget.h:89
virtual void InjectMouseMove(const int &xPos, const int &yPos, const MouseButtonId &button)=0
Ogre::Vector2 yCoef
Definition SO3Widget.h:93
virtual void InjectTouchAdd(const int &xPos, const int &yPos, const int &touchid)=0
virtual void SetFocusImpl(const bool &focusOnWidget)=0
float topOffset
Definition SO3Widget.h:79
virtual void SetMouseEnableImpl(const bool &enableMouseOnWidget)=0
virtual void SetTransparencyImpl(const bool &enableTransparency)=0
virtual void InjectTextEvent(const std::string &utf8)=0
virtual void InjectMouseWheel(const int &scrollX, const int &scrollY, const int &relativeScroll)=0
float transparentTresholdColor
Definition SO3Widget.h:90
Ogre::Vector2 xCoef
Definition SO3Widget.h:92
unsigned short width
Definition SO3Widget.h:80
Ogre::TexturePtr renderingTexture
Definition SO3Widget.h:88
unsigned short height
Definition SO3Widget.h:81
virtual void InjectMouseUp(const int &xPos, const int &yPos, const MouseButtonId &button)=0
Ogre::Viewport * currentViewport
Definition SO3Widget.h:87
unsigned short mTextureWidth
The actual texture width allocated in ogre.
Definition SO3Widget.h:82
SViewPort * viewport
Definition SO3Widget.h:86
bool compensateNPOT
Use to indicate if the texture size has be rounded to an exact pow2.
Definition SO3Widget.h:91
SScene * scene
Definition SO3Widget.h:85
float textureRatio
Texture ratio compared to widget size, usually 1.0.
Definition SO3Widget.h:84
std::string baseResourceName
Definition SO3Widget.h:75
virtual bool CheckPixelAlpha(const int &posX, const int &posY)=0
unsigned short mTextureHeight
The actual texture height allocated in ogre.
Definition SO3Widget.h:83
virtual void LoadURL(const std::string &url)=0
virtual void InjectTouchRemove(const int &touchid)=0
virtual void InjectTouchUpdate(const int &xPos, const int &yPos, const int &vx, const int &vy, const int &touchid)=0
virtual void SetKeyboardEnableImpl(const bool &enableKeyboardOnWidget)=0
float leftOffset
Definition SO3Widget.h:78
friend SWidgetManager
Definition SO3Widget.h:73
virtual void RunScriptFunction(const std::string &functionName, const std::vector< std::string > &argumentList)=0
virtual void InjectKeyEvent(const UINT &msg, const ScolWindowHandle &hwnd, const WPARAM &wParam, const LPARAM &lParam)=0