Example #1
0
Widgets Vertical_paned::Get_children() const
{
	Widgets w;
	w.push_back(top);
	w.push_back(bottom);
	return w;
}
Example #2
0
void Setup::action(const gcn::ActionEvent &event)
{
    if (event.getId() == "Apply")
    {
        setVisible(false);
        for_each(mTabs.begin(), mTabs.end(), std::mem_fun(&SetupTabContainer::apply));
    }
    else if (event.getId() == "Cancel")
    {
        setVisible(false);
        for_each(mTabs.begin(), mTabs.end(), std::mem_fun(&SetupTabContainer::cancel));
    }
    else if (event.getId() == "Reset Windows")
    {
        Widgets widgets = windowContainer->getWidgetList();
        WidgetIterator iter;

        for (iter = widgets.begin(); iter != widgets.end(); ++iter)
        {
            Window* window = dynamic_cast<Window*>(*iter);

            if (window)
                window->resetToDefaultSize();
        }
    }
}
Example #3
0
void  GUIPanel::render(float tick)
{
  if(!isAttached() || !parent)
    return;

  Widgets comboBoxes;
  GUIComboBox *cbPTR;

  if(visible)
  {
    renderClippedBounds();
    for(size_t t = 0; t < elements.size(); t++)
      if(elements[t]->getWidgetType() != WT_COMBO_BOX)
        elements[t]->render(tick);
      else
      {
        cbPTR = (GUIComboBox*)elements[t];
        if(!cbPTR->isDeployed())
          cbPTR->render(tick);
        else
          comboBoxes.push_back(elements[t]);
      }

    for(size_t t = 0; t < comboBoxes.size(); t++)
      comboBoxes[t]->render(tick);
  }
}
Example #4
0
Widgets Horizontal_paned::Get_children() const
{
	Widgets w;
	w.push_back(left);
	w.push_back(right);
	return w;
}
Example #5
0
Widgets Expander::Get_children() const
{
	Widgets w;
	if(child) {
		w.push_back(child);
	}
	return w;
}
Example #6
0
void HBox_view::Render(const Widget& widget) const
{
	const Box& box = dynamic_cast<const Box&>(widget);
	Widgets widgets = box.Get_widgets();
	for(Widgets::iterator i = widgets.begin(); i != widgets.end(); ++i)
	{
		(*i)->Render();
	}
}
Example #7
0
    virtual Widgets GetWidgets() const
    {
        Widgets widgets;
        widgets.push_back(m_sizerStatBox->GetStaticBox());
        widgets.push_back(m_statText);
#if wxUSE_MARKUP
        widgets.push_back(m_statMarkup);
#endif // wxUSE_MARKUP
#if wxUSE_STATLINE
        widgets.push_back(m_statLine);
#endif // wxUSE_STATLINE

        return widgets;
    }
Example #8
0
Vector2 Box_view::Request_size(const Widget& widget) const
{
	Vector2 size;
	const Box& box = dynamic_cast<const Box&>(widget);
	Widgets widgets = box.Get_widgets();
	for(Widgets::iterator i = widgets.begin(); i != widgets.end(); ++i)
	{
		Vector2 ws = (*i)->Request_size();
		size.y += ws.y;
		if(ws.x>size.x)
			size.x = ws.x;
	}
	return size;
}
Example #9
0
void Setup_Video::apply()
{
    const std::string mode = mModeListModel->getElementAt(mModeList->getSelected());

    if (mode.find("x") != std::string::npos)
    {
        const int width = atoi(mode.substr(0, mode.find("x")).c_str());
        const int height = atoi(mode.substr(mode.find("x") + 1).c_str());

        gui->resize(width, height);
    }

    // Full screen changes
    bool fullscreen = mFsCheckBox->isSelected();
    if (fullscreen != (config.getValue("screen", false) == 1))
    {
        /* The OpenGL test is only necessary on Windows, since switching
         * to/from full screen works fine on Linux. On Windows we'd have to
         * reinitialize the OpenGL state and reload all textures.
         *
         * See http://libsdl.org/cgi/docwiki.cgi/SDL_SetVideoMode
         */

#ifdef WIN32
        // checks for opengl usage
        if (!(config.getValue("opengl", false) == 1))
        {
#endif
            if (!graphics->setFullscreen(fullscreen))
            {
                fullscreen = !fullscreen;
                if (!graphics->setFullscreen(fullscreen))
                {
                    std::stringstream error;
                    error << _("Failed to switch to ") <<
                        (fullscreen ? _("windowed") : _("fullscreen")) <<
                        _("mode and restoration of old mode also failed!") <<
                        std::endl;
                    logger->error(error.str());
                }
            }
#ifdef WIN32
        }
        else
        {
            new OkDialog(_("Switching to full screen"),
                         _("Restart needed for changes to take effect."));
        }
#endif
        config.setValue("screen", fullscreen ? true : false);
    }

    // OpenGL change
    if (mOpenGLCheckBox->isSelected() != mOpenGLEnabled)
    {
        config.setValue("opengl", mOpenGLCheckBox->isSelected() ? true : false);

        // OpenGL can currently only be changed by restarting, notify user.
        new OkDialog(_("Changing OpenGL"),
                     _("Applying change to OpenGL requires restart."));
    }

    if ((int) mFontSizeSlider->getValue() != mFontSize)
    {
        const int val = (int) mFontSizeSlider->getValue();

        gui->changeFontSize(val);

        Widgets widgets = windowContainer->getWidgetList();
        WidgetIterator iter;

        for (iter = widgets.begin(); iter != widgets.end(); ++iter)
        {
            Popup* popup = dynamic_cast<Popup*>(*iter);

            if (popup)
            {
                popup->adaptToNewSize();
                continue;
            }
        }

        if (state != GAME_STATE && desktop)
            desktop->resize();

        config.setValue("fontSize", val);
    }

    mFps = (mFpsCheckBox->isSelected()) ? (int) mFpsSlider->getValue() : 0;

    mFpsSlider->setEnabled(mFps > 0);

    // FPS change
    config.setValue("fpslimit", mFps);

    // We sync old and new values at apply time
    mFullScreenEnabled = config.getValue("screen", false);
    mOpenGLEnabled = config.getValue("opengl", false);
    mCustomCursorEnabled = config.getValue("customcursor", true);
    mNameEnabled = config.getValue("showownname", false);
    mPickupChatEnabled = config.getValue("showpickupchat", true);
    mPickupParticleEnabled = config.getValue("showpickupparticle", false);
    mSpeechMode = (int) config.getValue("speech", 3);
    mOpacity = config.getValue("guialpha", 0.8);
    mMouseOpacity = config.getValue("mousealpha", 0.7);
    mScreenWidth = (int) config.getValue("screenwidth", 800);
    mScreenHeight = (int) config.getValue("screenheight", 600);
    mFontSize = (int) config.getValue("fontSize", 11);
    mOverlayDetail = (int) config.getValue("OverlayDetail", 2);
    mParticleDetail = 3 - (int) config.getValue("particleEmitterSkip", 1);
    config.setValue("particleeffects", mParticleDetail != -1);
}
Example #10
0
void Editor_controller::Handle_event(const Ustring& event_handle, const Event& event) {
	Layout& layout = layout_controller->Get_layout();
	if(event_handle == "save") {
		ALLEGRO_FILECHOOSER* fc = al_create_native_file_dialog(
			layout.Get_filename().Cstring(),
			"Save",
			"*",
			ALLEGRO_FILECHOOSER_SAVE);
		al_show_native_file_dialog(NULL, fc);
		if(al_get_native_file_dialog_count(fc) > 0) {
			const char *filename = al_get_native_file_dialog_path(fc, 0);
			layout.Set_filename(filename);

			bool s = layout.Save_yaml();
			std::cout<<(s?"Saved":"Save failed")<<std::endl;
		}
		al_destroy_native_file_dialog(fc);
	}
	if(event_handle == "load") {
		ALLEGRO_FILECHOOSER* fc = al_create_native_file_dialog(
			layout.Get_filename().Cstring(),
			"Load",
			"*",
			ALLEGRO_FILECHOOSER_FILE_MUST_EXIST);
		al_show_native_file_dialog(NULL, fc);
		if(al_get_native_file_dialog_count(fc) > 0) {
			const char *filename = al_get_native_file_dialog_path(fc, 0);
			layout.Set_filename(filename);

			layout_controller->Clear();
			if(layout.Load_yaml())
			{
				std::cout<<"Loaded"<<std::endl;
				const Name_to_widget& layout_widgets = layout.Get_widgets();

				layout_controller->Set_root(layout.Get_root());
				layout_controller->Get_root()->Set_size(Vector2(al_get_display_width(layout_display), al_get_display_height(layout_display)));
				layout_controller->Set_tree(layout_controller->Get_root_tree(), layout.Get_root());

				typedef std::stack<Tree*> Trees_todo;
				Trees_todo trees_todo;
				trees_todo.push(layout_controller->Get_root_tree());
				
				while(!trees_todo.empty())
				{
					Tree* current_tree = trees_todo.top();
					trees_todo.pop();

					Container* parent = dynamic_cast<Container*>(layout_controller->Get_widget(current_tree));

					if(parent)
					{
						Widgets children = parent->Get_children();
						for(Widgets::iterator i = children.begin(); i != children.end(); ++i)
						{
							Tree* tree_child = layout_controller->Get_skin().Clone<Tree>("tree");
							tree_child->Set_text((*i)->Get_name());
							layout_controller->Set_tree(tree_child, *i);
							current_tree->Add_child(tree_child);
							events[Event(tree_child, "selected")] = "select";
							trees_todo.push(tree_child);
						}
					}
				}
			}
			else
			{
				layout_controller->Set_root(layout_controller->Get_skin().Clone<Desktop>("desktop"));
				layout_controller->Get_root()->Set_position(Vector2(0, 0));
				layout_controller->Get_root()->Set_size(Vector2(al_get_display_width(layout_display), al_get_display_height(layout_display)));
				
				layout.Add_widget("root", layout_controller->Get_root(), NULL);
				layout_controller->Set_tree(layout_controller->Get_root_tree(), layout_controller->Get_root());
			}
			layout_controller->Select_tree(NULL);
		}
		al_destroy_native_file_dialog(fc);
	}
	if(event_handle == "remove") {
		Tree* parent = dynamic_cast<Tree*>(layout_controller->Get_current_tree()->Get_parent());
		if(parent)
		{
			dynamic_cast<Container*>(layout_controller->Get_widget(parent))->Remove_child(layout_controller->Get_current_widget());

			parent->Remove_child(layout_controller->Get_current_tree());
			Trees deadlist;
			deadlist.push_back(layout_controller->Get_current_tree());
			layout_controller->Select_tree(NULL);
			int count = 0;
			while(!deadlist.empty())
			{
				Tree* current = deadlist.back();
				deadlist.erase(--deadlist.end());
				Trees& children = current->Get_children();
				for(Trees::iterator i = children.begin(); i != children.end(); ++i)
				{
					deadlist.push_back(*i);
				}
				layout.Remove_widget(layout_controller->Get_widget(current));
				layout_controller->Destroy_widget(current);
				++count;
			}
			layout_controller->Select_tree(parent);
			parent->Select();
		}
	}
	if(event_handle == "create") {
		std::cout<<"Create"<<std::endl;
		if(layout_controller->Get_current_tree())
		{
			std::cout<<"Current tree"<<std::endl;
			Menu* create_menu = dynamic_cast<Menu*>(controller_layout.Get_widget("create menu"));
			int option = create_menu->Get_selected_option();
			if(option != -1){
				Widget* child = layout_controller->Get_skin().Clone<Widget>(create_menu->Get_option(option));
				Container* parent = dynamic_cast<Container*>(layout_controller->Get_current_widget());
				std::cout<<"parent: "<<parent<<std::endl;

				if(parent && parent->Add_child(child))
				{
					Ustring name = layout.Add_widget(create_menu->Get_option(option), child, parent);
					Tree* tree_child = layout_controller->Get_skin().Clone<Tree>("tree");
					tree_child->Set_text(name);
					layout_controller->Get_current_tree()->Add_child(tree_child);
					layout_controller->Set_tree(tree_child, child);
					layout_controller->Get_current_tree()->Open();
					Text_interface* has_text = dynamic_cast<Text_interface*>(child);
					if(has_text)
						has_text->Set_text(name);
					events[Event(tree_child, "selected")] = "select";
				}
				else
					delete child;
			}
		}
	}

	if(event_handle == "select")
	{
		Tree* newsel = dynamic_cast<Tree*>(event.source);
		if(newsel)
		{
			Widget* tw = layout_controller->Get_widget(newsel);
			if(tw)
			{
				Container* attributes_vbox = dynamic_cast<Container*>(controller_layout.Get_widget("attribute vbox"));
				layout_controller->Select_tree(newsel);
				Widgets widgets = attributes_vbox->Get_children();
				for(Widgets::iterator i = widgets.begin(); i != widgets.end(); ++i) {
					attributes_vbox->Remove_child(*i);
				}
				attributes_vbox->Add_child(attribute_controllers["widget"]->Get_root());
				attribute_controllers["widget"]->Synchronize_values();
				Attribute_controllers::iterator ac = attribute_controllers.find(tw->Get_prototype_name().Cstring());
				if(ac != attribute_controllers.end()) {
					attributes_vbox->Add_child(ac->second->Get_root());
					ac->second->Synchronize_values();
				}
			}
		}
	}
	if(event_handle == "move up") {
		Tree* currenttree = dynamic_cast<Tree*>(layout_controller->Get_current_tree());
		Tree* parenttree = dynamic_cast<Tree*>(currenttree->Get_parent());
		if(currenttree && parenttree)
		{
			Widget* widget = layout_controller->Get_current_widget();
			Container* parent = dynamic_cast<Container*>(widget->Get_parent());
			Widgets children = parent->Get_children();
			Widgets::iterator i = std::find(children.begin(), children.end(), widget);
			Trees treechildren = parenttree->Get_children();
			Trees::iterator itree = std::find(treechildren.begin(), treechildren.end(), currenttree);
			if(i != children.begin()) {
				i = children.erase(i);
				itree = treechildren.erase(itree);
				if(i != children.begin()){
					--i;
					--itree;
				}
				children.insert(i, widget);
				treechildren.insert(itree, currenttree);
				for(Widgets::iterator i = children.begin(); i != children.end(); ++i) {
					parent->Remove_child(*i);
				}
				for(Trees::iterator i = treechildren.begin(); i != treechildren.end(); ++i) {
					parenttree->Remove_child(*i);
				}
				for(Widgets::iterator i = children.begin(); i != children.end(); ++i) {
					parent->Add_child(*i);
				}
				for(Trees::iterator i = treechildren.begin(); i != treechildren.end(); ++i) {
					parenttree->Add_child(*i);
				}
			}
		}
	}
	if(event_handle == "move down") {
		Tree* currenttree = dynamic_cast<Tree*>(layout_controller->Get_current_tree());
		Tree* parenttree = dynamic_cast<Tree*>(currenttree->Get_parent());
		if(currenttree && parenttree)
		{
			Widget* widget = layout_controller->Get_current_widget();
			Container* parent = dynamic_cast<Container*>(widget->Get_parent());
			Widgets children = parent->Get_children();
			Widgets::iterator i = std::find(children.begin(), children.end(), widget);
			Trees treechildren = parenttree->Get_children();
			Trees::iterator itree = std::find(treechildren.begin(), treechildren.end(), currenttree);
			if(i+1 != children.end()) {
				i = children.erase(i);
				itree = treechildren.erase(itree);
				++i;
				++itree;
				children.insert(i, widget);
				treechildren.insert(itree, currenttree);
				for(Widgets::iterator i = children.begin(); i != children.end(); ++i) {
					parent->Remove_child(*i);
				}
				for(Trees::iterator i = treechildren.begin(); i != treechildren.end(); ++i) {
					parenttree->Remove_child(*i);
				}
				for(Widgets::iterator i = children.begin(); i != children.end(); ++i) {
					parent->Add_child(*i);
				}
				for(Trees::iterator i = treechildren.begin(); i != treechildren.end(); ++i) {
					parenttree->Add_child(*i);
				}
			}
		}
	}
	if(event_handle == "cut") {
		std::cout<<"Cut"<<std::endl;
		Tree* currenttree = dynamic_cast<Tree*>(layout_controller->Get_current_tree());
		Tree* parenttree = dynamic_cast<Tree*>(currenttree->Get_parent());
		if(currenttree && parenttree)
		{
			Widget* widget = layout_controller->Get_current_widget();
			Container* parent = dynamic_cast<Container*>(widget->Get_parent());
			
			parent->Remove_child(widget);
			parenttree->Remove_child(currenttree);

			layout_controller->Select_tree(NULL);
			layout_controller->Select_tree(parenttree);
			parenttree->Select();

			if(cut_widget) {
				Trees deadlist;
				deadlist.push_back(cut_tree);
				int count = 0;
				while(!deadlist.empty())
				{
					Tree* current = deadlist.back();
					deadlist.erase(--deadlist.end());
					Trees& children = current->Get_children();
					for(Trees::iterator i = children.begin(); i != children.end(); ++i)
					{
						deadlist.push_back(*i);
					}
					layout.Remove_widget(layout_controller->Get_widget(current));
					layout_controller->Destroy_widget(current);
					++count;
				}
				std::cout<<"Deleted "<<count<<" widgets in cut buffer"<<std::endl;
			}
			
			cut_widget = widget;
			cut_tree = currenttree;
		}
	}
	if(event_handle == "paste") {
		Container* parent = dynamic_cast<Container*>(layout_controller->Get_current_widget());
		if(cut_widget && parent)
		{
			Tree* currenttree = dynamic_cast<Tree*>(layout_controller->Get_current_tree());
			parent->Add_child(cut_widget);
			currenttree->Add_child(cut_tree);
			layout_controller->Select_tree(cut_tree);
			cut_tree->Select();
			cut_widget = NULL;
			cut_tree = NULL;
		}
	}
}
Example #11
0
int main(int argc, char *argv[])
{
    MSS_BEGIN(int);
    TEST_TAG(main);
    //Color and Style tests
    {
        TEST_TAG(Color);
        cout << Color::red << endl;
        cout << Color(0.1, 0.2, 0.3) << endl;
        cout << Color({0.1, 0.2, 0.3}) << endl;

        cout << endl << "Symmetric shades between -1 and 1" << endl;
        cout << Color::shade<-1, 1>(-0.1) << endl;
        cout << Color::shade<-1, 1>(0) << " " << Color::black << endl;
        cout << Color::shade<-1, 1>(0.1) << endl;

        cout << endl << "Asymmetric shades between 0 and 1" << endl;
        cout << Color::shade<0, 1>(0.4) << endl;
        cout << Color::shade<0, 1>(0.5) << " " << Color::olive << endl;
        cout << Color::shade<0, 1>(0.6) << endl;

        cout << endl;
        cout << Style().fill(Color::red).stroke(Color::green).width(1.5) << endl;
    }

    //Multiple initialization of SDL
    auto sdl1 = SDL::initialize();
    auto sdl2 = SDL::initialize();

    //Creation of the SDL canvas
    SDLCanvas canvas(200, 100);

    //Draw some primitives on the canvas
    {
        //Functor that will be called by Sequence
        struct DrawColor: Sequence<double>::EachBlock
        {
            DrawColor(SDLCanvas &c):
                canvas(c){}
            SDLCanvas &canvas;
            bool yield(double v)
            {
                ICanvas::DrawScope sc(canvas);
                canvas.clear(Color::shade<0, 1>(v));
                canvas.drawCircle(Point<>(50+v*100, 50), 40, Style().stroke(Color::shade<-1, 1>(-1.0+v)).width(3));
                canvas.drawRectangle(TwoPoint<>(25+v*100, 25, 75+v*100, 75), Style().stroke(Color::shade<-1, 1>(v)).width(3));
                nanosleep(0, 5000000);
                return true;
            }
        } dc(canvas);
        for (int i = 0; i < 3; ++i)
        {
            //From red to green
            Sequence<double>(0, 1, 0.01).each(dc);
            //From green to red
            Sequence<double>(1, 0, -0.01).each(dc);
        }
    }

    //Demonstrate the creation and handling of button, IMUI-style
    Widgets widgets;
    Timer timer(ResetType::NoAuto);
    while (timer.difference() < 10)
    {
        if (canvas.getIMUI()->escapeIsPressed())
            break;
        ICanvas::DrawScope sc(canvas);

        //Create 4 placeholders for widgets. We will get _the same_ place holders each time we
        //loop, but they will all 4 be different since widgets.get() checks who is calling it
        {
            WidgetProxy &b1 = widgets.get(GUBG_HERE());
            WidgetProxy &b2 = widgets.get(GUBG_HERE());
            WidgetProxy &b3 = widgets.get(GUBG_HERE());
            WidgetProxy &b4 = widgets.get(GUBG_HERE());
            switch (b1.process())
            {
                case WidgetState::Empty:
                    b1.set(auto_ptr<IWidget>(new Button(TwoPoint<>(0, 0, 100, 25), "Named1", Alignment::Left, canvas)));
                    break;
                case WidgetState::Activated:
                    cout << "Named1 was pressed" << endl;
                    break;
            }
            switch (b2.process())
            {
                case WidgetState::Empty:
                    b2.set(auto_ptr<IWidget>(new Button(TwoPoint<>(0, 25, 100, 50), "Named2", Alignment::Left, canvas)));
                    break;
                case WidgetState::Activated:
                    cout << "Named2 was pressed" << endl;
                    break;
            }
            switch (b3.process())
            {
                case WidgetState::Empty:
                    b3.set(auto_ptr<IWidget>(new Button(TwoPoint<>(0, 50, 100, 75), "Named3", Alignment::Left, canvas)));
                    break;
                case WidgetState::Activated:
                    cout << "Named3 was pressed" << endl;
                    break;
            }
            switch (b4.process())
            {
                case WidgetState::Empty:
                    b4.set(auto_ptr<IWidget>(new Button(TwoPoint<>(0, 75, 100, 100), "Named4", Alignment::Left, canvas)));
                    break;
                case WidgetState::Activated:
                    cout << "Named4 was pressed" << endl;
                    break;
            }
        }

        //We use a for-loop to create 4 similar buttons, but now the source code location of the caller of widgets.get()
        //is each time _the same_, so we need to insert extra differentiating info to enable widgets.get() to discriminate between them
        {
            for (int i = 0; i < 4; ++i)
            {
                WidgetProxy &b = widgets.get(GUBG_HERE(), i);
                std::ostringstream oss;
                oss << "Unnamed" << i;
                switch (b.process())
                {
                    case WidgetState::Empty:
                        b.set(auto_ptr<IWidget>(new Button(TwoPoint<>(100, i*25, 200, (i+1)*25), oss.str(), Alignment::Left, canvas)));
                        break;
                    case WidgetState::Activated:
                        cout << oss.str() << " was pressed" << endl;
                        break;
                }
            }
        }

        //Don't burn the CPU
        nanosleep(0, 10000000);
    }
    MSS_END();
}