Beispiel #1
0
bool EditRectOP::onDraw() const
{
	if (ZoomViewOP::onDraw()) return true;

	if (m_captured.shape)
	{
		if (m_cmpt)
		{
			if (RectShape* rect = dynamic_cast<RectShape*>(m_captured.shape))
			{
				PrimitiveDraw::drawCircle(Vector(rect->m_rect.xCenter(), rect->m_rect.yCenter()), 
					m_cmpt->getNodeCaptureDistance(), true, 2, Colorf(0.4f, 1.0f, 0.4f));
				if (m_captured.pos.isValid())
					PrimitiveDraw::drawCircle(m_captured.pos, m_cmpt->getNodeCaptureDistance(), 
						true, 2, Colorf(1.0f, 0.4f, 0.4f));
			}
		}
	}
	else
	{
		if (m_firstPress.isValid() && m_currPos.isValid())
			PrimitiveDraw::drawRect(m_firstPress, m_currPos);
	}

	return false;
}
Beispiel #2
0
bool EditBezierOP::onDraw() const
{
	if (ZoomViewOP::onDraw()) return true;

	if (m_captured.shape)
	{
		if (m_cmpt)
		{
			if (BezierShape* bezier = dynamic_cast<BezierShape*>(m_captured.shape))
			{
				PrimitiveDraw::drawCircle(Vector(bezier->getRect().xCenter(), bezier->getRect().yCenter()), 
					m_cmpt->getNodeCaptureDistance(), true, 2, Colorf(0.4f, 1.0f, 0.4f));
				if (m_captured.pos.isValid())
					PrimitiveDraw::drawCircle(m_captured.pos, m_cmpt->getNodeCaptureDistance(), 
					true, 2, Colorf(1.0f, 0.4f, 0.4f));
			}
		}
	}
	else
	{
		if (m_firstPress.isValid() && m_currPos.isValid())
		{
			BezierShape bezier(m_firstPress, m_currPos);
			bezier.draw();
		}
//			PrimitiveDraw::drawRect(m_firstPress, m_currPos);
	}

	return false;
}
Beispiel #3
0
Light::Light()
{
	m_diffuse			= Colorf(1,1,1);
	m_specular			= Colorf(1,1,1);
	m_ambient			= Colorf(0,0,0);
	m_intensity			= 1.f;
}
Beispiel #4
0
Colorf CVar::toColorf(bool* isValid) const
{
    if (m_type != Color)
    {
        if (com_developer && com_developer->toBoolean())
            orConsoleRef.print(orConsoleRef.Warning, "CVar %s is not a color", name().c_str());

        if (isValid != NULL)
            *isValid = false;

        return Colorf();
    }

    if (isValid != NULL)
        *isValid = true;

    int r, g, b, a;
    std::stringstream ss;

    ss << m_value;
    ss >> r;
    ss >> g;
    ss >> b;
    ss >> a;

    return Colorf(r*inv255, g*inv255, b*inv255, a*inv255);
}
Beispiel #5
0
ColorBank::Colorf ColorBank::colorf(DotPath const &path) const
{
    if (path.isEmpty()) return Colorf();
    Vector4d clamped = data(path).as<Impl::ColorData>().color;
    clamped = clamped.max(Vector4d(0, 0, 0, 0)).min(Vector4d(1, 1, 1, 1));
    return Colorf(float(clamped.x), float(clamped.y), float(clamped.z), float(clamped.w));
}
Beispiel #6
0
bool FullScreen::update()
{

	const float virtual_screen_width = 800.0f;
	const float virtual_screen_height = 600.0f;
	game_time.update();

	// Check for fullscreen switch
	if (fullscreen_requested != is_fullscreen)
	{
		is_fullscreen = fullscreen_requested;
		create_window();
	}

	if (window.get_gc() != canvas.get_gc()) 
	{
		canvas = Canvas(window); // Always get the graphic context, the window may have been recreated
	}

	canvas.clear(Colorf(0.0f,0.0f,0.2f));

	int font_size = 28;
	font_size *= canvas.get_width() / virtual_screen_width;
	font.set_height(font_size);
	canvas.set_transform(Mat4f::identity());
	if (is_fullscreen)
	{
		font.draw_text(canvas, 16, font_size, "Full Screen Mode. Press 'F' to switch to resizable window.");
	}
	else
	{
		font.draw_text(canvas, 16, font_size, "Resizable Window. Press 'F' to switch to full screen mode.");
	}

	// Scale the drawing to the screen to a virtual screen size
	Mat4f matrix = Mat4f::scale( (float) canvas.get_width() / virtual_screen_width, (float) canvas.get_height() /virtual_screen_height, 1.0f);
	canvas.set_transform(matrix);

	spr_logo.draw(canvas, virtual_screen_width-spr_logo.get_width(), virtual_screen_height-spr_logo.get_height());

	spr_background.set_scale(0.5f, 0.5f);
	spr_background.draw(canvas, 100, 100);

	// Show a few alpha-blending moving rectangles that moves in circles
	float x = cos(sin_count)*120.0f;
	float y = sin(sin_count)*120.0f;
	sin_count += 2.0f * game_time.get_time_elapsed();
	canvas.fill_rect(Rectf( 320.0f + x -30.0f, 300.0f + y -30.0f, Sizef(60.0f, 60.0f)), Colorf(0.0f, 1.0f, 0.0, 0.5f));
	x = cos(sin_count+3.14159f)*120.0f;
	y = sin(sin_count+3.14159f)*120.0f;
	canvas.fill_rect(Rectf( 320.0f + x -30.0f, 300 + y -30.0f, Sizef(60.0f, 60.0f)), Colorf(1.0f, 1.0f, 0.0, 0.5f));

	window.flip(1);

	return !quit;
}
Beispiel #7
0
	ColorHSLx<float, Colorf>::operator Colorf()
	{
		float hue = min(359.0f, max(0.0f, h)) / 360.0f;
		float saturation = min(1.0f, max(0.0f, s));
		float lightness = min(1.0f, max(0.0f, l));
		if (saturation == 0.0f)
		{
			return Colorf(lightness, lightness, lightness, a);
		}

		float q;
		if (lightness < 0.5f)
		{
			q = lightness * (1 + saturation);
		}
		else
		{
			q = lightness + saturation - lightness * saturation;
		}
		float p = 2.0f * lightness - q;
		float temp_rgb[3];
		temp_rgb[0] = hue + 1.0f / 3.0f;
		temp_rgb[1] = hue;
		temp_rgb[2] = hue - 1.0f / 3.0f;
		for (auto & elem : temp_rgb)
		{
			while (elem < 0.0f)
			{
				elem += 1.0f;
			}
			while (elem > 1.0f)
			{
				elem -= 1.0f;
			}

			if (elem < (1.0f / 6.0f))
			{
				elem = p + (q - p) * 6.0f * elem;
			}
			else if (elem < 0.5f)
			{
				elem = q;
			}
			else if (elem < (2.0f / 3.0f))
			{
				elem = p + (q - p) * 6.0f * ((2.0f / 3.0f) - elem);
			}
			else
			{
				elem = p;
			}
		}
		return Colorf(temp_rgb[0], temp_rgb[1], temp_rgb[2], a);
	}
Beispiel #8
0
Colorf ChessPiece::getColor(Surface32f surface, Vec2i pixel)
{
	float r = *surface.getDataRed(pixel);
	float g = *surface.getDataGreen(pixel);
	float b = *surface.getDataBlue(pixel);
	return Colorf(r, g, b);
}
Beispiel #9
0
/////////////////////////////////////////////////////////////////////////////
// Utilities
Colorf hsvToRgb( const vec3 &hsv )
{
    float hue = hsv.x;
    float sat = hsv.y;
    float val = hsv.z;

    float x = 0.0f, y = 0.0f, z = 0.0f;
    
    if( hue == 1 ) hue = 0;
    else
		hue *= 6;

    int i = static_cast<int>( floorf( hue ) );
    float f = hue - i;
    float p = val * ( 1 - sat );
    float q = val* ( 1 - ( sat * f ) );
    float t = val* ( 1 - ( sat * ( 1 - f ) ) );

    switch( i ) {
		case 0: x = val; y = t; z = p; break;
		case 1: x = q; y = val; z = p; break;
		case 2: x = p; y = val; z = t; break;
		case 3: x = p; y = q; z = val; break;
		case 4: x = t; y = p; z = val; break;
		case 5: x = val; y = p; z = q; break;
    }

    return Colorf( x, y, z );
}
Beispiel #10
0
void BoxStyle::set_border_none()
{
    impl->border.left.type = BoxBorderValue::type_none;
    impl->border.left.color = Colorf();
    impl->border.left.width = 0.0f;
    impl->border.right.type = BoxBorderValue::type_none;
    impl->border.right.color = Colorf();
    impl->border.right.width = 0.0f;
    impl->border.top.type = BoxBorderValue::type_none;
    impl->border.top.color = Colorf();
    impl->border.top.width = 0.0f;
    impl->border.bottom.type = BoxBorderValue::type_none;
    impl->border.bottom.color = Colorf();
    impl->border.bottom.width = 0.0f;
    if (impl->style_changed) impl->style_changed();
}
Beispiel #11
0
void App::draw_font_example()
{
	int offset_x = 10;
	int offset_y = 600;
	int descender = (int) font_metrics.get_descent();

	// Surrounding box
	canvas.fill_rect(Rect(offset_x, offset_y+descender, offset_x + font_size.width, offset_y+descender - font_size.height), Colorf(0.0f, 0.0f, 0.0f));

	// Draw the external leading line
	int external_leading_offset = offset_y+font_metrics.get_external_leading() + font_metrics.get_descent();
	canvas.draw_line(offset_x, external_leading_offset, offset_x + font_size.width, external_leading_offset, Colorf(0.5f, 0.5f, 0.0f));

	// Draw the internal leading line
	int internal_leading_offset = offset_y - font_metrics.get_ascent() + font_metrics.get_internal_leading();
	canvas.draw_line(offset_x, internal_leading_offset, offset_x + font_size.width, internal_leading_offset, Colorf(0.5f, 0.5f, 0.0f));

	// Draw outline to the bounding box
	canvas.draw_line(offset_x, offset_y+descender, offset_x + font_size.width, offset_y+descender, Colorf(1.0f, 0.0f, 0.0f));
	canvas.draw_line(offset_x, offset_y+descender- font_size.height, offset_x + font_size.width, offset_y+descender - font_size.height, Colorf(1.0f, 0.0f, 0.0f));
	canvas.draw_line(offset_x + font_size.width, offset_y+descender, offset_x + font_size.width, offset_y+descender - font_size.height, Colorf(1.0f, 0.0f, 0.0f));
	canvas.draw_line(offset_x, offset_y+descender, offset_x, offset_y+descender - font_size.height, Colorf(1.0f, 0.0f, 0.0f));

	// Base line
	canvas.draw_line(offset_x, offset_y, offset_x + font_size.width, offset_y, Colorf(0.0f, 1.0f, 0.0f));

	selected_font.draw_text(canvas, offset_x, offset_y, font_text,  Colorf::white);
}
CylinderMy::CylinderMy(double radius, const Point3d &base_center, const Point3d &top_center)
: radius_(radius)
, base_center_(base_center)
, top_center_(top_center)
, internal_rep_(NULL)
{
    facet_color_ = Colorf(0.0f, 0.0f, 0.0f, 1.0f);
}
void PhysicsDebugDraw_Impl::DrawPoint(const b2Vec2& p, float32 size, const b2Color& color)
{
	used_canvas->fill_rect(p.x-size,
					 p.y-size,
					 p.x+size,
					 p.y+size,
					 Colorf(color.r,color.g,color.b));
}
CylinderMy::CylinderMy()
: radius_(0.0f)
, base_center_(0.0f, 0.0f, 0.0f)
, top_center_(0.0f, 0.0f, 0.0f)
, internal_rep_(NULL)
{
    facet_color_ = Colorf(0.0f, 0.0f, 0.0f, 1.0f);
}
Beispiel #15
0
//Sets up some default lighting
void World::setup_lights() const
   {
   PT(AmbientLight) ambientLightPtr = new AmbientLight("ambientLight");
   PT(DirectionalLight) directionalLightPtr = new DirectionalLight("directionalLight");
   if(ambientLightPtr == NULL || directionalLightPtr == NULL)
      {
      nout << "ERROR: out of memory." << endl;
      return;
      }

   ambientLightPtr->set_color(Colorf(.4,.4,.35,1));
   directionalLightPtr->set_direction(LVector3f(0,8,-2.5));
   directionalLightPtr->set_color(Colorf(0.9,0.8,0.9,1));
   NodePath renderNp = m_windowFrameworkPtr->get_render();
   renderNp.set_light(renderNp.attach_new_node(directionalLightPtr));
   renderNp.set_light(renderNp.attach_new_node(ambientLightPtr));
   }
void PhysicsDebugDraw_Impl::DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color)
{
	used_canvas->draw_line(p1.x*physic_scale,
					 p1.y*physic_scale,
					 p2.x*physic_scale,
					 p2.y*physic_scale,
					 Colorf(color.r,color.g,color.b));
}
Beispiel #17
0
Sky::Sky() {
	turbidity = 10;

	// Initialize the Sun.
	sun_direction = Eigen::Vector3f(0, 20, 1);
	sun_direction.normalize();

	sun_power = Colorf(150e3, 150e3, 150e3);  // lx
}
Beispiel #18
0
void NanoApp::drawGrid (float size, float step)
{
   gl::color (Colorf (0.2f, 0.2f, 0.2f));
   for (float i = -size; i <= size; i += step)
   {
      gl::drawLine (vec3 (i, 0.0f, -size), vec3 (i, 0.0f, size));
      gl::drawLine (vec3 (-size, 0.0f, i), vec3 (size, 0.0f, i));
   }
}
inline Color32 coloring10B1(const double iter,long i,const long max_iter,double* xList,double* yList,const Colorf& errorColorIn,Colorf& errorColorOut){
    Colorf color=errorColorIn;
    if (iter==max_iter){
        const double x=xList[max_iter];
        const double y=yList[max_iter];
        double z=sqrt(x*x+y*y);
        color.addColor(Colorf(sinColorf(z*20*50-236),sinColorf(z*15*50+221),sinColorf(z*30*50-254)));
    }else{ 
        const double x=smoothXY10B(iter,i,xList);
        const double y=smoothXY10B(iter,i,yList);
        double z=sqrt(x*x+y*y);
        color.addColor(Colorf(sinColorf(x*20*2-236),sinColorf(y*15*2+221),sinColorf((x*y/sqrt(z))*30*2-254)));
    }
    Color32 resultColor=color.toColor32();
    errorColorOut=color;
    errorColorOut.subColor(resultColor);
    return resultColor;
}
Colorf ResourceManager::getColor(int index)
{
    if (index < 0 || index>=colors.size())
    {
        return Colorf(0, 0, 0);
    }
    
    return colors[index];
}
inline Color32 coloring9_s(const double iter,long i,const long max_iter,double* xList,double* yList,const Colorf& errorColorIn,Colorf& errorColorOut){
    Colorf color=errorColorIn;
    if (iter==max_iter){
        const double x=xList[max_iter];
        const double y=yList[max_iter];
        double z=sqrt(x*x+y*y);
        double zd=z-sqrt(xList[max_iter-1]*xList[max_iter-1]+yList[max_iter-1]*yList[max_iter-1]);
        color.addColor(Colorf(sinColorf(z*2000),sinColorf(y*x*1000),sinColorf(zd*1000)));
    }else{ 
        const double x=xList[i];
        const double y=yList[i];
        double z=sqrt(x*x+y*y);
        color.addColor(Colorf(sinColorf(z*20/20-236),sinColorf(z*15/20+221),sinColorf(z*30/20-254)));
    }
    Color32 resultColor=color.toColor32();
    errorColorOut=color;
    errorColorOut.subColor(resultColor);
    return resultColor;
}
Beispiel #22
0
void sTheme::init(string n)
{
	name=n;

	//if(name=="default_theme")
	{
		font="sf_font_25";
		label_font="sf_font_25";
		tooltip_font="tooltip_font_small";
		button_image=Rect(90,490, Size(12,40));

		slider_body_image=Rect(90,530, Size(12,50));
		slider_tick_image= Rect(107,530, Size(20,50));

		label_color=Colorf(255,255,255,170);
			color=Colorf(255,255,255,170);

	}


		if(name=="gui_theme")
	{
		font="sf_font_25";
		label_font="h3_font";
		tooltip_font="tooltip_font_small";
		button_image=Rect(90,490, Size(12,40));

		slider_body_image=Rect(90,530, Size(12,50));
		slider_tick_image= Rect(107,530, Size(20,50));

		label_color=Colorf(255,255,100,170);
			color=Colorf(255,255,255,170);

	}

		if(name=="wooden_theme")
	{
		font="gui_font";
		button_image=Rect(40,490, Size(15,50));
		color=Colorf(0,0,0,200);

	}
}
CylinderMy::CylinderMy(double radius, const Point3d &base_center, double height, const Vector3d &direction)
: radius_(radius)
, base_center_(base_center)
, internal_rep_(NULL)
{
    Vector3d dir = direction;
    dir = dir / std::sqrt(dir.squared_length());
    top_center_ = base_center_ + dir * height;
    facet_color_ = Colorf(0.0f, 0.0f, 0.0f, 1.0f);
}
Beispiel #24
0
void ChainShape::draw(const Colorf& color/* = Colorf(0, 0, 0)*/) const
{
	if (m_vertices.empty()) return;

	PrimitiveDraw::resetColorAndTexture();

	PrimitiveDraw::drawPolyline(m_vertices, color, m_isLoop);
	if (Settings::ctlPosSize != 0)
		PrimitiveDraw::drawCircles(m_vertices, Settings::ctlPosSize, true, 2, Colorf(0.4f, 0.8f, 0.4f));
}
Beispiel #25
0
// Macro-like function used to reduce the amount to code needed to create the
// on screen instructions
COnscreenText World6::gen_label_text(const string& text, int i) const
   {
   COnscreenText label("label");
   label.set_text(text);
   label.set_pos(LVecBase2f(-1.3, 0.95-0.05*i));
   label.set_fg(Colorf(1, 1, 1, 1));
   label.set_align(TextNode::A_left);
   label.set_scale(0.05);
   label.reparent_to(m_windowFramework->get_aspect_2d());
   return label;
   }
Beispiel #26
0
// Function to put title on the screen.
NodePath World::add_title(const string& text) const
   {
   COnscreenText title("title", COnscreenText::TS_plain);
   title.set_text(text);
   title.set_fg(Colorf(1,1,1,1));
   title.set_pos(LVecBase2f(1.3,-0.95));
   title.set_align(TextNode::A_right);
   title.set_scale(0.07);
   title.reparent_to(m_windowFrameworkPtr->get_aspect_2d());
   return title.generate();
   }
Beispiel #27
0
// Function to put instructions on the screen.
NodePath World::add_instructions(float pos, const string& msg) const
   {
   COnscreenText instructions("instructions", COnscreenText::TS_plain);
   instructions.set_text(msg);
   instructions.set_fg(Colorf(1,1,1,1));
   instructions.set_pos(LVecBase2f(-1.3, pos));
   instructions.set_align(TextNode::A_left);
   instructions.set_scale(0.05);
   instructions.reparent_to(m_windowFrameworkPtr->get_aspect_2d());
   return instructions.generate();
   }
void PhysicsDebugDraw_Impl::DrawTransform(const b2Transform& xf)
{
	Vec2f p1(xf.p.x,xf.p.y);
	Vec2f p2;
	const float32 k_axisScale = 0.4f;
	
	p2 = p1 + Vec2f(xf.q.GetXAxis().x,xf.q.GetXAxis().y) * k_axisScale;
	used_canvas->draw_line(p1.x*physic_scale,
					 p1.y*physic_scale,
					 p2.x*physic_scale,
					 p2.y*physic_scale,
					 Colorf(1.0f,0.0f,0.0f));

	p2 = p1 + Vec2f(xf.q.GetYAxis().x,xf.q.GetYAxis().y) * k_axisScale;
	used_canvas->draw_line(p1.x*physic_scale,
					 p1.y*physic_scale,
					 p2.x*physic_scale,
					 p2.y*physic_scale,
					 Colorf(0.0f,1.0f,0.0f));
	
}
Beispiel #29
0
void App::render(GraphicContext &gc)
{
	gc.clear(Colorf(0.0f, 0.0f, 0.0f, 1.0f));

	Rect viewport_rect(0, 0, Size(gc.get_width(), gc.get_height()));
	gc.set_viewport(viewport_rect);

	gc.clear_depth(1.0f);

	Mat4f modelview_matrix = scene.gs->camera_modelview;
	scene.Draw(modelview_matrix, gc);
	gc.reset_program_object();
}
Beispiel #30
0
vec3 ColorAT<T>::get( ColorModel cm ) const
{
	switch( cm ) {
		case CM_HSV:
			return rgbToHsv( Colorf( r, g, b ) );
		break;
		case CM_RGB:
			return vec3( CHANTRAIT<float>::convert( r ), CHANTRAIT<float>::convert( g ), CHANTRAIT<float>::convert( b ) );
		break;
		default:
			throw ImageIoExceptionIllegalColorModel();
	}
}