Exemple #1
0
	void slider_impl::paint(graphics_context& aGraphicsContext) const
	{
		scoped_units su(*this, UnitsPixels);
		rect rectBarBox = bar_box();
		colour ink = background_colour().light(0x80) ? background_colour().darker(0x80) : background_colour().lighter(0x80);
		aGraphicsContext.fill_rounded_rect(rectBarBox, 2.0, ink);
		rectBarBox.deflate(size{1.0, 1.0});
		aGraphicsContext.fill_rounded_rect(rectBarBox, 2.0, ink.mid(background_colour()));
		rect rectValue = rectBarBox;
		rectValue.cx = rectValue.width() * normalized_value();
		if (normalized_value() > 0.0)
			aGraphicsContext.fill_rounded_rect(rectValue, 2.0, app::instance().current_style().selection_colour());
		rect rectIndicator = indicator_box();
		colour indicatorColour = foreground_colour();
		if (iDragOffset != boost::none)
		{
			if (indicatorColour.light(0x40))
				indicatorColour.darken(0x40);
			else
				indicatorColour.lighten(0x40);
		}
		colour indicatorBorderColour = indicatorColour.darker(0x40);
		indicatorColour.lighten(0x40);
		aGraphicsContext.fill_circle(rectIndicator.centre(), rectIndicator.width() / 2.0, indicatorBorderColour);
		aGraphicsContext.fill_circle(rectIndicator.centre(), rectIndicator.width() / 2.0 - 1.0, indicatorColour);
	}
	void colour_picker_dialog::colour_selection::paint(graphics_context& aGraphicsContext) const
	{
		framed_widget::paint(aGraphicsContext);
		rect cr = client_rect(false);
		aGraphicsContext.fill_rect(cr, iParent.selected_colour());
		cr.y = cr.cy / 2.0;
		aGraphicsContext.fill_rect(cr, iParent.current_colour());
	}
Exemple #3
0
	graphics_context::graphics_context(const graphics_context& aOther) :
		iSurface(aOther.iSurface), 
		iNativeGraphicsContext(aOther.iNativeGraphicsContext->clone()), 
		iUnitsContext(*this), 
		iDefaultFont(aOther.iDefaultFont), 
		iOrigin(aOther.origin()),
		iExtents(aOther.extents()),
		iDrawingGlyphs(0)
	{
	}
Exemple #4
0
	scoped_coordinate_system::scoped_coordinate_system(graphics_context& aGc, const point& aOrigin, const size& aExtents, logical_coordinate_system aCoordinateSystem, const vector4& aCoordinates) :
		iGc(aGc), iPreviousCoordinateSystem(aGc.logical_coordinate_system()), iPreviousCoordinates(aGc.logical_coordinates())
	{
		iGc.set_logical_coordinate_system(aCoordinateSystem);
		iGc.set_logical_coordinates(aCoordinates);
		apply_origin(aOrigin, aExtents);
	}
Exemple #5
0
	void menu_item_widget::paint_non_client(graphics_context& aGraphicsContext) const
	{
		if (iMenu.has_selected_item() && iMenu.selected_item() == (iMenu.find_item(iMenuItem)))
		{
			bool openSubMenu = (iMenuItem.type() == i_menu_item::SubMenu && iMenuItem.sub_menu().is_open());
			colour background;
			if (openSubMenu && iMenu.type() == i_menu::MenuBar)
			{
				background = app::instance().current_style().colour().dark() ?
					app::instance().current_style().colour().darker(0x40) :
					app::instance().current_style().colour().lighter(0x40);
				if (background.similar_intensity(app::instance().current_style().colour(), 0.05))
				{
					background = app::instance().current_style().selection_colour();
					background.set_alpha(0x80);
				}
			}
			else
			{
				background = background_colour().light() ? background_colour().darker(0x40) : background_colour().lighter(0x40);
				background.set_alpha(0x80);
			}
			aGraphicsContext.fill_rect(client_rect(), background);
		}
	}
Exemple #6
0
	void toolbar_button::paint(graphics_context& aGraphicsContext) const
	{
		if (!iAction.is_separator())
			push_button::paint(aGraphicsContext);
		else
		{
			scoped_units su(*this, aGraphicsContext, UnitsPixels);
			rect line = client_rect();
			line.deflate(0, std::floor(client_rect().height() / 6.0));
			line.cx = 1.0;
			colour ink = (has_foreground_colour() ? foreground_colour() : app::instance().current_style().foreground_colour());
			aGraphicsContext.fill_rect(line, ink.darker(0x40));
			++line.x;
			aGraphicsContext.fill_rect(line, ink.lighter(0x40));
		}
	}
Exemple #7
0
	void menu_item_widget::paint(graphics_context& aGraphicsContext) const
	{
		if (iMenuItem.type() != i_menu_item::Action || !iMenuItem.action().is_separator())
		{
			widget::paint(aGraphicsContext);
			if (iMenuItem.type() == i_menu_item::SubMenu && iMenu.type() == i_menu::Popup)
			{
				bool openSubMenu = (iMenuItem.type() == i_menu_item::SubMenu && iMenuItem.sub_menu().is_open());
				colour ink = openSubMenu ? app::instance().current_style().selection_colour()
					: background_colour().light() ? background_colour().darker(0x80) : background_colour().lighter(0x80);
				if (iSubMenuArrow == boost::none || iSubMenuArrow->first != ink)
				{
					const uint8_t sArrowImagePattern[9][6]
					{
						{ 0, 0, 0, 0, 0, 0 },
						{ 0, 1, 0, 0, 0, 0 },
						{ 0, 1, 1, 0, 0, 0 },
						{ 0, 1, 1, 1, 0, 0 },
						{ 0, 1, 1, 1, 1, 0 },
						{ 0, 1, 1, 1, 0, 0 },
						{ 0, 1, 1, 0, 0, 0 },
						{ 0, 1, 0, 0, 0, 0 },
						{ 0, 0, 0, 0, 0, 0 },
					};
					iSubMenuArrow = std::make_pair(ink, image{ "neogfx::menu_item_widget::" + ink.to_string(), sArrowImagePattern, { { 0, colour{} },{ 1, ink } } });
				}
				rect rect = client_rect(false);
				aGraphicsContext.draw_texture(
					point{ rect.right() - iGap + std::floor((iGap - iSubMenuArrow->second.extents().cx) / 2.0), std::floor((rect.height() - iSubMenuArrow->second.extents().cy) / 2.0) },
					iSubMenuArrow->second);
			}
		}
		else
		{
			scoped_units su(*this, aGraphicsContext, UnitsPixels);
			rect line = client_rect(false);
			++line.y;
			line.cy = 1.0;
			line.x += (iIconSize + iGap * 2.0);
			line.cx -= (iIconSize + iGap * 3.0);
			colour ink = background_colour().light() ? background_colour().darker(0x60) : background_colour().lighter(0x60);
			ink.set_alpha(0x80);
			aGraphicsContext.fill_rect(line, ink);
		}
	}
	inline void draw_glyph_text(const graphics_context& aGraphicsContext, const point& aPoint, Iter aTextBegin, Iter aTextEnd, const font& aFont, const colour& aColour)
	{
		{
			graphics_context::glyph_drawing gd(aGraphicsContext);
			point pos = aPoint;
			for (Iter i = aTextBegin; i != aTextEnd; ++i)
			{
				aGraphicsContext.draw_glyph(pos + i->offset(), *i, aFont, aColour);
				pos.x += i->advance().cx;
			}
		}
		point pos = aPoint;
		for (Iter i = aTextBegin; i != aTextEnd; ++i)
		{
			if (i->underline() || (aGraphicsContext.mnemonics_shown() && i->mnemonic()))
				aGraphicsContext.draw_glyph_underline(pos, *i, aFont, aColour);
			pos.x += i->advance().cx;
		}
	}
Exemple #9
0
	void shape::paint(graphics_context& aGraphicsContext) const
	{
		if (frame_count() == 0)
			return;
		auto tm = transformation_matrix();
		auto m = map();
		for (auto& vertex : m)
			vertex = tm * vertex;
		if (current_frame().texture() != boost::none)
		{
			if (current_frame().texture_rect() == boost::none)
				aGraphicsContext.draw_texture(texture_map{ {m[0][0], m[0][1]}, {m[1][0], m[1][1]}, {m[2][0], m[2][1]}, {m[3][0], m[3][1]} }, *current_frame().texture());
			else
				aGraphicsContext.draw_texture(texture_map{ {m[0][0], m[0][1]}, {m[1][0], m[1][1]}, {m[2][0], m[2][1]}, {m[3][0], m[3][1]} }, *current_frame().texture(), *current_frame().texture_rect());
		}
		else if (current_frame().colour() != boost::none)
		{
			aGraphicsContext.fill_shape(position() - origin(), m, *current_frame().colour());
		}
	}
	void colour_picker_dialog::x_picker::paint(graphics_context& aGraphicsContext) const
	{
		framed_widget::paint(aGraphicsContext);
		scoped_units su(*this, UnitsPixels);
		rect cr = client_rect(false);
		for (uint32_t x = 0; x < cr.height(); ++x)
		{
			double nx = x / (cr.height() - 1.0);
			rect line{ cr.top_left() + point{ 0.0, cr.height() - x - 1.0 }, size{ cr.width(), 1.0 } };
			if (iParent.mode() == ModeHSV)
			{
				hsv_colour hsvColour{ nx * 359.0, 1.0, 1.0 };
				aGraphicsContext.fill_rect(line, hsvColour.to_rgb());
			}
		}
	}
	void colour_picker_dialog::yz_picker::paint(graphics_context& aGraphicsContext) const
	{
		framed_widget::paint(aGraphicsContext);
		rect cr = client_rect(false);
		for (uint32_t y = 0; y < cr.width(); ++y)
		{
			for (uint32_t z = 0; z < cr.height(); ++z)
			{
				double ny = y / (cr.width() - 1.0);
				double nz = z / (cr.height() - 1.0);
				if (iParent.mode() == ModeHSV)
				{
					hsv_colour hsvColour = iParent.selected_colour().to_hsv();
					hsvColour.set_saturation(ny);
					hsvColour.set_value(nz);
					aGraphicsContext.draw_pixel(cr.top_left() + point{ static_cast<coordinate>(y), cr.height() - z - 1.0 }, hsvColour.to_rgb());
				}
			}
		}
	}
Exemple #12
0
	void image_widget::paint(graphics_context& aGraphicsContext) const
	{
		if (iTexture.is_empty())
			return;
		scoped_units su(*this, UnitsPixels);
		rect placementRect(point{}, iTexture.extents());
		if (iAspectRatio == aspect_ratio::Stretch)
		{
			placementRect.cx = client_rect().width();
			placementRect.cy = client_rect().height();
		}
		else if (placementRect.width() >= placementRect.height())
		{
			switch (iAspectRatio)
			{
			case aspect_ratio::Ignore:
				if (placementRect.width() > client_rect().width())
					placementRect.cx = client_rect().width();
				if (placementRect.height() > client_rect().height())
					placementRect.cy = client_rect().height();
				break;
			case aspect_ratio::Keep:
				if (placementRect.width() > client_rect().width())
				{
					placementRect.cx = client_rect().width();
					placementRect.cy = placementRect.cx * iTexture.extents().cy / iTexture.extents().cx;
				}
				if (placementRect.height() > client_rect().height())
				{
					placementRect.cy = client_rect().height();
					placementRect.cx = placementRect.cy * iTexture.extents().cx / iTexture.extents().cy;
				}
				break;
			case aspect_ratio::KeepExpanding:
				if (placementRect.height() > client_rect().height())
				{
					placementRect.cy = client_rect().height();
					placementRect.cx = placementRect.cy * iTexture.extents().cx / iTexture.extents().cy;
				}
				break;
			}
		}
		else
		{
			switch (iAspectRatio)
			{
			case aspect_ratio::Ignore:
				if (placementRect.width() > client_rect().width())
					placementRect.cx = client_rect().width();
				if (placementRect.height() > client_rect().height())
					placementRect.cy = client_rect().height();
				break;
			case aspect_ratio::Keep:
				if (placementRect.height() > client_rect().height())
				{
					placementRect.cy = client_rect().height();
					placementRect.cx = placementRect.cy * iTexture.extents().cx / iTexture.extents().cy;
				}
				if (placementRect.width() > client_rect().width())
				{
					placementRect.cx = client_rect().width();
					placementRect.cy = placementRect.cx * iTexture.extents().cy / iTexture.extents().cx;
				}
				break;
			case aspect_ratio::KeepExpanding:
				if (placementRect.width() > client_rect().width())
				{
					placementRect.cx = client_rect().width();
					placementRect.cy = placementRect.cx * iTexture.extents().cy / iTexture.extents().cx;
				}
				break;
			}
		}
		switch (iPlacement)
		{
		case cardinal_placement::NorthWest:
			placementRect.position() = point{};
			break;
		case cardinal_placement::North:
			placementRect.position() = point{ std::floor((client_rect().width() - placementRect.cx) / 2.0), 0.0 };
			break;
		case cardinal_placement::NorthEast:
			placementRect.position() = point{ client_rect().width() - placementRect.width(), 0.0 };
			break;
		case cardinal_placement::West:
			placementRect.position() = point{ 0.0, std::floor((client_rect().height() - placementRect.cy) / 2.0) };
			break;
		case cardinal_placement::Centre:
			placementRect.position() = point{ std::floor((client_rect().width() - placementRect.cx) / 2.0), std::floor((client_rect().height() - placementRect.cy) / 2.0) };
			break;
		case cardinal_placement::East:
			placementRect.position() = point{ client_rect().width() - placementRect.width(), std::floor((client_rect().height() - placementRect.cy) / 2.0) };
			break;
		case cardinal_placement::SouthWest:
			placementRect.position() = point{ 0.0, client_rect().height() - placementRect.height() };
			break;
		case cardinal_placement::South:
			placementRect.position() = point{ std::floor((client_rect().width() - placementRect.cx) / 2.0), client_rect().height() - placementRect.height() };
			break;
		case cardinal_placement::SouthEast:
			placementRect.position() = point{ client_rect().width() - placementRect.width(), client_rect().height() - placementRect.height() };
			break;
		}
		if (effectively_disabled())
			aGraphicsContext.set_monochrome(true);
		aGraphicsContext.draw_texture(placementRect, iTexture, effectively_disabled() ? colour(0xFF, 0xFF, 0xFF, 0x80) : optional_colour());
		aGraphicsContext.set_monochrome(false);
	}
	void colour_picker_dialog::colour_box::paint(graphics_context& aGraphicsContext) const
	{
		framed_widget::paint(aGraphicsContext);
		aGraphicsContext.fill_rect(client_rect(false), iColour);
	}
Exemple #14
0
void window_magnifier::draw(const graphics_context& grx)
{
  switch (mode)
  {
    case 0: // Zoom mode
         
      grx.draw_frame(0,0,w(),h(), ft_bevel_out);
      grx.stretch_blit(get_sub_buffer(), (w()-3) / 4, (h()-3) / 4, (w()-3) / 2, (h()-3) / 2, 0+2, 0+2, w()-3, h()-3);
      break;
     

    case 1: // Reverse mode
     
      grx.draw_frame(0,0,w(),h(), ft_bevel_out);    
      reversed_blit(get_sub_buffer(), grx, 2, 2, 2+grx.get_ox(), 2+grx.get_oy(), w()-3, h()-3);    
      break;
     

    case 2: // Distort mode
     
      grx.draw_frame(0,0,w(),h(), ft_bevel_out);
      distort_blit(get_sub_buffer(), grx, 2, 2, 2+grx.get_ox(), 2+grx.get_oy(), w()-3, h()-3);
      break;
     
 
    case 3: // Plain mode
     
      grx.rect(0, 0, w(), h(), theme().black);    
      grx.blit(get_sub_buffer(), 1, 1, 1, 1, w()-1, h()-1);
      break;
     
    
    case 4: // Debug mode

      grx.rectfill(0, 0, w(), h(), RANDOM_COLOR());
      break;
  }
}
Exemple #15
0
void masked_image::draw(const graphics_context& grx)
{
  grx.blit(get_sub_buffer(), 0, 0, 0, 0, w()+1, h()+1);
}