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/osgwidgetcanvas/osgwidgetcanvas.cpp

    r9289 r9370  
    99 
    1010bool colorWidgetEnter(osgWidget::Event& event) { 
    11         event.getWidget()->addColor(0.5f, 0.2f, 0.3f, 0.0f); 
     11    event.getWidget()->addColor(0.5f, 0.2f, 0.3f, 0.0f); 
    1212 
    13         // osgWidget::warn() << "WIDGET mouseEnter " << event.getWidget()->getName() << std::endl; 
    14          
    15         return false; 
     13    // osgWidget::warn() << "WIDGET mouseEnter " << event.getWidget()->getName() << std::endl; 
     14     
     15    return false; 
    1616} 
    1717 
    1818bool colorWidgetLeave(osgWidget::Event& event) { 
    19         event.getWidget()->addColor(-0.5f, -0.2f, -0.3f, 0.0f); 
     19    event.getWidget()->addColor(-0.5f, -0.2f, -0.3f, 0.0f); 
    2020 
    21         // osgWidget::warn() << "WIDGET mouseLeave" << std::endl; 
    22          
    23         return true; 
     21    // osgWidget::warn() << "WIDGET mouseLeave" << std::endl; 
     22     
     23    return true; 
    2424} 
    2525 
    2626bool windowMouseOver(osgWidget::Event& event) { 
    27         osgWidget::XYCoord xy = event.getWindow()->localXY(event.x, event.y); 
     27    osgWidget::XYCoord xy = event.getWindow()->localXY(event.x, event.y); 
    2828 
    29         // osgWidget::warn() << "WINDOW " << xy.x() << " - " << xy.y() << std::endl; 
     29    // osgWidget::warn() << "WINDOW " << xy.x() << " - " << xy.y() << std::endl; 
    3030 
    31         return true; 
     31    return true; 
    3232} 
    3333 
    3434bool widgetMouseOver(osgWidget::Event& event) { 
    35         osgWidget::XYCoord xy = event.getWidget()->localXY(event.x, event.y); 
     35    osgWidget::XYCoord xy = event.getWidget()->localXY(event.x, event.y); 
    3636 
    37         // osgWidget::warn() << "WIDGET mouseOver " << xy.x() << " - " << xy.y() << std::endl; 
     37    // osgWidget::warn() << "WIDGET mouseOver " << xy.x() << " - " << xy.y() << std::endl; 
    3838 
    39         return true; 
     39    return true; 
    4040} 
    4141 
    4242osgWidget::Widget* createWidget( 
    43         const std::string&       name, 
    44         osgWidget::color_type    col, 
    45         osgWidget::Widget::Layer layer 
     43    const std::string&       name, 
     44    osgWidget::color_type    col, 
     45    osgWidget::Widget::Layer layer 
    4646) { 
    47         osgWidget::Widget* widget = new osgWidget::Widget(name, 200.0f, 200.0f); 
     47    osgWidget::Widget* widget = new osgWidget::Widget(name, 200.0f, 200.0f); 
    4848 
    49         widget->setEventMask(osgWidget::EVENT_ALL); 
    50         widget->addCallback(new osgWidget::Callback(&colorWidgetEnter, osgWidget::EVENT_MOUSE_PUSH)); 
    51         widget->addCallback(new osgWidget::Callback(&colorWidgetLeave, osgWidget::EVENT_MOUSE_RELEASE)); 
    52         widget->addCallback(new osgWidget::Callback(&colorWidgetEnter, osgWidget::EVENT_MOUSE_ENTER)); 
    53         widget->addCallback(new osgWidget::Callback(&colorWidgetLeave, osgWidget::EVENT_MOUSE_LEAVE)); 
    54         widget->addCallback(new osgWidget::Callback(&widgetMouseOver, osgWidget::EVENT_MOUSE_OVER)); 
    55         widget->setColor(col, col, col, 0.5f); 
    56         widget->setLayer(layer); 
    57          
    58         return widget; 
     49    widget->setEventMask(osgWidget::EVENT_ALL); 
     50    widget->addCallback(new osgWidget::Callback(&colorWidgetEnter, osgWidget::EVENT_MOUSE_PUSH)); 
     51    widget->addCallback(new osgWidget::Callback(&colorWidgetLeave, osgWidget::EVENT_MOUSE_RELEASE)); 
     52    widget->addCallback(new osgWidget::Callback(&colorWidgetEnter, osgWidget::EVENT_MOUSE_ENTER)); 
     53    widget->addCallback(new osgWidget::Callback(&colorWidgetLeave, osgWidget::EVENT_MOUSE_LEAVE)); 
     54    widget->addCallback(new osgWidget::Callback(&widgetMouseOver, osgWidget::EVENT_MOUSE_OVER)); 
     55    widget->setColor(col, col, col, 0.5f); 
     56    widget->setLayer(layer); 
     57     
     58    return widget; 
    5959} 
    6060 
    6161int main(int argc, char** argv) { 
    62         osgViewer::Viewer viewer; 
     62    osgViewer::Viewer viewer; 
    6363 
    64         osgWidget::WindowManager* wm = new osgWidget::WindowManager( 
    65                 &viewer, 
    66                 1280.0f, 
    67                 1024.0f, 
    68                 MASK_2D, 
    69                 osgWidget::WindowManager::WM_PICK_DEBUG 
    70         ); 
    71          
    72         osgWidget::Canvas* canvas = new osgWidget::Canvas("canvas"); 
     64    osgWidget::WindowManager* wm = new osgWidget::WindowManager( 
     65        &viewer, 
     66        1280.0f, 
     67        1024.0f, 
     68        MASK_2D, 
     69        osgWidget::WindowManager::WM_PICK_DEBUG 
     70    ); 
     71     
     72    osgWidget::Canvas* canvas = new osgWidget::Canvas("canvas"); 
    7373 
    74         canvas->addCallback(new osgWidget::Callback(&windowMouseOver, osgWidget::EVENT_MOUSE_OVER)); 
    75         canvas->attachMoveCallback(); 
    76         canvas->attachRotateCallback(); 
    77         canvas->attachScaleCallback(); 
     74    canvas->addCallback(new osgWidget::Callback(&windowMouseOver, osgWidget::EVENT_MOUSE_OVER)); 
     75    canvas->attachMoveCallback(); 
     76    canvas->attachRotateCallback(); 
     77    canvas->attachScaleCallback(); 
    7878 
    79         canvas->addWidget( 
    80                 createWidget("w1", 0.2f, osgWidget::Widget::LAYER_LOW), 
    81                 0.0f, 
    82                 0.0f 
    83         ); 
    84          
    85         canvas->addWidget( 
    86                 createWidget("w2", 0.4f, osgWidget::Widget::LAYER_MIDDLE), 
    87                 200.0f, 
    88                 0.0f 
    89         ); 
     79    canvas->addWidget( 
     80        createWidget("w1", 0.2f, osgWidget::Widget::LAYER_LOW), 
     81        0.0f, 
     82        0.0f 
     83    ); 
     84     
     85    canvas->addWidget( 
     86        createWidget("w2", 0.4f, osgWidget::Widget::LAYER_MIDDLE), 
     87        200.0f, 
     88        0.0f 
     89    ); 
    9090 
    91         canvas->addWidget( 
    92                 createWidget("w3", 0.6f, osgWidget::Widget::LAYER_HIGH), 
    93                 400.0f, 
    94                 0.0f 
    95         ); 
     91    canvas->addWidget( 
     92        createWidget("w3", 0.6f, osgWidget::Widget::LAYER_HIGH), 
     93        400.0f, 
     94        0.0f 
     95    ); 
    9696 
    97         // Add a child and then resize it relatively to the size of the parent Window. 
    98         osgWidget::Widget* relWidget = new osgWidget::Widget("relative"); 
     97    // Add a child and then resize it relatively to the size of the parent Window. 
     98    osgWidget::Widget* relWidget = new osgWidget::Widget("relative"); 
    9999 
    100         relWidget->setLayer(osgWidget::Widget::LAYER_LOW, 1); 
    101         relWidget->setCoordinateMode(osgWidget::Widget::CM_RELATIVE); 
    102         relWidget->setSize(0.2f, 0.2f); 
    103         relWidget->setColor(0.5f, 0.5f, 0.1f, 0.9f); 
     100    relWidget->setLayer(osgWidget::Widget::LAYER_LOW, 1); 
     101    relWidget->setCoordinateMode(osgWidget::Widget::CM_RELATIVE); 
     102    relWidget->setSize(0.2f, 0.2f); 
     103    relWidget->setColor(0.5f, 0.5f, 0.1f, 0.9f); 
    104104 
    105         osgWidget::warn() << canvas->getWidth() << std::endl; 
     105    osgWidget::warn() << canvas->getWidth() << std::endl; 
    106106 
    107         canvas->addWidget(relWidget, 0.4f, 0.4f); 
    108          
    109         relWidget->addOrigin(0.1f, 0.1f); 
    110         relWidget->addSize(0.2f, 0.2f); 
     107    canvas->addWidget(relWidget, 0.4f, 0.4f); 
     108     
     109    relWidget->addOrigin(0.1f, 0.1f); 
     110    relWidget->addSize(0.2f, 0.2f); 
    111111 
    112         canvas->resize(); 
     112    canvas->resize(); 
    113113 
    114         // Finally, add the whole thing to the WindowManager. 
    115         wm->addChild(canvas); 
     114    // Finally, add the whole thing to the WindowManager. 
     115    wm->addChild(canvas); 
    116116 
    117         return osgWidget::createExample(viewer, wm); 
     117    return osgWidget::createExample(viewer, wm); 
    118118} 
    119119 
    120120/* 
    121121int main(int argc, char** argv) { 
    122         osgViewer::Viewer viewer; 
     122    osgViewer::Viewer viewer; 
    123123 
    124         osgWidget::WindowManager* wm = new osgWidget::WindowManager( 
    125                 &viewer, 
    126                 1280.0f, 
    127                 1024.0f, 
    128                 MASK_2D, 
    129                 osgWidget::WindowManager::WM_PICK_DEBUG 
    130         ); 
    131          
    132         osgWidget::Canvas* canvas = new osgWidget::Canvas("canvas"); 
     124    osgWidget::WindowManager* wm = new osgWidget::WindowManager( 
     125        &viewer, 
     126        1280.0f, 
     127        1024.0f, 
     128        MASK_2D, 
     129        osgWidget::WindowManager::WM_PICK_DEBUG 
     130    ); 
     131     
     132    osgWidget::Canvas* canvas = new osgWidget::Canvas("canvas"); 
    133133 
    134         canvas->addWidget(new osgWidget::Widget("spacer", 2.0f, 300.0f), 1280.0f, 0.0f); 
     134    canvas->addWidget(new osgWidget::Widget("spacer", 2.0f, 300.0f), 1280.0f, 0.0f); 
    135135 
    136         canvas->setOrigin(0.0f, 300.0f); 
     136    canvas->setOrigin(0.0f, 300.0f); 
    137137 
    138         wm->addChild(canvas); 
     138    wm->addChild(canvas); 
    139139 
    140         return osgWidget::createExample(viewer, wm); 
     140    return osgWidget::createExample(viewer, wm); 
    141141} 
    142142*/