Revision: 2451
          http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2451&view=rev
Author:   rorthomas
Date:     2012-02-05 07:04:08 +0000 (Sun, 05 Feb 2012)
Log Message:
-----------
improved first skia example

Modified Paths:
--------------
    trunk/source/main/physics/threading/BeamWorkerManager.cpp
    trunk/source/main/physics/threading/BeamWorkerManager.h

Modified: trunk/source/main/physics/threading/BeamWorkerManager.cpp
===================================================================
--- trunk/source/main/physics/threading/BeamWorkerManager.cpp   2012-02-04 
22:26:29 UTC (rev 2450)
+++ trunk/source/main/physics/threading/BeamWorkerManager.cpp   2012-02-05 
07:04:08 UTC (rev 2451)
@@ -32,10 +32,6 @@
 #include <time.h>
 #include "OgrePanelOverlayElement.h"
 
-#ifdef USE_SKIA
-#include <CanvasTexture.h>
-#endif // USE_SKIA
-
 using namespace Ogre;
 
 void *threadWorkerManagerEntry(void* ptr)
@@ -54,6 +50,8 @@
                , done_count(0)
                , done_count_mutex()
                , done_count_cv()
+               , mCanvasTextureClock1(0)
+               , rot(0)
 
 {
        pthread_mutex_init(&api_mutex, NULL);
@@ -221,27 +219,57 @@
        // return to continue to do work
 }
 
-void BeamWorkerManager::initDebugging()
+bool BeamWorkerManager::frameStarted(const FrameEvent& evt)
+{
+#ifdef USE_SKIA
+       if(mCanvasTextureClock1)
+               updateDebugging(evt.timeSinceLastEvent);
+#endif // USE_SKIA
+       return true;
+}
+
+void BeamWorkerManager::updateDebugging(float dt)
 {
 #ifdef USE_SKIA
-       Ogre::Canvas::Texture *mCanvasTextureClock1 = new 
Ogre::Canvas::Texture("CanvasClock1", 150, 150);
-       mCanvasTextureClock1->createMaterial();
+       rot += dt;
 
        // paint
        Ogre::Canvas::Context* ctx = mCanvasTextureClock1->getContext();
        ctx->save();            
-       ctx->clearRect(0, 0, 150, 150);
+       ctx->clearRect(0, 0, 200, 150);
        ctx->strokeStyle(Ogre::ColourValue::Black);
        ctx->fillStyle(Ogre::ColourValue::White);
-       ctx->fillRect(0, 0, 150, 150);
+       ctx->fillRect(0, 0, 200, 150);
        ctx->translate(75, 75);
        ctx->scale(0.4f, 0.4f);
        ctx->rotate(-Ogre::Math::PI/2.0f);
        ctx->lineWidth(8);
        ctx->lineCap(Ogre::Canvas::LineCap_Round);
+       // Hour marks
+       //ctx->save();
+       for (float i=0; i<12; i++)
+       {
+               ctx->beginPath();
+               ctx->rotate(Ogre::Math::PI/6.0f  + rot);
+               ctx->moveTo(100, 0);
+               ctx->lineTo(120, 0);
+               ctx->stroke();
+       }
        ctx->restore();
+
+       ctx->fillText("dt: " + TOSTRING(dt), 10, 10);
+
        mCanvasTextureClock1->uploadTexture();
+#endif // USE_SKIA
+}
+void BeamWorkerManager::initDebugging()
+{
+#ifdef USE_SKIA
+       // first, create skia texture
+       mCanvasTextureClock1 = new Ogre::Canvas::Texture("CanvasClock1", 600, 
150);
+       mCanvasTextureClock1->createMaterial();
 
+       // the ogre overlay
        Ogre::Overlay* overlay = 
Ogre::OverlayManager::getSingleton().create("Canvas/Overlay");
        Ogre::PanelOverlayElement* panel = 
static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel",
 "CanvasClock1/Panel"));
        panel->setMetricsMode(Ogre::GMM_PIXELS);
@@ -250,5 +278,8 @@
        panel->setPosition(0, 0);
        overlay->add2D(panel);
        overlay->show();
+
+       // then add ourself as frame listener
+       Ogre::Root::getSingleton().addFrameListener(this);
 #endif // USE_SKIA
 }
\ No newline at end of file

Modified: trunk/source/main/physics/threading/BeamWorkerManager.h
===================================================================
--- trunk/source/main/physics/threading/BeamWorkerManager.h     2012-02-04 
22:26:29 UTC (rev 2450)
+++ trunk/source/main/physics/threading/BeamWorkerManager.h     2012-02-05 
07:04:08 UTC (rev 2451)
@@ -27,11 +27,16 @@
 #include "Singleton.h"
 #include "utils.h"
 
+#ifdef USE_SKIA
+#include <CanvasTexture.h>
+#endif // USE_SKIA
+
 class BeamThread;
 
 // Manager that manages all threads and the beam locking
 class BeamWorkerManager :
-         public RoRSingleton<BeamWorkerManager>
+           public RoRSingleton<BeamWorkerManager>
+         , Ogre::FrameListener
 {
        friend class BeamThread;
        friend class RoRSingleton<BeamWorkerManager>;
@@ -62,7 +67,14 @@
        void removeThread(BeamThread *bthread);
        void syncThreads(BeamThread *bthread);
        void initDebugging();
+       void updateDebugging(float dt);
 
+#ifdef USE_SKIA
+       Ogre::Canvas::Texture *mCanvasTextureClock1;
+       float rot;
+#endif // USE_SKIA
+
+       bool frameStarted(const FrameEvent& evt);
 public:
        static void createThread();
        void _startWorkerLoop();

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Rigsofrods-devel mailing list
Rigsofrods-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel

Reply via email to