Show
Ignore:
Timestamp:
07/16/08 00:03:59 (6 years ago)
Author:
robert
Message:

Converted tabs to four spaces

Files:
1 modified

Legend:

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

    r8588 r8600  
    1212// encapsulate into another class in osgWidget proper. 
    1313bool scrollWindow(osgWidget::Event& ev) { 
    14         // The first thing we need to do is make sure we have a Frame object... 
    15         osgWidget::Frame* frame = dynamic_cast<osgWidget::Frame*>(ev.getWindow()); 
     14    // The first thing we need to do is make sure we have a Frame object... 
     15    osgWidget::Frame* frame = dynamic_cast<osgWidget::Frame*>(ev.getWindow()); 
    1616 
    17         if(!frame) return false; 
     17    if(!frame) return false; 
    1818 
    19         // And now we need to make sure our Frame has a valid internal EmbeddedWindow widget. 
    20         osgWidget::Window::EmbeddedWindow* ew = 
    21                 dynamic_cast<osgWidget::Window::EmbeddedWindow*>(frame->getEmbeddedWindow()) 
    22         ; 
    23                  
    24         if(!ew) return false; 
    25          
    26         // Lets get the visible area so that we can use it to make sure our scrolling action 
    27         // is necessary in the first place. 
    28         const osgWidget::Quad& va = ew->getWindow()->getVisibleArea(); 
     19    // And now we need to make sure our Frame has a valid internal EmbeddedWindow widget. 
     20    osgWidget::Window::EmbeddedWindow* ew = 
     21        dynamic_cast<osgWidget::Window::EmbeddedWindow*>(frame->getEmbeddedWindow()) 
     22    ; 
     23         
     24    if(!ew) return false; 
     25     
     26    // Lets get the visible area so that we can use it to make sure our scrolling action 
     27    // is necessary in the first place. 
     28    const osgWidget::Quad& va = ew->getWindow()->getVisibleArea(); 
    2929 
    30         // The user wants to scroll up; make sure that the visible area's Y origin isn't already 
    31         // at 0.0f, 0.0f. 
    32         if(ev.getWindowManager()->isMouseScrollingUp() && va[1] != 0.0f) 
    33                 ew->getWindow()->addVisibleArea(0, -20) 
    34         ; 
    35          
    36         else if(va[1] <= (ew->getWindow()->getHeight() - ew->getHeight())) 
    37                 ew->getWindow()->addVisibleArea(0, 20) 
    38         ; 
     30    // The user wants to scroll up; make sure that the visible area's Y origin isn't already 
     31    // at 0.0f, 0.0f. 
     32    if(ev.getWindowManager()->isMouseScrollingUp() && va[1] != 0.0f) 
     33        ew->getWindow()->addVisibleArea(0, -20) 
     34    ; 
     35     
     36    else if(va[1] <= (ew->getWindow()->getHeight() - ew->getHeight())) 
     37        ew->getWindow()->addVisibleArea(0, 20) 
     38    ; 
    3939 
    40         // We need to manually call update to make sure the visible area scissoring is done 
    41         // properly. 
    42         frame->update(); 
     40    // We need to manually call update to make sure the visible area scissoring is done 
     41    // properly. 
     42    frame->update(); 
    4343 
    44         return true; 
     44    return true; 
    4545} 
    4646 
    4747bool changeTheme(osgWidget::Event& ev) { 
    48         std::string theme; 
     48    std::string theme; 
    4949 
    50         if(ev.key == osgGA::GUIEventAdapter::KEY_Right) 
    51                 theme = "osgWidget/theme-1.png" 
    52         ; 
     50    if(ev.key == osgGA::GUIEventAdapter::KEY_Right) 
     51        theme = "osgWidget/theme-1.png" 
     52    ; 
    5353 
    54         else if(ev.key == osgGA::GUIEventAdapter::KEY_Left) 
    55                 theme = "osgWidget/theme-2.png" 
    56         ; 
     54    else if(ev.key == osgGA::GUIEventAdapter::KEY_Left) 
     55        theme = "osgWidget/theme-2.png" 
     56    ; 
    5757 
    58         else return false; 
     58    else return false; 
    5959 
    60         osgWidget::Frame* frame = dynamic_cast<osgWidget::Frame*>(ev.getWindow()); 
     60    osgWidget::Frame* frame = dynamic_cast<osgWidget::Frame*>(ev.getWindow()); 
    6161 
    62         if(!frame) return false; 
     62    if(!frame) return false; 
    6363 
    64         // This is just one way to access all our Widgets; we could just as well have used: 
    65         // 
    66         // for(osgWidget::Frame::Iterator i = frame.begin(); i != frame.end() i++) {} 
    67         // 
    68         // ...and it have worked, too. 
    69         for(unsigned int row = 0; row < 3; row++) { 
    70                 for(unsigned int col = 0; col < 3; col++) { 
    71                         frame->getByRowCol(row, col)->setImage(theme); 
    72                 } 
    73         } 
     64    // This is just one way to access all our Widgets; we could just as well have used: 
     65    // 
     66    // for(osgWidget::Frame::Iterator i = frame.begin(); i != frame.end() i++) {} 
     67    // 
     68    // ...and it have worked, too. 
     69    for(unsigned int row = 0; row < 3; row++) { 
     70        for(unsigned int col = 0; col < 3; col++) { 
     71            frame->getByRowCol(row, col)->setImage(theme); 
     72        } 
     73    } 
    7474 
    75         return true; 
     75    return true; 
    7676} 
    7777 
    7878int main(int argc, char** argv) { 
    79         osgViewer::Viewer viewer; 
     79    osgViewer::Viewer viewer; 
    8080 
    81         osgWidget::WindowManager* wm = new osgWidget::WindowManager( 
    82                 &viewer, 
    83                 1280.0f, 
    84                 1024.0f, 
    85                 MASK_2D, 
    86                 osgWidget::WindowManager::WM_PICK_DEBUG 
    87         ); 
    88          
    89         osgWidget::Frame* frame = osgWidget::Frame::createSimpleFrameWithSingleTexture( 
    90                 "frame", 
    91                 "../examples/osgwidgetscrolled/theme-2.png", 
    92                 64.0f, 
    93                 64.0f, 
    94                 16.0f, 
    95                 16.0f, 
    96                 100.0f, 
    97                 100.0f 
    98         ); 
     81    osgWidget::WindowManager* wm = new osgWidget::WindowManager( 
     82        &viewer, 
     83        1280.0f, 
     84        1024.0f, 
     85        MASK_2D, 
     86        osgWidget::WindowManager::WM_PICK_DEBUG 
     87    ); 
     88     
     89    osgWidget::Frame* frame = osgWidget::Frame::createSimpleFrameWithSingleTexture( 
     90        "frame", 
     91        "../examples/osgwidgetscrolled/theme-2.png", 
     92        64.0f, 
     93        64.0f, 
     94        16.0f, 
     95        16.0f, 
     96        100.0f, 
     97        100.0f 
     98    ); 
    9999 
    100         frame->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f); 
     100    frame->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f); 
    101101 
    102         // This is our Transformers box. :) 
    103         osgWidget::Box*    box  = new osgWidget::Box("images", osgWidget::Box::VERTICAL); 
    104         osgWidget::Widget* img1 = new osgWidget::Widget("im1", 256.0f, 256.0f); 
    105         osgWidget::Widget* img2 = new osgWidget::Widget("im2", 256.0f, 256.0f); 
    106         osgWidget::Widget* img3 = new osgWidget::Widget("im3", 256.0f, 256.0f); 
    107         osgWidget::Widget* img4 = new osgWidget::Widget("im4", 256.0f, 256.0f); 
     102    // This is our Transformers box. :) 
     103    osgWidget::Box*    box  = new osgWidget::Box("images", osgWidget::Box::VERTICAL); 
     104    osgWidget::Widget* img1 = new osgWidget::Widget("im1", 256.0f, 256.0f); 
     105    osgWidget::Widget* img2 = new osgWidget::Widget("im2", 256.0f, 256.0f); 
     106    osgWidget::Widget* img3 = new osgWidget::Widget("im3", 256.0f, 256.0f); 
     107    osgWidget::Widget* img4 = new osgWidget::Widget("im4", 256.0f, 256.0f); 
    108108 
    109         img1->setImage("../examples/osgwidgetscrolled/images/starscream.jpg", true); 
    110         img2->setImage("../examples/osgwidgetscrolled/images/optimus.jpg", true); 
    111         img3->setImage("../examples/osgwidgetscrolled/images/megatron.jpg", true); 
    112         img4->setImage("../examples/osgwidgetscrolled/images/bumblebee.jpg", true); 
     109    img1->setImage("../examples/osgwidgetscrolled/images/starscream.jpg", true); 
     110    img2->setImage("../examples/osgwidgetscrolled/images/optimus.jpg", true); 
     111    img3->setImage("../examples/osgwidgetscrolled/images/megatron.jpg", true); 
     112    img4->setImage("../examples/osgwidgetscrolled/images/bumblebee.jpg", true); 
    113113 
    114         img1->setMinimumSize(10.0f, 10.0f); 
    115         img2->setMinimumSize(10.0f, 10.0f); 
    116         img3->setMinimumSize(10.0f, 10.0f); 
    117         img4->setMinimumSize(10.0f, 10.0f); 
     114    img1->setMinimumSize(10.0f, 10.0f); 
     115    img2->setMinimumSize(10.0f, 10.0f); 
     116    img3->setMinimumSize(10.0f, 10.0f); 
     117    img4->setMinimumSize(10.0f, 10.0f); 
    118118 
    119         box->addWidget(img1); 
    120         box->addWidget(img2); 
    121         box->addWidget(img3); 
    122         box->addWidget(img4); 
    123         box->setEventMask(osgWidget::EVENT_NONE); 
     119    box->addWidget(img1); 
     120    box->addWidget(img2); 
     121    box->addWidget(img3); 
     122    box->addWidget(img4); 
     123    box->setEventMask(osgWidget::EVENT_NONE); 
    124124 
    125         frame->getEmbeddedWindow()->setWindow(box); 
    126         frame->getEmbeddedWindow()->setColor(1.0f, 1.0f, 1.0f, 1.0f); 
    127         frame->resize(300.0f, 300.0f); 
    128         frame->addCallback(osgWidget::Callback(&scrollWindow, osgWidget::EVENT_MOUSE_SCROLL)); 
    129         frame->addCallback(osgWidget::Callback(&changeTheme, osgWidget::EVENT_KEY_DOWN)); 
     125    frame->getEmbeddedWindow()->setWindow(box); 
     126    frame->getEmbeddedWindow()->setColor(1.0f, 1.0f, 1.0f, 1.0f); 
     127    frame->resize(300.0f, 300.0f); 
     128    frame->addCallback(osgWidget::Callback(&scrollWindow, osgWidget::EVENT_MOUSE_SCROLL)); 
     129    frame->addCallback(osgWidget::Callback(&changeTheme, osgWidget::EVENT_KEY_DOWN)); 
    130130 
    131         wm->addChild(frame); 
     131    wm->addChild(frame); 
    132132 
    133         return osgWidget::createExample(viewer, wm); 
     133    return osgWidget::createExample(viewer, wm); 
    134134}