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 #include "SO3ObjWindowWidget.h"
00036 #include "../SO3Material/SO3Material.h"
00037 #include "../SO3Renderer/SO3ViewPort.h"
00038 #include "../SO3Renderer/SO3Window.h"
00039 #include "../SO3SceneGraph/SO3Scene.h"
00040 #include "../SO3Renderer/SO3Root.h"
00041 #include "../SO3Utils/SO3ConversionTools.h"
00042
00043 #include "SO3WidgetManager.h"
00044
00045 namespace SO3
00046 {
00047
00048 SObjWindowWidget::SObjWindowWidget(SScene* targetScene, std::string bitmapWidgetName, int xPos, int yPos, unsigned short widgetWidth, unsigned short widgetHeight, SViewPort* targetViewport, unsigned int widgetZOrder) : SWidget(targetScene, bitmapWidgetName, xPos, yPos, widgetWidth, widgetHeight, targetViewport, widgetZOrder, SO3_OBJ_WINDOW_WIDGET_TYPE)
00049 {
00050 CommonConstructorSequence();
00051 }
00052
00053 SObjWindowWidget::SObjWindowWidget(SScene* targetScene, std::string bitmapWidgetName, int xPos, int yPos, unsigned short widgetWidth, unsigned short widgetHeight, SViewPort* targetViewport) : SWidget(targetScene, bitmapWidgetName, xPos, yPos, widgetWidth, widgetHeight, targetViewport, SO3_OBJ_WINDOW_WIDGET_TYPE)
00054 {
00055 CommonConstructorSequence();
00056 }
00057
00058 SObjWindowWidget::SObjWindowWidget(SScene* targetScene, std::string bitmapWidgetName, unsigned short widgetWidth, unsigned short widgetHeight, SMaterial* targetMaterial, unsigned short targetTechnique, unsigned short targetPass, unsigned short targetTextureUnit) : SWidget(targetScene, bitmapWidgetName, widgetWidth, widgetHeight, targetMaterial, targetTechnique, targetPass, targetTextureUnit, SO3_OBJ_WINDOW_WIDGET_TYPE)
00059 {
00060 CommonConstructorSequence();
00061 }
00062
00063 void SObjWindowWidget::CommonConstructorSequence()
00064 {
00065 iLastWidth = 0;
00066 iLastHeight = 0;
00067 pixelsData = 0;
00068 bLastAlphaState = false;
00069 }
00070
00071 SObjWindowWidget::~SObjWindowWidget()
00072 {
00073 if (pixelsData)
00074 free(pixelsData);
00075 }
00076
00077 void SObjWindowWidget::LoadURL(const std::string& url)
00078 {
00079
00080 OGRE_EXCEPT(Ogre::Exception::ERR_NOT_IMPLEMENTED, "Cannot directly load an URL in a ObjWindow widget, use \"UpdateRawData\" function!", "SObjWindowWidget::LoadURL");
00081 }
00082
00083 void SObjWindowWidget::LoadFile(const std::string& file)
00084 {
00085
00086 OGRE_EXCEPT(Ogre::Exception::ERR_NOT_IMPLEMENTED, "Cannot directly load a file directly in a ObjWindow widget, use \"UpdateRawData\" function!", "SObjWindowWidget::LoadFile");
00087 }
00088
00089 void SObjWindowWidget::UpdateRawData(const void* objWindowBuffer)
00090 {
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 }
00115
00116 void SObjWindowWidget::InjectMouseMove(int xPos, int yPos, MouseButtonId button)
00117 {
00118
00119 }
00120
00121 void SObjWindowWidget::InjectMouseWheel(int scrollX, int scrollY, int relativeScroll)
00122 {
00123
00124 }
00125
00126 void SObjWindowWidget::InjectMouseDown(int xPos, int yPos, MouseButtonId button)
00127 {
00128
00129 }
00130
00131 void SObjWindowWidget::InjectMouseUp(int xPos, int yPos, MouseButtonId button)
00132 {
00133
00134 }
00135
00136 void SObjWindowWidget::InjectKeyEvent(UINT msg, WindowHandle hwnd, WPARAM wParam, LPARAM lParam)
00137 {
00138
00139 }
00140
00141 void SObjWindowWidget::InjectTextEvent(std::string utf8)
00142 {
00143
00144 }
00145
00146 void SObjWindowWidget::SetFocusImpl(bool focusOnWidget)
00147 {
00148
00149 }
00150
00151 void SObjWindowWidget::SetTransparencyImpl(bool enableTransparency)
00152 {
00153
00154 }
00155 void SObjWindowWidget::RunScriptFunction(std::string functionName, std::vector<std::string> argumentList)
00156 {
00157
00158 }
00159
00160 void SObjWindowWidget::SetKeyboardEnableImpl(bool enableKeyboardOnWidget)
00161 {
00162
00163 }
00164
00165 void SObjWindowWidget::SetMouseEnableImpl(bool enableMouseOnWidget)
00166 {
00167
00168 }
00169
00170 void SObjWindowWidget::SetSizeImpl(unsigned short newWidth, unsigned short newHeight)
00171 {
00172
00173 }
00174
00175 int SObjWindowWidget::GetPixelUnder(int posX, int posY)
00176 {
00177
00178
00179
00180
00181
00182
00183
00184 return -1;
00185 }
00186
00187 void SObjWindowWidget::CheckSizeAndAlloc(unsigned int newWidth, unsigned int newHeight, bool alpha)
00188 {
00189 if ((newWidth != iLastWidth) || (newHeight != iLastHeight) || (alpha != bLastAlphaState))
00190 {
00191 if (pixelsData)
00192 free(pixelsData);
00193
00194 iLastWidth = newWidth;
00195 iLastHeight = newHeight;
00196 bLastAlphaState = alpha;
00197
00198 int nbBytes = alpha ? 4 : 3;
00199 int size = alpha ? sizeof(Ogre::uint32*) : (sizeof(unsigned char*) * nbBytes);
00200 pixelsData = (void*)malloc(newWidth * newHeight * size);
00201 }
00202 }
00203
00204 void SObjWindowWidget::loadResource(Ogre::Resource* resource)
00205 {
00206 Ogre::Texture* tex = static_cast<Ogre::Texture*>(resource);
00207 tex->setTextureType(Ogre::TEX_TYPE_2D);
00208 tex->setWidth(textureWidth);
00209 tex->setHeight(textureHeight);
00210 tex->setNumMipmaps(0);
00211 tex->setFormat(Ogre::PF_BYTE_BGRA);
00212 tex->setUsage(Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
00213 tex->createInternalResources();
00214
00215 if(pixelsData)
00216 {
00217 Ogre::HardwarePixelBufferSharedPtr pixelBuffer = renderingTexture->getBuffer();
00218 pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD);
00219 const Ogre::PixelBox& pixelBox = pixelBuffer->getCurrentLock();
00220
00221
00222 const Ogre::PixelBox scolPixelBox(iLastWidth, iLastHeight, 1, bLastAlphaState ? Ogre::PF_R8G8B8A8 : Ogre::PF_R8G8B8, pixelsData);
00223
00224
00225 Ogre::Image::scale(scolPixelBox, pixelBox);
00226
00227
00228 pixelBuffer->unlock();
00229 }
00230
00231 forceRenderingUpdate = true;
00232 }
00233
00234 }