void GridLayoutTimeline::reload() { mGridLayouts.clear(); // playback mIdxCurrentLayout = -1; mIdxPrevLayout = -1; mTransitionAmt = 1.0f; mPlaybackSpeed = 1.0f; mTotalDuration = 0; mStartTime = 0; mPlayheadTime = 0; mLastFrameTime = getMilliCount(); loadAllGrids(); if (mIdxCurrentLayout == -1) { ci::app::console() << "Didn't find any serialized grids." << endl; // Add an empty layout GridLayout newLayout; newLayout.setTimestamp(0); newLayout.setTransitionDuration(kDefaultTransitionDuration); mGridLayouts.push_back(newLayout); mIdxCurrentLayout = 0; } newLayoutWasSet(); }
// static GridLayout* GridLayout::CreatePanel(View* host) { GridLayout* layout = new GridLayout(host); layout->SetInsets(kPanelVertMargin, kPanelHorizMargin, kPanelVertMargin, kPanelHorizMargin); return layout; }
ExchangeIntern(DeviceBuffer<TYPE, DIM>& source, GridLayout<DIM> memoryLayout, DataSpace<DIM> guardingCells, uint32_t exchange, uint32_t communicationTag, uint32_t area = BORDER, bool sizeOnDevice = false) : Exchange<TYPE, DIM>(exchange, communicationTag), deviceDoubleBuffer(NULL) { assert(!guardingCells.isOneDimensionGreaterThan(memoryLayout.getGuard())); DataSpace<DIM> tmp_size = memoryLayout.getDataSpaceWithoutGuarding(); /* DataSpace<DIM> tmp_size = memoryLayout.getDataSpace() - memoryLayout.getGuard() - memoryLayout.getGuard(); delete on each side 2xguard*/ DataSpace<DIM> exchangeDimensions = exchangeTypeToDim(exchange); for (uint32_t dim = 0; dim < DIM; dim++) { if (DIM > dim && exchangeDimensions[dim] == 1) tmp_size[dim] = guardingCells[dim]; } /*This is only a pointer to other device data */ this->deviceBuffer = new DeviceBufferIntern<TYPE, DIM > (source, tmp_size, exchangeTypeToOffset(exchange, memoryLayout, guardingCells, area), sizeOnDevice); if (DIM > DIM1) { /*create double buffer on gpu for faster memory transfers*/ this->deviceDoubleBuffer = new DeviceBufferIntern<TYPE, DIM > (tmp_size, false, true); } this->hostBuffer = new HostBufferIntern<TYPE, DIM > (tmp_size); }
MessageHeader(Space simSize, GridLayout<DIM2> layout, Space nodeOffset) : simSize(simSize), nodeOffset(nodeOffset) { nodeSize = layout.getDataSpace(); nodePictureSize = layout.getDataSpaceWithoutGuarding(); nodeGuardCells = layout.getGuard(); }
Debrief::Debrief() : Dialog("Debrief"), mDebriefing(NULL), mNextMission(NULL), mReplay(NULL), mHomeBase(NULL), mMissionSelector(NULL) { setBackground(new FrameBackground()); Dimension screenSize = rGUIManager()->getScreenDimension(); setSize(MAGIC_DEBRIEF_WIDTH, MAGIC_DEBRIEF_HEIGHT); centerOnScreen(); mDebriefing = new Label(L"DEBRIEFING"); mNextMission = new Button(L"Next Mission", this); mReplay = new Button(L"Replay Mission", this); mHomeBase = new Button(L"Home Base", this); mMissionSelector = new Button(L"Missions", this); GridLayout* gridLayout = new GridLayout(this, 32, 24); gridLayout->set_borders(3); gridLayout->set_padding(2); gridLayout->add(new Label(L"Mission Complete: Debriefing"), 0, 0, 26, 1); gridLayout->add(mDebriefing, 0, 1, 32, 22); gridLayout->add(mMissionSelector, 0, 23, 6, 1); gridLayout->add(mHomeBase, 6, 23, 6, 1); gridLayout->add(mReplay, 20, 23, 6, 1); gridLayout->add(mNextMission, 26, 23, 6, 1); layout(); }
AugmentedView::AugmentedView(UIElementCollection * window, Engine * engine, cv::Mat _cameraMatrix) { cameraMatrix = new Mat(); _cameraMatrix.copyTo(*cameraMatrix); rotation = new Mat(); position = new Mat(); objectVector = std::vector<ARObject*>(); LOGI(LOGTAG_POSITION, "Created AugmentedView"); canDraw = false; Scalar selectColor = Colors::DodgerBlue; selectColor[3] = 80; selectionIndicator = new ARObject(OpenGLHelper::CreateSolidColorCube(1,selectColor)); selectedObject = NULL; SET_TIME(&lastSelectionTime); testObject = new ARObject(OpenGLHelper::CreateSolidColorCube(10,Colors::OrangeRed)); tabs = new TabDisplay(true); window->AddChild(tabs); createNext =false; GridLayout * myGrid = new GridLayout(cv::Size2i(5,4)); cancelSelection = new Button("Cancel"); cancelSelection->AddClickDelegate(ClickEventDelegate::from_method<AugmentedView,&AugmentedView::ButtonPressed>(this)); myGrid->AddChild(cancelSelection,Point2i(4,3)); cancelSelection->SetVisible(false); cancelSelection->Name = "Cancel"; releaseSelection = new Button("Release"); releaseSelection->AddClickDelegate(ClickEventDelegate::from_method<AugmentedView,&AugmentedView::ButtonPressed>(this)); myGrid->AddChild(releaseSelection,Point2i(4,2)); releaseSelection->SetVisible(false); releaseSelection->Name = "Release"; Button * createCube = new Button("Create"); createCube->AddClickDelegate(ClickEventDelegate::from_method<AugmentedView,&AugmentedView::ButtonPressed>(this)); myGrid->AddChild(createCube,Point2i(4,1)); createCube->Name = "Create"; createCube->FillColor = Colors::LightGreen; Button * deleteObject = new Button("Delete"); deleteObject->AddClickDelegate(ClickEventDelegate::from_method<AugmentedView,&AugmentedView::ButtonPressed>(this)); myGrid->AddChild(deleteObject,Point2i(4,0)); deleteObject->Name = "Delete"; deleteObject->FillColor = Colors::Orange; tabs->AddTab("AR",myGrid); LOGD(LOGTAG_ARINPUT,"Laying out tabs %d,%d",engine->imageWidth,engine->imageHeight); tabs->DoLayout(Rect(0,0,engine->imageWidth,engine->imageHeight)); tabs->SetTab(0); }
void SchnyderLayout::doCall( const Graph &G, adjEntry adjExternal, GridLayout &gridLayout, IPoint &boundingBox, bool fixEmbedding) { // check for double edges & self loops OGDF_ASSERT(isSimple(G)); // handle special case of graphs with less than 3 nodes if (G.numberOfNodes() < 3) { node v1, v2; switch (G.numberOfNodes()) { case 0: boundingBox = IPoint(0, 0); return; case 1: v1 = G.firstNode(); gridLayout.x(v1) = gridLayout.y(v1) = 0; boundingBox = IPoint(0, 0); return; case 2: v1 = G.firstNode(); v2 = G.lastNode(); gridLayout.x(v1) = gridLayout.y(v1) = gridLayout.y(v2) = 0; gridLayout.x(v2) = 1; boundingBox = IPoint(1, 0); return; } } // make a copy for triangulation GraphCopy GC(G); // embed if (!fixEmbedding) { if (planarEmbed(GC) == false) { OGDF_THROW_PARAM(PreconditionViolatedException, pvcPlanar); } } triangulate(GC); schnyderEmbedding(GC, gridLayout, adjExternal); }
void GridLayoutPlanRepModule::callGrid(PlanRep &PG, GridLayout &gridLayout) { gridLayout.init(PG); if (!handleTrivial(PG, gridLayout, m_gridBoundingBox)) { doCall(PG, nullptr, gridLayout, m_gridBoundingBox, false); } }
void FPPLayout::computeCoordinates(const GraphCopy &G, IPoint &boundingBox, GridLayout &gridLayout, NodeArray<int> &num, NodeArray<adjEntry> &e_wp, NodeArray<adjEntry> &e_wq) { NodeArray<int> &x = gridLayout.x(); NodeArray<int> &y = gridLayout.y(); const int n = G.numberOfNodes(); NodeArray<int> x_rel(G); NodeArray<node> upper(G); NodeArray<node> next(G); Array<node, int> v(1, n); node w, vk, wp, wq; int k, xq, dx; forall_nodes(w, G) { v[num[w]] = (node) w; }
MessageReader::MessageReader() : Dialog("MessageReader"), mMessageList(NULL), mMessagePane(NULL), mCloseButton(NULL) { setBackground(new FrameBackground()); Dimension screenSize = rGUIManager()->getScreenDimension(); setSize(MAGIC_MESSAGE_READER_WIDTH, MAGIC_MESSAGE_READER_HEIGHT); centerOnScreen(); mMessageList = new List(3, this, true); mMessageList->setBackground(new FrameBackground()); mMessageList->setColumnWidth(0, 0.15); mMessageList->setColumnWidth(1, 0.30); mMessageList->setColumnWidth(2, 0.55); mMessagePane = new Label(); mMessagePane->setBackground(new FrameBackground()); mCloseButton = new Button(L"Close", this); GridLayout* gridLayout = new GridLayout(this, 32, 24); gridLayout->set_borders(3); gridLayout->set_padding(2); gridLayout->add(new Label(L"Messages"), 0, 0, 26, 1); gridLayout->add(mCloseButton, 26, 0, 6, 1); gridLayout->add(mMessageList, 0, 1, 32, 11); gridLayout->add(mMessagePane, 0, 12, 32, 12); layout(); }
void GridLayoutPlanRepModule::callGridFixEmbed( PlanRep &PG, GridLayout &gridLayout, adjEntry adjExternal) { gridLayout.init(PG); if (!handleTrivial(PG, gridLayout, m_gridBoundingBox)) { doCall(PG, adjExternal, gridLayout, m_gridBoundingBox, true); } }
void PlanarGridLayoutModule::callGridFixEmbed( const Graph &G, GridLayout &gridLayout, adjEntry adjExternal) { gridLayout.init(G); if (!handleTrivial(G, gridLayout, m_gridBoundingBox)) { doCall(G, adjExternal, gridLayout, m_gridBoundingBox, true); } }
void PlanRep::collapseVertices(const OrthoRep &OR, GridLayout &drawing) { for (node v : nodes) { const OrthoRep::VertexInfoUML *vi = OR.cageInfo(v); if(vi == nullptr || (typeOf(v) != Graph::highDegreeExpander && typeOf(v) != Graph::lowDegreeExpander)) continue; node vOrig = original(v); OGDF_ASSERT(vOrig != 0); node vCenter = newNode(); m_vOrig[vCenter] = vOrig; m_vCopy[vOrig] = vCenter; m_vOrig[v] = nullptr; node lowerLeft = vi->m_corner[odNorth]->theNode(); node lowerRight = vi->m_corner[odWest ]->theNode(); node upperLeft = vi->m_corner[odEast ]->theNode(); drawing.x(vCenter) = (drawing.x(lowerLeft)+drawing.x(lowerRight)) >> 1; drawing.y(vCenter) = (drawing.y(lowerLeft)+drawing.y(upperLeft )) >> 1; edge eOrig; forall_adj_edges(eOrig,vOrig) { if(eOrig->target() == vOrig) { node connect = m_eCopy[eOrig].back()->target(); edge eNew = newEdge(connect,vCenter); m_eOrig[eNew] = eOrig; m_eIterator[eNew] = m_eCopy[eOrig].pushBack(eNew); } else { node connect = m_eCopy[eOrig].front()->source(); edge eNew = newEdge(vCenter,connect); m_eOrig[eNew] = eOrig; m_eIterator[eNew] = m_eCopy[eOrig].pushFront(eNew); } } } }
CompleteView() : mList(1) { View::mRootWidget = &mList; mList.setBackground(true); GridLayout* layout = new GridLayout(2); layout->add(new Image(R_IMAGE_1), 0); layout->add(new Image(R_IMAGE_2), 0); layout->add(new Label("Hello World!", GREEN), 1); //should wind up on the top left? layout->add(new StringLabel("String", GREEN), 1); layout->add(new Textbox(10, 20, GREEN, GREEN), 1); mList.add(layout, 0, -1, true); Textbox* t = new Textbox(10, 200, GREEN, WHITE/*BRIGHT_RED*/); mList.add(t, 0, -1, true); t->setQwerty(); t->activate(); mList.add(new MultilineLabel("Line 1\nLine 10\nYet another line\n ", GREEN), 0); mList.add(new Label("Next label", WHITE), 0); mList.add(new HyperlinkLabel(this, "To close the program, \1click here\1.\n Now for a \1line-\nbroken\1 link.", GREEN, SKY_BLUE), 0); }
void GridLayoutModule::mapGridLayout(const Graph &G, GridLayout &gridLayout, GraphAttributes &AG) { double maxWidth = 0; // maximum width of columns and rows; double yMax = 0; node v; forall_nodes(v,G) { if (AG.width (v) > maxWidth) maxWidth = AG.width (v); if (AG.height(v) > maxWidth) maxWidth = AG.height(v); if (gridLayout.y(v) > yMax) yMax = gridLayout.y(v); } maxWidth += m_separation; // set position of nodes forall_nodes(v,G) { AG.x(v) = gridLayout.x(v) * maxWidth; AG.y(v) = (yMax - gridLayout.y(v)) * maxWidth; }
void LogConfigScreen::CreateViews() { using namespace UI; I18NCategory *di = GetI18NCategory("Dialog"); I18NCategory *dev = GetI18NCategory("Developer"); root_ = new ScrollView(ORIENT_VERTICAL); LinearLayout *vert = root_->Add(new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT))); vert->SetSpacing(0); LinearLayout *topbar = new LinearLayout(ORIENT_HORIZONTAL); topbar->Add(new Choice(di->T("Back")))->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack); topbar->Add(new Choice(di->T("Toggle All")))->OnClick.Handle(this, &LogConfigScreen::OnToggleAll); topbar->Add(new Choice(di->T("Enable All")))->OnClick.Handle(this, &LogConfigScreen::OnEnableAll); topbar->Add(new Choice(di->T("Disable All")))->OnClick.Handle(this, &LogConfigScreen::OnDisableAll); topbar->Add(new Choice(dev->T("Log Level")))->OnClick.Handle(this, &LogConfigScreen::OnLogLevel); vert->Add(topbar); vert->Add(new ItemHeader(dev->T("Logging Channels"))); LogManager *logMan = LogManager::GetInstance(); int cellSize = 400; UI::GridLayoutSettings gridsettings(cellSize, 64, 5); gridsettings.fillCells = true; GridLayout *grid = vert->Add(new GridLayout(gridsettings, new LayoutParams(FILL_PARENT, WRAP_CONTENT))); for (int i = 0; i < LogManager::GetNumChannels(); i++) { LogTypes::LOG_TYPE type = (LogTypes::LOG_TYPE)i; LogChannel *chan = logMan->GetLogChannel(type); LinearLayout *row = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(cellSize - 50, WRAP_CONTENT)); row->SetSpacing(0); row->Add(new CheckBox(&chan->enabled, "", "", new LinearLayoutParams(50, WRAP_CONTENT))); row->Add(new PopupMultiChoice((int *)&chan->level, chan->m_shortName, logLevelList, 1, 6, 0, screenManager(), new LinearLayoutParams(1.0))); grid->Add(row); } }
bool PlanarGridLayoutModule::handleTrivial(const Graph &G, GridLayout &gridLayout, IPoint &boundingBox) { // handle special case of graphs with less than 3 nodes node v1, v2; switch (G.numberOfNodes()) { case 0: boundingBox = IPoint(0, 0); return true; case 1: v1 = G.firstNode(); gridLayout.x(v1) = gridLayout.y(v1) = 0; boundingBox = IPoint(0, 0); return true; case 2: v1 = G.firstNode(); v2 = G.lastNode(); gridLayout.x(v1) = gridLayout.y(v1) = gridLayout.y(v2) = 0; gridLayout.x(v2) = 1; boundingBox = IPoint(1, 0); return true; } return false; }
void GridLayoutPlanRepModule::doCall( const Graph &G, adjEntry adjExternal, GridLayout &gridLayout, IPoint &boundingBox, bool fixEmbedding) { // create temporary graph copy and grid layout PlanRep PG(G); PG.initCC(0); // currently only for a single component! GridLayout glPG(PG); // determine adjacency entry on external face of PG (if required) if(adjExternal != nullptr) { edge eG = adjExternal->theEdge(); edge ePG = PG.copy(eG); adjExternal = (adjExternal == eG->adjSource()) ? ePG->adjSource() : ePG->adjTarget(); } // call algorithm for copy doCall(PG,adjExternal,glPG,boundingBox,fixEmbedding); // extract layout for original graph for(node v : G.nodes) { node vPG = PG.copy(v); gridLayout.x(v) = glPG.x(vPG); gridLayout.y(v) = glPG.y(vPG); } for(edge e : G.edges) { IPolyline &ipl = gridLayout.bends(e); ipl.clear(); for(edge ec : PG.chain(e)) ipl.conc(glPG.bends(ec)); } }
void GridLayoutModule::mapGridLayout(const Graph &G, GridLayout &gridLayout, GraphAttributes &AG) { // maximum width of columns and rows double maxWidth = 0; double yMax = 0; for(node v : G.nodes) { Math::updateMax<double>(maxWidth, AG.width(v)); Math::updateMax<double>(maxWidth, AG.height(v)); Math::updateMax<double>(yMax, gridLayout.y(v)); } maxWidth += m_separation; // set position of nodes for(node v : G.nodes) { AG.x(v) = gridLayout.x(v) * maxWidth; AG.y(v) = (yMax - gridLayout.y(v)) * maxWidth; } // transform bend points of edges for(edge e : G.edges) { IPolyline ipl = gridLayout.polyline(e); // Remove superfluous bendpoints node v = e->source(); while(!ipl.empty() && ipl.front() == IPoint(gridLayout.x(v), gridLayout.y(v))) { ipl.popFront(); } v = e->target(); while(!ipl.empty() && ipl.back() == IPoint(gridLayout.x(v), gridLayout.y(v))) { ipl.popBack(); } DPolyline &dpl = AG.bends(e); dpl.clear(); for (const IPoint &ip : ipl) { dpl.pushBack(DPoint(ip.m_x*maxWidth, (yMax-ip.m_y)*maxWidth)); } dpl.normalize(); } }
void MixedModelLayout::doCall( PlanRep &PG, adjEntry adjExternal, GridLayout &gridLayout, IPoint &boundingBox, bool fixEmbedding) { // handle graphs with less than 3 nodes node v1, v2; switch (PG.numberOfNodes()) { case 0: boundingBox = IPoint(0,0); return; case 1: v1 = PG.firstNode(); gridLayout.x(v1) = gridLayout.y(v1) = 0; boundingBox = IPoint(0,0); return; case 2: v1 = PG.firstNode(); v2 = v1->succ(); gridLayout.x(v1) = gridLayout.y(v1) = gridLayout.y(v2) = 0; gridLayout.x(v2) = 1; boundingBox = IPoint(1,0); return; } MixedModelBase mm(PG,gridLayout); if(fixEmbedding) { OGDF_ASSERT(PG.representsCombEmbedding()); PlanarAugmentationFix fixAugmenter; mm.computeOrder(fixAugmenter, 0, adjExternal, m_compOrder.get()); } else mm.computeOrder(m_augmenter.get(),&m_embedder.get(),0,m_compOrder.get()); mm.assignIopCoords(); mm.placeNodes(); mm.postprocessing1(); mm.setBends(); mm.postprocessing2(); m_crossingsBeautifier.get().call(PG,gridLayout); int xmin, ymin; gridLayout.computeBoundingBox(xmin,boundingBox.m_x,ymin,boundingBox.m_y); }
void FPPLayout::doCall( const Graph &G, adjEntry adjExternal, GridLayout &gridLayout, IPoint &boundingBox, bool fixEmbedding) { // check for double edges & self loops OGDF_ASSERT(isSimple(G)); // handle special case of graphs with less than 3 nodes if (G.numberOfNodes() < 3) { node v1, v2; switch (G.numberOfNodes()) { case 0: boundingBox = IPoint(0, 0); return; case 1: v1 = G.firstNode(); gridLayout.x(v1) = gridLayout.y(v1) = 0; boundingBox = IPoint(0, 0); return; case 2: v1 = G.firstNode(); v2 = G.lastNode(); gridLayout.x(v1) = gridLayout.y(v1) = gridLayout.y(v2) = 0; gridLayout.x(v2) = 1; boundingBox = IPoint(1, 0); return; } } // make a copy for triangulation GraphCopy GC(G); // embed if (!fixEmbedding) { if (planarEmbed(GC) == false) { OGDF_THROW_PARAM(PreconditionViolatedException, pvcPlanar); } } triangulate(GC); // get edges for outer face (triangle) adjEntry e_12; if (adjExternal != 0) { edge eG = adjExternal->theEdge(); edge eGC = GC.copy(eG); e_12 = (adjExternal == eG->adjSource()) ? eGC->adjSource() : eGC->adjTarget(); } else { e_12 = GC.firstEdge()->adjSource(); } adjEntry e_2n = e_12->faceCycleSucc(); NodeArray<int> num(GC); NodeArray<adjEntry> e_wp(GC); // List of predecessors on circle C_k NodeArray<adjEntry> e_wq(GC); // List of successors on circle C_k computeOrder(GC, num , e_wp, e_wq, e_12, e_2n, e_2n->faceCycleSucc()); computeCoordinates(GC, boundingBox, gridLayout, num, e_wp, e_wq); }
void PlanarizationGridLayout::doCall( const Graph &G, GridLayout &gridLayout, IPoint &bb) { m_nCrossings = 0; if(G.empty()) return; PlanRep pr(G); const int numCC = pr.numberOfCCs(); // (width,height) of the layout of each connected component Array<IPoint> boundingBox(numCC); for(int cc = 0; cc < numCC; ++cc) { //-------------------------------------- // 1. crossing minimization //-------------------------------------- int cr; m_crossMin.get().call(pr, cc, cr); m_nCrossings += cr; OGDF_ASSERT(isPlanar(pr)); GridLayout gridLayoutPG(pr); m_planarLayouter.get().callGrid(pr,gridLayoutPG); // copy grid layout of PG into grid layout of G for(int j = pr.startNode(); j < pr.stopNode(); ++j) { node vG = pr.v(j); gridLayout.x(vG) = gridLayoutPG.x(pr.copy(vG)); gridLayout.y(vG) = gridLayoutPG.y(pr.copy(vG)); adjEntry adj; forall_adj(adj,vG) { if ((adj->index() & 1) == 0) continue; edge eG = adj->theEdge(); IPolyline &ipl = gridLayout.bends(eG); ipl.clear(); bool firstTime = true; ListConstIterator<edge> itE; for(itE = pr.chain(eG).begin(); itE.valid(); ++itE) { if(!firstTime) { node v = (*itE)->source(); ipl.pushBack(IPoint(gridLayoutPG.x(v),gridLayoutPG.y(v))); } else firstTime = false; ipl.conc(gridLayoutPG.bends(*itE)); } } } boundingBox[cc] = m_planarLayouter.get().gridBoundingBox(); boundingBox[cc].m_x += 1; // one row/column space between components boundingBox[cc].m_y += 1; } Array<IPoint> offset(numCC); m_packer.get().call(boundingBox,offset,m_pageRatio); bb.m_x = bb.m_y = 0; for(int cc = 0; cc < numCC; ++cc) { const int dx = offset[cc].m_x; const int dy = offset[cc].m_y; if(boundingBox[cc].m_x + dx > bb.m_x) bb.m_x = boundingBox[cc].m_x + dx; if(boundingBox[cc].m_y + dy > bb.m_y) bb.m_y = boundingBox[cc].m_y + dy; // iterate over all nodes in i-th cc for(int j = pr.startNode(cc); j < pr.stopNode(cc); ++j) { node vG = pr.v(j); gridLayout.x(vG) += dx; gridLayout.y(vG) += dy; adjEntry adj; forall_adj(adj,vG) { if ((adj->index() & 1) == 0) continue; edge eG = adj->theEdge(); ListIterator<IPoint> it; for(it = gridLayout.bends(eG).begin(); it.valid(); ++it) { (*it).m_x += dx; (*it).m_y += dy; } } } } bb.m_x -= 1; // remove margin of topmost/rightmost box bb.m_y -= 1; }
void TouchControlVisibilityScreen::CreateViews() { using namespace UI; root_ = new ScrollView(ORIENT_VERTICAL); LinearLayout *vert = root_->Add(new LinearLayout(ORIENT_VERTICAL, new LayoutParams(FILL_PARENT, FILL_PARENT))); vert->SetSpacing(0); LinearLayout *topBar = new LinearLayout(ORIENT_HORIZONTAL); I18NCategory *di = GetI18NCategory("Dialog"); topBar->Add(new Choice(di->T("Back")))->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack); topBar->Add(new Choice(di->T("Toggle All")))->OnClick.Handle(this, &TouchControlVisibilityScreen::OnToggleAll); vert->Add(topBar); I18NCategory *co = GetI18NCategory("Controls"); vert->Add(new ItemHeader(co->T("Touch Control Visibility"))); const int cellSize = 400; UI::GridLayoutSettings gridsettings(cellSize, 64, 5); gridsettings.fillCells = true; GridLayout *grid = vert->Add(new GridLayout(gridsettings, new LayoutParams(FILL_PARENT, WRAP_CONTENT))); std::map<std::string, int> keyImages; keyImages["Circle"] = I_CIRCLE; keyImages["Cross"] = I_CROSS; keyImages["Square"] = I_SQUARE; keyImages["Triangle"] = I_TRIANGLE; keyImages["Start"] = I_START; keyImages["Select"] = I_SELECT; keyImages["L"] = I_L; keyImages["R"] = I_R; keyImages["Combo0"] = I_1; keyImages["Combo1"] = I_2; keyImages["Combo2"] = I_3; keyImages["Combo3"] = I_4; keyImages["Combo4"] = I_5; keyToggles.clear(); keyToggles["Circle"] = &g_Config.bShowTouchCircle; keyToggles["Cross"] = &g_Config.bShowTouchCross; keyToggles["Square"] = &g_Config.bShowTouchSquare; keyToggles["Triangle"] = &g_Config.bShowTouchTriangle; keyToggles["L"] = &g_Config.bShowTouchLTrigger; keyToggles["R"] = &g_Config.bShowTouchRTrigger; keyToggles["Start"] = &g_Config.bShowTouchStart; keyToggles["Select"] = &g_Config.bShowTouchSelect; keyToggles["Dpad"] = &g_Config.bShowTouchDpad; keyToggles["Analog Stick"] = &g_Config.bShowTouchAnalogStick; keyToggles["Unthrottle"] = &g_Config.bShowTouchUnthrottle; keyToggles["Combo0"] = &g_Config.bShowComboKey0; keyToggles["Combo1"] = &g_Config.bShowComboKey1; keyToggles["Combo2"] = &g_Config.bShowComboKey2; keyToggles["Combo3"] = &g_Config.bShowComboKey3; keyToggles["Combo4"] = &g_Config.bShowComboKey4; std::map<std::string, int>::iterator imageFinder; I18NCategory *mc = GetI18NCategory("MappableControls"); for (auto i = keyToggles.begin(); i != keyToggles.end(); ++i) { LinearLayout *row = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); row->SetSpacing(0); CheckBox *checkbox = new CheckBox(i->second, "", "", new LinearLayoutParams(50, WRAP_CONTENT)); row->Add(checkbox); imageFinder = keyImages.find(i->first); Choice *choice; if (imageFinder != keyImages.end()) { choice = new Choice(keyImages[imageFinder->first], new LinearLayoutParams(1.0f)); } else { choice = new Choice(mc->T(i->first.c_str()), new LinearLayoutParams(1.0f)); } ChoiceEventHandler *choiceEventHandler = new ChoiceEventHandler(checkbox); choice->OnClick.Handle(choiceEventHandler, &ChoiceEventHandler::onChoiceClick); choice->SetCentered(true); row->Add(choice); grid->Add(row); } }
void PlanarDrawLayout::doCall( const Graph &G, adjEntry adjExternal, GridLayout &gridLayout, IPoint &boundingBox, bool fixEmbedding) { // require to have a planar graph without multi-edges and self-loops; // planarity is checked below OGDF_ASSERT(isSimple(G) && isLoopFree(G)); // handle special case of graphs with less than 3 nodes if(G.numberOfNodes() < 3) { node v1, v2; switch(G.numberOfNodes()) { case 0: boundingBox = IPoint(0,0); return; case 1: v1 = G.firstNode(); gridLayout.x(v1) = gridLayout.y(v1) = 0; boundingBox = IPoint(0,0); return; case 2: v1 = G.firstNode(); v2 = G.lastNode (); gridLayout.x(v1) = gridLayout.y(v1) = gridLayout.y(v2) = 0; gridLayout.x(v2) = 1; boundingBox = IPoint(1,0); return; } } // we make a copy of G since we use planar biconnected augmentation GraphCopySimple GC(G); if(fixEmbedding) { PlanarAugmentationFix augmenter; augmenter.call(GC); } else { // augment graph planar biconnected m_augmenter.get().call(GC); // embed augmented graph PlanarModule pm; bool isPlanar = pm.planarEmbed(GC); if(isPlanar == false) OGDF_THROW_PARAM(PreconditionViolatedException, pvcPlanar); } // compute shelling order m_computeOrder.get().baseRatio(m_baseRatio); ShellingOrder order; m_computeOrder.get().call(GC,order,adjExternal); // compute grid coordinates for GC NodeArray<int> x(GC), y(GC); computeCoordinates(GC,order,x,y); boundingBox.m_x = x[order(1,order.len(1))]; boundingBox.m_y = 0; node v; forall_nodes(v,GC) if(y[v] > boundingBox.m_y) boundingBox.m_y = y[v]; // copy coordinates from GC to G forall_nodes(v,G) { node vCopy = GC.copy(v); gridLayout.x(v) = x[vCopy]; gridLayout.y(v) = y[vCopy]; }
void PlanarizationGridLayout::doCall( const Graph &G, GridLayout &gridLayout, IPoint &bb) { m_nCrossings = 0; if(G.empty()) return; PlanRep PG(G); const int numCC = PG.numberOfCCs(); // (width,height) of the layout of each connected component Array<IPoint> boundingBox(numCC); int i; for(i = 0; i < numCC; ++i) { PG.initCC(i); const int nOrigVerticesPG = PG.numberOfNodes(); List<edge> deletedEdges; m_subgraph.get().callAndDelete(PG, deletedEdges); m_inserter.get().call(PG,deletedEdges); m_nCrossings += PG.numberOfNodes() - nOrigVerticesPG; GridLayout gridLayoutPG(PG); m_planarLayouter.get().callGrid(PG,gridLayoutPG); // copy grid layout of PG into grid layout of G ListConstIterator<node> itV; for(itV = PG.nodesInCC(i).begin(); itV.valid(); ++itV) { node vG = *itV; gridLayout.x(vG) = gridLayoutPG.x(PG.copy(vG)); gridLayout.y(vG) = gridLayoutPG.y(PG.copy(vG)); adjEntry adj; forall_adj(adj,vG) { if ((adj->index() & 1) == 0) continue; edge eG = adj->theEdge(); IPolyline &ipl = gridLayout.bends(eG); ipl.clear(); bool firstTime = true; ListConstIterator<edge> itE; for(itE = PG.chain(eG).begin(); itE.valid(); ++itE) { if(!firstTime) { node v = (*itE)->source(); ipl.pushBack(IPoint(gridLayoutPG.x(v),gridLayoutPG.y(v))); } else firstTime = false; ipl.conc(gridLayoutPG.bends(*itE)); } } } boundingBox[i] = m_planarLayouter.get().gridBoundingBox(); boundingBox[i].m_x += 1; // one row/column space between components boundingBox[i].m_y += 1; } Array<IPoint> offset(numCC); m_packer.get().call(boundingBox,offset,m_pageRatio); bb.m_x = bb.m_y = 0; for(i = 0; i < numCC; ++i) { const List<node> &nodes = PG.nodesInCC(i); const int dx = offset[i].m_x; const int dy = offset[i].m_y; if(boundingBox[i].m_x + dx > bb.m_x) bb.m_x = boundingBox[i].m_x + dx; if(boundingBox[i].m_y + dy > bb.m_y) bb.m_y = boundingBox[i].m_y + dy; // iterate over all nodes in i-th cc ListConstIterator<node> it; for(it = nodes.begin(); it.valid(); ++it) { node vG = *it; gridLayout.x(vG) += dx; gridLayout.y(vG) += dy; adjEntry adj; forall_adj(adj,vG) { if ((adj->index() & 1) == 0) continue; edge eG = adj->theEdge(); ListIterator<IPoint> it; for(it = gridLayout.bends(eG).begin(); it.valid(); ++it) { (*it).m_x += dx; (*it).m_y += dy; } } } } bb.m_x -= 1; // remove margin of topmost/rightmost box bb.m_y -= 1; }
void PlanarStraightLayout::doCall( const Graph &G, adjEntry adjExternal, GridLayout &gridLayout, IPoint &boundingBox, bool fixEmbedding) { // require to have a planar graph without multi-edges and self-loops; // planarity is checked below OGDF_ASSERT(isSimple(G) && isLoopFree(G)); // handle special case of graphs with less than 3 nodes if(G.numberOfNodes() < 3) { node v1, v2; switch(G.numberOfNodes()) { case 0: boundingBox = IPoint(0,0); return; case 1: v1 = G.firstNode(); gridLayout.x(v1) = gridLayout.y(v1) = 0; boundingBox = IPoint(0,0); return; case 2: v1 = G.firstNode(); v2 = G.lastNode (); gridLayout.x(v1) = gridLayout.y(v1) = gridLayout.y(v2) = 0; gridLayout.x(v2) = 1; boundingBox = IPoint(1,0); return; } } // we make a copy of G since we use planar biconnected augmentation GraphCopySimple GC(G); if(fixEmbedding) { // determine adjacency entry on external face of GC (if required) if(adjExternal != 0) { edge eG = adjExternal->theEdge(); edge eGC = GC.copy(eG); adjExternal = (adjExternal == eG->adjSource()) ? eGC->adjSource() : eGC->adjTarget(); } PlanarAugmentationFix augmenter; augmenter.call(GC); } else { adjExternal = 0; // augment graph planar biconnected m_augmenter.get().call(GC); // embed augmented graph m_embedder.get().call(GC,adjExternal); } // compute shelling order with shelling order module m_computeOrder.get().baseRatio(m_baseRatio); ShellingOrder order; m_computeOrder.get().callLeftmost(GC,order,adjExternal); // compute grid coordinates for GC NodeArray<int> x(GC), y(GC); computeCoordinates(GC,order,x,y); boundingBox.m_x = x[order(1,order.len(1))]; boundingBox.m_y = 0; node v; forall_nodes(v,GC) if(y[v] > boundingBox.m_y) boundingBox.m_y = y[v]; // copy coordinates from GC to G forall_nodes(v,G) { node vCopy = GC.copy(v); gridLayout.x(v) = x[vCopy]; gridLayout.y(v) = y[vCopy]; }
MissionSelector::MissionSelector() : Dialog("MissionSelector"), mCampaignList(NULL), mCampaignDesc(NULL), mMissionList(NULL), mMissionDesc(NULL), mHomeBaseButton(NULL), mStartButton(NULL), mCloseButton(NULL), mMissionNum(0), mCurrentCampaign(NULL) { setBackground(new FrameBackground()); Dimension screenSize = rGUIManager()->getScreenDimension(); setSize(MAGIC_MISSION_SELECTOR_WIDTH, MAGIC_MISSION_SELECTOR_HEIGHT); centerOnScreen(); mCampaignList = new List(1, this); mCampaignList->setBackground(new FrameBackground()); mCampaignDesc = new Label(); mCampaignDesc->setBackground(new FrameBackground()); mMissionList = new List(1, this); mMissionList->setBackground(new FrameBackground()); mMissionDesc = new Label(); mMissionDesc->setBackground(new FrameBackground()); mHomeBaseButton = new Button(L"Home Base", this); mStartButton = new Button(L"Start Mission", this); mCloseButton = new Button(L"Close", this); GridLayout* gridLayout = new GridLayout(this, 32, 24); gridLayout->set_borders(3); gridLayout->set_padding(2); gridLayout->add(new Label(L"Missions available - Select Campaign"), 0, 0, 26, 1); gridLayout->add(mCampaignList, 0, 1, 14, 7); gridLayout->add(mCampaignDesc, 14, 1, 18, 7); gridLayout->add(new Label(L"Available missions"), 0, 8, 26, 1); gridLayout->add(mMissionList, 0, 9, 14, 14); gridLayout->add(mMissionDesc, 14, 9, 18, 14); gridLayout->add(mHomeBaseButton, 6, 23, 6, 1); gridLayout->add(mStartButton, 0, 23, 6, 1); gridLayout->add(mCloseButton, 26, 23, 6, 1); layout(); }
void SchnyderLayout::schnyderEmbedding( GraphCopy& GC, GridLayout &gridLayout, adjEntry adjExternal) { NodeArray<int> &xcoord = gridLayout.x(); NodeArray<int> &ycoord = gridLayout.y(); node v; List<node> L; // (un)contraction order GraphCopy T = GraphCopy(GC); // the realizer tree (reverse direction of edges!!!) EdgeArray<int> rValues(T); // the realizer values // choose outer face a,b,c adjEntry adja; if (adjExternal != 0) { edge eG = adjExternal->theEdge(); edge eGC = GC.copy(eG); adja = (adjExternal == eG->adjSource()) ? eGC->adjSource() : eGC->adjTarget(); } else { adja = GC.firstEdge()->adjSource(); } adjEntry adjb = adja->faceCyclePred(); adjEntry adjc = adjb->faceCyclePred(); node a = adja->theNode(); node b = adjb->theNode(); node c = adjc->theNode(); node a_in_T = T.copy(GC.original(a)); node b_in_T = T.copy(GC.original(b)); node c_in_T = T.copy(GC.original(c)); contract(GC, a, b, c, L); realizer(GC, L, a, b, c, rValues, T); NodeArray<int> t1(T); NodeArray<int> t2(T); NodeArray<int> val(T, 1); NodeArray<int> P1(T); NodeArray<int> P3(T); NodeArray<int> v1(T); NodeArray<int> v2(T); subtreeSizes(rValues, 1, a_in_T, t1); subtreeSizes(rValues, 2, b_in_T, t2); prefixSum(rValues, 1, a_in_T, val, P1); prefixSum(rValues, 3, c_in_T, val, P3); // now Pi = depth of all nodes in Tree T(i) (depth[root] = 1) prefixSum(rValues, 2, b_in_T, t1, v1); // special treatment for a v1[a_in_T] = t1[a_in_T]; /* * v1[v] now is the sum of the * "count of nodes in t1" minus the "subtree size for node x" * for every node x on a path from b to v in t2 */ prefixSum(rValues, 3, c_in_T, t1, val); // special treatment for a val[a_in_T] = t1[a_in_T]; /* * val[v] now is the sum of the * "count of nodes in t1" minus the "subtree size for node x" * for every node x on a path from c to v in t3 */ // r1[v]=v1[v]+val[v]-t1[v] is the number of nodes in region 1 from v forall_nodes(v, T) { // calc v1' v1[v] += val[v] - t1[v] - P3[v]; }
ExampleApplication() : nanogui::Screen(Eigen::Vector2i(1024, 768), "NanoGUI Test") { using namespace nanogui; Window *window = new Window(this, "Button demo"); window->setPosition(Vector2i(15, 15)); window->setLayout(new GroupLayout()); /* No need to store a pointer, the data structure will be automatically freed when the parent window is deleted */ new Label(window, "Push buttons", "sans-bold"); Button *b = new Button(window, "Plain button"); b->setCallback([] { cout << "pushed!" << endl; }); b = new Button(window, "Styled", ENTYPO_ICON_ROCKET); b->setBackgroundColor(Color(0, 0, 255, 25)); b->setCallback([] { cout << "pushed!" << endl; }); new Label(window, "Toggle buttons", "sans-bold"); b = new Button(window, "Toggle me"); b->setFlags(Button::ToggleButton); b->setChangeCallback([](bool state) { cout << "Toggle button state: " << state << endl; }); new Label(window, "Radio buttons", "sans-bold"); b = new Button(window, "Radio button 1"); b->setFlags(Button::RadioButton); b = new Button(window, "Radio button 2"); b->setFlags(Button::RadioButton); new Label(window, "A tool palette", "sans-bold"); Widget *tools = new Widget(window); tools->setLayout(new BoxLayout(Orientation::Horizontal, Alignment::Middle, 0, 6)); b = new ToolButton(tools, ENTYPO_ICON_CLOUD); b = new ToolButton(tools, ENTYPO_ICON_FF); b = new ToolButton(tools, ENTYPO_ICON_COMPASS); b = new ToolButton(tools, ENTYPO_ICON_INSTALL); new Label(window, "Popup buttons", "sans-bold"); PopupButton *popupBtn = new PopupButton(window, "Popup", ENTYPO_ICON_EXPORT); Popup *popup = popupBtn->popup(); popup->setLayout(new GroupLayout()); new Label(popup, "Arbitrary widgets can be placed here"); new CheckBox(popup, "A check box"); popupBtn = new PopupButton(popup, "Recursive popup", ENTYPO_ICON_FLASH); popup = popupBtn->popup(); popup->setLayout(new GroupLayout()); new CheckBox(popup, "Another check box"); window = new Window(this, "Basic widgets"); window->setPosition(Vector2i(200, 15)); window->setLayout(new GroupLayout()); new Label(window, "Message dialog", "sans-bold"); tools = new Widget(window); tools->setLayout(new BoxLayout(Orientation::Horizontal, Alignment::Middle, 0, 6)); b = new Button(tools, "Info"); b->setCallback([&] { auto dlg = new MessageDialog(this, MessageDialog::Type::Information, "Title", "This is an information message"); dlg->setCallback([](int result) { cout << "Dialog result: " << result << endl; }); }); b = new Button(tools, "Warn"); b->setCallback([&] { auto dlg = new MessageDialog(this, MessageDialog::Type::Warning, "Title", "This is a warning message"); dlg->setCallback([](int result) { cout << "Dialog result: " << result << endl; }); }); b = new Button(tools, "Ask"); b->setCallback([&] { auto dlg = new MessageDialog(this, MessageDialog::Type::Warning, "Title", "This is a question message", "Yes", "No", true); dlg->setCallback([](int result) { cout << "Dialog result: " << result << endl; }); }); std::vector<std::pair<int, std::string>> icons = loadImageDirectory(mNVGContext, "icons"); new Label(window, "Image panel & scroll panel", "sans-bold"); PopupButton *imagePanelBtn = new PopupButton(window, "Image Panel"); imagePanelBtn->setIcon(ENTYPO_ICON_FOLDER); popup = imagePanelBtn->popup(); VScrollPanel *vscroll = new VScrollPanel(popup); ImagePanel *imgPanel = new ImagePanel(vscroll); imgPanel->setImages(icons); popup->setFixedSize(Vector2i(245, 150)); auto img_window = new Window(this, "Selected image"); img_window->setPosition(Vector2i(675, 15)); img_window->setLayout(new GroupLayout()); auto img = new ImageView(img_window); img->setPolicy(ImageView::SizePolicy::Expand); img->setFixedSize(Vector2i(300, 300)); img->setImage(icons[0].first); imgPanel->setCallback([&, img, imgPanel, imagePanelBtn](int i) { img->setImage(imgPanel->images()[i].first); cout << "Selected item " << i << endl; }); auto img_cb = new CheckBox(img_window, "Expand", [img](bool state) { if (state) img->setPolicy(ImageView::SizePolicy::Expand); else img->setPolicy(ImageView::SizePolicy::Fixed); }); img_cb->setChecked(true); new Label(window, "File dialog", "sans-bold"); tools = new Widget(window); tools->setLayout(new BoxLayout(Orientation::Horizontal, Alignment::Middle, 0, 6)); b = new Button(tools, "Open"); b->setCallback([&] { cout << "File dialog result: " << file_dialog( { {"png", "Portable Network Graphics"}, {"txt", "Text file"} }, false) << endl; }); b = new Button(tools, "Save"); b->setCallback([&] { cout << "File dialog result: " << file_dialog( { {"png", "Portable Network Graphics"}, {"txt", "Text file"} }, true) << endl; }); new Label(window, "Combo box", "sans-bold"); new ComboBox(window, { "Combo box item 1", "Combo box item 2", "Combo box item 3"}); new Label(window, "Check box", "sans-bold"); CheckBox *cb = new CheckBox(window, "Flag 1", [](bool state) { cout << "Check box 1 state: " << state << endl; } ); cb->setChecked(true); cb = new CheckBox(window, "Flag 2", [](bool state) { cout << "Check box 2 state: " << state << endl; } ); new Label(window, "Progress bar", "sans-bold"); mProgress = new ProgressBar(window); new Label(window, "Slider and text box", "sans-bold"); Widget *panel = new Widget(window); panel->setLayout(new BoxLayout(Orientation::Horizontal, Alignment::Middle, 0, 20)); Slider *slider = new Slider(panel); slider->setValue(0.5f); slider->setFixedWidth(80); TextBox *textBox = new TextBox(panel); textBox->setFixedSize(Vector2i(60, 25)); textBox->setValue("50"); textBox->setUnits("%"); slider->setCallback([textBox](float value) { textBox->setValue(std::to_string((int) (value * 100))); }); slider->setFinalCallback([&](float value) { cout << "Final slider value: " << (int) (value * 100) << endl; }); textBox->setFixedSize(Vector2i(60,25)); textBox->setFontSize(20); textBox->setAlignment(TextBox::Alignment::Right); window = new Window(this,"Misc. widgets"); window->setPosition(Vector2i(425,15)); window->setLayout(new GroupLayout()); new Label(window,"Color wheel","sans-bold"); new ColorWheel(window); new Label(window, "Function graph", "sans-bold"); Graph *graph = new Graph(window, "Some function"); graph->setHeader("E = 2.35e-3"); graph->setFooter("Iteration 89"); VectorXf &func = graph->values(); func.resize(100); for (int i = 0; i < 100; ++i) func[i] = 0.5f * (0.5f * std::sin(i / 10.f) + 0.5f * std::cos(i / 23.f) + 1); window = new Window(this, "Grid of small widgets"); window->setPosition(Vector2i(425, 288)); GridLayout *layout = new GridLayout(Orientation::Horizontal, 2, Alignment::Middle, 15, 5); layout->setColAlignment( { Alignment::Maximum, Alignment::Fill }); layout->setSpacing(0, 10); window->setLayout(layout); { new Label(window, "Floating point :", "sans-bold"); textBox = new TextBox(window); textBox->setEditable(true); textBox->setFixedSize(Vector2i(100, 20)); textBox->setValue("50"); textBox->setUnits("GiB"); textBox->setDefaultValue("0.0"); textBox->setFontSize(16); textBox->setFormat("[-]?[0-9]*\\.?[0-9]+"); } { new Label(window, "Positive integer :", "sans-bold"); textBox = new TextBox(window); textBox->setEditable(true); textBox->setFixedSize(Vector2i(100, 20)); textBox->setValue("50"); textBox->setUnits("Mhz"); textBox->setDefaultValue("0.0"); textBox->setFontSize(16); textBox->setFormat("[1-9][0-9]*"); } { new Label(window, "Checkbox :", "sans-bold"); cb = new CheckBox(window, "Check me"); cb->setFontSize(16); cb->setChecked(true); } new Label(window, "Combo box :", "sans-bold"); ComboBox *cobo = new ComboBox(window, { "Item 1", "Item 2", "Item 3" }); cobo->setFontSize(16); cobo->setFixedSize(Vector2i(100,20)); new Label(window, "Color button :", "sans-bold"); popupBtn = new PopupButton(window, "", 0); popupBtn->setBackgroundColor(Color(255, 120, 0, 255)); popupBtn->setFontSize(16); popupBtn->setFixedSize(Vector2i(100, 20)); popup = popupBtn->popup(); popup->setLayout(new GroupLayout()); ColorWheel *colorwheel = new ColorWheel(popup); colorwheel->setColor(popupBtn->backgroundColor()); Button *colorBtn = new Button(popup, "Pick"); colorBtn->setFixedSize(Vector2i(100, 25)); Color c = colorwheel->color(); colorBtn->setBackgroundColor(c); colorwheel->setCallback([colorBtn](const Color &value) { colorBtn->setBackgroundColor(value); }); colorBtn->setChangeCallback([colorBtn, popupBtn](bool pushed) { if (pushed) { popupBtn->setBackgroundColor(colorBtn->backgroundColor()); popupBtn->setPushed(false); } }); performLayout(mNVGContext); /* All NanoGUI widgets are initialized at this point. Now create an OpenGL shader to draw the main window contents. NanoGUI comes with a simple Eigen-based wrapper around OpenGL 3, which eliminates most of the tedious and error-prone shader and buffer object management. */ mShader.init( /* An identifying name */ "a_simple_shader", /* Vertex shader */ "#version 330\n" "uniform mat4 modelViewProj;\n" "in vec4 vertex;\n" "in vec3 color;\n" "out vec3 varying_color;\n" "void main() {\n" " gl_Position = modelViewProj * vertex;\n" " varying_color = color;\n" "}", /* Fragment shader */ "#version 330\n" "in vec3 varying_color;\n" "out vec4 frag_color;\n" "uniform float intensity;\n" "void main() {\n" " frag_color = vec4(intensity * varying_color, 1.0);\n" "}" ); mShader.registerAttribs({ {"color", "vec3"} }); mShader.registerUniforms({ {"modelViewProj", "mat4"}, {"intensity", "float"} }); }
ExampleApplication() : nanogui::Screen(Eigen::Vector2i(1024, 768), "NanoGUI Test") { using namespace nanogui; Window *window = new Window(this, "Button demo"); window->setPosition(Vector2i(15, 15)); window->setLayout(new GroupLayout()); /* No need to store a pointer, the data structure will be automatically freed when the parent window is deleted */ new Label(window, "Push buttons", "sans-bold"); Button *b = new Button(window, "Plain button"); b->setCallback([] { cout << "pushed!" << endl; }); /* Alternative construction notation using variadic template */ b = window->add<Button>("Styled", ENTYPO_ICON_ROCKET); b->setBackgroundColor(Color(0, 0, 255, 25)); b->setCallback([] { cout << "pushed!" << endl; }); new Label(window, "Toggle buttons", "sans-bold"); b = new Button(window, "Toggle me"); b->setFlags(Button::ToggleButton); b->setChangeCallback([](bool state) { cout << "Toggle button state: " << state << endl; }); new Label(window, "Radio buttons", "sans-bold"); b = new Button(window, "Radio button 1"); b->setFlags(Button::RadioButton); b = new Button(window, "Radio button 2"); b->setFlags(Button::RadioButton); new Label(window, "A tool palette", "sans-bold"); Widget *tools = new Widget(window); tools->setLayout(new BoxLayout(Orientation::Horizontal, Alignment::Middle, 0, 6)); b = new ToolButton(tools, ENTYPO_ICON_CLOUD); b = new ToolButton(tools, ENTYPO_ICON_FF); b = new ToolButton(tools, ENTYPO_ICON_COMPASS); b = new ToolButton(tools, ENTYPO_ICON_INSTALL); new Label(window, "Popup buttons", "sans-bold"); PopupButton *popupBtn = new PopupButton(window, "Popup", ENTYPO_ICON_EXPORT); Popup *popup = popupBtn->popup(); popup->setLayout(new GroupLayout()); new Label(popup, "Arbitrary widgets can be placed here"); new CheckBox(popup, "A check box"); popupBtn = new PopupButton(popup, "Recursive popup", ENTYPO_ICON_FLASH); popup = popupBtn->popup(); popup->setLayout(new GroupLayout()); new CheckBox(popup, "Another check box"); window = new Window(this, "Basic widgets"); window->setPosition(Vector2i(200, 15)); window->setLayout(new GroupLayout()); new Label(window, "Message dialog", "sans-bold"); tools = new Widget(window); tools->setLayout(new BoxLayout(Orientation::Horizontal, Alignment::Middle, 0, 6)); b = new Button(tools, "Info"); b->setCallback([&] { auto dlg = new MessageDialog(this, MessageDialog::Type::Information, "Title", "This is an information message"); dlg->setCallback([](int result) { cout << "Dialog result: " << result << endl; }); }); b = new Button(tools, "Warn"); b->setCallback([&] { auto dlg = new MessageDialog(this, MessageDialog::Type::Warning, "Title", "This is a warning message"); dlg->setCallback([](int result) { cout << "Dialog result: " << result << endl; }); }); b = new Button(tools, "Ask"); b->setCallback([&] { auto dlg = new MessageDialog(this, MessageDialog::Type::Warning, "Title", "This is a question message", "Yes", "No", true); dlg->setCallback([](int result) { cout << "Dialog result: " << result << endl; }); }); std::vector<std::pair<int, std::string>> icons = loadImageDirectory(mNVGContext, "icons"); new Label(window, "Image panel & scroll panel", "sans-bold"); PopupButton *imagePanelBtn = new PopupButton(window, "Image Panel"); imagePanelBtn->setIcon(ENTYPO_ICON_FOLDER); popup = imagePanelBtn->popup(); VScrollPanel *vscroll = new VScrollPanel(popup); ImagePanel *imgPanel = new ImagePanel(vscroll); imgPanel->setImages(icons); popup->setFixedSize(Vector2i(245, 150)); auto img_window = new Window(this, "Selected image"); img_window->setPosition(Vector2i(710, 15)); img_window->setLayout(new GroupLayout()); auto img = new ImageView(img_window); img->setPolicy(ImageView::SizePolicy::Expand); img->setFixedSize(Vector2i(275, 275)); img->setImage(icons[0].first); imgPanel->setCallback([&, img, imgPanel, imagePanelBtn](int i) { img->setImage(imgPanel->images()[i].first); cout << "Selected item " << i << endl; }); auto img_cb = new CheckBox(img_window, "Expand", [img](bool state) { if (state) img->setPolicy(ImageView::SizePolicy::Expand); else img->setPolicy(ImageView::SizePolicy::Fixed); }); img_cb->setChecked(true); new Label(window, "File dialog", "sans-bold"); tools = new Widget(window); tools->setLayout(new BoxLayout(Orientation::Horizontal, Alignment::Middle, 0, 6)); b = new Button(tools, "Open"); b->setCallback([&] { cout << "File dialog result: " << file_dialog( { {"png", "Portable Network Graphics"}, {"txt", "Text file"} }, false) << endl; }); b = new Button(tools, "Save"); b->setCallback([&] { cout << "File dialog result: " << file_dialog( { {"png", "Portable Network Graphics"}, {"txt", "Text file"} }, true) << endl; }); new Label(window, "Combo box", "sans-bold"); new ComboBox(window, { "Combo box item 1", "Combo box item 2", "Combo box item 3"}); new Label(window, "Check box", "sans-bold"); CheckBox *cb = new CheckBox(window, "Flag 1", [](bool state) { cout << "Check box 1 state: " << state << endl; } ); cb->setChecked(true); cb = new CheckBox(window, "Flag 2", [](bool state) { cout << "Check box 2 state: " << state << endl; } ); new Label(window, "Progress bar", "sans-bold"); mProgress = new ProgressBar(window); new Label(window, "Slider and text box", "sans-bold"); Widget *panel = new Widget(window); panel->setLayout(new BoxLayout(Orientation::Horizontal, Alignment::Middle, 0, 20)); Slider *slider = new Slider(panel); slider->setValue(0.5f); slider->setFixedWidth(80); TextBox *textBox = new TextBox(panel); textBox->setFixedSize(Vector2i(60, 25)); textBox->setValue("50"); textBox->setUnits("%"); slider->setCallback([textBox](float value) { textBox->setValue(std::to_string((int) (value * 100))); }); slider->setFinalCallback([&](float value) { cout << "Final slider value: " << (int) (value * 100) << endl; }); textBox->setFixedSize(Vector2i(60,25)); textBox->setFontSize(20); textBox->setAlignment(TextBox::Alignment::Right); window = new Window(this, "Misc. widgets"); window->setPosition(Vector2i(425,15)); window->setLayout(new GroupLayout()); TabWidget* tabWidget = window->add<TabWidget>(); Widget* layer = tabWidget->createTab("Color Wheel"); layer->setLayout(new GroupLayout()); // Use overloaded variadic add to fill the tab widget with Different tabs. layer->add<Label>("Color wheel widget", "sans-bold"); layer->add<ColorWheel>(); layer = tabWidget->createTab("Function Graph"); layer->setLayout(new GroupLayout()); layer->add<Label>("Function graph widget", "sans-bold"); Graph *graph = layer->add<Graph>("Some Function"); graph->setHeader("E = 2.35e-3"); graph->setFooter("Iteration 89"); VectorXf &func = graph->values(); func.resize(100); for (int i = 0; i < 100; ++i) func[i] = 0.5f * (0.5f * std::sin(i / 10.f) + 0.5f * std::cos(i / 23.f) + 1); // Dummy tab used to represent the last tab button. tabWidget->createTab("+"); // A simple counter. int counter = 1; tabWidget->setCallback([tabWidget, this, counter] (int index) mutable { if (index == (tabWidget->tabCount()-1)) { // When the "+" tab has been clicked, simply add a new tab. string tabName = "Dynamic " + to_string(counter); Widget* layerDyn = tabWidget->createTab(index, tabName); layerDyn->setLayout(new GroupLayout()); layerDyn->add<Label>("Function graph widget", "sans-bold"); Graph *graphDyn = layerDyn->add<Graph>("Dynamic function"); graphDyn->setHeader("E = 2.35e-3"); graphDyn->setFooter("Iteration " + to_string(index*counter)); VectorXf &funcDyn = graphDyn->values(); funcDyn.resize(100); for (int i = 0; i < 100; ++i) funcDyn[i] = 0.5f * std::abs((0.5f * std::sin(i / 10.f + counter) + 0.5f * std::cos(i / 23.f + 1 + counter))); ++counter; // We must invoke perform layout from the screen instance to keep everything in order. // This is essential when creating tabs dynamically. performLayout(); // Ensure that the newly added header is visible on screen tabWidget->ensureTabVisible(index); } }); tabWidget->setActiveTab(0); // A button to go back to the first tab and scroll the window. panel = window->add<Widget>(); panel->add<Label>("Jump to tab: "); panel->setLayout(new BoxLayout(Orientation::Horizontal, Alignment::Middle, 0, 6)); auto ib = panel->add<IntBox<int>>(); ib->setEditable(true); b = panel->add<Button>("", ENTYPO_ICON_FORWARD); b->setFixedSize(Vector2i(22, 22)); ib->setFixedHeight(22); b->setCallback([tabWidget, ib] { int value = ib->value(); if (value >= 0 && value < tabWidget->tabCount()) { tabWidget->setActiveTab(value); tabWidget->ensureTabVisible(value); } }); window = new Window(this, "Grid of small widgets"); window->setPosition(Vector2i(425, 300)); GridLayout *layout = new GridLayout(Orientation::Horizontal, 2, Alignment::Middle, 15, 5); layout->setColAlignment( { Alignment::Maximum, Alignment::Fill }); layout->setSpacing(0, 10); window->setLayout(layout); { new Label(window, "Floating point :", "sans-bold"); textBox = new TextBox(window); textBox->setEditable(true); textBox->setFixedSize(Vector2i(100, 20)); textBox->setValue("50"); textBox->setUnits("GiB"); textBox->setDefaultValue("0.0"); textBox->setFontSize(16); textBox->setFormat("[-]?[0-9]*\\.?[0-9]+"); } { new Label(window, "Positive integer :", "sans-bold"); auto intBox = new IntBox<int>(window); intBox->setEditable(true); intBox->setFixedSize(Vector2i(100, 20)); intBox->setValue(50); intBox->setUnits("Mhz"); intBox->setDefaultValue("0"); intBox->setFontSize(16); intBox->setFormat("[1-9][0-9]*"); intBox->setSpinnable(true); intBox->setMinValue(1); intBox->setValueIncrement(2); } { new Label(window, "Checkbox :", "sans-bold"); cb = new CheckBox(window, "Check me"); cb->setFontSize(16); cb->setChecked(true); } new Label(window, "Combo box :", "sans-bold"); ComboBox *cobo = new ComboBox(window, { "Item 1", "Item 2", "Item 3" }); cobo->setFontSize(16); cobo->setFixedSize(Vector2i(100,20)); new Label(window, "Color button :", "sans-bold"); popupBtn = new PopupButton(window, "", 0); popupBtn->setBackgroundColor(Color(255, 120, 0, 255)); popupBtn->setFontSize(16); popupBtn->setFixedSize(Vector2i(100, 20)); popup = popupBtn->popup(); popup->setLayout(new GroupLayout()); ColorWheel *colorwheel = new ColorWheel(popup); colorwheel->setColor(popupBtn->backgroundColor()); Button *colorBtn = new Button(popup, "Pick"); colorBtn->setFixedSize(Vector2i(100, 25)); Color c = colorwheel->color(); colorBtn->setBackgroundColor(c); colorwheel->setCallback([colorBtn](const Color &value) { colorBtn->setBackgroundColor(value); }); colorBtn->setChangeCallback([colorBtn, popupBtn](bool pushed) { if (pushed) { popupBtn->setBackgroundColor(colorBtn->backgroundColor()); popupBtn->setPushed(false); } }); performLayout(); /* All NanoGUI widgets are initialized at this point. Now create an OpenGL shader to draw the main window contents. NanoGUI comes with a simple Eigen-based wrapper around OpenGL 3, which eliminates most of the tedious and error-prone shader and buffer object management. */ mShader.init( /* An identifying name */ "a_simple_shader", /* Vertex shader */ "#version 330\n" "uniform mat4 modelViewProj;\n" "in vec3 position;\n" "void main() {\n" " gl_Position = modelViewProj * vec4(position, 1.0);\n" "}", /* Fragment shader */ "#version 330\n" "out vec4 color;\n" "uniform float intensity;\n" "void main() {\n" " color = vec4(vec3(intensity), 1.0);\n" "}" ); MatrixXu indices(3, 2); /* Draw 2 triangles */ indices.col(0) << 0, 1, 2; indices.col(1) << 2, 3, 0; MatrixXf positions(3, 4); positions.col(0) << -1, -1, 0; positions.col(1) << 1, -1, 0; positions.col(2) << 1, 1, 0; positions.col(3) << -1, 1, 0; mShader.bind(); mShader.uploadIndices(indices); mShader.uploadAttrib("position", positions); mShader.setUniform("intensity", 0.5f); }