Show
Ignore:
Timestamp:
12/16/08 21:29:00 (6 years ago)
Author:
robert
Message:

From Cedric Pinson and Jeremey Moles, Changes to OpenSceneGraph-osgWidget-dev branch.

Notes from Robert Osfield, Merged changes to OpenSceneGraph-osgWidget-dev r9367 (prior to my botched attempt at merged svn/trunk into the branch).

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgwidgetprogress/osgwidgetprogress.cpp

    r9289 r9370  
    1010 
    1111struct UpdateProgressNode: public osg::NodeCallback { 
    12         float start; 
    13         float done; 
     12    float start; 
     13    float done; 
    1414 
    15         UpdateProgressNode(): 
    16         start (0.0f), 
    17         done  (5.0f) { 
    18         } 
     15    UpdateProgressNode(): 
     16    start (0.0f), 
     17    done  (5.0f) { 
     18    } 
    1919 
    20         virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) { 
    21                 const osg::FrameStamp* fs = nv->getFrameStamp(); 
     20    virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) { 
     21        const osg::FrameStamp* fs = nv->getFrameStamp(); 
    2222 
    23                 float t = fs->getSimulationTime(); 
     23        float t = fs->getSimulationTime(); 
    2424 
    25                 if(start == 0.0f) start = t; 
     25        if(start == 0.0f) start = t; 
    2626 
    27                 float width   = ((t - start) / done) * 512.0f; 
    28                 float percent = (width / 512.0f) * 100.0f; 
    29          
    30                 if(width < 1.0f || width > 512.0f) return; 
     27        float width   = ((t - start) / done) * 512.0f; 
     28        float percent = (width / 512.0f) * 100.0f; 
     29     
     30        if(width < 1.0f || width > 512.0f) return; 
    3131 
    32                 osgWidget::Window* window = dynamic_cast<osgWidget::Window*>(node); 
     32        osgWidget::Window* window = dynamic_cast<osgWidget::Window*>(node); 
    3333 
    34                 if(!window) return; 
     34        if(!window) return; 
    3535 
    36                 osgWidget::Widget* w = window->getByName("pMeter"); 
    37                 osgWidget::Label*  l = dynamic_cast<osgWidget::Label*>(window->getByName("pLabel")); 
     36        osgWidget::Widget* w = window->getByName("pMeter"); 
     37        osgWidget::Label*  l = dynamic_cast<osgWidget::Label*>(window->getByName("pLabel")); 
    3838 
    39                 if(!w || !l) return; 
     39        if(!w || !l) return; 
    4040 
    41                 w->setWidth(width); 
    42                 w->setTexCoordRegion(0.0f, 0.0f, width, 64.0f); 
     41        w->setWidth(width); 
     42        w->setTexCoordRegion(0.0f, 0.0f, width, 64.0f); 
    4343 
    44                 std::ostringstream ss; 
     44        std::ostringstream ss; 
    4545 
    46                 ss << osg::round(percent) << "% Done" << std::endl; 
     46        ss << osg::round(percent) << "% Done" << std::endl; 
    4747 
    48                 l->setLabel(ss.str()); 
    49         } 
     48        l->setLabel(ss.str()); 
     49    } 
    5050}; 
    5151 
    5252int main(int argc, char** argv) { 
    53         osgViewer::Viewer viewer; 
     53    osgViewer::Viewer viewer; 
    5454 
    55         osgWidget::WindowManager* wm = new osgWidget::WindowManager( 
    56                 &viewer, 
    57                 1280.0f, 
    58                 1024.0f, 
    59                 MASK_2D, 
    60                 osgWidget::WindowManager::WM_PICK_DEBUG 
    61         ); 
    62          
    63         osgWidget::Canvas* canvas   = new osgWidget::Canvas("canvas"); 
    64         osgWidget::Widget* pOutline = new osgWidget::Widget("pOutline", 512.0f, 64.0f); 
    65         osgWidget::Widget* pMeter   = new osgWidget::Widget("pMeter", 0.0f, 64.0f); 
    66         osgWidget::Label*  pLabel   = new osgWidget::Label("pLabel", "0% Done"); 
     55    osgWidget::WindowManager* wm = new osgWidget::WindowManager( 
     56        &viewer, 
     57        1280.0f, 
     58        1024.0f, 
     59        MASK_2D, 
     60        osgWidget::WindowManager::WM_PICK_DEBUG 
     61    ); 
     62     
     63    osgWidget::Canvas* canvas   = new osgWidget::Canvas("canvas"); 
     64    osgWidget::Widget* pOutline = new osgWidget::Widget("pOutline", 512.0f, 64.0f); 
     65    osgWidget::Widget* pMeter   = new osgWidget::Widget("pMeter", 0.0f, 64.0f); 
     66    osgWidget::Label*  pLabel   = new osgWidget::Label("pLabel", "0% Done"); 
    6767 
    68         pOutline->setImage("osgWidget/progress-outline.png", true); 
    69         pOutline->setLayer(osgWidget::Widget::LAYER_MIDDLE, 2); 
    70          
    71         pMeter->setImage("osgWidget/progress-meter.png"); 
    72         pMeter->setColor(0.7f, 0.1f, 0.1f, 0.7f); 
    73         pMeter->setLayer(osgWidget::Widget::LAYER_MIDDLE, 1); 
     68    pOutline->setImage("osgWidget/progress-outline.png", true); 
     69    pOutline->setLayer(osgWidget::Widget::LAYER_MIDDLE, 2); 
     70     
     71    pMeter->setImage("osgWidget/progress-meter.png"); 
     72    pMeter->setColor(0.7f, 0.1f, 0.1f, 0.7f); 
     73    pMeter->setLayer(osgWidget::Widget::LAYER_MIDDLE, 1); 
    7474 
    75         pLabel->setFont("fonts/VeraMono.ttf"); 
    76         pLabel->setFontSize(20); 
    77         pLabel->setFontColor(1.0f, 1.0f, 1.0f, 1.0f); 
    78         pLabel->setSize(512.0f, 64.0f); 
    79         pLabel->setLayer(osgWidget::Widget::LAYER_MIDDLE, 3); 
     75    pLabel->setFont("fonts/VeraMono.ttf"); 
     76    pLabel->setFontSize(20); 
     77    pLabel->setFontColor(1.0f, 1.0f, 1.0f, 1.0f); 
     78    pLabel->setSize(512.0f, 64.0f); 
     79    pLabel->setLayer(osgWidget::Widget::LAYER_MIDDLE, 3); 
    8080 
    81         canvas->setOrigin(300.0f, 300.0f); 
    82         canvas->addWidget(pMeter, 0.0f, 0.0f); 
    83         canvas->addWidget(pOutline, 0.0f, 0.0f); 
    84         canvas->addWidget(pLabel, 0.0f, 0.0f); 
    85         canvas->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f); 
    86         canvas->setUpdateCallback(new UpdateProgressNode()); 
     81    canvas->setOrigin(300.0f, 300.0f); 
     82    canvas->addWidget(pMeter, 0.0f, 0.0f); 
     83    canvas->addWidget(pOutline, 0.0f, 0.0f); 
     84    canvas->addWidget(pLabel, 0.0f, 0.0f); 
     85    canvas->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f); 
     86    canvas->setUpdateCallback(new UpdateProgressNode()); 
    8787 
    88         wm->addChild(canvas); 
     88    wm->addChild(canvas); 
    8989 
    90         return osgWidget::createExample(viewer, wm, osgDB::readNodeFile("cow.osg")); 
     90    return osgWidget::createExample(viewer, wm, osgDB::readNodeFile("cow.osg")); 
    9191}