コード例 #1
0
ファイル: drawing_context.cpp プロジェクト: Grumbel/netbrush
void
DrawingContext::draw(SDL_Surface* target_surf, const Rect& rect, int x_of, int y_of)
{
  // rect is in screenspace, x_of, y_of tell how to go from canvas to screenspace

  if (1) // no zoom
    {
      SDL_Rect target_pos;
      target_pos.x = rect.left;
      target_pos.y = rect.top;
      target_pos.w = rect.get_width();
      target_pos.h = rect.get_height();

      SDL_Rect source_pos;
      source_pos.x = rect.left - x_of;
      source_pos.y = rect.top  - y_of;
      source_pos.w = rect.get_width();
      source_pos.h = rect.get_height();

      SDL_Rect r;
      r.x = 0;
      r.y = 0;
      r.w = drawable->w;
      r.h = drawable->h;

      clip_to(&source_pos, &r);
      SDL_BlitSurface(drawable, &source_pos, target_surf, &target_pos);
    }
  else
    {
      SDL_LockSurface(target_surf);
      SDL_LockSurface(drawable);

      Uint8* target = static_cast<Uint8*>(target_surf->pixels);
      Uint8* source = static_cast<Uint8*>(drawable->pixels);

      // FIXME: do clipping or do clipping at a higher level in the code
      float zoom = 2.0f;
      for(int y = rect.top; y < rect.bottom; ++y)
        for(int x = rect.left; x < rect.right; ++x)
          {
            int sx = int(x * zoom);
            int sy = int(y * zoom);

            target[y * target_surf->pitch + target_surf->format->BytesPerPixel * x + 2] = source[sy * drawable->pitch + drawable->format->BytesPerPixel * sx + 0];
            target[y * target_surf->pitch + target_surf->format->BytesPerPixel * x + 1] = source[sy * drawable->pitch + drawable->format->BytesPerPixel * sx + 1];
            target[y * target_surf->pitch + target_surf->format->BytesPerPixel * x + 0] = source[sy * drawable->pitch + drawable->format->BytesPerPixel * sx + 2];
          }

      SDL_UnlockSurface(drawable);
      SDL_UnlockSurface(target_surf);
    }
}
コード例 #2
0
void
GrayscaleBuffer::fill_rect(const Rect& rect_, Uint8 c)
{
  Rect rect = rect_;
  clip_to(rect, Rect(0, 0, width, height));

  // FIXME: Ugly way to clip
  if (rect.left < rect.right && rect.top < rect.bottom)
    for(int y = rect.top; y < rect.bottom; ++y)
      {
        memset(buffer + y * width + rect.left, c, rect.get_width());
      }
}
コード例 #3
0
VNGError VngoRect::clip_to(VngoPointF *p1,VngoPointF *p2,dword flags)
{
    VngoPoint   tp1,tp2;
    tp1.x = int(p1->x);
    tp1.y = int(p1->y);

    tp2.x = int(p2->x);
    tp2.y = int(p2->y);

    if (flags & VNGO_CLIP_SHADE)
    {
        tp1.shade = int(p1->shade);
        tp2.shade = int(p2->shade);
    }
    if (flags & VNGO_CLIP_Z)
    {
        tp1.z = int(p1->z * float(0xffffffff));
        tp2.z = int(p2->z * float(0xffffffff));
    }
    VNGError tret = clip_to(&tp1,&tp2,flags | VNGO_CLIP_VERBOSE);
    if (tret != VNGO_NO_ERROR)
    {
        if (flags & VNGO_CLIP_VERBOSE)
            return tret;
        else if (tret == VNGO_FULLY_CLIPPED)
            return VNGO_FULLY_CLIPPED;
        else
            return VNGO_NO_ERROR;
    }
    p1->x = float(tp1.x);
    p1->y = float(tp1.y);
    p2->x = float(tp2.x);
    p2->y = float(tp2.y);
    if (flags & VNGO_CLIP_Z)
    {
        p1->z = float(tp1.z) / float(0xffffffff);
        p2->z = float(tp2.z) / float(0xffffffff);
    }
    if (flags & VNGO_CLIP_SHADE)
    {
        p1->shade = float(tp1.shade);
        p2->shade = float(tp2.shade);
    }

    return VNGO_NO_ERROR;
}
コード例 #4
0
ファイル: drawing_context.cpp プロジェクト: Grumbel/netbrush
void
DrawingContext::draw_stroke(const Stroke& stroke, DrawingParameter* param)
{
  Rect rect = stroke.get_bounding_rect();

  rect.left -= param->thickness()/2;
  rect.top  -= param->thickness()/2;

  rect.right  += param->thickness()/2;
  rect.bottom += param->thickness()/2;

  clip_to(rect, Rect(0, 0, get_width(), get_height()));

  stroke_buffer->clear(rect);
  stroke_buffer->set_param(param);
  stroke_buffer->draw_stroke(stroke, param);
  stroke_buffer->draw(drawable, rect, 0, 0);

  screen_buffer->mark_dirty(rect);

  // FIXME: Limit this to what changed on the buffer instead of whole screen
  navigation->update();
}
コード例 #5
0
ファイル: toolwnd.cpp プロジェクト: Bluehorn/wxPython
void wxToolWindow::CalcResizedRect( wxRect& rect, wxPoint& delta, const wxSize& minDim )
{
    // Microsoft's rect-coordinates are best suited
    // for the case of corner-clipping

    int left   = mInitialRect.x;
    int top    = mInitialRect.y;
    int right  = mInitialRect.x + mInitialRect.width;
    int bottom = mInitialRect.y + mInitialRect.height;

    // constraint delta edge is dragged

    switch ( mCursorType )
    {
        case HITS_WND_LEFT_EDGE   : delta.y = 0; break;
        case HITS_WND_RIGHT_EDGE  : delta.y = 0; break;
        case HITS_WND_TOP_EDGE    : delta.x = 0; break;
        case HITS_WND_BOTTOM_EDGE : delta.x = 0; break;
        default: break;
    }

    if ( mCursorType == HITS_WND_TOP_EDGE ||
         mCursorType == HITS_WND_TOP_LEFT_CORNER )
    {
        left += delta.x;
        top  += delta.y;

        clip_to( left, -FL_INFINITY, mInitialRect.x + mInitialRect.width  - minDim.x  );
        clip_to( top,  -FL_INFINITY, mInitialRect.y + mInitialRect.height - minDim.y );
    }
    else
    if ( mCursorType == HITS_WND_LEFT_EDGE ||
         mCursorType == HITS_WND_BOTTOM_LEFT_CORNER )
    {
        left   += delta.x;
        bottom += delta.y;

        clip_to( left,    -FL_INFINITY, mInitialRect.x + mInitialRect.width  - minDim.x  );
        clip_to( bottom,  mInitialRect.y + minDim.y, FL_INFINITY );
    }
    else
    if ( mCursorType == HITS_WND_RIGHT_EDGE ||
        mCursorType == HITS_WND_TOP_RIGHT_CORNER )
    {
        right += delta.x;
        top   += delta.y;

        clip_to( right, mInitialRect.x + minDim.x, FL_INFINITY );
        clip_to( top,   -FL_INFINITY, mInitialRect.y + mInitialRect.height - minDim.y );
    }
    else
    if ( mCursorType == HITS_WND_BOTTOM_EDGE ||
         mCursorType == HITS_WND_BOTTOM_RIGHT_CORNER )
    {
        right  += delta.x;
        bottom += delta.y;

        clip_to( right,  mInitialRect.x + minDim.x,  FL_INFINITY );
        clip_to( bottom, mInitialRect.y + minDim.y, FL_INFINITY );
    }
    else
    {
        wxFAIL_MSG( _T("what did the cursor hit?") );
    }

    rect.x = left;
    rect.y = top;
    rect.width  = right - left;
    rect.height = bottom - top;
}