void MapNodeHelper::parse(MapNode* mapNode, osg::ArgumentParser& args, osgViewer::View* view, osg::Group* root, Container* userContainer ) const { if ( !root ) root = mapNode; // options to use for the load osg::ref_ptr<osgDB::Options> dbOptions = Registry::instance()->cloneOrCreateOptions(); // parse out custom example arguments first: bool useMGRS = args.read("--mgrs"); bool useDMS = args.read("--dms"); bool useDD = args.read("--dd"); bool useCoords = args.read("--coords") || useMGRS || useDMS || useDD; bool useAutoClip = args.read("--autoclip"); bool showActivity = args.read("--activity"); bool useLogDepth = args.read("--logdepth"); bool useLogDepth2 = args.read("--logdepth2"); bool kmlUI = args.read("--kmlui"); std::string kmlFile; args.read( "--kml", kmlFile ); std::string imageFolder; args.read( "--images", imageFolder ); std::string imageExtensions; args.read("--image-extensions", imageExtensions); // animation path: std::string animpath; if ( args.read("--path", animpath) ) { view->setCameraManipulator( new osgGA::AnimationPathManipulator(animpath) ); } // Install a new Canvas for our UI controls, or use one that already exists. ControlCanvas* canvas = ControlCanvas::getOrCreate( view ); Container* mainContainer; if ( userContainer ) { mainContainer = userContainer; } else { mainContainer = new VBox(); mainContainer->setAbsorbEvents( true ); mainContainer->setBackColor( Color(Color::Black, 0.8) ); mainContainer->setHorizAlign( Control::ALIGN_LEFT ); mainContainer->setVertAlign( Control::ALIGN_BOTTOM ); } canvas->addControl( mainContainer ); // Add an event handler to toggle the canvas with a key press; view->addEventHandler(new ToggleCanvasEventHandler(canvas, 'y')); // look for external data in the map node: const Config& externals = mapNode->externalConfig(); // some terrain effects. // TODO: Most of these are likely to move into extensions. const Config& vertScaleConf = externals.child("vertical_scale"); // Loading KML from the command line: if ( !kmlFile.empty() ) { KMLOptions kml_options; kml_options.declutter() = true; // set up a default icon for point placemarks: IconSymbol* defaultIcon = new IconSymbol(); defaultIcon->url()->setLiteral(KML_PUSHPIN_URL); kml_options.defaultIconSymbol() = defaultIcon; TextSymbol* defaultText = new TextSymbol(); defaultText->halo() = Stroke(0.3,0.3,0.3,1.0); kml_options.defaultTextSymbol() = defaultText; osg::Node* kml = KML::load( URI(kmlFile), mapNode, kml_options ); if ( kml ) { if (kmlUI) { Control* c = AnnotationGraphControlFactory().create(kml, view); if ( c ) { c->setVertAlign( Control::ALIGN_TOP ); canvas->addControl( c ); } } root->addChild( kml ); } else { OE_NOTICE << "Failed to load " << kmlFile << std::endl; } } //// Configure the de-cluttering engine for labels and annotations: //if ( !screenSpaceLayoutConf.empty() ) //{ // ScreenSpaceLayout::setOptions( ScreenSpaceLayoutOptions(screenSpaceLayoutConf) ); //} // Configure the mouse coordinate readout: if ( useCoords ) { LabelControl* readout = new LabelControl(); readout->setBackColor( Color(Color::Black, 0.8) ); readout->setHorizAlign( Control::ALIGN_RIGHT ); readout->setVertAlign( Control::ALIGN_BOTTOM ); Formatter* formatter = useMGRS ? (Formatter*)new MGRSFormatter(MGRSFormatter::PRECISION_1M, 0L, MGRSFormatter::USE_SPACES) : useDMS ? (Formatter*)new LatLongFormatter(LatLongFormatter::FORMAT_DEGREES_MINUTES_SECONDS) : useDD ? (Formatter*)new LatLongFormatter(LatLongFormatter::FORMAT_DECIMAL_DEGREES) : 0L; MouseCoordsTool* mcTool = new MouseCoordsTool( mapNode ); mcTool->addCallback( new MouseCoordsLabelCallback(readout, formatter) ); view->addEventHandler( mcTool ); canvas->addControl( readout ); } // Configure for an ortho camera: if ( args.read("--ortho") ) { view->getCamera()->setProjectionMatrixAsOrtho(-1, 1, -1, 1, 0, 1); } // activity monitor (debugging) if ( showActivity ) { VBox* vbox = new VBox(); vbox->setBackColor( Color(Color::Black, 0.8) ); vbox->setHorizAlign( Control::ALIGN_RIGHT ); vbox->setVertAlign( Control::ALIGN_BOTTOM ); view->addEventHandler( new ActivityMonitorTool(vbox) ); canvas->addControl( vbox ); } // Install an auto clip plane clamper if ( useAutoClip ) { mapNode->addCullCallback( new AutoClipPlaneCullCallback(mapNode) ); } // Install logarithmic depth buffer on main camera if ( useLogDepth ) { OE_INFO << LC << "Activating logarithmic depth buffer (vertex-only) on main camera" << std::endl; osgEarth::Util::LogarithmicDepthBuffer logDepth; logDepth.setUseFragDepth( false ); logDepth.install( view->getCamera() ); } else if ( useLogDepth2 ) { OE_INFO << LC << "Activating logarithmic depth buffer (precise) on main camera" << std::endl; osgEarth::Util::LogarithmicDepthBuffer logDepth; logDepth.setUseFragDepth( true ); logDepth.install( view->getCamera() ); } // Scan for images if necessary. if ( !imageFolder.empty() ) { std::vector<std::string> extensions; if ( !imageExtensions.empty() ) StringTokenizer( imageExtensions, extensions, ",;", "", false, true ); if ( extensions.empty() ) extensions.push_back( "tif" ); OE_INFO << LC << "Loading images from " << imageFolder << "..." << std::endl; ImageLayerVector imageLayers; DataScanner scanner; scanner.findImageLayers( imageFolder, extensions, imageLayers ); if ( imageLayers.size() > 0 ) { mapNode->getMap()->beginUpdate(); for( ImageLayerVector::iterator i = imageLayers.begin(); i != imageLayers.end(); ++i ) { mapNode->getMap()->addImageLayer( i->get() ); } mapNode->getMap()->endUpdate(); } OE_INFO << LC << "...found " << imageLayers.size() << " image layers." << std::endl; } // Install vertical scaler. // TODO: deprecate this, or move it to an extension. if ( !vertScaleConf.empty() ) { mapNode->getTerrainEngine()->addEffect( new VerticalScale(vertScaleConf) ); } // Generic named value uniform with min/max. VBox* uniformBox = 0L; while( args.find( "--uniform" ) >= 0 ) { std::string name; float minval, maxval; if ( args.read( "--uniform", name, minval, maxval ) ) { if ( uniformBox == 0L ) { uniformBox = new VBox(); uniformBox->setBackColor(0,0,0,0.5); uniformBox->setAbsorbEvents( true ); canvas->addControl( uniformBox ); } osg::Uniform* uniform = new osg::Uniform(osg::Uniform::FLOAT, name); uniform->set( minval ); root->getOrCreateStateSet()->addUniform( uniform, osg::StateAttribute::OVERRIDE ); HBox* box = new HBox(); box->addControl( new LabelControl(name) ); HSliderControl* hs = box->addControl( new HSliderControl(minval, maxval, minval, new ApplyValueUniform(uniform))); hs->setHorizFill(true, 200); box->addControl( new LabelControl(hs) ); uniformBox->addControl( box ); OE_INFO << LC << "Installed uniform controller for " << name << std::endl; } } // Map inspector: if (args.read("--inspect")) { mapNode->addExtension( Extension::create("mapinspector", ConfigOptions()) ); } // Memory monitor: if (args.read("--monitor")) { mapNode->addExtension(Extension::create("monitor", ConfigOptions()) ); } // Simple sky model: if (args.read("--sky")) { mapNode->addExtension(Extension::create("sky_simple", ConfigOptions()) ); } // Simple ocean model: if (args.read("--ocean")) { mapNode->addExtension(Extension::create("ocean_simple", ConfigOptions())); } // Arbitrary extension: std::string extname; if (args.read("--extension", extname)) { Extension* ext = Extension::create(extname, ConfigOptions()); if (ext) mapNode->addExtension(ext); } // Hook up the extensions! for(std::vector<osg::ref_ptr<Extension> >::const_iterator eiter = mapNode->getExtensions().begin(); eiter != mapNode->getExtensions().end(); ++eiter) { Extension* e = eiter->get(); // Check for a View interface: ExtensionInterface<osg::View>* viewIF = ExtensionInterface<osg::View>::get( e ); if ( viewIF ) viewIF->connect( view ); // Check for a Control interface: ExtensionInterface<Control>* controlIF = ExtensionInterface<Control>::get( e ); if ( controlIF ) controlIF->connect( mainContainer ); } // Shadowing. This is last because it needs access to a light which may be provided // by one of the Sky extensions. if (args.read("--shadows")) { int unit; if ( mapNode->getTerrainEngine()->getResources()->reserveTextureImageUnit(unit, "ShadowCaster") ) { ShadowCaster* caster = new ShadowCaster(); caster->setTextureImageUnit( unit ); caster->setLight( view->getLight() ); caster->getShadowCastingGroup()->addChild( mapNode->getModelLayerGroup() ); //insertParent(caster, mapNode); //root = findTopOfGraph(caster)->asGroup(); if ( mapNode->getNumParents() > 0 ) { insertGroup(caster, mapNode->getParent(0)); } else { caster->addChild(mapNode); root = caster; } } } root->addChild( canvas ); }
TeamsSelectionBox::TeamsSelectionBox(const Point2i &_size, bool network, bool w_border) : HBox(_size.y, w_border, false) { if (!w_border) SetNoBorder(); SetMargin(0); // How many teams ? VBox *tmp = new VBox(120, false, false, true); if (network) { local_teams_nb = new SpinButtonWithPicture(_("Local teams:"), "menu/team_number", Point2i(100, 130), 0, 1, 0, MAX_NB_TEAMS); } else { local_teams_nb = new SpinButtonWithPicture(_("Number of teams:"), "menu/team_number", Point2i(100, 130), 2, 1, 2, MAX_NB_TEAMS); } tmp->AddWidget(local_teams_nb); //tmp->AddWidget(new NullWidget(Point2i(120, 120))); AddWidget(tmp); uint box_w = _size.x - local_teams_nb->GetSizeX() - 10; Point2i grid_size = Point2i(box_w, _size.y); Point2i grid_dim = grid_size / Point2i(300 + 10, 130 + 10); Point2i box_size; bool use_list; if (grid_dim.x*grid_dim.y < (int)MAX_NB_TEAMS) { use_list = true; box_size.SetValues(box_w - 40, 120); } else { use_list = false; box_size.SetValues((grid_size / grid_dim) - 10); } for (uint i=0; i < MAX_NB_TEAMS; i++) { std::string player_name = _("Player") ; char num_player[4]; sprintf(num_player, " %d", i+1); player_name += num_player; teams_selections.push_back(new TeamBox(player_name, box_size)); } // If the intended gridbox would be too big for the intended size, // instead create a listbox if (use_list) { // Warning: this box takes the ownership of the widgets in teams_selections: // while any other Box will delete the ones it contains, TeamScrollBox // doesn't really contain them as widgets. They therefore aren't released // through this mechanism, but with a manual one. This manual mechanism // requires we have a *real* copy of the vector for when it is destroyed. list_box = new TeamScrollBox(teams_selections, Point2i(box_w-20, _size.y-10)); list_box->SetNbTeams(0); AddWidget(list_box); } else { list_box = NULL; Box * teams_grid_box = new GridBox(grid_dim.y, grid_dim.x, 10, false); teams_grid_box->SetNoBorder(); for (uint i=0; i<MAX_NB_TEAMS; i++) teams_grid_box->AddWidget(teams_selections[i]); AddWidget(teams_grid_box); } // Load Teams' list GetTeamsList().full_list.sort(compareTeams); }
void System::layout2() { VBox* b = vbox(); if (b) { b->layout(); setbbox(b->bbox()); return; } setPos(0.0, 0.0); QList<std::pair<int,SysStaff*>> visibleStaves; int firstStaffIdx = -1; int lastStaffIdx = 0; int firstStaffInitialIdx = -1; int lastStaffInitialIdx = 0; Measure* fm = firstMeasure(); for (int i = 0; i < _staves.size(); ++i) { Staff* s = score()->staff(i); SysStaff* ss = _staves[i]; if (s->show() && ss->show()) { visibleStaves.append(std::pair<int,SysStaff*>(i, ss)); if (firstStaffIdx == -1) firstStaffIdx = i; if (i > lastStaffIdx) lastStaffIdx = i; if (fm && fm->visible(i)) { if (firstStaffInitialIdx == -1) firstStaffInitialIdx = i; lastStaffInitialIdx = i; } } else { ss->setbbox(QRectF()); // already done in layout() ? } } if (firstStaffIdx == -1) firstStaffIdx = 0; if (firstStaffInitialIdx == -1) firstStaffInitialIdx = 0; qreal _spatium = spatium(); qreal y = 0.0; qreal minVerticalDistance = score()->styleP(StyleIdx::minVerticalDistance); qreal staffDistance = score()->styleP(StyleIdx::staffDistance); qreal akkoladeDistance = score()->styleP(StyleIdx::akkoladeDistance); if (visibleStaves.empty()) { qDebug("====no visible staves, staves %d, score staves %d", _staves.size(), score()->nstaves()); } for (auto i = visibleStaves.begin();; ++i) { SysStaff* ss = i->second; int si1 = i->first; Staff* staff = score()->staff(si1); auto ni = i + 1; qreal h = staff->height(); if (ni == visibleStaves.end()) { ss->setYOff(staff->lines() == 1 ? _spatium * staff->mag() : 0.0); ss->bbox().setRect(_leftMargin, y, width() - _leftMargin, h); break; } int si2 = ni->first; qreal dist = h; switch (staff->innerBracket()) { case BracketType::BRACE: dist += akkoladeDistance; break; case BracketType::NORMAL: case BracketType::SQUARE: case BracketType::LINE: case BracketType::NO_BRACKET: dist += staffDistance; break; } dist += score()->staff(si2)->userDist(); for (MeasureBase* mb : ml) { if (!mb->isMeasure()) continue; Measure* m = toMeasure(mb); Shape& s1 = m->staffShape(si1); Shape& s2 = m->staffShape(si2); qreal d = s1.minVerticalDistance(s2) + minVerticalDistance; dist = qMax(dist, d); Spacer* sp = m->mstaff(si1)->_vspacerDown; if (sp) { if (sp->spacerType() == SpacerType::FIXED) { dist = staff->height() + sp->gap(); break; } else dist = qMax(dist, staff->height() + sp->gap()); } sp = m->mstaff(si2)->_vspacerUp; if (sp) dist = qMax(dist, sp->gap()); } ss->setYOff(staff->lines() == 1 ? _spatium * staff->mag() : 0.0); ss->bbox().setRect(_leftMargin, y, width() - _leftMargin, h); y += dist; } qreal systemHeight = staff(lastStaffIdx)->bbox().bottom(); setHeight(systemHeight); for (MeasureBase* m : ml) { if (m->isMeasure()) { // note that the factor 2 * _spatium must be corrected for when exporting // system distance in MusicXML (issue #24733) m->bbox().setRect(0.0, -_spatium, m->width(), systemHeight + 2.0 * _spatium); } else if (m->isHBox()) { m->bbox().setRect(0.0, 0.0, m->width(), systemHeight); toHBox(m)->layout2(); } else if (m->isTBox()) { // m->bbox().setRect(0.0, 0.0, m->width(), systemHeight); toTBox(m)->layout(); } else qDebug("unhandled measure type %s", m->name()); } if (fm) { Segment* s = fm->first(); BarLine* _barLine = s->isBeginBarLineType() ? toBarLine(s->element(0)) : 0; if (_barLine) { _barLine->setTrack(firstStaffInitialIdx * VOICES); _barLine->setSpan(lastStaffInitialIdx - firstStaffInitialIdx + 1); if (score()->staff(firstStaffInitialIdx)->lines() == 1) _barLine->setSpanFrom(BARLINE_SPAN_1LINESTAFF_FROM); else _barLine->setSpanFrom(0); int llines = score()->staff(lastStaffInitialIdx)->lines(); int spanTo = llines == 1 ? BARLINE_SPAN_1LINESTAFF_TO : (llines - 1) * 2; _barLine->setSpanTo(spanTo); _barLine->layout(); } } //--------------------------------------------------- // layout brackets vertical position //--------------------------------------------------- for (Bracket* b : _brackets) { int staffIdx1 = b->firstStaff(); int staffIdx2 = b->lastStaff(); qreal sy = 0; // assume bracket not visible qreal ey = 0; // if start staff not visible, try next staff while (staffIdx1 <= staffIdx2 && !_staves[staffIdx1]->show()) ++staffIdx1; // if end staff not visible, try prev staff while (staffIdx1 <= staffIdx2 && !_staves[staffIdx2]->show()) --staffIdx2; // the bracket will be shown IF: // it spans at least 2 visible staves (staffIdx1 < staffIdx2) OR // it spans just one visible staff (staffIdx1 == staffIdx2) but it is required to do so // (the second case happens at least when the bracket is initially dropped) bool notHidden = (staffIdx1 < staffIdx2) || (b->span() == 1 && staffIdx1 == staffIdx2); if (notHidden) { // set vert. pos. and height to visible spanned staves sy = _staves[staffIdx1]->bbox().top(); ey = _staves[staffIdx2]->bbox().bottom(); } b->rypos() = sy; // if (score()->staff(firstStaffInitialIdx)->lines() == 1) // bbox of one line staff bad? // b->rypos() -= _spatium; b->setHeight(ey - sy); b->layout(); } //--------------------------------------------------- // layout instrument names //--------------------------------------------------- int staffIdx = 0; for (Part* p : score()->parts()) { SysStaff* s = staff(staffIdx); SysStaff* s2; int nstaves = p->nstaves(); if (s->show()) { for (InstrumentName* t : s->instrumentNames) { // // override Text->layout() // qreal y1, y2; switch (t->layoutPos()) { default: case 0: // center at part y1 = s->bbox().top(); s2 = staff(staffIdx); for (int i = staffIdx + nstaves - 1; i > 0; --i) { SysStaff* s = staff(i); if (s->show()) { s2 = s; break; } } y2 = s2->bbox().bottom(); break; case 1: // center at first staff y1 = s->bbox().top(); y2 = s->bbox().bottom(); break; // TODO: // sort out invisible staves case 2: // center between first and second staff y1 = s->bbox().top(); y2 = staff(staffIdx + 1)->bbox().bottom(); break; case 3: // center at second staff y1 = staff(staffIdx + 1)->bbox().top(); y2 = staff(staffIdx + 1)->bbox().bottom(); break; case 4: // center between first and second staff y1 = staff(staffIdx + 1)->bbox().top(); y2 = staff(staffIdx + 2)->bbox().bottom(); break; case 5: // center at third staff y1 = staff(staffIdx + 2)->bbox().top(); y2 = staff(staffIdx + 2)->bbox().bottom(); break; } t->rypos() = y1 + (y2 - y1) * .5 + t->textStyle().offset(t->spatium()).y(); } } staffIdx += nstaves; } }
void Box::read(const QDomElement& de) { _leftMargin = _rightMargin = _topMargin = _bottomMargin = 0.0; bool keepMargins = false; // whether original margins have to be kept when reading old file for (QDomElement e = de.firstChildElement(); !e.isNull(); e = e.nextSiblingElement()) { const QString& tag(e.tagName()); if (setProperty(tag, e)) ; else if (tag == "Text") { Text* t; if (type() == TBOX) { t = static_cast<TBox*>(this)->getText(); t->read(e); } else { t = new Text(score()); t->read(e); add(t); } } else if (tag == "Symbol") { Symbol* s = new Symbol(score()); s->read(e); add(s); } else if (tag == "Image") { // look ahead for image type QString path; QDomElement ee = e.firstChildElement("path"); if (!ee.isNull()) path = ee.text(); Image* image = 0; QString s(path.toLower()); if (s.endsWith(".svg")) image = new SvgImage(score()); else if (s.endsWith(".jpg") || s.endsWith(".png") || s.endsWith(".gif") || s.endsWith(".xpm") ) { image = new RasterImage(score()); } else { qDebug("unknown image format <%s>\n", path.toLatin1().data()); } if (image) { image->setTrack(score()->curTrack); image->read(e); add(image); } } else if (tag == "LayoutBreak") { LayoutBreak* lb = new LayoutBreak(score()); lb->read(e); add(lb); } else if (tag == "HBox") { HBox* hb = new HBox(score()); hb->read(e); add(hb); keepMargins = true; // in old file, box nesting used outer box margins } else if (tag == "VBox") { VBox* vb = new VBox(score()); vb->read(e); add(vb); keepMargins = true; // in old file, box nesting used outer box margins } else domError(e); } // with .msc versions prior to 1.17, box margins were only used when nesting another box inside this box: // for backward compatibility set them to 0 in all other cases if (score()->mscVersion() < 117 && (type() == HBOX || type() == VBOX) && !keepMargins) { _leftMargin = _rightMargin = _topMargin = _bottomMargin = 0.0; } }
int main(int argc, char** argv) { // allocate pager threads based on CPU configuration. int cores = Registry::capabilities().getNumProcessors(); osg::DisplaySettings::instance()->setNumOfDatabaseThreadsHint( osg::clampAbove(cores, 2) ); osg::DisplaySettings::instance()->setNumOfHttpDatabaseThreadsHint( osg::clampAbove(cores/2, 1) ); // parse the command line. osg::ArgumentParser arguments(&argc,argv); osgViewer::Viewer viewer(arguments); // set up the motion model. viewer.setCameraManipulator( new EarthManipulator() ); // simple UI. VBox* vbox = new VBox(); vbox->setMargin( 3 ); vbox->setChildSpacing( 5 ); vbox->setAbsorbEvents( true ); vbox->setHorizAlign( Control::ALIGN_RIGHT ); vbox->setVertAlign ( Control::ALIGN_BOTTOM ); // Control instructions: Grid* grid = vbox->addControl( new Grid() ); grid->setControl( 0, 0, new LabelControl("Pan:")); grid->setControl( 1, 0, new LabelControl("Left mouse")); grid->setControl( 0, 1, new LabelControl("Zoom:")); grid->setControl( 1, 1, new LabelControl("Right mouse / scroll")); grid->setControl( 0, 2, new LabelControl("Rotate:") ); grid->setControl( 1, 2, new LabelControl("Middle mouse")); grid->setControl( 0, 3, new LabelControl("Go to:")); grid->setControl( 1, 3, new LabelControl("Double-click")); ControlCanvas::getOrCreate(&viewer)->addControl(vbox); // Load an earth file osg::Node* node = MapNodeHelper().load(arguments, &viewer); if ( !node ) return usage( "Failed to load earth file." ); viewer.setSceneData( node ); #ifdef Q_WS_X11 // required for multi-threaded viewer on linux: XInitThreads(); #endif QApplication app(argc, argv); QWidget* viewerWidget = new ViewerWidget( &viewer ); QMainWindow win; win.setWindowTitle( "osgEarth -- The #1 Open Source Terrain SDK for Mission-Critical Applications" ); win.setCentralWidget( viewerWidget ); win.setGeometry(100, 100, 1024, 800); win.statusBar()->showMessage(QString("osgEarth. Copyright 2014 Pelican Mapping. Please visit http://osgearth.org")); win.show(); app.exec(); }
void Box::read(XmlReader& e) { _leftMargin = _rightMargin = _topMargin = _bottomMargin = 0.0; bool keepMargins = false; // whether original margins have to be kept when reading old file while (e.readNextStartElement()) { const QStringRef& tag(e.name()); if (tag == "height") _boxHeight = Spatium(e.readDouble()); else if (tag == "width") _boxWidth = Spatium(e.readDouble()); else if (tag == "topGap") _topGap = e.readDouble(); else if (tag == "bottomGap") _bottomGap = e.readDouble(); else if (tag == "leftMargin") _leftMargin = e.readDouble(); else if (tag == "rightMargin") _rightMargin = e.readDouble(); else if (tag == "topMargin") _topMargin = e.readDouble(); else if (tag == "bottomMargin") _bottomMargin = e.readDouble(); else if (tag == "Text") { Text* t; if (type() == TBOX) { t = static_cast<TBox*>(this)->getText(); t->read(e); } else { t = new Text(score()); t->read(e); add(t); if (score()->mscVersion() <= 114) t->setLayoutToParentWidth(true); } } else if (tag == "Symbol") { Symbol* s = new Symbol(score()); s->read(e); add(s); } else if (tag == "Image") { Image* image = new Image(score()); image->setTrack(e.track()); image->read(e); add(image); } else if (tag == "FretDiagram") { FretDiagram* f = new FretDiagram(score()); f->read(e); add(f); } else if (tag == "LayoutBreak") { LayoutBreak* lb = new LayoutBreak(score()); lb->read(e); add(lb); } else if (tag == "HBox") { HBox* hb = new HBox(score()); hb->read(e); add(hb); keepMargins = true; // in old file, box nesting used outer box margins } else if (tag == "VBox") { VBox* vb = new VBox(score()); vb->read(e); add(vb); keepMargins = true; // in old file, box nesting used outer box margins } else if (Element::readProperties(e)) ; else e.unknown(); } // with .msc versions prior to 1.17, box margins were only used when nesting another box inside this box: // for backward compatibility set them to 0 in all other cases if (score()->mscVersion() < 117 && (type() == HBOX || type() == VBOX) && !keepMargins) { _leftMargin = _rightMargin = _topMargin = _bottomMargin = 0.0; } }
bool UIFocusTestNestedLayout3::init() { if (UIFocusTestBase::init()) { Size winSize = Director::getInstance()->getVisibleSize(); _verticalLayout = VBox::create(); _verticalLayout->setPosition(Vec2(40, winSize.height - 70)); _uiLayer->addChild(_verticalLayout); _verticalLayout->setScale(0.8); _verticalLayout->setFocused(true); _verticalLayout->setLoopFocus(true); _verticalLayout->setTag(-1000); _firstFocusedWidget = _verticalLayout; HBox *upperHBox = HBox::create(); upperHBox->setTag(-200); _verticalLayout->addChild(upperHBox); LinearLayoutParameter *params = LinearLayoutParameter::create(); params->setMargin(Margin(0,0,50,0)); LinearLayoutParameter *vparams = LinearLayoutParameter::create(); vparams->setMargin(Margin(10, 0, 0, 140)); upperHBox->setLayoutParameter(vparams); int count = 3; for (int i=0; i<count; ++i) { VBox *firstVbox = VBox::create(); firstVbox->setScale(0.5); firstVbox->setLayoutParameter(params); firstVbox->setTag((i+1) * 100); int count1 = 3; for (int j=0; j<count1; ++j) { ImageView *w = ImageView::create("cocosui/scrollviewbg.png"); w->setTouchEnabled(true); w->setTag(j+firstVbox->getTag()+1); w->addTouchEventListener(CC_CALLBACK_2(UIFocusTestBase::onImageViewClicked, this)); firstVbox->addChild(w); } upperHBox->addChild(firstVbox); } HBox *bottomHBox = HBox::create(); bottomHBox->setScale(0.5); bottomHBox->setTag(600); bottomHBox->setLayoutParameter(vparams); count = 3; LinearLayoutParameter *bottomParams = LinearLayoutParameter::create(); bottomParams->setMargin(Margin(0, 0, 8, 0)); for (int i=0; i < count; ++i) { ImageView *w = ImageView::create("cocosui/scrollviewbg.png"); w->setLayoutParameter(bottomParams); w->setTouchEnabled(true); w->setTag(i+601); w->addTouchEventListener(CC_CALLBACK_2(UIFocusTestBase::onImageViewClicked, this)); bottomHBox->addChild(w); } _verticalLayout->addChild(bottomHBox); _loopText = Text::create("loop enabled", "Airal", 20); _loopText->setPosition(Vec2(winSize.width/2, winSize.height - 50)); _loopText->setColor(Color3B::GREEN); this->addChild(_loopText); auto btn = Button::create("cocosui/switch-mask.png"); btn->setTitleText("Toggle Loop"); btn->setPosition(Vec2(60, winSize.height - 50)); btn->setTitleColor(Color3B::RED); btn->addTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout3::toggleFocusLoop, this)); this->addChild(btn); return true; } return false; }
void createControls( ControlCanvas* cs ) { // a container centered on the screen, containing an image and a text label. { VBox* center = new VBox(); center->setFrame( new RoundedFrame() ); center->getFrame()->setBackColor( 1,1,1,0.5 ); center->setPadding( 10 ); center->setHorizAlign( Control::ALIGN_CENTER ); center->setVertAlign( Control::ALIGN_CENTER ); // Add an image: osg::ref_ptr<osg::Image> image; if ( HTTPClient::readImageFile("http://osgearth.org/chrome/site/osgearth.gif", image) == HTTPClient::RESULT_OK ) { ImageControl* imageCon = new ImageControl( image.get() ); imageCon->setHorizAlign( Control::ALIGN_CENTER ); imageCon->setFixSizeForRotation( true ); imageCon->addEventHandler( new ImageRotationHandler ); center->addControl( imageCon ); center->setHorizAlign( Control::ALIGN_CENTER ); } // Add a text label: LabelControl* label = new LabelControl( "osgEarth Controls Toolkit" ); label->setFont( osgText::readFontFile( "arialbd.ttf" ) ); label->setFontSize( 24.0f ); label->setHorizAlign( Control::ALIGN_CENTER ); label->setMargin( 5 ); center->addControl( label ); // Add another LabelControl* label2 = new LabelControl( "(Click the osgEarth logo to rotate it)" ); label2->setHorizAlign( Control::ALIGN_CENTER ); center->addControl( label2 ); cs->addControl( center ); } // a simple vbox with absolute positioning in the upper left with two text labels. { VBox* ul = new VBox(); ul->setPosition( 20, 20 ); ul->setPadding( 10 ); { LabelControl* title = new LabelControl( "Upper left control", 22, osg::Vec4f(1,1,0,1) ); ul->addControl( title ); LabelControl* content = new LabelControl( "Here is some text in the upper left control" ); ul->addControl( content ); HBox* c2 = new HBox(); c2->setChildSpacing( 10 ); { HSliderControl* slider = new HSliderControl( 0, 100 ); slider->setBackColor( .6,0,0,1 ); slider->setHeight( 25 ); slider->setWidth( 300 ); slider->addEventHandler( new MySliderHandler() ); c2->addControl( slider ); s_sliderLabel = new LabelControl(); s_sliderLabel->setVertAlign( Control::ALIGN_CENTER ); c2->addControl( s_sliderLabel ); } ul->addControl( c2 ); HBox* c3 = new HBox(); c3->setHorizAlign( Control::ALIGN_CENTER ); c3->setChildSpacing( 10 ); { HBox* c4 = new HBox(); c4->setChildSpacing( 5 ); { c4->addControl( new CheckBoxControl( true ) ); c4->addControl( new LabelControl( "Checkbox 1" ) ); } c3->addControl( c4 ); HBox* c5 = new HBox(); c5->setChildSpacing( 5 ); { c5->addControl( new CheckBoxControl( false ) ); c5->addControl( new LabelControl( "Checkbox 2" ) ); } c3->addControl( c5 ); } ul->addControl( c3 ); } cs->addControl( ul ); ul->addEventHandler( new MyClickHandler ); } // a centered hbox container along the bottom on the screen. { HBox* bottom = new HBox(); bottom->setFrame( new RoundedFrame() ); bottom->getFrame()->setBackColor(0,0,0,0.5); bottom->setMargin( 10 ); bottom->setChildSpacing( 145 ); bottom->setVertAlign( Control::ALIGN_BOTTOM ); bottom->setHorizAlign( Control::ALIGN_CENTER ); for( int i=0; i<4; ++i ) { LabelControl* label = new LabelControl(); std::stringstream buf; buf << "Label_" << i; label->setText( buf.str() ); label->setMargin( 10 ); label->setBackColor( 1,1,1,0.4 ); bottom->addControl( label ); label->setActiveColor(1,.3,.3,1); label->addEventHandler( new MyClickHandler ); } cs->addControl( bottom ); } }
void MapNodeHelper::parse(MapNode* mapNode, osg::ArgumentParser& args, osgViewer::View* view, osg::Group* root, Container* userContainer ) const { if ( !root ) root = mapNode; // options to use for the load osg::ref_ptr<osgDB::Options> dbOptions = Registry::instance()->cloneOrCreateOptions(); // parse out custom example arguments first: bool useSky = args.read("--sky"); bool useOcean = args.read("--ocean"); bool useMGRS = args.read("--mgrs"); bool useDMS = args.read("--dms"); bool useDD = args.read("--dd"); bool useCoords = args.read("--coords") || useMGRS || useDMS || useDD; bool useOrtho = args.read("--ortho"); bool useAutoClip = args.read("--autoclip"); bool useShadows = args.read("--shadows"); bool animateSky = args.read("--animate-sky"); bool showActivity = args.read("--activity"); bool useLogDepth = args.read("--logdepth"); bool useLogDepth2 = args.read("--logdepth2"); bool kmlUI = args.read("--kmlui"); bool inspect = args.read("--inspect"); if (args.read("--verbose")) osgEarth::setNotifyLevel(osg::INFO); if (args.read("--quiet")) osgEarth::setNotifyLevel(osg::FATAL); float ambientBrightness = 0.2f; args.read("--ambientBrightness", ambientBrightness); std::string kmlFile; args.read( "--kml", kmlFile ); std::string imageFolder; args.read( "--images", imageFolder ); std::string imageExtensions; args.read("--image-extensions", imageExtensions); // animation path: std::string animpath; if ( args.read("--path", animpath) ) { view->setCameraManipulator( new osgGA::AnimationPathManipulator(animpath) ); } // Install a new Canvas for our UI controls, or use one that already exists. ControlCanvas* canvas = ControlCanvas::getOrCreate( view ); Container* mainContainer; if ( userContainer ) { mainContainer = userContainer; } else { mainContainer = new VBox(); mainContainer->setAbsorbEvents( true ); mainContainer->setBackColor( Color(Color::Black, 0.8) ); mainContainer->setHorizAlign( Control::ALIGN_LEFT ); mainContainer->setVertAlign( Control::ALIGN_BOTTOM ); } canvas->addControl( mainContainer ); // look for external data in the map node: const Config& externals = mapNode->externalConfig(); const Config& skyConf = externals.child("sky"); const Config& oceanConf = externals.child("ocean"); const Config& annoConf = externals.child("annotations"); const Config& declutterConf = externals.child("decluttering"); // some terrain effects. // TODO: Most of these are likely to move into extensions. const Config& lodBlendingConf = externals.child("lod_blending"); const Config& vertScaleConf = externals.child("vertical_scale"); const Config& contourMapConf = externals.child("contour_map"); // Adding a sky model: if ( useSky || !skyConf.empty() ) { SkyOptions options(skyConf); if ( options.getDriver().empty() ) { if ( mapNode->getMapSRS()->isGeographic() ) options.setDriver("simple"); else options.setDriver("gl"); } SkyNode* sky = SkyNode::create(options, mapNode); if ( sky ) { sky->attach( view, 0 ); if ( mapNode->getNumParents() > 0 ) { osgEarth::insertGroup(sky, mapNode->getParent(0)); } else { sky->addChild( mapNode ); root = sky; } Control* c = SkyControlFactory().create(sky, view); if ( c ) mainContainer->addControl( c ); if (animateSky) { sky->setUpdateCallback( new AnimateSkyUpdateCallback() ); } } } // Adding an ocean model: if ( useOcean || !oceanConf.empty() ) { OceanNode* ocean = OceanNode::create(OceanOptions(oceanConf), mapNode); if ( ocean ) { // if there's a sky, we want to ocean under it osg::Group* parent = osgEarth::findTopMostNodeOfType<SkyNode>(root); if ( !parent ) parent = root; parent->addChild( ocean ); Control* c = OceanControlFactory().create(ocean); if ( c ) mainContainer->addControl(c); } } // Shadowing. if ( useShadows ) { int unit; if ( mapNode->getTerrainEngine()->getResources()->reserveTextureImageUnit(unit, "ShadowCaster") ) { ShadowCaster* caster = new ShadowCaster(); caster->setTextureImageUnit( unit ); caster->setLight( view->getLight() ); caster->getShadowCastingGroup()->addChild( mapNode ); //->getModelLayerGroup() ); if ( mapNode->getNumParents() > 0 ) { insertGroup(caster, mapNode->getParent(0)); } else { caster->addChild(mapNode); root = caster; } } } // Loading KML from the command line: if ( !kmlFile.empty() ) { KMLOptions kml_options; kml_options.declutter() = true; // set up a default icon for point placemarks: IconSymbol* defaultIcon = new IconSymbol(); defaultIcon->url()->setLiteral(KML_PUSHPIN_URL); kml_options.defaultIconSymbol() = defaultIcon; osg::Node* kml = KML::load( URI(kmlFile), mapNode, kml_options ); if ( kml ) { if (kmlUI) { Control* c = AnnotationGraphControlFactory().create(kml, view); if ( c ) { c->setVertAlign( Control::ALIGN_TOP ); canvas->addControl( c ); } } root->addChild( kml ); } else { OE_NOTICE << "Failed to load " << kmlFile << std::endl; } } // Annotations in the map node externals: if ( !annoConf.empty() ) { osg::Group* annotations = 0L; AnnotationRegistry::instance()->create( mapNode, annoConf, dbOptions.get(), annotations ); if ( annotations ) { mapNode->addChild( annotations ); //root->addChild( annotations ); } } // Configure the de-cluttering engine for labels and annotations: if ( !declutterConf.empty() ) { Decluttering::setOptions( DeclutteringOptions(declutterConf) ); } // Configure the mouse coordinate readout: if ( useCoords ) { LabelControl* readout = new LabelControl(); readout->setBackColor( Color(Color::Black, 0.8) ); readout->setHorizAlign( Control::ALIGN_RIGHT ); readout->setVertAlign( Control::ALIGN_BOTTOM ); Formatter* formatter = useMGRS ? (Formatter*)new MGRSFormatter(MGRSFormatter::PRECISION_1M, 0L, MGRSFormatter::USE_SPACES) : useDMS ? (Formatter*)new LatLongFormatter(LatLongFormatter::FORMAT_DEGREES_MINUTES_SECONDS) : useDD ? (Formatter*)new LatLongFormatter(LatLongFormatter::FORMAT_DECIMAL_DEGREES) : 0L; MouseCoordsTool* mcTool = new MouseCoordsTool( mapNode ); mcTool->addCallback( new MouseCoordsLabelCallback(readout, formatter) ); view->addEventHandler( mcTool ); canvas->addControl( readout ); } // Configure for an ortho camera: if ( useOrtho ) { view->getCamera()->setProjectionMatrixAsOrtho(-1, 1, -1, 1, 0, 1); } // activity monitor (debugging) if ( showActivity ) { VBox* vbox = new VBox(); vbox->setBackColor( Color(Color::Black, 0.8) ); vbox->setHorizAlign( Control::ALIGN_RIGHT ); vbox->setVertAlign( Control::ALIGN_BOTTOM ); view->addEventHandler( new ActivityMonitorTool(vbox) ); canvas->addControl( vbox ); } // Install an auto clip plane clamper if ( useAutoClip ) { mapNode->addCullCallback( new AutoClipPlaneCullCallback(mapNode) ); } // Install logarithmic depth buffer on main camera if ( useLogDepth ) { OE_INFO << LC << "Activating logarithmic depth buffer (vertex-only) on main camera" << std::endl; osgEarth::Util::LogarithmicDepthBuffer logDepth; logDepth.setUseFragDepth( false ); logDepth.install( view->getCamera() ); } else if ( useLogDepth2 ) { OE_INFO << LC << "Activating logarithmic depth buffer (precise) on main camera" << std::endl; osgEarth::Util::LogarithmicDepthBuffer logDepth; logDepth.setUseFragDepth( true ); logDepth.install( view->getCamera() ); } // Scan for images if necessary. if ( !imageFolder.empty() ) { std::vector<std::string> extensions; if ( !imageExtensions.empty() ) StringTokenizer( imageExtensions, extensions, ",;", "", false, true ); if ( extensions.empty() ) extensions.push_back( "tif" ); OE_INFO << LC << "Loading images from " << imageFolder << "..." << std::endl; ImageLayerVector imageLayers; DataScanner scanner; scanner.findImageLayers( imageFolder, extensions, imageLayers ); if ( imageLayers.size() > 0 ) { mapNode->getMap()->beginUpdate(); for( ImageLayerVector::iterator i = imageLayers.begin(); i != imageLayers.end(); ++i ) { mapNode->getMap()->addImageLayer( i->get() ); } mapNode->getMap()->endUpdate(); } OE_INFO << LC << "...found " << imageLayers.size() << " image layers." << std::endl; } // Install elevation morphing if ( !lodBlendingConf.empty() ) { mapNode->getTerrainEngine()->addEffect( new LODBlending(lodBlendingConf) ); } // Install vertical scaler if ( !vertScaleConf.empty() ) { mapNode->getTerrainEngine()->addEffect( new VerticalScale(vertScaleConf) ); } // Install a contour map effect. if ( !contourMapConf.empty() ) { mapNode->getTerrainEngine()->addEffect( new ContourMap(contourMapConf) ); } // Generic named value uniform with min/max. VBox* uniformBox = 0L; while( args.find( "--uniform" ) >= 0 ) { std::string name; float minval, maxval; if ( args.read( "--uniform", name, minval, maxval ) ) { if ( uniformBox == 0L ) { uniformBox = new VBox(); uniformBox->setBackColor(0,0,0,0.5); uniformBox->setAbsorbEvents( true ); canvas->addControl( uniformBox ); } osg::Uniform* uniform = new osg::Uniform(osg::Uniform::FLOAT, name); uniform->set( minval ); root->getOrCreateStateSet()->addUniform( uniform, osg::StateAttribute::OVERRIDE ); HBox* box = new HBox(); box->addControl( new LabelControl(name) ); HSliderControl* hs = box->addControl( new HSliderControl(minval, maxval, minval, new ApplyValueUniform(uniform))); hs->setHorizFill(true, 200); box->addControl( new LabelControl(hs) ); uniformBox->addControl( box ); OE_INFO << LC << "Installed uniform controller for " << name << std::endl; } } if ( inspect ) { mapNode->addExtension( Extension::create("mapinspector", ConfigOptions()) ); } // Process extensions. for(std::vector<osg::ref_ptr<Extension> >::const_iterator eiter = mapNode->getExtensions().begin(); eiter != mapNode->getExtensions().end(); ++eiter) { Extension* e = eiter->get(); // Check for a View interface: ExtensionInterface<osg::View>* viewIF = ExtensionInterface<osg::View>::get( e ); if ( viewIF ) viewIF->connect( view ); // Check for a Control interface: ExtensionInterface<Control>* controlIF = ExtensionInterface<Control>::get( e ); if ( controlIF ) controlIF->connect( mainContainer ); } root->addChild( canvas ); }
bool UIFocusTestNestedLayout2::init() { if (UIFocusTestBase::init()) { Size winSize = Director::getInstance()->getVisibleSize(); _horizontalLayout = HBox::create(); _horizontalLayout->setPosition(Vec2(winSize.width/2 - 200, winSize.height - 70)); _uiLayer->addChild(_horizontalLayout); _horizontalLayout->setScale(0.6); _horizontalLayout->setFocused(true); _horizontalLayout->setLoopFocus(true); _horizontalLayout->setTag(100); _firstFocusedWidget = _horizontalLayout; int count1 = 2; for (int i=0; i<count1; ++i) { ImageView *w = ImageView::create("cocosui/scrollviewbg.png"); w->setAnchorPoint(Vec2(0,1)); w->setTouchEnabled(true); w->setTag(i+count1); w->setScaleY(2.4); w->addTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout2::onImageViewClicked, this)); _horizontalLayout->addChild(w); } //add HBox into VBox VBox *vbox = VBox::create(); vbox->setScale(0.8); vbox->setTag(101); _horizontalLayout->addChild(vbox); int count2 = 2; for (int i=0; i < count2; ++i) { ImageView *w = ImageView::create("cocosui/scrollviewbg.png"); w->setAnchorPoint(Vec2(0,1)); w->setScaleX(2.0); w->setTouchEnabled(true); w->setTag(i+count1+count2); w->addTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout2::onImageViewClicked, this)); vbox->addChild(w); } HBox *innerHBox = HBox::create(); vbox->addChild(innerHBox); innerHBox->setTag(102); // innerVBox->setPassFocusToChild(false); // innerVBox->setFocusEnabled(false); int count3 = 2; for (int i=0; i<count3; ++i) { ImageView *w = ImageView::create("cocosui/scrollviewbg.png"); w->setTouchEnabled(true); w->setTag(i+count1+count2+count3); w->addTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout2::onImageViewClicked, this)); innerHBox->addChild(w); } _loopText = Text::create("loop enabled", "Airal", 20); _loopText->setPosition(Vec2(winSize.width/2, winSize.height - 50)); _loopText->setColor(Color3B::GREEN); this->addChild(_loopText); auto btn = Button::create("cocosui/switch-mask.png"); btn->setTitleText("Toggle Loop"); btn->setPosition(Vec2(60, winSize.height - 50)); btn->setTitleColor(Color3B::RED); btn->addTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout2::toggleFocusLoop, this)); this->addChild(btn); return true; } return false; }
int main(int argc, char *argv[]) { TestAction actionBidon; int init_flags = SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_JOYSTICK; if ( SDL_Init(init_flags) < 0 ) { fprintf(stderr, "SDL initialisation error: %s\n", SDL_GetError()); exit(1); } GameLoop *loop = GameUIDefaults::GAME_LOOP; SDL_Surface *display = SDL_SetVideoMode( 640, 480, 0, SDL_ANYFORMAT|SDL_HWSURFACE|SDL_DOUBLEBUF); if ( display == NULL ) { fprintf(stderr, "SDL_SetVideoMode error: %s\n", SDL_GetError()); exit(1); } loop->setSurface(display); atexit(SDL_Quit); SDL_ShowCursor(SDL_DISABLE); SDL_WM_SetCaption("FloboPop by iOS-Software",NULL); // Font par défaut SoFont *darkFont = SoFont_new(); SoFont *menuFont = SoFont_new(); SoFont *textFont = SoFont_new(); SoFont_load_ttf(darkFont, "data/base.000/gfx/font.ttf", 17, SoFont_DARK); SoFont_load_ttf(menuFont, "data/base.000/gfx/font.ttf", 17, SoFont_STD); SoFont_load_ttf(textFont, "data/base.000/gfx/font.ttf", 24, SoFont_GREY); GameUIDefaults::FONT_TEXT = textFont; GameUIDefaults::FONT = menuFont; GameUIDefaults::FONT_INACTIVE = darkFont; GameCursor *cursor = new GameCursor("data/base.000/gfx/cursor.png"); loop->addDrawable(cursor); loop->addIdle(cursor); Screen scr(0, 0, 640, 480); pscr = &scr; VBox bidonBox; Text bidonText("Hello"); ShowModalDialogAction showDialogAction(scr.getRootContainer()); FramePicture fpict(IIM_Load_Absolute_DisplayFormatAlpha("data/base.000/gfx/frame.png"), 25, 28, 25, 19, 26, 23); windowFramePict = &fpict; FramePicture fpict2(IIM_Load_Absolute_DisplayFormatAlpha( "data/base.000/gfx/editfield.png"), 5, 23, 4, 6, 10, 3); FramePicture fpict3(IIM_Load_Absolute_DisplayFormatAlpha( "data/base.000/gfx/separator.png"), 63, 2, 63, 2, 4, 2); RGBA blackTranslucient = {(Uint8)0x00, (Uint8)0x00, (Uint8)0x00, (Uint8)0x80}; RGBA buttonGray = {(Uint8)0xCC, (Uint8)0x95, (Uint8)0x36, (Uint8)0xFF}; RGBA textFieldColor = {(Uint8)0xFA, (Uint8)0xEF, (Uint8)0xDB, (Uint8)0xFF}; fpict.setContentColor(blackTranslucient); fpict2.setContentColor(textFieldColor); fpict3.setContentColor(buttonGray); Frame frame(&fpict), frame2(&fpict2); frame2.setFocusedPicture(&fpict3); //frame.setPreferedSize(Vec3(100, 100)); FramedButton framedButton1("Hi1", NULL, &fpict2, &fpict3); Button bidonButton1("Hi2", &showDialogAction); TestFloboStatsAction statsAction; Button bidonButton2("Stats", &statsAction); Button bidonButton3("Hop"); FramedEditField bidonField("toto", NULL, &fpict2, &fpict2); IIM_Surface *upArrow = IIM_Load_Absolute_DisplayFormatAlpha ("data/base.000/gfx/uparrow.png"); IIM_Surface *downArrow = IIM_Load_Absolute_DisplayFormatAlpha ("data/base.000/gfx/downarrow.png"); bidonBox.setPolicy(USE_MIN_SIZE); ListView list(10, upArrow, downArrow, &fpict); IIM_Surface *onSwitchImage = IIM_Load_Absolute_DisplayFormatAlpha ("data/base.000/gfx/switch-on.png"); IIM_Surface *offSwitchImage = IIM_Load_Absolute_DisplayFormatAlpha ("data/base.000/gfx/switch-off.png"); SwitchedButton prefSwitchA(String("Mon switch tout neuf A"), true, onSwitchImage, offSwitchImage, String("test.widget.switchbuttonAB")); SwitchedButton prefSwitchB(String("Mon switch tout neuf B sur la même pref que A"), true, onSwitchImage, offSwitchImage, String("test.widget.switchbuttonAB")); SwitchedButton prefSwitchC(String("Mon switch tout neuf C sur une autre pref"), false, onSwitchImage, offSwitchImage, String("test.widget.switchbuttonC")); bidonBox.add(&prefSwitchA); bidonBox.add(&prefSwitchB); bidonBox.add(&prefSwitchC); bidonBox.add(&bidonText); //bidonBox.add(&framedButton1); //bidonBox.add(&bidonButton1); bidonBox.add(&bidonButton2); //bidonBox.add(&frame2); bidonBox.add(&bidonField); bidonBox.add(&frame); for (int i = 0 ; i < 100 ; i++) { String newEntry("Bla bla "); list.addEntry(new ListViewEntry(newEntry + i, &actionBidon)); } frame.add(&list); //bidonBox.add(&list); bidonBox.add(&bidonButton3); //list.add(&bidonButton1); //list.add(&bidonButton2); BusyWidget busy; scr.add(&busy); scr.add(&bidonBox); GameUIDefaults::SCREEN_STACK->push(&scr); GameUIDefaults::GAME_LOOP->run(); return 0; }
bool Box::readProperties(XmlReader& e) { const QStringRef& tag(e.name()); if (tag == "height") _boxHeight = Spatium(e.readDouble()); else if (tag == "width") _boxWidth = Spatium(e.readDouble()); else if (tag == "topGap") { _topGap = e.readDouble(); if (score()->mscVersion() >= 203) _topGap *= score()->spatium(); } else if (tag == "bottomGap") { _bottomGap = e.readDouble(); if (score()->mscVersion() >= 203) _bottomGap *= score()->spatium(); } else if (tag == "leftMargin") _leftMargin = e.readDouble(); else if (tag == "rightMargin") _rightMargin = e.readDouble(); else if (tag == "topMargin") _topMargin = e.readDouble(); else if (tag == "bottomMargin") _bottomMargin = e.readDouble(); else if (tag == "Text") { Text* t; if (type() == Element::Type::TBOX) { t = static_cast<TBox*>(this)->text(); t->read(e); } else { t = new Text(score()); t->read(e); if (t->isEmpty()) { qDebug("read empty text"); } else add(t); } } else if (tag == "Symbol") { Symbol* s = new Symbol(score()); s->read(e); add(s); } else if (tag == "Image") { if (MScore::noImages) e.skipCurrentElement(); else { Image* image = new Image(score()); image->setTrack(e.track()); image->read(e); add(image); } } else if (tag == "FretDiagram") { FretDiagram* f = new FretDiagram(score()); f->read(e); add(f); } else if (tag == "LayoutBreak") { LayoutBreak* lb = new LayoutBreak(score()); lb->read(e); add(lb); } else if (tag == "HBox") { HBox* hb = new HBox(score()); hb->read(e); add(hb); } else if (tag == "VBox") { VBox* vb = new VBox(score()); vb->read(e); add(vb); } else if (Element::readProperties(e)) ; else return false; return true; }
/** creates some UI controls for adjusting the decluttering parameters. */ void createControls( osgViewer::View* view ) { ControlCanvas* canvas = ControlCanvas::getOrCreate(view); // title bar VBox* vbox = canvas->addControl(new VBox(Control::ALIGN_NONE, Control::ALIGN_BOTTOM, 2, 1 )); vbox->setBackColor( Color(Color::Black, 0.5) ); vbox->addControl( new LabelControl("osgEarth Tracks Demo", Color::Yellow) ); // checkbox that toggles decluttering of tracks struct ToggleDecluttering : public ControlEventHandler { void onValueChanged( Control* c, bool on ) { Decluttering::setEnabled( on ); } }; HBox* dcToggle = vbox->addControl( new HBox() ); dcToggle->addControl( new CheckBoxControl(true, new ToggleDecluttering()) ); dcToggle->addControl( new LabelControl("Declutter") ); // checkbox that toggles the coordinate display struct ToggleCoords : public ControlEventHandler { void onValueChanged( Control* c, bool on ) { g_showCoords = on; } }; HBox* coordsToggle = vbox->addControl( new HBox() ); coordsToggle->addControl( new CheckBoxControl(true, new ToggleCoords()) ); coordsToggle->addControl( new LabelControl("Show locations") ); // grid for the slider controls so they look nice Grid* grid = vbox->addControl( new Grid() ); grid->setHorizFill( true ); grid->setChildHorizAlign( Control::ALIGN_LEFT ); grid->setChildSpacing( 6 ); unsigned r=0; // event handler for changing decluttering options struct ChangeFloatOption : public ControlEventHandler { optional<float>& _param; LabelControl* _label; ChangeFloatOption( optional<float>& param, LabelControl* label ) : _param(param), _label(label) { } void onValueChanged( Control* c, float value ) { _param = value; _label->setText( Stringify() << std::fixed << std::setprecision(1) << value ); Decluttering::setOptions( g_dcOptions ); } }; grid->setControl( 0, r, new LabelControl("Sim loop duration:") ); LabelControl* speedLabel = grid->setControl( 2, r, new LabelControl(Stringify() << std::fixed << std::setprecision(1) << *g_duration) ); HSliderControl* speedSlider = grid->setControl( 1, r, new HSliderControl( 600.0, 30.0, *g_duration, new ChangeFloatOption(g_duration, speedLabel) ) ); speedSlider->setHorizFill( true, 200 ); grid->setControl( 0, ++r, new LabelControl("Min scale:") ); LabelControl* minAnimationScaleLabel = grid->setControl( 2, r, new LabelControl(Stringify() << std::fixed << std::setprecision(1) << *g_dcOptions.minAnimationScale()) ); grid->setControl( 1, r, new HSliderControl( 0.0, 1.0, *g_dcOptions.minAnimationScale(), new ChangeFloatOption(g_dcOptions.minAnimationScale(), minAnimationScaleLabel) ) ); grid->setControl( 0, ++r, new LabelControl("Min alpha:") ); LabelControl* alphaLabel = grid->setControl( 2, r, new LabelControl(Stringify() << std::fixed << std::setprecision(1) << *g_dcOptions.minAnimationAlpha()) ); grid->setControl( 1, r, new HSliderControl( 0.0, 1.0, *g_dcOptions.minAnimationAlpha(), new ChangeFloatOption(g_dcOptions.minAnimationAlpha(), alphaLabel) ) ); grid->setControl( 0, ++r, new LabelControl("Activate time (s):") ); LabelControl* actLabel = grid->setControl( 2, r, new LabelControl(Stringify() << std::fixed << std::setprecision(1) << *g_dcOptions.inAnimationTime()) ); grid->setControl( 1, r, new HSliderControl( 0.0, 2.0, *g_dcOptions.inAnimationTime(), new ChangeFloatOption(g_dcOptions.inAnimationTime(), actLabel) ) ); grid->setControl( 0, ++r, new LabelControl("Deactivate time (s):") ); LabelControl* deactLabel = grid->setControl( 2, r, new LabelControl(Stringify() << std::fixed << std::setprecision(1) << *g_dcOptions.outAnimationTime()) ); grid->setControl( 1, r, new HSliderControl( 0.0, 2.0, *g_dcOptions.outAnimationTime(), new ChangeFloatOption(g_dcOptions.outAnimationTime(), deactLabel) ) ); }
ColorPopup::ColorPopup(const ColorButtonOptions& options) : PopupWindowPin(" ", // Non-empty to create title-bar and close button ClickBehavior::CloseOnClickInOtherWindow, options.canPinSelector) , m_vbox(VERTICAL) , m_topBox(HORIZONTAL) , m_color(app::Color::fromMask()) , m_closeButton(nullptr) , m_colorPaletteContainer(options.showIndexTab ? new ui::View: nullptr) , m_colorPalette(options.showIndexTab ? new PaletteView(false, PaletteView::SelectOneColor, this, 7*guiscale()): nullptr) , m_simpleColors(nullptr) , m_oldAndNew(Shade(2), ColorShades::ClickEntries) , m_maskLabel("Transparent Color Selected") , m_canPin(options.canPinSelector) , m_insideChange(false) , m_disableHexUpdate(false) { if (options.showSimpleColors) { if (!g_simplePal) { ResourceFinder rf; rf.includeDataDir("palettes/tags.gpl"); if (rf.findFirst()) g_simplePal.reset(load_palette(rf.filename().c_str())); } if (g_simplePal) m_simpleColors = new SimpleColors(this, &m_tooltips); } ButtonSet::Item* item = m_colorType.addItem("Index"); item->setFocusStop(false); if (!options.showIndexTab) item->setVisible(false); m_colorType.addItem("RGB")->setFocusStop(false); m_colorType.addItem("HSV")->setFocusStop(false); m_colorType.addItem("HSL")->setFocusStop(false); m_colorType.addItem("Gray")->setFocusStop(false); m_colorType.addItem("Mask")->setFocusStop(false); m_topBox.setBorder(gfx::Border(0)); m_topBox.setChildSpacing(0); if (m_colorPalette) { m_colorPaletteContainer->attachToView(m_colorPalette); m_colorPaletteContainer->setExpansive(true); } m_sliders.setExpansive(true); m_topBox.addChild(&m_colorType); m_topBox.addChild(new Separator("", VERTICAL)); m_topBox.addChild(&m_hexColorEntry); m_topBox.addChild(&m_oldAndNew); // TODO fix this hack for close button in popup window // Move close button (decorative widget) inside the m_topBox { WidgetsList decorators; for (auto child : children()) { if (child->type() == kWindowCloseButtonWidget) { m_closeButton = child; removeChild(child); break; } } if (m_closeButton) { m_topBox.addChild(new BoxFiller); VBox* vbox = new VBox; vbox->addChild(m_closeButton); m_topBox.addChild(vbox); } } setText(""); // To remove title m_vbox.addChild(&m_tooltips); if (m_simpleColors) m_vbox.addChild(m_simpleColors); m_vbox.addChild(&m_topBox); if (m_colorPaletteContainer) m_vbox.addChild(m_colorPaletteContainer); m_vbox.addChild(&m_sliders); m_vbox.addChild(&m_maskLabel); addChild(&m_vbox); m_colorType.ItemChange.connect(base::Bind<void>(&ColorPopup::onColorTypeClick, this)); m_sliders.ColorChange.connect(&ColorPopup::onColorSlidersChange, this); m_hexColorEntry.ColorChange.connect(&ColorPopup::onColorHexEntryChange, this); m_oldAndNew.Click.connect(&ColorPopup::onSelectOldColor, this); // Set RGB just for the sizeHint(), and then deselect the color type // (the first setColor() call will setup it correctly.) selectColorType(app::Color::RgbType); m_colorType.deselectItems(); m_onPaletteChangeConn = App::instance()->PaletteChange.connect(&ColorPopup::onPaletteChange, this); InitTheme.connect( [this]{ setSizeHint(gfx::Size(300*guiscale(), sizeHint().h)); }); initTheme(); }
DinoGUI::DinoGUI(int argc, char** argv) : m_seq("Dino", m_song), m_proxy(m_song), m_dbus("org.nongnu.dino"), m_dbus_obj(0), m_plif(*this, m_song, m_seq, m_proxy, m_dbus.get_name()), m_plib(m_plif), m_valid(false) { if (!m_seq.is_valid()) { MessageDialog dlg("Could not initialise the sequencer!", false, MESSAGE_ERROR); dlg.run(); return; } if (!init_lash(argc, argv, m_seq.get_jack_name())) { MessageDialog dlg("Could not initialise LASH!", false, MESSAGE_ERROR); dlg.run(); return; } m_valid = true; m_dbus_obj = new DinoDBusObject(m_proxy, m_seq); m_dbus.register_object("/", m_dbus_obj); signal_timeout(). connect(bind(mem_fun(m_dbus, &DBus::Connection::run), 0), 50); // initialise the main window m_window.set_title("Dino"); Gtk::Window::set_default_icon_from_file(DATA_DIR "/head.png"); VBox* vbox = manage(new VBox); m_window.add(*vbox); MenuBar* mbar = manage(new MenuBar); init_menus(*mbar); vbox->pack_start(*mbar, PACK_SHRINK); vbox->pack_start(m_nb); m_statusbar.set_has_resize_grip(false); vbox->pack_start(m_statusbar, PACK_SHRINK); m_nb.set_border_width(3); // initialise the "About" dialog m_about_dialog.set_icon_from_file(DATA_DIR "/head.png"); m_about_dialog.set_name("Dino"); m_about_dialog.set_version(VERSION); m_about_dialog.set_copyright("\u00A9 " CR_YEAR " Lars Luthman " "<*****@*****.**>"); m_about_dialog.set_comments("A pattern based MIDI sequencer for GNU/Linux"); m_about_dialog.set_license(GPL_TEXT); m_about_dialog.set_logo(Pixbuf::create_from_file(DATA_DIR "/midisaurus.png")); // initialise the "Plugins" dialog m_plug_dialog.set_icon_from_file(DATA_DIR "/head.png"); m_plug_dialog.set_library(m_plib); m_nb.signal_switch_page(). connect(sigc::hide<0>(mem_fun(*this, &DinoGUI::page_switched))); load_plugins(argc, argv); reset_gui(); set_status("Welcome to Dino!"); }