示例#1
0
d_define_method_override(container, draw)(struct s_object *self, struct s_object *environment) {
  d_using(container);
  struct s_drawable_attributes *drawable_attributes_self = d_cast(self, drawable), *drawable_attributes_entry;
  struct s_uiable_attributes *uiable_attributes_self = d_cast(self, uiable), *uiable_attributes_entry;
  struct s_square_attributes *square_attributes;
  struct s_environment_attributes *environment_attributes = d_cast(environment, environment);
  struct s_camera_attributes *camera_attributes = d_cast(environment_attributes->current_camera, camera);
  struct s_container_drawable *current_container;
  double position_x_self, position_y_self, normalized_position_x_self, normalized_position_y_self, position_x_entry, position_y_entry, center_x_self,
    center_y_self, center_x_entry, center_y_entry, max_w = container_attributes->border_left + container_attributes->border_right,
    max_h = container_attributes->border_top + container_attributes->border_bottom, current_w, current_h;
  int result = d_drawable_return_last;
  d_call(&(drawable_attributes_self->point_destination), m_point_get, &position_x_self, &position_y_self);
  d_call(&(drawable_attributes_self->point_normalized_destination), m_point_get, &normalized_position_x_self, &normalized_position_y_self);
  d_call(&(drawable_attributes_self->point_center), m_point_get, &center_x_self, &center_y_self);
  d_foreach(&(container_attributes->entries), current_container, struct s_container_drawable) {
    drawable_attributes_entry = d_cast(current_container->drawable, drawable);
    position_x_entry = position_x_self + current_container->position_x + container_attributes->border_left;
    position_y_entry = position_y_self + current_container->position_y + container_attributes->border_top;
    center_x_entry = (position_x_self + center_x_self) - position_x_entry;
    center_y_entry = (position_y_self + center_y_self) - position_y_entry;
    d_call(current_container->drawable, m_drawable_set_position, position_x_entry, position_y_entry);
    if (((drawable_attributes_entry->flags & e_drawable_kind_ui_no_attribute_angle) != e_drawable_kind_ui_no_attribute_angle) &&
        ((drawable_attributes_entry->flags & e_drawable_kind_ui_no_attribute_zoom) != e_drawable_kind_ui_no_attribute_zoom))
      d_call(current_container->drawable, m_drawable_set_center, center_x_entry, center_y_entry);
    if ((drawable_attributes_entry->flags & e_drawable_kind_ui_no_attribute_angle) != e_drawable_kind_ui_no_attribute_angle)
      drawable_attributes_entry->angle = drawable_attributes_self->angle;
    if ((drawable_attributes_entry->flags & e_drawable_kind_ui_no_attribute_zoom) != e_drawable_kind_ui_no_attribute_zoom)
      drawable_attributes_entry->zoom = container_attributes->distributed_zoom;
    if ((drawable_attributes_entry->flags & e_drawable_kind_ui_no_attribute_flip) != e_drawable_kind_ui_no_attribute_flip)
      drawable_attributes_entry->flip = drawable_attributes_self->flip;
    if ((d_call(current_container->drawable, m_drawable_normalize_scale, camera_attributes->scene_reference_w, camera_attributes->scene_reference_h,
      camera_attributes->scene_offset_x, camera_attributes->scene_offset_y, camera_attributes->scene_center_x, camera_attributes->scene_center_y,
      camera_attributes->screen_w, camera_attributes->screen_h, camera_attributes->scene_zoom))) {
      square_attributes = d_cast(&(drawable_attributes_entry->square_collision_box), square);
      current_w = d_math_max(d_math_max(square_attributes->normalized_top_left_x, square_attributes->normalized_top_right_x),
                    d_math_max(square_attributes->normalized_bottom_left_x, square_attributes->normalized_bottom_right_x)) - normalized_position_x_self;
      current_h = d_math_max(d_math_max(square_attributes->normalized_top_left_y, square_attributes->normalized_top_right_y),
                    d_math_max(square_attributes->normalized_bottom_left_y, square_attributes->normalized_bottom_right_y)) - normalized_position_y_self;
      if ((uiable_attributes_entry = d_cast(current_container->drawable, uiable))) {
        /* we need to take in consideration the border of the object that is not considered in the collision square */
        current_w += uiable_attributes_entry->border_w;
        current_h += uiable_attributes_entry->border_h;
      }
      /* normalization for ratio and environmental zoom */
      current_w = ((current_w * camera_attributes->scene_reference_w) / camera_attributes->screen_w) / camera_attributes->scene_zoom;
      current_h = ((current_h * camera_attributes->scene_reference_h) / camera_attributes->screen_h) / camera_attributes->scene_zoom;
      max_w = d_math_max(max_w, current_w);
      max_h = d_math_max(max_h, current_h);
    }
  }
  d_call(self, m_drawable_set_dimension, (max_w + uiable_attributes_self->border_w), (max_h + uiable_attributes_self->border_h));
  if ((d_call(self, m_drawable_normalize_scale, camera_attributes->scene_reference_w, camera_attributes->scene_reference_h, camera_attributes->scene_offset_x,
    camera_attributes->scene_offset_y, camera_attributes->scene_center_x, camera_attributes->scene_center_y, camera_attributes->screen_w,
    camera_attributes->screen_h, camera_attributes->scene_zoom))) {
    result = (intptr_t)d_call_owner(self, uiable, m_drawable_draw, environment); /* recall the father's draw method */
    d_foreach(&(container_attributes->entries), current_container, struct s_container_drawable)
      while (((intptr_t)d_call(current_container->drawable, m_drawable_draw, environment)) == d_drawable_return_continue);
  }
示例#2
0
d_define_method_override(label, draw)(struct s_object *self, struct s_object *environment) {
    d_using(label);
    struct s_drawable_attributes *drawable_attributes = d_cast(self, drawable);
    struct s_uiable_attributes *uiable_attributes = d_cast(self, uiable);
    struct s_environment_attributes *environment_attributes = d_cast(environment, environment);
    double position_x, position_y, dimension_w, dimension_h, center_x, center_y, width_factor, height_factor;
    int result = (intptr_t)d_call_owner(self, uiable, m_drawable_draw, environment); /* recall the father's draw method */
    SDL_Rect source, destination;
    SDL_Point center;
    if (label_attributes->image) {
        d_call(&(drawable_attributes->point_normalized_destination), m_point_get, &position_x, &position_y);
        d_call(&(drawable_attributes->point_normalized_dimension), m_point_get, &dimension_w, &dimension_h);
        d_call(&(drawable_attributes->point_normalized_center), m_point_get, &center_x, &center_y);
        width_factor = (dimension_w/label_attributes->last_width);
        height_factor = (dimension_h/label_attributes->last_height);
        source.x = 0;
        source.y = 0;
        destination.x = (position_x + uiable_attributes->border_w);
        destination.y = (position_y + uiable_attributes->border_h);
        if (label_attributes->format == e_label_background_format_fixed) {
            source.w = d_math_min((label_attributes->last_width - (uiable_attributes->border_w * 2.0)), label_attributes->string_width);
            source.h = d_math_min((label_attributes->last_height - (uiable_attributes->border_h * 2.0)), label_attributes->string_height);
            switch (label_attributes->alignment_x) {
                case e_label_alignment_center:
                    if ((source.x = d_math_max(((label_attributes->string_width-label_attributes->last_width)/2.0), 0)) == 0)
                        destination.x = position_x + (((label_attributes->last_width - label_attributes->string_width)/2.0) *
                                width_factor);
                    break;
                case e_label_alignment_right:
                    if ((source.x = d_math_max((label_attributes->string_width-label_attributes->last_width), 0)) == 0)
                        destination.x = position_x + ((label_attributes->last_width - label_attributes->string_width) * width_factor);
                default:
                    break;
            }
            switch (label_attributes->alignment_y) {
                case e_label_alignment_center:
                    if ((source.y = d_math_max(((label_attributes->string_height-label_attributes->last_height)/2.0), 0)) == 0)
                        destination.y = position_y + (((label_attributes->last_height - label_attributes->string_height)/2.0) *
                                height_factor);
                    break;
                case e_label_alignment_bottom:
                    if ((source.y = d_math_max((label_attributes->string_height-label_attributes->last_height), 0)) == 0)
                        destination.y = position_y + ((label_attributes->last_height - label_attributes->string_height) *
                                height_factor);
                default:
                    break;
            }
        } else if (label_attributes->format == e_label_background_format_adaptable) {
            source.w = label_attributes->string_width;
            source.h = label_attributes->string_height;
        }
        destination.w = source.w * width_factor;
        destination.h = source.h * height_factor;
        center.x = (position_x + center_x) - destination.x;
        center.y = (position_y + center_y) - destination.y;
        label_attributes->last_source = source;
        label_attributes->last_destination = destination;
        SDL_RenderCopyEx(environment_attributes->renderer, label_attributes->image, &source, &destination, drawable_attributes->angle, &center,
                (SDL_RendererFlip)drawable_attributes->flip);
    }
    d_cast_return(result);
}