- Enable drawing of resources as ``3d'' cubes
git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1059 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
c2819ab0ea
commit
c1d72439b5
|
@ -83,16 +83,59 @@ CairoElements::draw_3dsphere(const Point& center, float radius, const Color& cl)
|
|||
}
|
||||
|
||||
void
|
||||
CairoElements::draw_3dcube(const Rectangle& area, const Color& cl)
|
||||
CairoElements::draw_3dcube(const Rectangle& area, const Color& cl,
|
||||
const float x_percent, const float y_percent)
|
||||
{
|
||||
cairo_t*& cr = _ctx;
|
||||
const float& x0 = area.x0;
|
||||
const float& y0 = area.y0;
|
||||
const float& w = area.w;
|
||||
const float& h = area.h;
|
||||
const float& r = cl.r;
|
||||
const float& g = cl.b;
|
||||
const float& b = cl.b;
|
||||
|
||||
cairo_save(cr);
|
||||
cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND);
|
||||
|
||||
// Front side of the cube:
|
||||
cairo_rectangle(cr,
|
||||
x0, y0 + (1 - y_percent) * h,
|
||||
w * x_percent, h * y_percent);
|
||||
|
||||
cairo_set_source_rgb(cr, r, g, b);
|
||||
cairo_fill_preserve(cr);
|
||||
cairo_set_source_rgb(cr, 0, 0, 0);
|
||||
cairo_stroke(cr);
|
||||
|
||||
// ``Upper'' visible cube side:
|
||||
cairo_new_path(cr);
|
||||
cairo_move_to(cr, x0, y0 + (1 - y_percent) * h);
|
||||
cairo_line_to(cr, x0 + (1 - x_percent) * w, y0);
|
||||
cairo_line_to(cr, x0 + w, y0);
|
||||
cairo_line_to(cr, x0 + w * x_percent, y0 + (1 - y_percent) * h);
|
||||
cairo_close_path(cr);
|
||||
|
||||
cairo_set_source_rgb(cr, r - 0.2, g - 0.2, b - 0.2);
|
||||
cairo_fill_preserve(cr);
|
||||
cairo_set_source_rgb(cr, 0, 0, 0);
|
||||
cairo_stroke(cr);
|
||||
|
||||
|
||||
// FIXME : not implemented
|
||||
// ``Right'' visible cube side:
|
||||
cairo_new_path(cr);
|
||||
cairo_move_to(cr, x0 + w * x_percent, y0 + (1 - y_percent) * h);
|
||||
cairo_line_to(cr, x0 + w, y0);
|
||||
cairo_line_to(cr, x0 + w, y0 + y_percent * h);
|
||||
cairo_line_to(cr, x0 + w * x_percent, y0 + h);
|
||||
cairo_close_path(cr);
|
||||
|
||||
cairo_set_source_rgb(cr, r - 0.4, g - 0.4, b - 0.4);
|
||||
cairo_fill_preserve(cr);
|
||||
cairo_set_source_rgb(cr, 0, 0, 0);
|
||||
cairo_stroke(cr);
|
||||
|
||||
cairo_restore(cr);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ namespace sgpem
|
|||
CairoElements(cairo_t* const ctx);
|
||||
|
||||
void draw_3dsphere(const Point& center, float radius, const Color& cl);
|
||||
void draw_3dcube(const Rectangle& area, const Color& cl);
|
||||
void draw_3dcube(const Rectangle& area, const Color& cl, const float x_percent, const float y_percent);
|
||||
void draw_container(const Rectangle& area);
|
||||
void draw_expandable(const Rectangle& area, bool expanded = false);
|
||||
|
||||
|
|
|
@ -104,30 +104,38 @@ HoltResource::~HoltResource()
|
|||
|
||||
void HoltResource::draw(cairo_t *cr)
|
||||
{
|
||||
// draw rectangle
|
||||
cairo_rectangle(cr,
|
||||
_pos.real() - _radius, _pos.imag() - _radius,
|
||||
2*_radius, 2*_radius);
|
||||
// fill
|
||||
cairo_set_source_rgb (cr, 1, 1, 1);
|
||||
cairo_fill_preserve (cr);
|
||||
static const Color white(1, 1, 1);
|
||||
|
||||
static const float x_percent = 3.5f / 4;
|
||||
static const float y_percent = 4.5f / 5;
|
||||
|
||||
CairoElements ce(cr);
|
||||
|
||||
// outline
|
||||
cairo_set_source_rgb (cr, 0, 0, 0);
|
||||
|
||||
// draw rectangle
|
||||
Rectangle area(_pos.real() - _radius, _pos.imag() - _radius, 2*_radius, 2*_radius);
|
||||
ce.draw_3dcube(area, white, x_percent, y_percent);
|
||||
|
||||
cairo_save(cr);
|
||||
// clip text outside region
|
||||
cairo_clip_preserve (cr);
|
||||
cairo_rectangle(cr, _pos.real() - _radius, _pos.imag() - _radius,
|
||||
2 * _radius * x_percent, 2 * _radius * y_percent);
|
||||
|
||||
cairo_clip(cr);
|
||||
// draw text
|
||||
cairo_text_extents_t extents;
|
||||
cairo_text_extents(cr, _resource->get_name().c_str(), &extents);
|
||||
// cairo_move_to(cr, xpos - _radius, ypos - _radius + extents.height);
|
||||
cairo_move_to(cr, _pos.real() - extents.width/2, _pos.imag() + extents.height/2);
|
||||
cairo_move_to(cr,
|
||||
_pos.real() - extents.width * (1 - x_percent + x_percent / 2),
|
||||
_pos.imag() + extents.height * ((1 - y_percent) / 2 + 0.5) );
|
||||
cairo_show_text(cr, _resource->get_name().c_str());
|
||||
cairo_reset_clip (cr); // reset clip region
|
||||
|
||||
// stroke all
|
||||
cairo_stroke (cr);
|
||||
|
||||
cairo_restore(cr);
|
||||
}
|
||||
|
||||
Vec2 HoltResource::get_intersection_to(Vec2 pt)
|
||||
|
|
Loading…
Reference in New Issue