Beispiel #1
0
/**
* @brief Blits a region of this surface on a specified location of another surface.
* @param src_position the subrectangle of this surface to pick
* @param dst_surface the destination surface
* @param dst_position the destination position where the current surface will be blitted on dst
*/
void Surface::draw_region(const Rectangle &src_position, Surface& dst_surface, const Rectangle &dst_position) 
{
  Rectangle src_position2(src_position);
  Rectangle dst_position2(dst_position);
  SDL_BlitSurface(internal_surface, src_position2.get_internal_rect(),
      dst_surface.internal_surface, dst_position2.get_internal_rect());
}
Beispiel #2
0
/**
 * \brief Draws this surface on another surface.
 * \param dst_surface The destination surface.
 * \param dst_position Coordinates on the destination surface.
 */
void Surface::raw_draw(Surface& dst_surface, const Rectangle& dst_position) {

  // Make a copy of the rectangle because SDL_BlitSurface modifies it.
  Rectangle dst_position2(dst_position);
  SDL_BlitSurface(internal_surface, NULL,
      dst_surface.internal_surface, dst_position2.get_internal_rect());
}
Beispiel #3
0
/**
 * \brief Draws a subrectangle of this text surface on another surface.
 * \param region The subrectangle to draw in this object.
 * \param dst_surface The destination surface.
 * \param dst_position Coordinates on the destination surface.
 */
void TextSurface::raw_draw_region(const Rectangle& region,
                                  Surface& dst_surface, const Rectangle& dst_position) {

    if (surface != NULL) {

        Rectangle dst_position2(text_position);
        dst_position2.add_xy(dst_position);
        surface->raw_draw_region(region, dst_surface, dst_position2);
    }
}
Beispiel #4
0
/**
 * \brief Draws a subrectangle of this object, applying dynamic effects.
 * \param region The rectangle to draw in this object.
 * \param dst_surface The destination surface
 * \param dst_position Position on this surface
 * (will be added to the position obtained by previous movements).
 */
void Drawable::draw_region(const Rectangle& region,
    Surface& dst_surface, const Rectangle& dst_position) {

  Rectangle dst_position2(dst_position);
  dst_position2.add_xy(xy);

  if (transition != NULL) {
    draw_transition(*transition);
  }

  raw_draw_region(region, dst_surface, dst_position2);
}
Beispiel #5
0
/**
 * \brief Draws a subrectangle of the current frame of this sprite.
 * \param region The subrectangle to draw, relative to the origin point.
 * It may be bigger than the frame: in this case it will be clipped.
 * \param dst_surface The destination surface.
 * \param dst_position Coordinates on the destination surface.
 * The origin point of the sprite will appear at these coordinates.
 */
void Sprite::raw_draw_region(
    const Rectangle& region,
    Surface& dst_surface,
    const Rectangle& dst_position) {

  if (!is_animation_finished()
      && (blink_delay == 0 || blink_is_sprite_visible)) {

    get_intermediate_surface().fill_with_color(Color::get_black());
    const Rectangle& origin = get_origin();
    current_animation->draw(
        get_intermediate_surface(),
        origin,
        current_direction,
        current_frame);

    // If the region is bigger than the current frame, clip it.
    // Otherwise, more than the current frame could be visible.
    Rectangle src_position(region);
    src_position.add_xy(origin.get_x(), origin.get_y());
    const Rectangle& frame_size = get_size();
    if (src_position.get_x() < 0) {
      src_position.set_width(src_position.get_width() + src_position.get_x());
      src_position.set_x(0);
    }
    if (src_position.get_x() + src_position.get_width() > frame_size.get_width()) {
      src_position.set_width(frame_size.get_width() - src_position.get_x());
    }
    if (src_position.get_y() < 0) {
      src_position.set_height(src_position.get_height() + src_position.get_y());
      src_position.set_y(0);
    }
    if (src_position.get_y() + src_position.get_height() > frame_size.get_height()) {
      src_position.set_height(frame_size.get_height() - src_position.get_y());
    }

    if (src_position.get_width() <= 0 || src_position.get_height() <= 0) {
      // Nothing remains visible.
      return;
    }

    // Calculate the destination coordinates.
    Rectangle dst_position2(dst_position);
    dst_position2.add_xy(src_position.get_x(), src_position.get_y());  // Let a space for the part outside the region.
    dst_position2.add_xy(-origin.get_x(), -origin.get_y());  // Input coordinates were relative to the origin.
    get_intermediate_surface().draw_region(src_position, dst_surface, dst_position2);
  }
}
Beispiel #6
0
/**
 * \brief Draws the sprite on a surface, with its current animation,
 * direction and frame.
 * \param dst_surface The destination surface.
 * \param dst_position Coordinates on the destination surface
 * (the origin will be placed at this position).
 */
void Sprite::raw_draw(
    Surface& dst_surface,
    const Rectangle& dst_position) {

  if (!is_animation_finished()
      && (blink_delay == 0 || blink_is_sprite_visible)) {

    if (intermediate_surface == NULL) {
      current_animation->draw(dst_surface, dst_position,
          current_direction, current_frame);
    }
    else {
      intermediate_surface->fill_with_color(Color::get_black());
      current_animation->draw(*intermediate_surface, get_origin(),
          current_direction, current_frame);
      Rectangle dst_position2(dst_position);
      dst_position2.add_xy(-get_origin().get_x(), -get_origin().get_y());
      intermediate_surface->draw_region(get_size(), dst_surface, dst_position2);
    }
  }
}
Beispiel #7
0
/**
 * @brief Blits a subarea of this surface on a specified location of another surface.
 * @param src_position the subrectangle of this surface to pick
 * @param dst the destination surface
 * @param dst_position the destination position where the current surface will be blitted on dst
 */
void Surface::blit(const Rectangle &src_position, Surface *dst, const Rectangle &dst_position) {

  Rectangle src_position2(src_position);
  Rectangle dst_position2(dst_position);
  SDL_BlitSurface(internal_surface, src_position2.get_internal_rect(), dst->internal_surface, dst_position2.get_internal_rect());
}
Beispiel #8
0
/**
 * @brief Blits this whole surface on a specified location of another surface.
 * @param dst the destination surface
 * @param dst_position the destination position where the current surface will be blitted on dst
 */
void Surface::blit(Surface *dst, const Rectangle &dst_position) {

  Rectangle dst_position2(dst_position);
  SDL_BlitSurface(internal_surface, NULL, dst->internal_surface, dst_position2.get_internal_rect());
}