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 "SO3FlashWidget.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 "impl/FlashHandler.h"
00042 #include "impl/FlashSite.h"
00043 #include "impl/RenderBuffer.h"
00044 #include "SO3WidgetManager.h"
00045 #include <OgreBitwise.h>
00046
00047 namespace SO3
00048 {
00049
00050 SFlashWidget::SFlashWidget(SScene* targetScene, std::string flashWidgetName, int xPos, int yPos, unsigned short widgetWidth, unsigned short widgetHeight, SViewPort* targetViewport, unsigned int widgetZOrder) : SWidget(targetScene, flashWidgetName, xPos, yPos, widgetWidth, widgetHeight, targetViewport, widgetZOrder, SO3_FLASH_WIDGET_TYPE)
00051 {
00052 CommonConstructorSequence(true);
00053 SetRenderingQuality(SO3_FLASH_QUALITY_AUTOHIGH);
00054 SetScaleMode(SO3_FLASH_SCALE_SHOWALL);
00055 }
00056
00057 SFlashWidget::SFlashWidget(SScene* targetScene, std::string flashWidgetName, int xPos, int yPos, unsigned short widgetWidth, unsigned short widgetHeight, SViewPort* targetViewport) : SWidget(targetScene, flashWidgetName, xPos, yPos, widgetWidth, widgetHeight, targetViewport, SO3_FLASH_WIDGET_TYPE)
00058 {
00059 CommonConstructorSequence(true);
00060 SetRenderingQuality(SO3_FLASH_QUALITY_AUTOHIGH);
00061 SetScaleMode(SO3_FLASH_SCALE_SHOWALL);
00062 }
00063
00064 SFlashWidget::SFlashWidget(SScene* targetScene, std::string flashWidgetName, unsigned short widgetWidth, unsigned short widgetHeight, SMaterial* targetMaterial, unsigned short targetTechnique, unsigned short targetPass, unsigned short targetTextureUnit) : SWidget(targetScene, flashWidgetName, widgetWidth, widgetHeight, targetMaterial, targetTechnique, targetPass, targetTextureUnit, SO3_FLASH_WIDGET_TYPE)
00065 {
00066 CommonConstructorSequence(false);
00067 SetRenderingQuality(SO3_FLASH_QUALITY_AUTOHIGH);
00068 SetScaleMode(SO3_FLASH_SCALE_EXACTFIT);
00069 }
00070
00071 void SFlashWidget::CommonConstructorSequence(bool overlayedFlashControl)
00072 {
00073 okayToDelete = false;
00074 lastDirtyWidth = 0;
00075 lastDirtyHeight = 0;
00076 isTotallyDirty = false;
00077 isInputListener = true;
00078 isVisible = true;
00079 comCount = 0;
00080 mainContext = altContext = 0;
00081 mainBitmap = altBitmap = 0;
00082 mainBuffer = altBuffer = 0;
00083
00084
00085 IFlashControl::name = SWidget::name;
00086 IFlashControl::width = SWidget::width;
00087 IFlashControl::height = SWidget::height;
00088 IFlashControl::isOverlay = overlayedFlashControl;
00089
00090
00091 renderBuffer = new Hikari::Impl::RenderBuffer(SWidget::width, SWidget::height);
00092 site = new Hikari::Impl::FlashSite();
00093 site->AddRef();
00094 site->Init(this, NULL);
00095
00096
00097 HMODULE flashLib = Hikari::HikariManager::getSingleton().flashLib;
00098
00099
00100 if(flashLib)
00101 {
00102 IClassFactory* factory = 0;
00103 GetClassObject getClassFunc = (GetClassObject)GetProcAddress(flashLib, "DllGetClassObject");
00104 HRESULT result = getClassFunc(ShockwaveFlashObjects::CLSID_ShockwaveFlash, IID_IClassFactory, (void**)&factory);
00105 if(SUCCEEDED(result))
00106 {
00107
00108 factory->CreateInstance(NULL, IID_IOleObject, (void**)&oleObject);
00109 factory->Release();
00110 }
00111 }
00112
00113
00114 if(!oleObject)
00115 {
00116 HRESULT result = CoCreateInstance(ShockwaveFlashObjects::CLSID_ShockwaveFlash, 0, CLSCTX_INPROC_SERVER, IID_IOleObject, (void**)&oleObject);
00117 if(FAILED(result))
00118 OGRE_EXCEPT(Ogre::Exception::ERR_RT_ASSERTION_FAILED, "Unable to load the Flash ActiveX control.", "SFlashWidget::CommonConstructorSequence");
00119 }
00120
00121
00122 IOleClientSite* clientSite = 0;
00123 site->QueryInterface(__uuidof(IOleClientSite), (void**)&clientSite);
00124 oleObject->SetClientSite(clientSite);
00125
00126
00127 IOleInPlaceObject* inPlaceObject = 0;
00128 HRESULT result = oleObject->QueryInterface(__uuidof(IOleInPlaceObject), (LPVOID*)&inPlaceObject);
00129 if(FAILED(result))
00130 OGRE_EXCEPT(Ogre::Exception::ERR_RT_ASSERTION_FAILED, "Unable to load the Flash ActiveX control.", "SFlashWidget::CommonConstructorSequence");
00131
00132 if(inPlaceObject)
00133 {
00134 invalidateTotally();
00135 inPlaceObject->SetObjectRects(&dirtyBounds, &dirtyBounds);
00136 inPlaceObject->Release();
00137 }
00138
00139 result = oleObject->QueryInterface(__uuidof(ShockwaveFlashObjects::IShockwaveFlash), (LPVOID*)&flashInterface);
00140 if(FAILED(result))
00141 OGRE_EXCEPT(Ogre::Exception::ERR_RT_ASSERTION_FAILED, "Unable to load the Flash ActiveX control.", "SFlashWidget::CommonConstructorSequence");
00142
00143 flashInterface->PutWMode("opaque");
00144
00145
00146 oleObject->DoVerb(OLEIVERB_INPLACEACTIVATE, 0, clientSite, 0, 0, 0);
00147 clientSite->Release();
00148
00149
00150 result = oleObject->QueryInterface(__uuidof(IOleInPlaceObjectWindowless), (LPVOID*)&windowlessObject);
00151 if(FAILED(result))
00152 OGRE_EXCEPT(Ogre::Exception::ERR_RT_ASSERTION_FAILED, "Unable to load the Flash ActiveX control.", "SFlashWidget::CommonConstructorSequence");
00153
00154
00155 handler = new Hikari::Impl::FlashHandler();
00156 handler->AddRef();
00157 handler->Init(this);
00158
00159 IViewObject* curView = 0;
00160 result = flashInterface->QueryInterface(IID_IViewObject, (void**)&curView);
00161 if(FAILED(result))
00162 OGRE_EXCEPT(Ogre::Exception::ERR_RT_ASSERTION_FAILED, "Unable to load the Flash ActiveX control.", "SFlashWidget::CommonConstructorSequence");
00163
00164 curView->Release();
00165
00166
00167 SetKeyboardEnable(true);
00168 SetMouseEnable(true);
00169
00170
00171 Hikari::HikariManager::getSingletonPtr()->setFlashControl(this);
00172 }
00173
00174 SFlashWidget::~SFlashWidget()
00175 {
00176
00177 okayToDelete = true;
00178 Hikari::HikariManager::getSingletonPtr()->update();
00179
00180
00181 if(windowlessObject)
00182 {
00183 windowlessObject->Release();
00184 windowlessObject = 0;
00185 }
00186
00187 if(flashInterface)
00188 {
00189 flashInterface->Release();
00190 flashInterface = 0;
00191 }
00192
00193 if(handler)
00194 {
00195 handler->Shutdown();
00196 handler->Release();
00197 handler = 0;
00198 }
00199
00200 if(oleObject)
00201 {
00202 oleObject->Close(OLECLOSE_NOSAVE);
00203 oleObject->Release();
00204 oleObject = 0;
00205 }
00206
00207 if(site)
00208 {
00209 site->Release();
00210 site = 0;
00211 }
00212
00213 if(mainContext)
00214 ::DeleteDC(mainContext);
00215
00216 if(altContext)
00217 ::DeleteDC(altContext);
00218
00219 if(mainBitmap)
00220 ::DeleteObject(mainBitmap);
00221
00222 if(altBitmap)
00223 ::DeleteObject(altBitmap);
00224
00225
00226 SAFE_DELETE(renderBuffer);
00227 }
00228
00229 void SFlashWidget::LoadURL(const std::string& url)
00230 {
00231 std::string urlString = CheckUrl(url);
00232 flashInterface->PutMovie(urlString.c_str());
00233 }
00234
00235 void SFlashWidget::LoadFile(const std::string& file)
00236 {
00237 FILE* fileIndex = fopen((char*)(file.c_str()), "r");
00238 if(fileIndex)
00239 {
00240 fclose(fileIndex);
00241 flashInterface->PutMovie((char*)(file.c_str()));
00242 }
00243 else
00244 {
00245 OGRE_EXCEPT(Ogre::Exception::ERR_FILE_NOT_FOUND, "Could not load '" + file + "', the file was not found.", "FlashControl::LoadFile");
00246 }
00247 }
00248
00249 void SFlashWidget::InjectMouseMove(int xPos, int yPos, MouseButtonId button)
00250 {
00251 injectMouseMove(xPos - leftPos , yPos - topPos, static_cast<int> (button));
00252 }
00253
00254 void SFlashWidget::InjectMouseWheel(int scrollX, int scrollY, int relativeScroll)
00255 {
00256 injectMouseWheel(relativeScroll, scrollX, scrollY);
00257 }
00258
00259 void SFlashWidget::InjectMouseDown(int xPos, int yPos, MouseButtonId button)
00260 {
00261 injectMouseDown(xPos - leftPos , yPos - topPos, static_cast<int> (button));
00262 }
00263
00264 void SFlashWidget::InjectMouseUp(int xPos, int yPos, MouseButtonId button)
00265 {
00266 injectMouseUp(xPos - leftPos , yPos - topPos, static_cast<int> (button));
00267 }
00268
00269 void SFlashWidget::InjectKeyEvent(UINT msg, WindowHandle hwnd, WPARAM wParam, LPARAM lParam)
00270 {
00271 handleKeyEvent(msg, wParam, lParam);
00272 }
00273
00274 void SFlashWidget::InjectTextEvent(std::string utf8)
00275 {
00276 }
00277
00278 void SFlashWidget::SetFocusImpl(bool focusOnWidget)
00279 {
00280 if (focusOnWidget)
00281 focus();
00282 }
00283
00284 void SFlashWidget::SetTransparencyImpl(bool enableTransparency)
00285 {
00286 setTransparent(enableTransparency, enableTransparency);
00287 }
00288
00289 SFlashWidget::FlashRenderQuality SFlashWidget::GetRenderingQuality()
00290 {
00291 return renderingQuality;
00292 }
00293
00294 void SFlashWidget::SetRenderingQuality(SFlashWidget::FlashRenderQuality newQuality)
00295 {
00296 setQuality(newQuality);
00297 }
00298
00299 void SFlashWidget::Play()
00300 {
00301 play();
00302 }
00303
00304 void SFlashWidget::Stop()
00305 {
00306 stop();
00307 }
00308
00309 void SFlashWidget::Rewind()
00310 {
00311 rewind();
00312 }
00313
00314 void SFlashWidget::Seek(long seekFrame)
00315 {
00316 gotoFrame(seekFrame);
00317 }
00318
00319 void SFlashWidget::SetScaleMode(SFlashWidget::FlashScaleMode widgetScaleMode)
00320 {
00321 setScaleMode(static_cast<short>(widgetScaleMode));
00322 }
00323
00324 SFlashWidget::FlashScaleMode SFlashWidget::GetScaleMode()
00325 {
00326 return scaleMode;
00327 }
00328
00329 WindowHandle SFlashWidget::getTopWindow()
00330 {
00331 WindowHandle olewin;
00332 windowlessObject->GetWindow(&olewin);
00333
00334 WindowHandle oletop = GetWindow(olewin, GW_CHILD);
00335 if (oletop)
00336 return oletop;
00337 else
00338 return olewin;
00339 }
00340
00341 void SFlashWidget::RunScriptFunction(std::string functionName, std::vector<std::string> argumentList)
00342 {
00343 string argumentStr;
00344
00345
00346 std::vector<wchar_t> functionNameUnicodeTab(functionName.length()+1);
00347 int i = mbstowcs(&functionNameUnicodeTab[0], functionName.c_str(), functionName.length()+1);
00348 const std::wstring functionNameUnicode = std::wstring(&functionNameUnicodeTab[0]);
00349
00350
00351 Hikari::Arguments hikariArgumentList;
00352 std::vector<std::string>::iterator iArgumentList = argumentList.begin();
00353 while (iArgumentList != argumentList.end())
00354 {
00355 std::string currentArgument = *iArgumentList;
00356 std::vector<wchar_t> currentArgumentUnicodeTab(currentArgument.length()+1);
00357 int i = mbstowcs(¤tArgumentUnicodeTab[0], currentArgument.c_str(), currentArgument.length()+1);
00358 const std::wstring currentArgumentUnicode = std::wstring(¤tArgumentUnicodeTab[0]);
00359 hikariArgumentList.push_back(Hikari::FlashValue(currentArgumentUnicode));
00360
00361 iArgumentList++;
00362 }
00363
00364
00365
00366 callFunction(functionNameUnicode, hikariArgumentList);
00367 }
00368
00369 void SFlashWidget::SetKeyboardEnableImpl(bool enableKeyboardOnWidget)
00370 {
00371 IFlashControl::keyBoardEnable = enableKeyboardOnWidget;
00372 isBlocked = !enableKeyboardOnWidget;
00373 }
00374
00375 void SFlashWidget::SetMouseEnableImpl(bool enableMouseOnWidget)
00376 {
00377 IFlashControl::mouseEnable = enableMouseOnWidget;
00378 }
00379
00380 void SFlashWidget::SetSizeImpl(unsigned short newWidth, unsigned short newHeight)
00381 {
00382 SAFE_DELETE(renderBuffer);
00383 renderBuffer = new Hikari::Impl::RenderBuffer(newWidth, newHeight);
00384 invalidateTotally();
00385 }
00386
00387 void SFlashWidget::setZOrder(unsigned short zorder)
00388 {
00389
00390 }
00391
00392 unsigned short SFlashWidget::getZOrder()
00393 {
00394
00395 return 0;
00396 }
00397
00398 int SFlashWidget::getRelativeX(int absX)
00399 {
00400
00401 return -1;
00402 }
00403
00404 int SFlashWidget::getRelativeY(int absY)
00405 {
00406
00407 return -1;
00408 }
00409
00410 bool SFlashWidget::isPointOverMe(int screenX, int screenY)
00411 {
00412
00413 return false;
00414 }
00415
00416 void SFlashWidget::invalidateTotally()
00417 {
00418 isClean = false;
00419 isTotallyDirty = true;
00420 dirtyBounds.left = 0;
00421 dirtyBounds.top = 0;
00422 dirtyBounds.right = IFlashControl::width = SWidget::width;
00423 dirtyBounds.bottom = IFlashControl::height = SWidget::height;
00424
00425 IOleInPlaceObject* inPlaceObject = 0;
00426 oleObject->QueryInterface(__uuidof(IOleInPlaceObject), (LPVOID*)&inPlaceObject);
00427
00428 if(inPlaceObject)
00429 {
00430 inPlaceObject->SetObjectRects(&dirtyBounds, &dirtyBounds);
00431 inPlaceObject->Release();
00432 }
00433
00434 forceRenderingUpdate = true;
00435 }
00436
00437 void SFlashWidget::handleFlashCall(const std::wstring& xmlString)
00438 {
00439 std::wstring funcName;
00440 Hikari::Arguments args;
00441
00442 if(!Hikari::Impl::deserializeInvocation(xmlString, funcName, args))
00443 return;
00444
00445
00446 WidgetScriptFunction functionCalled;
00447
00448
00449 std::string invokeName;
00450 invokeName.resize(funcName.size());
00451 wcstombs(&invokeName[0], &funcName[0], funcName.size());
00452 functionCalled.function = invokeName.c_str();
00453
00454
00455 Hikari::Arguments::iterator iArguments = args.begin();
00456 while(iArguments != args.end())
00457 {
00458 float val;
00459 std::string argumentValue;
00460 std::ostringstream oss;
00461 switch((*iArguments).getType())
00462 {
00463 case Hikari::FT_NUMBER:
00464 val = static_cast<float> ((*iArguments).getNumber());
00465 oss << val;
00466 argumentValue = oss.str();
00467 break;
00468 case Hikari::FT_BOOLEAN:
00469 val = static_cast<float>((*iArguments).getBool());
00470 oss << val;
00471 argumentValue = oss.str();
00472 break;
00473 case Hikari::FT_STRING:
00474 argumentValue = (*iArguments).getString();
00475 break;
00476 case Hikari::FT_WSTRING:
00477 std::wstring argumentValueUnicode = (*iArguments).getWString();
00478 argumentValue.resize(argumentValueUnicode.size());
00479 wcstombs(&argumentValue[0], &argumentValueUnicode[0], argumentValueUnicode.size());
00480 break;
00481 }
00482
00483
00484 functionCalled.arguments.push_back(argumentValue);
00485 iArguments++;
00486 }
00487
00488
00489 SWidgetManager::getSingleton()._FireScriptWidgetEvent(this, functionCalled);
00490 }
00491
00492 void SFlashWidget::update()
00493 {
00494 if((isClean)&&(!forceRenderingUpdate))
00495 return;
00496
00497 int dirtyWidth = dirtyBounds.right - dirtyBounds.left;
00498 int dirtyHeight = dirtyBounds.bottom - dirtyBounds.top;
00499 int dirtyBufSize = dirtyWidth * dirtyHeight * 4;
00500
00501 IViewObject* curView = 0;
00502 flashInterface->QueryInterface(IID_IViewObject, (void**)&curView);
00503
00504 if(!oleObject || !curView)
00505 return;
00506
00507 if(!mainContext || dirtyWidth != lastDirtyWidth || dirtyHeight != lastDirtyHeight)
00508 {
00509 if(mainContext)
00510 {
00511 DeleteDC(mainContext);
00512 mainContext = 0;
00513 }
00514 if(mainBitmap)
00515 {
00516 DeleteObject(mainBitmap);
00517 mainBitmap = 0;
00518 }
00519
00520 lastDirtyWidth = dirtyWidth;
00521 lastDirtyHeight = dirtyHeight;
00522
00523 HDC hdc = GetDC(NULL);
00524 BITMAPINFOHEADER bih = {0};
00525 bih.biSize = sizeof(BITMAPINFOHEADER);
00526 bih.biBitCount = 32;
00527 bih.biCompression = BI_RGB;
00528 bih.biPlanes = 1;
00529 bih.biWidth = dirtyWidth;
00530 bih.biHeight = -dirtyHeight;
00531 mainContext = CreateCompatibleDC(hdc);
00532 mainBitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bih, DIB_RGB_COLORS, (void**)&mainBuffer, 0, 0);
00533 SelectObject(mainContext, mainBitmap);
00534
00535 if(altContext)
00536 {
00537 DeleteDC(altContext);
00538 altContext = 0;
00539 }
00540 if(altBitmap)
00541 {
00542 DeleteObject(altBitmap);
00543 altBitmap = 0;
00544 }
00545
00546 altContext = CreateCompatibleDC(hdc);
00547 altBitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bih, DIB_RGB_COLORS, (void **)&altBuffer, 0, 0);
00548 SelectObject(altContext, altBitmap);
00549
00550 ReleaseDC(0, hdc);
00551 }
00552
00553 RECT local;
00554 local.left = -dirtyBounds.left;
00555 local.top = -dirtyBounds.top;
00556 local.right = local.left + dirtyBounds.right;
00557 local.bottom = local.top + dirtyBounds.bottom;
00558
00559 memset(mainBuffer, 0, dirtyBufSize);
00560 memset(altBuffer, 255, dirtyBufSize);
00561
00562 OleDraw(curView, DVASPECT_TRANSPARENT, mainContext, &local);
00563 OleDraw(curView, DVASPECT_TRANSPARENT, altContext, &local);
00564
00565
00566
00567
00568 BYTE *blackBuffer, *whiteBuffer;
00569 blackBuffer = mainBuffer;
00570 whiteBuffer = altBuffer;
00571 BYTE blackRed, whiteRed;
00572 int size = dirtyWidth * dirtyHeight;
00573 for(int i = 0; i < size; i++)
00574 {
00575 blackRed = *blackBuffer;
00576 whiteRed = *whiteBuffer;
00577 blackBuffer += 3;
00578 whiteBuffer += 4;
00579 *blackBuffer++ = (255 - (whiteRed - blackRed)) & 0xFF;
00580 }
00581
00582 renderBuffer->copyArea(dirtyBounds, mainBuffer, dirtyWidth * 4);
00583
00584
00585 Ogre::HardwarePixelBufferSharedPtr pixelBuffer = renderingTexture->getBuffer();
00586 pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD);
00587 const Ogre::PixelBox& pixelBox = pixelBuffer->getCurrentLock();
00588
00589
00590 const Ogre::PixelBox scolPixelBox(renderBuffer->width, renderBuffer->height, 1, renderingTexture->getFormat(), renderBuffer->getBuffer());
00591
00592
00593 Ogre::Image::scale(scolPixelBox, pixelBox);
00594
00595
00596 pixelBuffer->unlock();
00597
00598 isClean = true;
00599 isTotallyDirty = false;
00600 forceRenderingUpdate = false;
00601 }
00602
00603 void SFlashWidget::load(const std::string& movieFilename, Hikari::HikariManager* hikariMgr, int type)
00604 {
00605
00606 }
00607
00608 void SFlashWidget::play()
00609 {
00610 flashInterface->Play();
00611 }
00612
00613 void SFlashWidget::stop()
00614 {
00615 flashInterface->Stop();
00616 }
00617
00618 void SFlashWidget::rewind()
00619 {
00620 flashInterface->Rewind();
00621 }
00622
00623 void SFlashWidget::gotoFrame(long frameNum)
00624 {
00625 flashInterface->raw_GotoFrame(frameNum);
00626 }
00627
00628 void SFlashWidget::setLoop(bool shouldLoop)
00629 {
00630 flashInterface->PutLoop(shouldLoop);
00631 }
00632
00633 void SFlashWidget::setTransparent(bool isWidgetTransparent, bool useAlphaHack)
00634 {
00635 IFlashControl::isTransparent = isWidgetTransparent;
00636 if(isWidgetTransparent)
00637 flashInterface->PutWMode("transparent");
00638 else
00639 flashInterface->PutWMode("opaque");
00640 }
00641
00642 void SFlashWidget::setQuality(short renderQuality)
00643 {
00644 switch(renderQuality)
00645 {
00646 case SO3_FLASH_QUALITY_LOW:
00647 flashInterface->PutQuality2("low");
00648 break;
00649 case SO3_FLASH_QUALITY_MEDIUM:
00650 flashInterface->PutQuality2("medium");
00651 break;
00652 case SO3_FLASH_QUALITY_HIGH:
00653 flashInterface->PutQuality2("high");
00654 break;
00655 case SO3_FLASH_QUALITY_BEST:
00656 flashInterface->PutQuality2("best");
00657 break;
00658 case SO3_FLASH_QUALITY_AUTOLOW:
00659 flashInterface->PutQuality2("autolow");
00660 break;
00661 case SO3_FLASH_QUALITY_AUTOHIGH:
00662 flashInterface->PutQuality2("autohigh");
00663 break;
00664 }
00665 renderingQuality = static_cast <FlashRenderQuality> (renderQuality);
00666 }
00667
00668 void SFlashWidget::setScaleMode(short widgetScaleMode)
00669 {
00670 flashInterface->PutScaleMode(widgetScaleMode);
00671 scaleMode = static_cast <FlashScaleMode> (widgetScaleMode);
00672
00673
00674 }
00675
00676 void SFlashWidget::setDraggable(bool widgetDraggable)
00677 {
00678
00679 }
00680
00681 void SFlashWidget::setIgnoreTransparentPixels(bool shouldIgnore, float threshold)
00682 {
00683
00684 }
00685
00686 const std::string& SFlashWidget::getName() const
00687 {
00688 return SData::name;
00689 }
00690
00691 const std::string& SFlashWidget::getMaterialName() const
00692 {
00693
00694 return std::string("unused");
00695 }
00696
00697 void SFlashWidget::bind(const std::wstring& funcName, const Hikari::FlashDelegate& callback)
00698 {
00699
00700 }
00701
00702 void SFlashWidget::unbind(const std::wstring& funcName)
00703 {
00704
00705 }
00706
00707 Hikari::FlashValue SFlashWidget::callFunction(const std::wstring& funcName, const Hikari::Arguments& args)
00708 {
00709 BSTR returnVal = 0;
00710 HRESULT result = flashInterface->raw_CallFunction(_bstr_t(Hikari::Impl::serializeInvocation(funcName, args).c_str()), &returnVal);
00711 if(FAILED(result))
00712 {
00713
00714 std::string stringFunctionName;
00715 stringFunctionName.resize(funcName.size());
00716 wcstombs(&stringFunctionName[0], &funcName[0], funcName.size());
00717 OGRE_EXCEPT(Ogre::Exception::ERR_RT_ASSERTION_FAILED, "Failed to call ActionScript function '" + stringFunctionName + "' from FlashControl '" + SWidget::name + "'", "SFlashWidget::callFunction");
00718 }
00719
00720 return Hikari::Impl::deserializeValue((wchar_t*)returnVal);
00721 }
00722
00723 void SFlashWidget::hide()
00724 {
00725
00726 }
00727
00728 void SFlashWidget::show()
00729 {
00730
00731 }
00732
00733 bool SFlashWidget::getVisibility() const
00734 {
00735 return const_cast<SFlashWidget*> (this)->GetVisible();
00736 }
00737
00738 void SFlashWidget::setOpacity(float opacity)
00739 {
00740 }
00741
00742 void SFlashWidget::focus()
00743 {
00744 WindowHandle olewin = getTopWindow();
00745 SetFocus(olewin);
00746 }
00747
00748 void SFlashWidget::move(int deltaX, int deltaY)
00749 {
00750
00751 }
00752
00753 void SFlashWidget::getExtents(unsigned short& width, unsigned short& height) const
00754 {
00755
00756 }
00757
00758 void SFlashWidget::getUVScale(float& uScale, float& vScale) const
00759 {
00760 uScale = vScale = 1.0f;
00761 if(IsCompensateNPOT())
00762 {
00763 uScale = (float)SWidget::width/(float)textureWidth;
00764 vScale = (float)SWidget::height/(float)textureHeight;
00765 }
00766 }
00767
00768 void SFlashWidget::injectMouseMove(int xPos, int yPos, int btn)
00769 {
00770 LRESULT result;
00771 windowlessObject->OnWindowMessage(WM_MOUSEMOVE, btn, MAKELPARAM(xPos, yPos), &result);
00772 }
00773
00774 void SFlashWidget::injectMouseDown(int xPos, int yPos, int index)
00775 {
00776 LRESULT result;
00777 windowlessObject->OnWindowMessage(MouseButtonMessageConverter(index, true), index, MAKELPARAM(xPos, yPos), &result);
00778 }
00779
00780 void SFlashWidget::injectMouseUp(int xPos, int yPos, int index)
00781 {
00782 LRESULT result;
00783 windowlessObject->OnWindowMessage(MouseButtonMessageConverter(index, false), index, MAKELPARAM(xPos, yPos), &result);
00784 }
00785
00786 void SFlashWidget::injectMouseWheel(int relScroll, int xPos, int yPos)
00787 {
00788 LRESULT result;
00789 windowlessObject->OnWindowMessage(WM_MOUSEWHEEL, MAKEWPARAM(0, relScroll), MAKELPARAM(xPos, yPos), &result);
00790 }
00791
00792 void SFlashWidget::handleKeyEvent(UINT msg, WPARAM wParam, LPARAM lParam)
00793 {
00794 LRESULT aResult;
00795 windowlessObject->OnWindowMessage(msg, wParam, lParam, &aResult);
00796 }
00797
00798 UINT SFlashWidget::MouseButtonMessageConverter(const int button, bool pressed)
00799 {
00800 UINT value = WM_NULL;
00801 if(pressed)
00802 {
00803 switch(button)
00804 {
00805 case MK_LBUTTON:
00806 value = WM_LBUTTONDOWN;
00807 break;
00808 case MK_RBUTTON:
00809 value = WM_RBUTTONDOWN;
00810 break;
00811 case MK_MBUTTON:
00812 value = WM_MBUTTONDOWN;
00813 break;
00814 }
00815 }
00816 else
00817 {
00818 switch(button)
00819 {
00820 case MK_LBUTTON:
00821 value = WM_LBUTTONUP;
00822 break;
00823 case MK_RBUTTON:
00824 value = WM_RBUTTONUP;
00825 break;
00826 case MK_MBUTTON:
00827 value = WM_MBUTTONUP;
00828 break;
00829 }
00830 }
00831 return value;
00832 };
00833
00834 int SFlashWidget::GetPixelUnder(int posX, int posY)
00835 {
00836 if((posX <= SWidget::width) && (posY <= SWidget::height))
00837 {
00838 int color = renderBuffer->getBuffer()[posY*renderBuffer->rowSpan + posX*4 + 3];
00839 if (color > transparentTresholdColor * 255)
00840 return color;
00841 }
00842 return -1;
00843 }
00844
00845 }