44SObjWindowWidget::SObjWindowWidget(
SScene* targetScene,
const std::string& bitmapWidgetName,
const int& xPos,
const int& yPos,
const unsigned short& widgetWidth,
const unsigned short& widgetHeight,
SViewPort* targetViewport,
const unsigned int& widgetZOrder) :
SWidget(targetScene, bitmapWidgetName, xPos, yPos, widgetWidth, widgetHeight, targetViewport, widgetZOrder, SO3_OBJ_WINDOW_WIDGET_TYPE)
49SObjWindowWidget::SObjWindowWidget(
SScene* targetScene,
const std::string& bitmapWidgetName,
const int& xPos,
const int& yPos,
const unsigned short& widgetWidth,
const unsigned short& widgetHeight,
SViewPort* targetViewport) :
SWidget(targetScene, bitmapWidgetName, xPos, yPos, widgetWidth, widgetHeight, targetViewport, SO3_OBJ_WINDOW_WIDGET_TYPE)
54SObjWindowWidget::SObjWindowWidget(
SScene* targetScene,
const std::string& bitmapWidgetName,
const unsigned short& widgetWidth,
const unsigned short& widgetHeight,
SMaterial* targetMaterial,
const unsigned short& targetTechnique,
const unsigned short& targetPass,
const unsigned short& targetTextureUnit) :
SWidget(targetScene, bitmapWidgetName, widgetWidth, widgetHeight, targetMaterial, targetTechnique, targetPass, targetTextureUnit, SO3_OBJ_WINDOW_WIDGET_TYPE)
61 targetWindowHandle = 0;
62 lastWindowWithBordersWidth = -1;
63 lastWindowWithBordersHeight = -1;
74 DestroyDevicesContexts();
75 DestroyMemoryBitmap();
81 assert(targetWindowHandle == 0);
82 targetWindowHandle = targetWindowHandlePtr;
89 OGRE_EXCEPT(Ogre::Exception::ERR_NOT_IMPLEMENTED,
"Cannot directly load an URL in a ObjWindow widget, use \"UpdateRawData\" function!",
"SObjWindowWidget::LoadURL");
96 OGRE_EXCEPT(Ogre::Exception::ERR_NOT_IMPLEMENTED,
"Cannot directly load a file directly in a ObjWindow widget, use \"UpdateRawData\" function!",
"SObjWindowWidget::LoadFile");
101 if(CheckWindowIsStillValid())
105 InjectMouseMessage(xPos, yPos, WM_MOUSEMOVE);
111 if(CheckWindowIsStillValid())
114 InjectMouseMessage(scrollX, scrollY, WM_MOUSEHWHEEL, MAKEWPARAM(0, relativeScroll));
120 if(CheckWindowIsStillValid())
126 InjectMouseMessage(xPos, yPos, WM_LBUTTONDOWN);
129 InjectMouseMessage(xPos, yPos, WM_MBUTTONDOWN);
132 InjectMouseMessage(xPos, yPos, WM_RBUTTONDOWN);
140 if(CheckWindowIsStillValid())
146 InjectMouseMessage(xPos, yPos, WM_LBUTTONUP);
149 InjectMouseMessage(xPos, yPos, WM_MBUTTONUP);
152 InjectMouseMessage(xPos, yPos, WM_RBUTTONUP);
175 if(CheckWindowIsStillValid())
178 PostMessage(targetWindowHandle, msg, wParam, lParam);
189 if(CheckWindowIsStillValid())
235 drawBorders = drawBordersEnable;
238void SObjWindowWidget::InjectMouseMessage(
const int& xPos,
const int& yPos,
const unsigned int& message,
const WPARAM& wParam)
240 if(CheckWindowIsStillValid())
243 WINDOWINFO parentWindowInfos;
244 GetWindowInfo(targetWindowHandle, &parentWindowInfos);
250 localPosition.x =
static_cast<int>((
static_cast<long>(xPos) * (parentWindowInfos.rcWindow.right - parentWindowInfos.rcWindow.left) /
static_cast<long>(
width)) - (parentWindowInfos.rcClient.left - parentWindowInfos.rcWindow.left));
251 localPosition.y =
static_cast<int>((
static_cast<long>(yPos) * (parentWindowInfos.rcWindow.bottom - parentWindowInfos.rcWindow.top) /
static_cast<long>(
height)) - (parentWindowInfos.rcClient.top - parentWindowInfos.rcWindow.top));
255 localPosition.x =
static_cast<int>(
static_cast<long>(xPos) * (parentWindowInfos.rcClient.right - parentWindowInfos.rcClient.left) /
static_cast<long>(
width));
256 localPosition.y =
static_cast<int>(
static_cast<long>(yPos) * (parentWindowInfos.rcClient.bottom - parentWindowInfos.rcClient.top) /
static_cast<long>(
height));
260 WINDOWINFO chilWindowInfos;
261 ScolWindowHandle childWindowHandle = 0;
262 ScolWindowHandle lastChildWindowHandle = 0;
266 if(lastChildWindowHandle == 0)
267 lastChildWindowHandle = targetWindowHandle;
269 GetWindowInfo(lastChildWindowHandle, &parentWindowInfos);
272 childWindowHandle = ChildWindowFromPoint(lastChildWindowHandle, localPosition);
273 if(childWindowHandle == 0)
274 lastChildWindowHandle = 0;
277 if(childWindowHandle != lastChildWindowHandle)
280 GetWindowInfo(childWindowHandle, &chilWindowInfos);
283 localPosition.x = localPosition.x - (chilWindowInfos.rcWindow.left - parentWindowInfos.rcClient.left);
284 localPosition.y = localPosition.y - (chilWindowInfos.rcWindow.top - parentWindowInfos.rcClient.top);
285 lastChildWindowHandle = childWindowHandle;
286 childWindowHandle = 0;
288 }
while (childWindowHandle != lastChildWindowHandle);
291 if(lastChildWindowHandle == 0)
292 lastChildWindowHandle = targetWindowHandle;
295 SetCapture(targetWindowHandle);
296 SendMessage(lastChildWindowHandle, WM_SETCURSOR, (WPARAM)(0), (LPARAM)(MAKELONG(HTCLIENT, message)));
297 SendMessage(lastChildWindowHandle, message, wParam, MAKELPARAM(localPosition.x, localPosition.y));
304 if(CheckWindowIsStillValid())
307 WINDOWINFO targetWindowInfos;
308 GetWindowInfo(targetWindowHandle, &targetWindowInfos);
311 long targetWindowWithBordersWidth = targetWindowInfos.rcWindow.right - targetWindowInfos.rcWindow.left;
312 long targetWindowWithBordersHeight = targetWindowInfos.rcWindow.bottom - targetWindowInfos.rcWindow.top;
315 if((lastWindowWithBordersWidth != targetWindowWithBordersWidth) || (lastWindowWithBordersHeight != targetWindowWithBordersHeight))
317 CreateDevicesContexts();
318 CreateMemoryBitmap(targetWindowWithBordersWidth, targetWindowWithBordersHeight);
321 lastWindowWithBordersWidth = targetWindowWithBordersWidth;
322 lastWindowWithBordersHeight = targetWindowWithBordersHeight;
326 if((targetWindowDC != 0) && (memoryBitmapDC != 0) && (memoryBitmap != 0) && (pixelsData!=0))
329 LPARAM printFlags = 0|PRF_CHILDREN|PRF_CLIENT|PRF_ERASEBKGND|PRF_OWNED|PRF_NONCLIENT;
332 SelectObject(memoryBitmapDC, memoryBitmap);
334 SendMessage(targetWindowHandle, WM_PRINT, (WPARAM)memoryBitmapDC, printFlags);
337 Ogre::PixelBox scolPixelBox(targetWindowWithBordersWidth, targetWindowWithBordersHeight, 1, Ogre::PF_BYTE_BGR, pixelsData);
342 long targetWindowWithoutBordersWidth = targetWindowInfos.rcClient.right - targetWindowInfos.rcClient.left;
343 long targetWindowWithoutBordersHeight = targetWindowInfos.rcClient.bottom - targetWindowInfos.rcClient.top;
344 long xOffset = targetWindowInfos.rcClient.left - targetWindowInfos.rcWindow.left;
345 long yOffsetTop = targetWindowInfos.rcClient.top - targetWindowInfos.rcWindow.top;
346 Ogre::Box windowRectWithoutBorders(xOffset, yOffsetTop, targetWindowWithoutBordersWidth + xOffset, targetWindowWithoutBordersHeight + yOffsetTop);
347 scolPixelBox = scolPixelBox.getSubVolume(windowRectWithoutBorders);
351 Ogre::HardwarePixelBufferSharedPtr pixelBuffer =
renderingTexture->getBuffer();
352 pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD);
353 const Ogre::PixelBox& pixelBox = pixelBuffer->getCurrentLock();
356 Ogre::Image::scale(scolPixelBox, pixelBox);
359 pixelBuffer->unlock();
364void SObjWindowWidget::CreateDevicesContexts()
366 if(CheckWindowIsStillValid())
369 DestroyDevicesContexts();
372 targetWindowDC = GetWindowDC(targetWindowHandle);
373 memoryBitmapDC = CreateCompatibleDC(targetWindowDC);
377void SObjWindowWidget::DestroyDevicesContexts()
382 DeleteDC(memoryBitmapDC);
386 if(CheckWindowIsStillValid())
390 ReleaseDC(targetWindowHandle, targetWindowDC);
396void SObjWindowWidget::CreateMemoryBitmap(
const long& targetWindowWidth,
const long& targetWindowHeight)
398 if(CheckWindowIsStillValid())
401 DestroyMemoryBitmap();
406 BITMAPINFOHEADER infoHeader;
407 infoHeader.biSize =
sizeof(BITMAPINFOHEADER);
408 infoHeader.biWidth = targetWindowWidth;
409 infoHeader.biHeight = -targetWindowHeight;
410 infoHeader.biPlanes = 1;
411 infoHeader.biBitCount = 32;
412 infoHeader.biCompression = BI_RGB;
416 info.bmiHeader = infoHeader;
419 memoryBitmap = CreateDIBSection(targetWindowDC, &info, DIB_RGB_COLORS, (
void**)&pixelsData, 0, 0);
424void SObjWindowWidget::DestroyMemoryBitmap()
429 DeleteObject(memoryBitmap);
435bool SObjWindowWidget::CheckWindowIsStillValid()
437 bool stillValid =
false;
438 if(targetWindowHandle)
440 if(IsWindow(targetWindowHandle))
443 targetWindowHandle = 0;
448bool SObjWindowWidget::GetMinimizeMaximizeAnimation()
450 ANIMATIONINFO animationInfo;
451 animationInfo.cbSize =
sizeof(ANIMATIONINFO);
452 SystemParametersInfo(SPI_GETANIMATION, animationInfo.cbSize, &animationInfo, 0);
455 if (animationInfo.iMinAnimate == 0)
461void SObjWindowWidget::SetMinimizeMaximizeAnimation(
const bool& status)
464 if (status != GetMinimizeMaximizeAnimation())
472 ANIMATIONINFO animationInfo;
473 animationInfo.cbSize =
sizeof(ANIMATIONINFO);
474 animationInfo.iMinAnimate = intStatus;
475 SystemParametersInfo(SPI_SETANIMATION, animationInfo.cbSize, &animationInfo, SPIF_SENDCHANGE);