Example #1
0
	tab_bar::tab_bar(i_layout& aLayout, i_tab_page_container& aContainer) :
		widget(aLayout), iContainer(aContainer)
	{
		set_margins(neogfx::margins{});
		set_layout(std::make_shared<horizontal_layout>(*this));
		layout().set_margins(neogfx::margins{});
		layout().set_spacing(size{});
	}
Example #2
0
void create_game(ng::i_layout& aLayout)
{
    auto spritePlane = std::make_shared<ng::sprite_plane>();
    aLayout.add_item(spritePlane);
    spritePlane->set_font(ng::font(spritePlane->font(), ng::font::Bold, 28));
    spritePlane->set_background_colour(ng::colour::Black);
    spritePlane->enable_z_sorting(true);
    for (uint32_t i = 0; i < 1000; ++i)
        spritePlane->add_shape(std::make_shared<ng::rectangle>(
                                   *spritePlane,
                                   ng::vec3{static_cast<ng::scalar>(std::rand() % 800), static_cast<ng::scalar>(std::rand() % 800), -(static_cast<ng::scalar>(std::rand() % 32))},
                                   ng::size{static_cast<ng::scalar>(std::rand() % 64), static_cast<ng::scalar>(std::rand() % 64)},
                                   ng::colour(std::rand() % 64, std::rand() % 64, std::rand() % 64)));
    //spritePlane->set_uniform_gravity();
    //spritePlane->set_gravitational_constant(0.0);
    //spritePlane->create_earth();
    auto& spaceshipSprite = spritePlane->create_sprite(ng::image(sSpaceshipImagePattern, { {0, ng::colour()}, {1, ng::colour::LightGoldenrod}, {2, ng::colour::DarkGoldenrod4} }));
    spaceshipSprite.physics().set_mass(1.0);
    spaceshipSprite.set_size(ng::size(36.0, 36.0));
    spaceshipSprite.set_position_3D(ng::vec3(400.0, 18.0, 1.0));
    auto shipInfo = std::make_shared<ng::text>(*spritePlane, ng::vec3{}, "", ng::font("SnareDrum One NBP", "Regular", 24.0), ng::colour::White);
    shipInfo->set_border(1.0);
    shipInfo->set_margins(ng::margins(2.0));
    shipInfo->set_buddy(spaceshipSprite, ng::vec3{18.0, 18.0, 0.0});
    spritePlane->add_shape(shipInfo);
    spritePlane->sprites_painted([spritePlane](ng::graphics_context& aGraphicsContext)
    {
        aGraphicsContext.draw_text(ng::point(0.0, 0.0), "Hello, World!", spritePlane->font(), ng::colour::White);
    });
    spritePlane->physics_applied([spritePlane, &spaceshipSprite, shipInfo]()
    {
        const auto& keyboard = ng::app::instance().keyboard();
        spaceshipSprite.physics().set_acceleration({
            keyboard.is_key_pressed(ng::ScanCode_RIGHT) ? 16.0 : keyboard.is_key_pressed(ng::ScanCode_LEFT) ? -16.0 : 0.0,
            keyboard.is_key_pressed(ng::ScanCode_UP) ? 16.0 : keyboard.is_key_pressed(ng::ScanCode_DOWN) ? -16.0 : 0.0
        });
        if (keyboard.is_key_pressed(ng::ScanCode_X))
            spaceshipSprite.physics().set_spin_degrees(30.0);
        else if (keyboard.is_key_pressed(ng::ScanCode_Z))
            spaceshipSprite.physics().set_spin_degrees(-30.0);
        else
            spaceshipSprite.physics().set_spin_degrees(0.0);
        if (keyboard.is_key_pressed(ng::ScanCode_SPACE))
            spritePlane->add_sprite(std::make_shared<bullet>(spaceshipSprite));
        std::ostringstream oss;
        oss << "VELOCITY:  " << spaceshipSprite.physics().velocity().magnitude() << " m/s" << "\n";
        oss << "ACCELERATION:  " << spaceshipSprite.physics().acceleration().magnitude() << " m/s/s";
        shipInfo->set_value(oss.str());
    });
}
Example #3
0
    ViewingArea::ViewingArea(GLFWwindow* ptr, GLContext* context):PythonObject<ViewingArea>(this),zCamera_(-1),angle_(0),zScaleOrtho_(0.01f),glfwWindowPointer_(ptr),glContext_(context)
    {
      for(unsigned int i = 0;i<N_4X4_ELEMENTS;i++)   
	projectionMatrix_[i]=inverseProjectionMatrix_[i]=screenToDeviceMatrix_[i]=deviceToScreenMatrix_[i]=i%5?0:1;
      centerAndRelative_[X_INDEX]=centerAndRelative_[Y_INDEX]=0;
      insetCenter_[X_INDEX]=insetCenter_[Y_INDEX]=insetRelative_[X_INDEX]=insetRelative_[Y_INDEX]=0;
      int w,h;
      glfwGetWindowSize(ptr,&w,&h);
      set_size(w,h);
      set_margins(100,100,100,100);
      blow_up(0,0,1,1);
      set_z_camera(-1);
      set_viewing_angle(45);

    }
Example #4
0
	void slider_impl::init()
	{
		set_margins(neogfx::margins{});
		if (iType == Horizontal)
			set_size_policy(neogfx::size_policy{ neogfx::size_policy::Expanding, neogfx::size_policy::Minimum });
		else
			set_size_policy(neogfx::size_policy{ neogfx::size_policy::Minimum, neogfx::size_policy::Expanding });

		auto step_up = [this]()
		{
			set_normalized_value(std::max(0.0, std::min(1.0, normalized_value() + normalized_step_value())));
		};
		auto step_down = [this]()
		{
			set_normalized_value(std::max(0.0, std::min(1.0, normalized_value() - normalized_step_value())));
		};
	}
Example #5
0
	toolbar::toolbar(i_layout& aLayout) : widget(aLayout)
	{
		set_margins(neogfx::margins{});
		set_layout(std::make_shared<horizontal_layout>(*this));
	}
Example #6
0
	toolbar::toolbar()
	{
		set_margins(neogfx::margins{});
		set_layout(std::make_shared<horizontal_layout>(*this));
	}
Example #7
0
	void menu_item_widget::init()
	{
		set_margins(neogfx::margins{});
		iLayout.set_margins(neogfx::margins{ iGap, 0.0, iGap * (iMenu.type() == i_menu::Popup ? 2.0 : 1.0), 0.0 });
		iLayout.set_spacing(size{ iGap, 0.0 });
		if (iMenu.type() == i_menu::Popup)
			iIcon.set_fixed_size(size{ iIconSize, iIconSize });
		else
			iIcon.set_fixed_size(size{});
		iSpacer.set_minimum_size(size{ 0.0, 0.0 });
		auto text_updated = [this]()
		{
			auto m = mnemonic_from_text(iText.text());
			if (!m.empty())
				app::instance().add_mnemonic(*this);
			else
				app::instance().remove_mnemonic(*this);
		};
		iText.text_changed(text_updated, this);
		text_updated();
		if (iMenuItem.type() == i_menu_item::Action)
		{
			auto action_changed = [this]()
			{
				iIcon.set_image(iMenuItem.action().is_unchecked() ? iMenuItem.action().image() : iMenuItem.action().checked_image());
				if (!iIcon.image().is_empty())
					iIcon.set_fixed_size(size{ iIconSize, iIconSize });
				else if (iMenu.type() == i_menu::MenuBar)
					iIcon.set_fixed_size(size{});
				iText.set_text(iMenuItem.action().menu_text());
				if (iMenu.type() != i_menu::MenuBar)
					iShortcutText.set_text(iMenuItem.action().shortcut() != boost::none ? iMenuItem.action().shortcut()->as_text() : std::string());
				iSpacer.set_minimum_size(size{ iMenuItem.action().shortcut() != boost::none && iMenu.type() != i_menu::MenuBar ? iGap * 2.0 : 0.0, 0.0 });
				enable(iMenuItem.action().is_enabled());
			};
			iMenuItem.action().changed(action_changed, this);
			iMenuItem.action().checked(action_changed, this);
			iMenuItem.action().unchecked(action_changed, this);
			iMenuItem.action().enabled(action_changed, this);
			iMenuItem.action().disabled(action_changed, this);
			action_changed();
		}
		else
		{
			iMenuItem.sub_menu().opened([this]() {update(); }, this);
			iMenuItem.sub_menu().closed([this]() {update(); }, this);
			auto menu_changed = [this]() 
			{ 
				iIcon.set_image(iMenuItem.sub_menu().image());
				iText.set_text(iMenuItem.sub_menu().title());
			};
			iMenuItem.sub_menu().menu_changed(menu_changed, this);
			menu_changed();
		}
		iMenuItem.selected([this]()
		{
			if (iMenuItem.type() == i_menu_item::SubMenu && iMenu.type() == i_menu::Popup)
			{
				iSubMenuOpener = std::make_unique<neolib::callback_timer>(app::instance(), [this](neolib::callback_timer&)
				{
					if (!iMenuItem.sub_menu().is_open())
					{
						destroyed_flag destroyed(*this);
						iMenu.open_sub_menu.trigger(iMenuItem.sub_menu());
						if (!destroyed)
							update();
					}
				}, 250);
			}
		}, this);
		iMenuItem.deselected([this]()
		{
			iSubMenuOpener.reset();
		}, this);
	}
Example #8
0
	image_widget::image_widget(i_layout& aLayout, const i_image& aImage, aspect_ratio aAspectRatio, cardinal_placement aPlacement) :
		widget(aLayout), iTexture(aImage), iAspectRatio(aAspectRatio), iPlacement(aPlacement)
	{
		set_margins(neogfx::margins(0.0));
		set_ignore_mouse_events(true);
	}
Example #9
0
	image_widget::image_widget(i_widget& aParent, const i_texture& aTexture, aspect_ratio aAspectRatio, cardinal_placement aPlacement) :
		widget(aParent), iTexture(aTexture), iAspectRatio(aAspectRatio), iPlacement(aPlacement)
	{
		set_margins(neogfx::margins(0.0));
		set_ignore_mouse_events(true);
	}
Example #10
0
/**
 * \brief Set the vertical margin between the children components.
 * \param m The vertical margin between the children components.
 */
void bear::gui::horizontal_flow::set_vertical_margin( size_type m )
{
  set_margins( m_horizontal_margin, m );
} // horizontal_flow::set_vertical_margin()
Example #11
0
	colour_picker_dialog::yz_picker::yz_picker(colour_picker_dialog& aParent) :
		framed_widget(aParent.iRightTopLayout), iParent(aParent)
	{
		set_margins(neogfx::margins{});
	}
Example #12
0
	void colour_picker_dialog::init()
	{
		scoped_units su(static_cast<framed_widget&>(*this), UnitsPixels);
		static const std::set<colour> sBasicColours
		{
			colour::AliceBlue, colour::AntiqueWhite, colour::Aquamarine, colour::Azure, colour::Beige, colour::Bisque, colour::Black, colour::BlanchedAlmond, 
			colour::Blue, colour::BlueViolet, colour::Brown, colour::Burlywood, colour::CadetBlue, colour::Chartreuse, colour::Chocolate, colour::Coral, 
			colour::CornflowerBlue, colour::Cornsilk, colour::Cyan, colour::DarkBlue, colour::DarkCyan, colour::DarkGoldenrod, colour::DarkGray, colour::DarkGreen, 
			colour::DarkKhaki, colour::DarkMagenta, colour::DarkOliveGreen, colour::DarkOrange, colour::DarkOrchid, colour::DarkRed, colour::DarkSalmon, 
			colour::DarkSeaGreen, colour::DarkSlateBlue, colour::DarkSlateGray, colour::DarkTurquoise, colour::DarkViolet, colour::DebianRed, colour::DeepPink, 
			colour::DeepSkyBlue, colour::DimGray, colour::DodgerBlue, colour::Firebrick, colour::FloralWhite, colour::ForestGreen, colour::Gainsboro, 
			colour::GhostWhite, colour::Gold, colour::Goldenrod, colour::Gray, colour::Green, colour::GreenYellow, colour::Honeydew, colour::HotPink, 
			colour::IndianRed, colour::Ivory, colour::Khaki, colour::Lavender, colour::LavenderBlush, colour::LawnGreen, colour::LemonChiffon, colour::LightBlue, 
			colour::LightCoral, colour::LightCyan, colour::LightGoldenrod, colour::LightGoldenrodYellow, colour::LightGray, colour::LightGreen, colour::LightPink, 
			colour::LightSalmon, colour::LightSeaGreen, colour::LightSkyBlue, colour::LightSlateBlue, colour::LightSlateGray, colour::LightSteelBlue, 
			colour::LightYellow, colour::LimeGreen, colour::Linen, colour::Magenta, colour::Maroon, colour::MediumAquamarine, colour::MediumBlue, colour::MediumOrchid, 
			colour::MediumPurple, colour::MediumSeaGreen, colour::MediumSlateBlue, colour::MediumSpringGreen, colour::MediumTurquoise, colour::MediumVioletRed,
			colour::MidnightBlue, colour::MintCream, colour::MistyRose, colour::Moccasin, colour::NavajoWhite, colour::Navy, colour::NavyBlue, colour::OldLace, 
			colour::OliveDrab, colour::Orange, colour::OrangeRed, colour::Orchid, colour::PaleGoldenrod, colour::PaleGreen, colour::PaleTurquoise, colour::PaleVioletRed, 
			colour::PapayaWhip, colour::PeachPuff, colour::Peru, colour::Pink, colour::Plum, colour::PowderBlue, colour::Purple, colour::Red, colour::RosyBrown, 
			colour::RoyalBlue, colour::SaddleBrown, colour::Salmon, colour::SandyBrown, colour::SeaGreen, colour::Seashell, colour::Sienna, colour::SkyBlue, 
			colour::SlateBlue, colour::SlateGray, colour::Snow, colour::SpringGreen, colour::SteelBlue, colour::Tan, colour::Thistle, colour::Tomato, 
			colour::Turquoise, colour::Violet, colour::VioletRed, colour::Wheat, colour::White, colour::WhiteSmoke, colour::Yellow, colour::YellowGreen 
		};
		set_margins(neogfx::margins{16.0});
		iLayout.set_margins(neogfx::margins{});
		iLayout.set_spacing(16.0);
		iLayout2.set_margins(neogfx::margins{});
		iLayout2.set_spacing(16.0);
		iRightLayout.set_spacing(16.0);
		iRightTopLayout.set_spacing(16.0);
		iRightBottomLayout.set_spacing(8.0);
		iChannelLayout.set_spacing(8.0);
		iH.first.label().text().set_text("&Hue:"); iH.second.set_size_policy(size_policy::Minimum); iH.second.text_box().set_hint("000000"); iH.second.set_minimum(0); iH.second.set_maximum(360); iH.second.set_step(1);
		iS.first.label().text().set_text("&Sat:"); iS.second.set_size_policy(size_policy::Minimum); iS.second.text_box().set_hint("000000"); iS.second.set_minimum(0); iS.second.set_maximum(100); iS.second.set_step(1);
		iV.first.label().text().set_text("&Val:"); iV.second.set_size_policy(size_policy::Minimum); iV.second.text_box().set_hint("000000"); iV.second.set_minimum(0); iV.second.set_maximum(100); iV.second.set_step(1);
		iR.first.label().text().set_text("&Red:"); iR.second.set_size_policy(size_policy::Minimum); iR.second.text_box().set_hint("000000"); iR.second.set_minimum(0); iR.second.set_maximum(255); iR.second.set_step(1);
		iG.first.label().text().set_text("&Green:"); iG.second.set_size_policy(size_policy::Minimum); iG.second.text_box().set_hint("000000"); iG.second.set_minimum(0); iG.second.set_maximum(255); iG.second.set_step(1);
		iB.first.label().text().set_text("&Blue:"); iB.second.set_size_policy(size_policy::Minimum); iB.second.text_box().set_hint("000000"); iB.second.set_minimum(0); iB.second.set_maximum(255); iB.second.set_step(1);
		iA.first.label().text().set_text("&Alpha:"); iA.second.set_size_policy(size_policy::Minimum); iA.second.text_box().set_hint("000000"); iA.second.set_minimum(0); iA.second.set_maximum(255); iA.second.set_step(1);
		iRgb.first.text().set_text("&#:"); iRgb.second.set_size_policy(size_policy::Minimum); iRgb.second.set_hint("000000"); 
		iChannelLayout.set_dimensions(4, 4);
		iChannelLayout.add_item(iH.first); iChannelLayout.add_item(iH.second);
		iChannelLayout.add_item(iR.first); iChannelLayout.add_item(iR.second);
		iChannelLayout.add_item(iS.first); iChannelLayout.add_item(iS.second);
		iChannelLayout.add_item(iG.first); iChannelLayout.add_item(iG.second);
		iChannelLayout.add_item(iV.first); iChannelLayout.add_item(iV.second);
		iChannelLayout.add_item(iB.first); iChannelLayout.add_item(iB.second);
		iChannelLayout.add_item(iRgb.first); iChannelLayout.add_item(iRgb.second);
		iChannelLayout.add_item(iA.first); iChannelLayout.add_item(iA.second);
		iBasicColoursLayout.set_dimensions(12, 12);
		for (auto const& basicColour : sBasicColours)
			iBasicColoursLayout.add_item(std::make_shared<colour_box>(*this, basicColour));
		iCustomColoursLayout.set_dimensions(2, 12);
		for (uint32_t i = 0; i < 24; ++i)
			iCustomColoursLayout.add_item(std::make_shared<colour_box>(*this, colour::White));
		button_box().add_button(dialog_button_box::Ok);
		button_box().add_button(dialog_button_box::Cancel);
		resize(minimum_size());
		rect desktopRect{ app::instance().surface_manager().desktop_rect(surface()) };
		move_surface((desktopRect.extents() - surface_size()) / 2.0);
	}
Example #13
0
	colour_picker_dialog::colour_box::colour_box(colour_picker_dialog& aParent, const colour& aColour) :
		framed_widget(aParent, SolidFrame), iParent(aParent), iColour(aColour)
	{
		set_margins(neogfx::margins{});
	}
Example #14
0
	colour_picker_dialog::colour_selection::colour_selection(colour_picker_dialog& aParent) :
		framed_widget(aParent.iRightBottomLayout), iParent(aParent)
	{
		set_margins(neogfx::margins{});
	}
Example #15
0
	void dialog_button_box::init()
	{
		set_margins(neogfx::margins{});
		iLayout.set_margins(neogfx::margins{});
	}