Esempio n. 1
0
Cursor::Cursor() :
    _surface(Ego::Graphics::SDL::createSurface(8, 8)) {
    uint32_t col = make_rgb(_surface, Ego::Math::Colour3b::white()); // opaque (255) white (255,255,255)
    uint32_t loc = make_rgb(_surface, Ego::Math::Colour3b(24, 24, 24)); // opaque (255) black-grey (24,24,24)
    uint32_t clr = make_rgba(_surface, Ego::Math::Colour4b(0, 0, 0, 64)); // almost transparent (64) black (0,0,0)

    // Simple triangle
    SDL_Rect rtmp;
    rtmp.x = 0;
    rtmp.y = 0;
    rtmp.w = 8;
    rtmp.h = 1;
    SDL_FillRect(_surface.get(), &rtmp, loc);

    for (int y = 0; y < 8; y++) {
        for (int x = 0; x < 8; x++) {
            if (x + y < 8) Ego::Graphics::SDL::putPixel(_surface, x, y, col);
            else Ego::Graphics::SDL::putPixel(_surface, x, y, clr);
        }
    }
}
Esempio n. 2
0
GUI_Cursor::GUI_Cursor() :
    _surface(Ego::Graphics::SDL::createSurface(8, 8))
{
    uint32_t col = make_rgb(_surface, 255, 255, 255); // white (255,255,255), fully opaquw
    uint32_t loc = make_rgb(_surface, 24, 24, 24);    // black-grey (24,24,24), fully opaque
    uint32_t clr = make_rgba(_surface, 0, 0, 0, 64);  // black (0,0,0), almost transparent (64)

    // Simple triangle
    SDL_Rect rtmp;
    rtmp.x = 0;
    rtmp.y = 0;
    rtmp.w = 8;
    rtmp.h = 1;
    SDL_FillRect(_surface.get(), &rtmp, loc);

    for (int y = 0; y < 8; y++)
    {
        for (int x = 0; x < 8; x++)
        {
            if (x + y < 8) Ego::Graphics::SDL::putPixel(_surface, x, y, col);
            else Ego::Graphics::SDL::putPixel(_surface, x, y, clr);
        }
    }
}
Esempio n. 3
0
int DisplayTree::RenderShape(
    const Shape& shape,
    const Matrix& transform,
    const ColorMatrix* color_matrix,
    int clip_width, int clip_height,
    renderer_base& ren_base,
    renderer_scanline& ren) {
  agg::compound_shape  m_shape;
  m_shape.set_shape(&shape);
  m_shape.m_affine = transform;
  m_shape.m_color_matrix = color_matrix;
  while (m_shape.read_next()) {
//    m_shape.scale(clip_width, height);
    agg::rasterizer_scanline_aa<agg::rasterizer_sl_clip_dbl> ras;
    agg::rasterizer_compound_aa<agg::rasterizer_sl_clip_dbl> rasc;
    agg::scanline_u8 sl;
    agg::scanline_bin sl_bin;
    Matrix m_scale;
    agg::conv_transform<agg::compound_shape> shape(m_shape, m_scale);
    agg::conv_stroke<agg::conv_transform<agg::compound_shape> > stroke(shape);
    agg::span_allocator<Color> alloc;
//    m_shape.approximation_scale(m_scale.scale());
//    printf("Filling shapes.\n");
    // Fill shape
    //----------------------
    rasc.clip_box(0, 0, clip_width, clip_height);
    rasc.reset();
    rasc.layer_order(agg::layer_direct);
    for(int i = 0; i < m_shape.paths(); i++)
    {
      rasc.styles(m_shape.style(i).left_fill,
                  m_shape.style(i).right_fill);
      rasc.add_path(shape, m_shape.style(i).path_id);
    }
    agg::render_scanlines_compound(rasc, sl, sl_bin, ren_base, alloc, m_shape);

    ras.clip_box(0, 0, clip_width, clip_height);
    for(int i = 0; i < m_shape.paths(); i++) {
      ras.reset();
      if(m_shape.style(i).line >= 0) {
        const LineStyle& style = m_shape.line_style(m_shape.style(i).line);
        if (style.width == 0) continue;
        // Special handling for 'hairline' strokes that should be scale invariant.
        const double width = style.width == 1 ? 
            1.0 : (double)style.width * m_shape.m_affine.scale();
        stroke.width(width);
        switch (style.join_style) {
          case LineStyle::kJoinBevel:
            stroke.line_join(agg::bevel_join);
            break;
          case LineStyle::kJoinMiter:
            stroke.line_join(agg::miter_join);
            if (style.miter_limit_factor > 0) {
              stroke.miter_limit(style.miter_limit_factor);
            }
            break;
          case LineStyle::kJoinRound:  // Fall through
          default:
            stroke.line_join(agg::round_join);
            break;
        }
        switch (style.start_cap_style) {
          case LineStyle::kCapRound:
            stroke.line_cap(agg::round_cap);
            break;
          case LineStyle::kCapSquare:
            stroke.line_cap(agg::square_cap);
            break;
          case LineStyle::kCapNone:  // Fall through
          default:
            stroke.line_cap(agg::butt_cap);
            break;
        }
        Color c = make_rgba(style.rgba);
        if (color_matrix) {
          color_matrix->transform(&c);
        }
        ren.color(c);
        ras.add_path(stroke, m_shape.style(i).path_id);
        agg::render_scanlines(ras, sl, ren);
      }
    }
  }
  return 0;  
}