Converted tabs to four spaces

This commit is contained in:
Robert Osfield
2008-07-15 22:03:59 +00:00
parent e6c99b0434
commit 8fe0820bb8
8 changed files with 655 additions and 655 deletions

View File

@@ -11,124 +11,124 @@ const unsigned int MASK_2D = 0xF0000000;
class ABCWidget: public osgWidget::Label {
public:
ABCWidget(const std::string& label):
osgWidget::Label("", label) {
setFont("fonts/Calibri1.ttf");
setFontSize(20);
setCanFill(true);
setShadow(0.08f);
addSize(10.0f, 10.0f);
}
ABCWidget(const std::string& label):
osgWidget::Label("", label) {
setFont("fonts/Calibri1.ttf");
setFontSize(20);
setCanFill(true);
setShadow(0.08f);
addSize(10.0f, 10.0f);
}
};
class Button: public osgWidget::Label {
public:
Button(const std::string& label):
osgWidget::Label("", label) {
setFont("fonts/Calibri1.ttf");
setFontSize(30);
setColor(0.8f, 0.2f, 0.2f, 0.8f);
setCanFill(true);
setShadow(0.1f);
setEventMask(osgWidget::EVENT_MASK_MOUSE_CLICK);
addSize(20.0f, 20.0f);
}
Button(const std::string& label):
osgWidget::Label("", label) {
setFont("fonts/Calibri1.ttf");
setFontSize(30);
setColor(0.8f, 0.2f, 0.2f, 0.8f);
setCanFill(true);
setShadow(0.1f);
setEventMask(osgWidget::EVENT_MASK_MOUSE_CLICK);
addSize(20.0f, 20.0f);
}
// NOTE! I need to make it clearer than Push/Release can happen so fast that
// the changes you make aren't visible with your refresh rate. Throttling state
// changes and what-have-you on mousePush/mouseRelease/etc. is going to be
// annoying...
// NOTE! I need to make it clearer than Push/Release can happen so fast that
// the changes you make aren't visible with your refresh rate. Throttling state
// changes and what-have-you on mousePush/mouseRelease/etc. is going to be
// annoying...
virtual bool mousePush(double, double, osgWidget::WindowManager*) {
addColor(0.2f, 0.2f, 0.2f, 0.0f);
return true;
}
virtual bool mousePush(double, double, osgWidget::WindowManager*) {
addColor(0.2f, 0.2f, 0.2f, 0.0f);
return true;
}
virtual bool mouseRelease(double, double, osgWidget::WindowManager*) {
addColor(-0.2f, -0.2f, -0.2f, 0.0f);
return true;
}
virtual bool mouseRelease(double, double, osgWidget::WindowManager*) {
addColor(-0.2f, -0.2f, -0.2f, 0.0f);
return true;
}
};
class AddRemove: public osgWidget::Box {
osg::ref_ptr<osgWidget::Window> _win1;
osg::ref_ptr<osgWidget::Window> _win1;
public:
AddRemove():
osgWidget::Box ("buttons", osgWidget::Box::VERTICAL),
_win1 (new osgWidget::Box("win1", osgWidget::Box::VERTICAL)) {
addWidget(new Button("Add Widget"));
addWidget(new Button("Remove Widget"));
AddRemove():
osgWidget::Box ("buttons", osgWidget::Box::VERTICAL),
_win1 (new osgWidget::Box("win1", osgWidget::Box::VERTICAL)) {
addWidget(new Button("Add Widget"));
addWidget(new Button("Remove Widget"));
// Take special note here! Not only do the Button objects have their
// own overridden methods for changing the color, but they have attached
// callbacks for doing the work with local data.
getByName("Widget_1")->addCallback(osgWidget::Callback(
&AddRemove::handlePressAdd,
this,
osgWidget::EVENT_MOUSE_PUSH
));
// Take special note here! Not only do the Button objects have their
// own overridden methods for changing the color, but they have attached
// callbacks for doing the work with local data.
getByName("Widget_1")->addCallback(osgWidget::Callback(
&AddRemove::handlePressAdd,
this,
osgWidget::EVENT_MOUSE_PUSH
));
getByName("Widget_2")->addCallback(osgWidget::Callback(
&AddRemove::handlePressRemove,
this,
osgWidget::EVENT_MOUSE_PUSH
));
}
getByName("Widget_2")->addCallback(osgWidget::Callback(
&AddRemove::handlePressRemove,
this,
osgWidget::EVENT_MOUSE_PUSH
));
}
virtual void managed(osgWidget::WindowManager* wm) {
osgWidget::Box::managed(wm);
virtual void managed(osgWidget::WindowManager* wm) {
osgWidget::Box::managed(wm);
_win1->setOrigin(250.0f, 0.0f);
_win1->setOrigin(250.0f, 0.0f);
wm->addChild(_win1.get());
}
wm->addChild(_win1.get());
}
bool handlePressAdd(osgWidget::Event& ev) {
static unsigned int num = 0;
bool handlePressAdd(osgWidget::Event& ev) {
static unsigned int num = 0;
std::stringstream ss;
std::stringstream ss;
ss << "a random widget " << num;
ss << "a random widget " << num;
_win1->addWidget(new ABCWidget(ss.str()));
_win1->resize();
_win1->addWidget(new ABCWidget(ss.str()));
_win1->resize();
num++;
num++;
return true;
}
return true;
}
bool handlePressRemove(osgWidget::Event& ev) {
// TODO: Temporary hack!
const osgWidget::Box::Vector& v = _win1->getObjects();
if(!v.size()) return false;
bool handlePressRemove(osgWidget::Event& ev) {
// TODO: Temporary hack!
const osgWidget::Box::Vector& v = _win1->getObjects();
if(!v.size()) return false;
osgWidget::Widget* w = _win1->getObjects()[v.size() - 1].get();
osgWidget::Widget* w = _win1->getObjects()[v.size() - 1].get();
_win1->removeWidget(w);
_win1->resize();
_win1->removeWidget(w);
_win1->resize();
return true;
}
return true;
}
};
int main(int argc, char** argv) {
osgViewer::Viewer viewer;
osgViewer::Viewer viewer;
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
&viewer,
1280.0f,
1024.0f,
MASK_2D
);
osgWidget::Box* buttons = new AddRemove();
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
&viewer,
1280.0f,
1024.0f,
MASK_2D
);
osgWidget::Box* buttons = new AddRemove();
wm->addChild(buttons);
wm->addChild(buttons);
return createExample(viewer, wm);
return createExample(viewer, wm);
}

View File

@@ -9,81 +9,81 @@
const unsigned int MASK_2D = 0xF0000000;
int main(int argc, char** argv) {
osgViewer::Viewer viewer;
osgViewer::Viewer viewer;
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
&viewer,
1280.0f,
1024.0f,
MASK_2D,
osgWidget::WindowManager::WM_PICK_DEBUG
);
osgWidget::Frame* frame = osgWidget::Frame::createSimpleFrame(
"frame",
32.0f,
32.0f,
300.0f,
300.0f
);
osgWidget::Table* table = new osgWidget::Table("table", 2, 2);
osgWidget::Box* bottom = new osgWidget::Box("panel", osgWidget::Box::HORIZONTAL);
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
&viewer,
1280.0f,
1024.0f,
MASK_2D,
osgWidget::WindowManager::WM_PICK_DEBUG
);
osgWidget::Frame* frame = osgWidget::Frame::createSimpleFrame(
"frame",
32.0f,
32.0f,
300.0f,
300.0f
);
osgWidget::Table* table = new osgWidget::Table("table", 2, 2);
osgWidget::Box* bottom = new osgWidget::Box("panel", osgWidget::Box::HORIZONTAL);
table->addWidget(new osgWidget::Widget("red", 300.0f, 300.0f), 0, 0);
table->addWidget(new osgWidget::Widget("white", 300.0f, 300.0f), 0, 1);
table->addWidget(new osgWidget::Widget("yellow", 300.0f, 300.0f), 1, 0);
table->addWidget(new osgWidget::Widget("purple", 300.0f, 300.0f), 1, 1);
table->getByRowCol(0, 0)->setColor(1.0f, 0.0f, 0.0f, 1.0f);
table->getByRowCol(0, 1)->setColor(1.0f, 1.0f, 1.0f, 1.0f);
table->getByRowCol(1, 0)->setColor(1.0f, 1.0f, 0.0f, 1.0f);
table->getByRowCol(1, 1)->setColor(1.0f, 0.0f, 1.0f, 1.0f);
table->getByRowCol(0, 0)->setMinimumSize(100.0f, 100.0f);
table->getByRowCol(0, 1)->setMinimumSize(100.0f, 100.0f);
table->getByRowCol(1, 0)->setMinimumSize(100.0f, 100.0f);
table->getByRowCol(1, 1)->setMinimumSize(100.0f, 100.0f);
table->addWidget(new osgWidget::Widget("red", 300.0f, 300.0f), 0, 0);
table->addWidget(new osgWidget::Widget("white", 300.0f, 300.0f), 0, 1);
table->addWidget(new osgWidget::Widget("yellow", 300.0f, 300.0f), 1, 0);
table->addWidget(new osgWidget::Widget("purple", 300.0f, 300.0f), 1, 1);
table->getByRowCol(0, 0)->setColor(1.0f, 0.0f, 0.0f, 1.0f);
table->getByRowCol(0, 1)->setColor(1.0f, 1.0f, 1.0f, 1.0f);
table->getByRowCol(1, 0)->setColor(1.0f, 1.0f, 0.0f, 1.0f);
table->getByRowCol(1, 1)->setColor(1.0f, 0.0f, 1.0f, 1.0f);
table->getByRowCol(0, 0)->setMinimumSize(100.0f, 100.0f);
table->getByRowCol(0, 1)->setMinimumSize(100.0f, 100.0f);
table->getByRowCol(1, 0)->setMinimumSize(100.0f, 100.0f);
table->getByRowCol(1, 1)->setMinimumSize(100.0f, 100.0f);
frame->setWindow(table);
frame->setWindow(table);
// Give frame some nice textures.
// TODO: This has to be done after setWindow(); wtf?
frame->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f);
// Give frame some nice textures.
// TODO: This has to be done after setWindow(); wtf?
frame->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f);
osgWidget::Widget* l = frame->getBorder(osgWidget::Frame::BORDER_LEFT);
osgWidget::Widget* r = frame->getBorder(osgWidget::Frame::BORDER_RIGHT);
osgWidget::Widget* t = frame->getBorder(osgWidget::Frame::BORDER_TOP);
osgWidget::Widget* b = frame->getBorder(osgWidget::Frame::BORDER_BOTTOM);
osgWidget::Widget* l = frame->getBorder(osgWidget::Frame::BORDER_LEFT);
osgWidget::Widget* r = frame->getBorder(osgWidget::Frame::BORDER_RIGHT);
osgWidget::Widget* t = frame->getBorder(osgWidget::Frame::BORDER_TOP);
osgWidget::Widget* b = frame->getBorder(osgWidget::Frame::BORDER_BOTTOM);
l->setImage("../examples/osgwidgetframe/images/border-left.tga", true);
r->setImage("../examples/osgwidgetframe/images/border-right.tga", true);
t->setImage("../examples/osgwidgetframe/images/border-top.tga", true);
b->setImage("../examples/osgwidgetframe/images/border-bottom.tga", true);
l->setImage("../examples/osgwidgetframe/images/border-left.tga", true);
r->setImage("../examples/osgwidgetframe/images/border-right.tga", true);
t->setImage("../examples/osgwidgetframe/images/border-top.tga", true);
b->setImage("../examples/osgwidgetframe/images/border-bottom.tga", true);
l->setTexCoordWrapVertical();
r->setTexCoordWrapVertical();
t->setTexCoordWrapHorizontal();
b->setTexCoordWrapHorizontal();
l->setTexCoordWrapVertical();
r->setTexCoordWrapVertical();
t->setTexCoordWrapHorizontal();
b->setTexCoordWrapHorizontal();
// Create the bottom, XArt panel.
osgWidget::Widget* left = new osgWidget::Widget("left", 512.0f, 256.0f);
osgWidget::Widget* center = new osgWidget::Widget("center", 256.0f, 256.0f);
osgWidget::Widget* right = new osgWidget::Widget("right", 512.0f, 256.0f);
// Create the bottom, XArt panel.
osgWidget::Widget* left = new osgWidget::Widget("left", 512.0f, 256.0f);
osgWidget::Widget* center = new osgWidget::Widget("center", 256.0f, 256.0f);
osgWidget::Widget* right = new osgWidget::Widget("right", 512.0f, 256.0f);
left->setImage("../examples/osgwidgetframe/images/panel-left.tga", true);
center->setImage("../examples/osgwidgetframe/images/panel-center.tga", true);
right->setImage("../examples/osgwidgetframe/images/panel-right.tga", true);
left->setImage("../examples/osgwidgetframe/images/panel-left.tga", true);
center->setImage("../examples/osgwidgetframe/images/panel-center.tga", true);
right->setImage("../examples/osgwidgetframe/images/panel-right.tga", true);
center->setTexCoordWrapHorizontal();
center->setTexCoordWrapHorizontal();
bottom->addWidget(left);
bottom->addWidget(center);
bottom->addWidget(right);
bottom->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f);
bottom->setOrigin(0.0f, 1024.0f - 256.0f);
bottom->addWidget(left);
bottom->addWidget(center);
bottom->addWidget(right);
bottom->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f);
bottom->setOrigin(0.0f, 1024.0f - 256.0f);
// Add everything to the WindowManager.
wm->addChild(frame);
wm->addChild(bottom);
// Add everything to the WindowManager.
wm->addChild(frame);
wm->addChild(bottom);
return osgWidget::createExample(viewer, wm);
return osgWidget::createExample(viewer, wm);
}

View File

@@ -14,173 +14,173 @@
const unsigned int MASK_2D = 0xF0000000;
const char* INFO =
"Use the Input Wigets below to enter the X, Y, and Z position of a\n"
"sphere to be inserted into the scene. Once you've done this, use\n"
"the button below to add it!"
"Use the Input Wigets below to enter the X, Y, and Z position of a\n"
"sphere to be inserted into the scene. Once you've done this, use\n"
"the button below to add it!"
;
void setupLabel(osgWidget::Label* label) {
label->setFontSize(16);
label->setFontColor(1.0f, 1.0f, 1.0f, 1.0f);
// label->setFont("fonts/monospace.ttf");
label->setFont("fonts/Calibri1.ttf");
label->setPadding(2.0f);
label->setHeight(18.0f);
label->setCanFill(true);
label->setFontSize(16);
label->setFontColor(1.0f, 1.0f, 1.0f, 1.0f);
// label->setFont("fonts/monospace.ttf");
label->setFont("fonts/Calibri1.ttf");
label->setPadding(2.0f);
label->setHeight(18.0f);
label->setCanFill(true);
}
osgWidget::Input* createTableRow(
osgWidget::Table* table,
unsigned int rowNum,
const std::string& valName
osgWidget::Table* table,
unsigned int rowNum,
const std::string& valName
) {
std::stringstream ssLabel;
std::stringstream ssInput;
std::stringstream ssLabel;
std::stringstream ssInput;
ssLabel << "Label_Row" << rowNum;
ssInput << "Input_Row" << rowNum;
ssLabel << "Label_Row" << rowNum;
ssInput << "Input_Row" << rowNum;
osgWidget::Label* label = new osgWidget::Label(ssLabel.str(), valName);
osgWidget::Input* input = new osgWidget::Input(ssInput.str(), "", 20);
osgWidget::Label* label = new osgWidget::Label(ssLabel.str(), valName);
osgWidget::Input* input = new osgWidget::Input(ssInput.str(), "", 20);
setupLabel(label);
setupLabel(input);
setupLabel(label);
setupLabel(input);
label->setWidth(50.0f);
label->setColor(0.1f, 0.1f, 0.1f, 1.0f);
label->setWidth(50.0f);
label->setColor(0.1f, 0.1f, 0.1f, 1.0f);
input->setWidth(150.0f);
input->setColor(0.4f, 0.4f, 0.4f, 1.0f);
input->setWidth(150.0f);
input->setColor(0.4f, 0.4f, 0.4f, 1.0f);
table->addWidget(label, rowNum, 0);
table->addWidget(input, rowNum, 1);
table->addWidget(label, rowNum, 0);
table->addWidget(input, rowNum, 1);
return input;
return input;
}
osgWidget::Label* createLabel(const std::string& text) {
osgWidget::Label* label = new osgWidget::Label("", text);
osgWidget::Label* label = new osgWidget::Label("", text);
setupLabel(label);
setupLabel(label);
return label;
return label;
}
class Button: public osgWidget::Label {
public:
typedef std::vector<osgWidget::Input*> Inputs;
typedef std::vector<osgWidget::Input*> Inputs;
private:
Inputs _xyz;
Inputs _xyz;
public:
Button(const std::string& text, const Inputs& inputs):
osgWidget::Label("", text),
_xyz(inputs) {
setupLabel(this);
Button(const std::string& text, const Inputs& inputs):
osgWidget::Label("", text),
_xyz(inputs) {
setupLabel(this);
setEventMask(osgWidget::EVENT_MASK_MOUSE_CLICK);
setShadow(0.1f);
addHeight(4.0f);
}
setEventMask(osgWidget::EVENT_MASK_MOUSE_CLICK);
setShadow(0.1f);
addHeight(4.0f);
}
bool mousePush(double, double, osgWidget::WindowManager*) {
osgWidget::warn()
<< "x: " << _xyz[0]->getLabel() << std::endl
<< "y: " << _xyz[1]->getLabel() << std::endl
<< "z: " << _xyz[2]->getLabel() << std::endl
;
bool mousePush(double, double, osgWidget::WindowManager*) {
osgWidget::warn()
<< "x: " << _xyz[0]->getLabel() << std::endl
<< "y: " << _xyz[1]->getLabel() << std::endl
<< "z: " << _xyz[2]->getLabel() << std::endl
;
return false;
}
return false;
}
};
// TODO: Testing our _parent/EmbeddedWindow stuff.
bool info(osgWidget::Event& ev) {
osgWidget::warn() << "MousePush @ Window: " << ev.getWindow()->getName() << std::endl;
osgWidget::warn() << "MousePush @ Window: " << ev.getWindow()->getName() << std::endl;
return true;
return true;
}
int main(int argc, char** argv) {
osgViewer::Viewer viewer;
osgViewer::Viewer viewer;
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
&viewer,
1280.0f,
1024.0f,
MASK_2D,
osgWidget::WindowManager::WM_PICK_DEBUG
);
osgWidget::Box* box = new osgWidget::Box("vbox", osgWidget::Box::VERTICAL);
osgWidget::Table* table = new osgWidget::Table("table", 3, 2);
osgWidget::Box* lbox1 = new osgWidget::Box("lbox1", osgWidget::Box::HORIZONTAL);
osgWidget::Box* lbox2 = new osgWidget::Box("lbox2", osgWidget::Box::HORIZONTAL);
osgWidget::Frame* frame = osgWidget::Frame::createSimpleFrameWithSingleTexture(
"frame",
"osgWidget/theme.png",
64.0f,
64.0f,
16.0f,
16.0f,
100.0f,
100.0f
);
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
&viewer,
1280.0f,
1024.0f,
MASK_2D,
osgWidget::WindowManager::WM_PICK_DEBUG
);
osgWidget::Box* box = new osgWidget::Box("vbox", osgWidget::Box::VERTICAL);
osgWidget::Table* table = new osgWidget::Table("table", 3, 2);
osgWidget::Box* lbox1 = new osgWidget::Box("lbox1", osgWidget::Box::HORIZONTAL);
osgWidget::Box* lbox2 = new osgWidget::Box("lbox2", osgWidget::Box::HORIZONTAL);
osgWidget::Frame* frame = osgWidget::Frame::createSimpleFrameWithSingleTexture(
"frame",
"osgWidget/theme.png",
64.0f,
64.0f,
16.0f,
16.0f,
100.0f,
100.0f
);
osgWidget::Input* x = createTableRow(table, 0, "X Position");
osgWidget::Input* y = createTableRow(table, 1, "Y Position");
osgWidget::Input* z = createTableRow(table, 2, "Z Position");
Button::Inputs inputs;
osgWidget::Input* x = createTableRow(table, 0, "X Position");
osgWidget::Input* y = createTableRow(table, 1, "Y Position");
osgWidget::Input* z = createTableRow(table, 2, "Z Position");
Button::Inputs inputs;
inputs.push_back(x);
inputs.push_back(y);
inputs.push_back(z);
inputs.push_back(x);
inputs.push_back(y);
inputs.push_back(z);
table->addCallback(osgWidget::Callback(&info, osgWidget::EVENT_MOUSE_PUSH));
table->addCallback(osgWidget::Callback(&info, osgWidget::EVENT_MOUSE_PUSH));
lbox1->addWidget(createLabel(INFO));
lbox2->addWidget(new Button("Add To Scene...", inputs));
lbox1->addWidget(createLabel(INFO));
lbox2->addWidget(new Button("Add To Scene...", inputs));
box->addWidget(lbox1->embed());
box->addWidget(table->embed());
box->addWidget(lbox2->embed());
box->addCallback(osgWidget::Callback(&info, osgWidget::EVENT_MOUSE_PUSH));
box->addWidget(lbox1->embed());
box->addWidget(table->embed());
box->addWidget(lbox2->embed());
box->addCallback(osgWidget::Callback(&info, osgWidget::EVENT_MOUSE_PUSH));
frame->setWindow(box);
frame->getEmbeddedWindow()->setSize(box->getWidth(), box->getHeight());
frame->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f);
frame->attachTabFocusCallback();
frame->setWindow(box);
frame->getEmbeddedWindow()->setSize(box->getWidth(), box->getHeight());
frame->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f);
frame->attachTabFocusCallback();
for(osgWidget::Frame::Iterator i = frame->begin(); i != frame->end(); i++) {
if(i->valid()) i->get()->setColor(0.5f, 0.7f, 1.0f, 1.0f);
}
for(osgWidget::Frame::Iterator i = frame->begin(); i != frame->end(); i++) {
if(i->valid()) i->get()->setColor(0.5f, 0.7f, 1.0f, 1.0f);
}
wm->addChild(frame);
wm->addChild(frame);
/*
// Print out our focus list, it should just have 3 widgets.
osgWidget::WidgetList wl;
/*
// Print out our focus list, it should just have 3 widgets.
osgWidget::WidgetList wl;
box->getFocusList(wl);
box->getFocusList(wl);
for(osgWidget::WidgetList::iterator i = wl.begin(); i != wl.end(); i++) {
osgWidget::warn() << i->get()->getName() << std::endl;
}
*/
lbox1->getBackground()->setColor(1.0f, 0.0f, 0.0f, 1.0f, osgWidget::Widget::UPPER_LEFT);
lbox1->getBackground()->setColor(0.0f, 1.0f, 0.0f, 1.0f, osgWidget::Widget::LOWER_LEFT);
lbox1->getBackground()->setColor(0.0f, 0.0f, 1.0f, 1.0f, osgWidget::Widget::LOWER_RIGHT);
lbox1->getBackground()->setColor(1.0f, 1.0f, 1.0f, 1.0f, osgWidget::Widget::UPPER_RIGHT);
lbox1->setVisibilityMode(osgWidget::Window::VM_ENTIRE);
lbox1->update();
for(osgWidget::WidgetList::iterator i = wl.begin(); i != wl.end(); i++) {
osgWidget::warn() << i->get()->getName() << std::endl;
}
*/
lbox1->getBackground()->setColor(1.0f, 0.0f, 0.0f, 1.0f, osgWidget::Widget::UPPER_LEFT);
lbox1->getBackground()->setColor(0.0f, 1.0f, 0.0f, 1.0f, osgWidget::Widget::LOWER_LEFT);
lbox1->getBackground()->setColor(0.0f, 0.0f, 1.0f, 1.0f, osgWidget::Widget::LOWER_RIGHT);
lbox1->getBackground()->setColor(1.0f, 1.0f, 1.0f, 1.0f, osgWidget::Widget::UPPER_RIGHT);
lbox1->setVisibilityMode(osgWidget::Window::VM_ENTIRE);
lbox1->update();
int r = osgWidget::createExample(viewer, wm);
int r = osgWidget::createExample(viewer, wm);
// osgWidget::writeWindowManagerNode(wm);
// osgDB::writeNodeFile(*box, "osgWidget.osg");
// osgWidget::writeWindowManagerNode(wm);
// osgDB::writeNodeFile(*box, "osgWidget.osg");
return r;
return r;
}

View File

@@ -10,111 +10,111 @@
const unsigned int MASK_2D = 0xF0000000;
const char* LABEL1 =
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed\n"
"do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n"
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris\n"
"nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in..."
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed\n"
"do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n"
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris\n"
"nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in..."
;
const char* LABEL2 =
"...reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla\n"
"pariatur. Excepteur sint occaecat cupidatat non proident, sunt in \n"
"culpa qui officia deserunt mollit anim id est laborum. BBBBB"
"...reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla\n"
"pariatur. Excepteur sint occaecat cupidatat non proident, sunt in \n"
"culpa qui officia deserunt mollit anim id est laborum. BBBBB"
;
osgWidget::Label* createLabel(const std::string& l, unsigned int size=13) {
osgWidget::Label* label = new osgWidget::Label("", "");
osgWidget::Label* label = new osgWidget::Label("", "");
label->setFont("fonts/arial.ttf");
label->setFontSize(size);
label->setFontColor(1.0f, 1.0f, 1.0f, 1.0f);
label->setLabel(l);
label->setFont("fonts/arial.ttf");
label->setFontSize(size);
label->setFontColor(1.0f, 1.0f, 1.0f, 1.0f);
label->setLabel(l);
/*
text->setBackdropType(osgText::Text::DROP_SHADOW_BOTTOM_RIGHT);
text->setBackdropImplementation(osgText::Text::NO_DEPTH_BUFFER);
text->setBackdropOffset(0.2f);
*/
/*
text->setBackdropType(osgText::Text::DROP_SHADOW_BOTTOM_RIGHT);
text->setBackdropImplementation(osgText::Text::NO_DEPTH_BUFFER);
text->setBackdropOffset(0.2f);
*/
return label;
return label;
}
int main(int argc, char** argv) {
osgViewer::Viewer viewer;
osgViewer::Viewer viewer;
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
&viewer,
1280.0f,
1024.0f,
MASK_2D,
osgWidget::WindowManager::WM_PICK_DEBUG |
osgWidget::WindowManager::WM_NO_INVERT_Y
);
osgWidget::Box* box = new osgWidget::Box("HBOX", osgWidget::Box::HORIZONTAL);
osgWidget::Box* vbox = new osgWidget::Box("vbox", osgWidget::Box::VERTICAL);
osgWidget::Label* label1 = createLabel(LABEL1);
osgWidget::Label* label2 = createLabel(LABEL2);
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
&viewer,
1280.0f,
1024.0f,
MASK_2D,
osgWidget::WindowManager::WM_PICK_DEBUG |
osgWidget::WindowManager::WM_NO_INVERT_Y
);
osgWidget::Box* box = new osgWidget::Box("HBOX", osgWidget::Box::HORIZONTAL);
osgWidget::Box* vbox = new osgWidget::Box("vbox", osgWidget::Box::VERTICAL);
osgWidget::Label* label1 = createLabel(LABEL1);
osgWidget::Label* label2 = createLabel(LABEL2);
// Setup the labels for horizontal box.
label1->setPadding(10.0f);
label2->setPadding(10.0f);
// Setup the labels for horizontal box.
label1->setPadding(10.0f);
label2->setPadding(10.0f);
label1->addSize(21.0f, 22.0f);
label2->addSize(21.0f, 22.0f);
label1->addSize(21.0f, 22.0f);
label2->addSize(21.0f, 22.0f);
label1->setColor(1.0f, 0.5f, 0.0f, 0.0f);
label2->setColor(1.0f, 0.5f, 0.0f, 0.0f);
label1->setColor(1.0f, 0.5f, 0.0f, 0.0f);
label2->setColor(1.0f, 0.5f, 0.0f, 0.0f);
box->addWidget(label1);
box->addWidget(label2);
box->attachMoveCallback();
box->attachScaleCallback();
box->attachRotateCallback();
box->addWidget(label1);
box->addWidget(label2);
box->attachMoveCallback();
box->attachScaleCallback();
box->attachRotateCallback();
// Setup the labels for the vertical box.
osgWidget::Label* label3 = createLabel("Label 3", 80);
osgWidget::Label* label4 = createLabel("Label 4", 60);
osgWidget::Label* label5 = createLabel("ABCDEFGHIJK", 93);
// Setup the labels for the vertical box.
osgWidget::Label* label3 = createLabel("Label 3", 80);
osgWidget::Label* label4 = createLabel("Label 4", 60);
osgWidget::Label* label5 = createLabel("ABCDEFGHIJK", 93);
label3->setPadding(3.0f);
label4->setPadding(3.0f);
label5->setPadding(3.0f);
label3->setPadding(3.0f);
label4->setPadding(3.0f);
label5->setPadding(3.0f);
label3->setColor(0.0f, 0.0f, 0.5f, 0.5f);
label4->setColor(0.0f, 0.0f, 0.5f, 0.5f);
label5->setColor(0.0f, 0.0f, 0.5f, 0.5f);
label5->setAlignHorizontal(osgWidget::Widget::HA_LEFT);
label5->setAlignVertical(osgWidget::Widget::VA_BOTTOM);
label3->setColor(0.0f, 0.0f, 0.5f, 0.5f);
label4->setColor(0.0f, 0.0f, 0.5f, 0.5f);
label5->setColor(0.0f, 0.0f, 0.5f, 0.5f);
label5->setAlignHorizontal(osgWidget::Widget::HA_LEFT);
label5->setAlignVertical(osgWidget::Widget::VA_BOTTOM);
// Test our label copy construction...
osgWidget::Label* label6 = label5->cloneAs("label6");
// Test our label copy construction...
osgWidget::Label* label6 = label5->cloneAs("label6");
label6->setLabel("abcdefghijklmnopqrs");
label6->setLabel("abcdefghijklmnopqrs");
vbox->addWidget(label3);
vbox->addWidget(label4);
vbox->addWidget(label5);
vbox->addWidget(label6);
vbox->attachMoveCallback();
vbox->attachScaleCallback();
vbox->addWidget(label3);
vbox->addWidget(label4);
vbox->addWidget(label5);
vbox->addWidget(label6);
vbox->attachMoveCallback();
vbox->attachScaleCallback();
vbox->resize();
vbox->resize();
// vbox->setVisibilityMode(osgWidget::Window::VM_ENTIRE);
// vbox->setVisibleArea(50, 50, 500, 200);
// vbox->setAnchorVertical(osgWidget::Window::VA_TOP);
// vbox->setAnchorHorizontal(osgWidget::Window::HA_RIGHT);
// vbox->setVisibilityMode(osgWidget::Window::VM_ENTIRE);
// vbox->setVisibleArea(50, 50, 500, 200);
// vbox->setAnchorVertical(osgWidget::Window::VA_TOP);
// vbox->setAnchorHorizontal(osgWidget::Window::HA_RIGHT);
// Test our label-in-window copy construction...
osgWidget::Box* clonedBox = box->cloneAs("HBOX-new");
clonedBox->getBackground()->setColor(0.0f, 1.0f, 0.0f, 0.5f);
// Test our label-in-window copy construction...
osgWidget::Box* clonedBox = box->cloneAs("HBOX-new");
clonedBox->getBackground()->setColor(0.0f, 1.0f, 0.0f, 0.5f);
wm->addChild(box);
wm->addChild(vbox);
wm->addChild(clonedBox);
wm->addChild(box);
wm->addChild(vbox);
wm->addChild(clonedBox);
return osgWidget::createExample(viewer, wm);
return osgWidget::createExample(viewer, wm);
}

View File

@@ -15,115 +15,115 @@ const unsigned int MASK_2D = 0xF0000000;
const unsigned int MASK_3D = 0x0F000000;
struct ColorLabel: public osgWidget::Label {
ColorLabel(const char* label):
osgWidget::Label("", "") {
setFont("fonts/Calibri1.ttf");
setFontSize(14);
setFontColor(1.0f, 1.0f, 1.0f, 1.0f);
setColor(0.3f, 0.3f, 0.3f, 1.0f);
addHeight(18.0f);
setCanFill(true);
setLabel(label);
setEventMask(osgWidget::EVENT_MOUSE_PUSH | osgWidget::EVENT_MASK_MOUSE_MOVE);
}
ColorLabel(const char* label):
osgWidget::Label("", "") {
setFont("fonts/Calibri1.ttf");
setFontSize(14);
setFontColor(1.0f, 1.0f, 1.0f, 1.0f);
setColor(0.3f, 0.3f, 0.3f, 1.0f);
addHeight(18.0f);
setCanFill(true);
setLabel(label);
setEventMask(osgWidget::EVENT_MOUSE_PUSH | osgWidget::EVENT_MASK_MOUSE_MOVE);
}
bool mousePush(double, double, osgWidget::WindowManager*) {
return true;
}
bool mousePush(double, double, osgWidget::WindowManager*) {
return true;
}
bool mouseEnter(double, double, osgWidget::WindowManager*) {
setColor(0.6f, 0.6f, 0.6f, 1.0f);
return true;
}
bool mouseEnter(double, double, osgWidget::WindowManager*) {
setColor(0.6f, 0.6f, 0.6f, 1.0f);
return true;
}
bool mouseLeave(double, double, osgWidget::WindowManager*) {
setColor(0.3f, 0.3f, 0.3f, 1.0f);
return true;
}
bool mouseLeave(double, double, osgWidget::WindowManager*) {
setColor(0.3f, 0.3f, 0.3f, 1.0f);
return true;
}
};
class ColorLabelMenu: public ColorLabel {
osg::ref_ptr<osgWidget::Window> _window;
osg::ref_ptr<osgWidget::Window> _window;
public:
ColorLabelMenu(const char* label):
ColorLabel(label) {
_window = new osgWidget::Box(
std::string("Menu_") + label,
osgWidget::Box::VERTICAL,
true
);
ColorLabelMenu(const char* label):
ColorLabel(label) {
_window = new osgWidget::Box(
std::string("Menu_") + label,
osgWidget::Box::VERTICAL,
true
);
_window->addWidget(new ColorLabel("Open Some Stuff"));
_window->addWidget(new ColorLabel("Do It Now"));
_window->addWidget(new ColorLabel("Hello, How Are U?"));
_window->addWidget(new ColorLabel("Hmmm..."));
_window->addWidget(new ColorLabel("Option 5"));
_window->addWidget(new ColorLabel("Open Some Stuff"));
_window->addWidget(new ColorLabel("Do It Now"));
_window->addWidget(new ColorLabel("Hello, How Are U?"));
_window->addWidget(new ColorLabel("Hmmm..."));
_window->addWidget(new ColorLabel("Option 5"));
_window->resize();
_window->resize();
setColor(0.8f, 0.8f, 0.8f, 0.8f);
}
setColor(0.8f, 0.8f, 0.8f, 0.8f);
}
void managed(osgWidget::WindowManager* wm) {
osgWidget::Label::managed(wm);
void managed(osgWidget::WindowManager* wm) {
osgWidget::Label::managed(wm);
wm->addChild(_window.get());
wm->addChild(_window.get());
_window->hide();
}
_window->hide();
}
void positioned() {
osgWidget::Label::positioned();
void positioned() {
osgWidget::Label::positioned();
_window->setOrigin(getX(), getHeight());
_window->resize(getWidth());
}
_window->setOrigin(getX(), getHeight());
_window->resize(getWidth());
}
bool mousePush(double, double, osgWidget::WindowManager*) {
if(!_window->isVisible()) _window->show();
bool mousePush(double, double, osgWidget::WindowManager*) {
if(!_window->isVisible()) _window->show();
else _window->hide();
else _window->hide();
return true;
}
return true;
}
bool mouseLeave(double, double, osgWidget::WindowManager*) {
if(!_window->isVisible()) setColor(0.8f, 0.8f, 0.8f, 0.8f);
bool mouseLeave(double, double, osgWidget::WindowManager*) {
if(!_window->isVisible()) setColor(0.8f, 0.8f, 0.8f, 0.8f);
return true;
}
return true;
}
};
int main(int argc, char** argv) {
osgViewer::Viewer viewer;
osgViewer::Viewer viewer;
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
&viewer,
1280.0f,
1024.0f,
MASK_2D,
osgWidget::WindowManager::WM_PICK_DEBUG |
osgWidget::WindowManager::WM_NO_BETA_WARN
);
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
&viewer,
1280.0f,
1024.0f,
MASK_2D,
osgWidget::WindowManager::WM_PICK_DEBUG |
osgWidget::WindowManager::WM_NO_BETA_WARN
);
osgWidget::Window* menu = new osgWidget::Box("menu", osgWidget::Box::HORIZONTAL);
osgWidget::Window* menu = new osgWidget::Box("menu", osgWidget::Box::HORIZONTAL);
menu->addWidget(new ColorLabelMenu("Pick me!"));
menu->addWidget(new ColorLabelMenu("No, wait, pick me!"));
menu->addWidget(new ColorLabelMenu("Dont pick them..."));
menu->addWidget(new ColorLabelMenu("Grarar!?!"));
menu->addWidget(new ColorLabelMenu("Pick me!"));
menu->addWidget(new ColorLabelMenu("No, wait, pick me!"));
menu->addWidget(new ColorLabelMenu("Dont pick them..."));
menu->addWidget(new ColorLabelMenu("Grarar!?!"));
wm->addChild(menu);
menu->getBackground()->setColor(1.0f, 1.0f, 1.0f, 0.0f);
menu->resizePercent(100.0f);
wm->addChild(menu);
menu->getBackground()->setColor(1.0f, 1.0f, 1.0f, 0.0f);
menu->resizePercent(100.0f);
osg::Node* model = osgDB::readNodeFile("osgcool.osg");
osg::Node* model = osgDB::readNodeFile("osgcool.osg");
model->setNodeMask(MASK_3D);
model->setNodeMask(MASK_3D);
return osgWidget::createExample(viewer, wm, model);
return osgWidget::createExample(viewer, wm, model);
}

View File

@@ -12,123 +12,123 @@ const unsigned int MASK_2D = 0xF0000000;
const unsigned int MASK_3D = 0x0F000000;
class Notebook: public osgWidget::Box {
osg::ref_ptr<osgWidget::Box> _tabs;
osg::ref_ptr<osgWidget::Canvas> _windows;
osg::ref_ptr<osgWidget::Box> _tabs;
osg::ref_ptr<osgWidget::Canvas> _windows;
public:
// NOTE: This whole thing is just a hack to demonstrate a concept. The real
// implementation would need to be much cleaner.
bool callbackTabPressed(osgWidget::Event& ev) {
osgWidget::Canvas::Vector& objs = _windows->getObjects();
// NOTE: This whole thing is just a hack to demonstrate a concept. The real
// implementation would need to be much cleaner.
bool callbackTabPressed(osgWidget::Event& ev) {
osgWidget::Canvas::Vector& objs = _windows->getObjects();
for(unsigned int i = 0; i < objs.size(); i++) objs[i]->setLayer(
osgWidget::Widget::LAYER_MIDDLE,
i
);
for(unsigned int i = 0; i < objs.size(); i++) objs[i]->setLayer(
osgWidget::Widget::LAYER_MIDDLE,
i
);
_windows->getByName(ev.getWidget()->getName())->setLayer(
osgWidget::Widget::LAYER_MIDDLE,
objs.size()
);
_windows->getByName(ev.getWidget()->getName())->setLayer(
osgWidget::Widget::LAYER_MIDDLE,
objs.size()
);
_windows->resize();
_windows->resize();
return true;
}
return true;
}
Notebook(const std::string& name):
osgWidget::Box(name, osgWidget::Box::VERTICAL) {
_tabs = new osgWidget::Box("tabs", osgWidget::Box::HORIZONTAL);
_windows = new osgWidget::Canvas("canvas");
Notebook(const std::string& name):
osgWidget::Box(name, osgWidget::Box::VERTICAL) {
_tabs = new osgWidget::Box("tabs", osgWidget::Box::HORIZONTAL);
_windows = new osgWidget::Canvas("canvas");
for(unsigned int i = 0; i < 4; i++) {
std::stringstream ss;
for(unsigned int i = 0; i < 4; i++) {
std::stringstream ss;
// Setup everything for our Tab...
ss << "Tab_" << i;
// Setup everything for our Tab...
ss << "Tab_" << i;
osgWidget::Label* label1 = new osgWidget::Label(ss.str());
osgWidget::Label* label1 = new osgWidget::Label(ss.str());
label1->setFont("fonts/monospace.ttf");
label1->setFontSize(20);
label1->setFontColor(1.0f, 1.0f, 1.0f, 1.0f);
label1->setColor(0.0f, i / 4.0f, 0.3f, 1.0f);
label1->setLabel(ss.str());
label1->addSize(20.0f, 20.0f);
label1->setShadow(0.1f);
label1->setCanFill(true);
label1->setFont("fonts/monospace.ttf");
label1->setFontSize(20);
label1->setFontColor(1.0f, 1.0f, 1.0f, 1.0f);
label1->setColor(0.0f, i / 4.0f, 0.3f, 1.0f);
label1->setLabel(ss.str());
label1->addSize(20.0f, 20.0f);
label1->setShadow(0.1f);
label1->setCanFill(true);
_tabs->addWidget(label1);
_tabs->addWidget(label1);
// Setup everything for the Window corresponding to the Tab
// in the Canvas down below.
std::stringstream descr;
// Setup everything for the Window corresponding to the Tab
// in the Canvas down below.
std::stringstream descr;
descr
<< "This is some text" << std::endl
<< "for the Tab_" << i << " tab." << std::endl
<< "Press the button up top" << std::endl
<< "And this should go to the next Window!" << std::endl
;
descr
<< "This is some text" << std::endl
<< "for the Tab_" << i << " tab." << std::endl
<< "Press the button up top" << std::endl
<< "And this should go to the next Window!" << std::endl
;
osgWidget::Label* label2 = new osgWidget::Label(ss.str());
osgWidget::Label* label2 = new osgWidget::Label(ss.str());
label2->setFont("fonts/monospace.ttf");
label2->setFontSize(15);
label2->setFontColor(1.0f, 1.0f, 1.0f, 1.0f);
label2->setColor(0.0f, i / 4.0f, 0.3f, 1.0f);
label2->setLabel(descr.str());
label2->setLayer(osgWidget::Widget::LAYER_MIDDLE, i);
label2->addSize(50.0f, 50.0f);
label2->setFont("fonts/monospace.ttf");
label2->setFontSize(15);
label2->setFontColor(1.0f, 1.0f, 1.0f, 1.0f);
label2->setColor(0.0f, i / 4.0f, 0.3f, 1.0f);
label2->setLabel(descr.str());
label2->setLayer(osgWidget::Widget::LAYER_MIDDLE, i);
label2->addSize(50.0f, 50.0f);
_windows->addWidget(label2, 0.0f, 0.0f);
_windows->addWidget(label2, 0.0f, 0.0f);
label1->setEventMask(osgWidget::EVENT_MOUSE_PUSH);
label1->addCallback(osgWidget::Callback(
&Notebook::callbackTabPressed,
this,
osgWidget::EVENT_MOUSE_PUSH
));
}
label1->setEventMask(osgWidget::EVENT_MOUSE_PUSH);
label1->addCallback(osgWidget::Callback(
&Notebook::callbackTabPressed,
this,
osgWidget::EVENT_MOUSE_PUSH
));
}
osgWidget::Label* label = new osgWidget::Label("label");
osgWidget::Label* label = new osgWidget::Label("label");
label->setFont("fonts/monospace.ttf");
label->setFontSize(15);
label->setFontColor(1.0f, 1.0f, 1.0f, 1.0f);
label->setLabel("Drag the window here...");
label->addSize(20.0f, 20.0f);
label->setShadow(0.08f);
label->setCanFill(true);
label->setFont("fonts/monospace.ttf");
label->setFontSize(15);
label->setFontColor(1.0f, 1.0f, 1.0f, 1.0f);
label->setLabel("Drag the window here...");
label->addSize(20.0f, 20.0f);
label->setShadow(0.08f);
label->setCanFill(true);
addWidget(label);
addWidget(_tabs->embed());
addWidget(_windows->embed());
}
addWidget(label);
addWidget(_tabs->embed());
addWidget(_windows->embed());
}
};
int main(int argc, char** argv) {
osgViewer::Viewer viewer;
osgViewer::Viewer viewer;
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
&viewer,
1280.0f,
720.0f,
MASK_2D,
osgWidget::WindowManager::WM_PICK_DEBUG
);
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
&viewer,
1280.0f,
720.0f,
MASK_2D,
osgWidget::WindowManager::WM_PICK_DEBUG
);
Notebook* notebook = new Notebook("notebook");
Notebook* notebook = new Notebook("notebook");
osgWidget::warn()
<< "Sizes are..." << std::endl
<< "Cur: " << notebook->getSize() << std::endl
<< "Min: " << notebook->getMinSize() << std::endl
;
osgWidget::warn()
<< "Sizes are..." << std::endl
<< "Cur: " << notebook->getSize() << std::endl
<< "Min: " << notebook->getMinSize() << std::endl
;
notebook->attachMoveCallback();
notebook->attachMoveCallback();
wm->addChild(notebook);
wm->addChild(notebook);
return osgWidget::createExample(viewer, wm);
return osgWidget::createExample(viewer, wm);
}

View File

@@ -11,124 +11,124 @@ const unsigned int MASK_2D = 0xF0000000;
// NOTE: THIS IS JUST A TEMPORARY HACK! :) This functionality will all eventually be
// encapsulate into another class in osgWidget proper.
bool scrollWindow(osgWidget::Event& ev) {
// The first thing we need to do is make sure we have a Frame object...
osgWidget::Frame* frame = dynamic_cast<osgWidget::Frame*>(ev.getWindow());
// The first thing we need to do is make sure we have a Frame object...
osgWidget::Frame* frame = dynamic_cast<osgWidget::Frame*>(ev.getWindow());
if(!frame) return false;
if(!frame) return false;
// And now we need to make sure our Frame has a valid internal EmbeddedWindow widget.
osgWidget::Window::EmbeddedWindow* ew =
dynamic_cast<osgWidget::Window::EmbeddedWindow*>(frame->getEmbeddedWindow())
;
if(!ew) return false;
// Lets get the visible area so that we can use it to make sure our scrolling action
// is necessary in the first place.
const osgWidget::Quad& va = ew->getWindow()->getVisibleArea();
// And now we need to make sure our Frame has a valid internal EmbeddedWindow widget.
osgWidget::Window::EmbeddedWindow* ew =
dynamic_cast<osgWidget::Window::EmbeddedWindow*>(frame->getEmbeddedWindow())
;
if(!ew) return false;
// Lets get the visible area so that we can use it to make sure our scrolling action
// is necessary in the first place.
const osgWidget::Quad& va = ew->getWindow()->getVisibleArea();
// The user wants to scroll up; make sure that the visible area's Y origin isn't already
// at 0.0f, 0.0f.
if(ev.getWindowManager()->isMouseScrollingUp() && va[1] != 0.0f)
ew->getWindow()->addVisibleArea(0, -20)
;
else if(va[1] <= (ew->getWindow()->getHeight() - ew->getHeight()))
ew->getWindow()->addVisibleArea(0, 20)
;
// The user wants to scroll up; make sure that the visible area's Y origin isn't already
// at 0.0f, 0.0f.
if(ev.getWindowManager()->isMouseScrollingUp() && va[1] != 0.0f)
ew->getWindow()->addVisibleArea(0, -20)
;
else if(va[1] <= (ew->getWindow()->getHeight() - ew->getHeight()))
ew->getWindow()->addVisibleArea(0, 20)
;
// We need to manually call update to make sure the visible area scissoring is done
// properly.
frame->update();
// We need to manually call update to make sure the visible area scissoring is done
// properly.
frame->update();
return true;
return true;
}
bool changeTheme(osgWidget::Event& ev) {
std::string theme;
std::string theme;
if(ev.key == osgGA::GUIEventAdapter::KEY_Right)
theme = "osgWidget/theme-1.png"
;
if(ev.key == osgGA::GUIEventAdapter::KEY_Right)
theme = "osgWidget/theme-1.png"
;
else if(ev.key == osgGA::GUIEventAdapter::KEY_Left)
theme = "osgWidget/theme-2.png"
;
else if(ev.key == osgGA::GUIEventAdapter::KEY_Left)
theme = "osgWidget/theme-2.png"
;
else return false;
else return false;
osgWidget::Frame* frame = dynamic_cast<osgWidget::Frame*>(ev.getWindow());
osgWidget::Frame* frame = dynamic_cast<osgWidget::Frame*>(ev.getWindow());
if(!frame) return false;
if(!frame) return false;
// This is just one way to access all our Widgets; we could just as well have used:
//
// for(osgWidget::Frame::Iterator i = frame.begin(); i != frame.end() i++) {}
//
// ...and it have worked, too.
for(unsigned int row = 0; row < 3; row++) {
for(unsigned int col = 0; col < 3; col++) {
frame->getByRowCol(row, col)->setImage(theme);
}
}
// This is just one way to access all our Widgets; we could just as well have used:
//
// for(osgWidget::Frame::Iterator i = frame.begin(); i != frame.end() i++) {}
//
// ...and it have worked, too.
for(unsigned int row = 0; row < 3; row++) {
for(unsigned int col = 0; col < 3; col++) {
frame->getByRowCol(row, col)->setImage(theme);
}
}
return true;
return true;
}
int main(int argc, char** argv) {
osgViewer::Viewer viewer;
osgViewer::Viewer viewer;
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
&viewer,
1280.0f,
1024.0f,
MASK_2D,
osgWidget::WindowManager::WM_PICK_DEBUG
);
osgWidget::Frame* frame = osgWidget::Frame::createSimpleFrameWithSingleTexture(
"frame",
"../examples/osgwidgetscrolled/theme-2.png",
64.0f,
64.0f,
16.0f,
16.0f,
100.0f,
100.0f
);
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
&viewer,
1280.0f,
1024.0f,
MASK_2D,
osgWidget::WindowManager::WM_PICK_DEBUG
);
osgWidget::Frame* frame = osgWidget::Frame::createSimpleFrameWithSingleTexture(
"frame",
"../examples/osgwidgetscrolled/theme-2.png",
64.0f,
64.0f,
16.0f,
16.0f,
100.0f,
100.0f
);
frame->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f);
frame->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f);
// This is our Transformers box. :)
osgWidget::Box* box = new osgWidget::Box("images", osgWidget::Box::VERTICAL);
osgWidget::Widget* img1 = new osgWidget::Widget("im1", 256.0f, 256.0f);
osgWidget::Widget* img2 = new osgWidget::Widget("im2", 256.0f, 256.0f);
osgWidget::Widget* img3 = new osgWidget::Widget("im3", 256.0f, 256.0f);
osgWidget::Widget* img4 = new osgWidget::Widget("im4", 256.0f, 256.0f);
// This is our Transformers box. :)
osgWidget::Box* box = new osgWidget::Box("images", osgWidget::Box::VERTICAL);
osgWidget::Widget* img1 = new osgWidget::Widget("im1", 256.0f, 256.0f);
osgWidget::Widget* img2 = new osgWidget::Widget("im2", 256.0f, 256.0f);
osgWidget::Widget* img3 = new osgWidget::Widget("im3", 256.0f, 256.0f);
osgWidget::Widget* img4 = new osgWidget::Widget("im4", 256.0f, 256.0f);
img1->setImage("../examples/osgwidgetscrolled/images/starscream.jpg", true);
img2->setImage("../examples/osgwidgetscrolled/images/optimus.jpg", true);
img3->setImage("../examples/osgwidgetscrolled/images/megatron.jpg", true);
img4->setImage("../examples/osgwidgetscrolled/images/bumblebee.jpg", true);
img1->setImage("../examples/osgwidgetscrolled/images/starscream.jpg", true);
img2->setImage("../examples/osgwidgetscrolled/images/optimus.jpg", true);
img3->setImage("../examples/osgwidgetscrolled/images/megatron.jpg", true);
img4->setImage("../examples/osgwidgetscrolled/images/bumblebee.jpg", true);
img1->setMinimumSize(10.0f, 10.0f);
img2->setMinimumSize(10.0f, 10.0f);
img3->setMinimumSize(10.0f, 10.0f);
img4->setMinimumSize(10.0f, 10.0f);
img1->setMinimumSize(10.0f, 10.0f);
img2->setMinimumSize(10.0f, 10.0f);
img3->setMinimumSize(10.0f, 10.0f);
img4->setMinimumSize(10.0f, 10.0f);
box->addWidget(img1);
box->addWidget(img2);
box->addWidget(img3);
box->addWidget(img4);
box->setEventMask(osgWidget::EVENT_NONE);
box->addWidget(img1);
box->addWidget(img2);
box->addWidget(img3);
box->addWidget(img4);
box->setEventMask(osgWidget::EVENT_NONE);
frame->getEmbeddedWindow()->setWindow(box);
frame->getEmbeddedWindow()->setColor(1.0f, 1.0f, 1.0f, 1.0f);
frame->resize(300.0f, 300.0f);
frame->addCallback(osgWidget::Callback(&scrollWindow, osgWidget::EVENT_MOUSE_SCROLL));
frame->addCallback(osgWidget::Callback(&changeTheme, osgWidget::EVENT_KEY_DOWN));
frame->getEmbeddedWindow()->setWindow(box);
frame->getEmbeddedWindow()->setColor(1.0f, 1.0f, 1.0f, 1.0f);
frame->resize(300.0f, 300.0f);
frame->addCallback(osgWidget::Callback(&scrollWindow, osgWidget::EVENT_MOUSE_SCROLL));
frame->addCallback(osgWidget::Callback(&changeTheme, osgWidget::EVENT_KEY_DOWN));
wm->addChild(frame);
wm->addChild(frame);
return osgWidget::createExample(viewer, wm);
return osgWidget::createExample(viewer, wm);
}

View File

@@ -8,67 +8,67 @@
const unsigned int MASK_2D = 0xF0000000;
osgWidget::Widget* createWidget(
const std::string& name,
osgWidget::color_type col,
osgWidget::Widget::LAYER layer
const std::string& name,
osgWidget::color_type col,
osgWidget::Widget::LAYER layer
) {
osgWidget::Widget* widget = new osgWidget::Widget(name, 200.0f, 200.0f);
osgWidget::Widget* widget = new osgWidget::Widget(name, 200.0f, 200.0f);
widget->setColor(col, col, col, 0.2f);
widget->setLayer(layer);
widget->setColor(col, col, col, 0.2f);
widget->setLayer(layer);
return widget;
return widget;
}
int main(int argc, char** argv) {
osgViewer::Viewer viewer;
osgViewer::Viewer viewer;
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
&viewer,
1280.0f,
1024.0f,
MASK_2D
);
osgWidget::Canvas* canvas = new osgWidget::Canvas("canvas");
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
&viewer,
1280.0f,
1024.0f,
MASK_2D
);
osgWidget::Canvas* canvas = new osgWidget::Canvas("canvas");
canvas->attachMoveCallback();
canvas->attachScaleCallback();
canvas->attachMoveCallback();
canvas->attachScaleCallback();
canvas->addWidget(
createWidget("w1", 0.2f, osgWidget::Widget::LAYER_LOW),
0.0f,
0.0f
);
canvas->addWidget(
createWidget("w2", 0.4f, osgWidget::Widget::LAYER_MIDDLE),
200.0f,
0.0f
);
canvas->addWidget(
createWidget("w1", 0.2f, osgWidget::Widget::LAYER_LOW),
0.0f,
0.0f
);
canvas->addWidget(
createWidget("w2", 0.4f, osgWidget::Widget::LAYER_MIDDLE),
200.0f,
0.0f
);
canvas->addWidget(
createWidget("w3", 0.6f, osgWidget::Widget::LAYER_HIGH),
400.0f,
0.0f
);
canvas->addWidget(
createWidget("w3", 0.6f, osgWidget::Widget::LAYER_HIGH),
400.0f,
0.0f
);
wm->addChild(canvas);
wm->addChild(canvas);
osg::Program* program = new osg::Program();
osg::Program* program = new osg::Program();
program->addShader(osg::Shader::readShaderFile(
osg::Shader::VERTEX,
"osgWidget/osgwidgetshader-vert.glsl"
));
program->addShader(osg::Shader::readShaderFile(
osg::Shader::FRAGMENT,
"osgWidget/osgwidgetshader-frag.glsl"
));
program->addShader(osg::Shader::readShaderFile(
osg::Shader::VERTEX,
"osgWidget/osgwidgetshader-vert.glsl"
));
program->addShader(osg::Shader::readShaderFile(
osg::Shader::FRAGMENT,
"osgWidget/osgwidgetshader-frag.glsl"
));
canvas->getGeode()->getOrCreateStateSet()->setAttribute(program);
canvas->getGeode()->getOrCreateStateSet()->setAttribute(program);
return osgWidget::createExample(viewer, wm);
return osgWidget::createExample(viewer, wm);
}