Пример #1
0
int
main (int    argc,
      char **argv)
{
  ply_array_t *array;
  int i;
  char **data;

  array = ply_array_new (PLY_ARRAY_ELEMENT_TYPE_POINTER);

  ply_array_add_pointer_element (array, "foo");
  ply_array_add_pointer_element (array, "bar");
  ply_array_add_pointer_element (array, "baz");
  ply_array_add_pointer_element (array, "qux");

  data = (char **) ply_array_get_pointer_elements (array);
  for (i = 0; data[i] != NULL; i++)
    {
      printf ("element '%d' has data '%s'\n", i, data[i]);
      i++;
    }

  ply_array_free (array);
  return 0;
}
Пример #2
0
static bool
animate_at_time (ply_throbber_t *throbber,
                 double          time)
{
        int number_of_frames;
        ply_pixel_buffer_t *const *frames;
        bool should_continue;
        double percent_in_sequence;

        number_of_frames = ply_array_get_size (throbber->frames);

        if (number_of_frames == 0)
                return true;

        should_continue = true;
        percent_in_sequence = fmod (time, THROBBER_DURATION) / THROBBER_DURATION;
        throbber->frame_number = (int) (number_of_frames * percent_in_sequence);

        if (throbber->stop_trigger != NULL)
                if (throbber->frame_number == number_of_frames - 1)
                        should_continue = false;

        frames = (ply_pixel_buffer_t *const *) ply_array_get_pointer_elements (throbber->frames);
        ply_pixel_buffer_get_size (frames[throbber->frame_number], &throbber->frame_area);
        throbber->frame_area.x = throbber->x;
        throbber->frame_area.y = throbber->y;
        ply_pixel_display_draw_area (throbber->display,
                                     throbber->x, throbber->y,
                                     throbber->frame_area.width,
                                     throbber->frame_area.height);

        return should_continue;
}
Пример #3
0
void
ply_throbber_draw_area (ply_throbber_t     *throbber,
                        ply_pixel_buffer_t *buffer,
                        long                x,
                        long                y,
                        unsigned long       width,
                        unsigned long       height)
{
        ply_pixel_buffer_t *const *frames;

        if (throbber->is_stopped)
                return;

        frames = (ply_pixel_buffer_t *const *) ply_array_get_pointer_elements (throbber->frames);
        ply_pixel_buffer_fill_with_buffer (buffer,
                                           frames[throbber->frame_number],
                                           throbber->x,
                                           throbber->y);
}
Пример #4
0
void
ply_progress_animation_draw (ply_progress_animation_t *progress_animation)
{
        int number_of_frames;
        int frame_number;
        ply_image_t *const *frames;
        ply_pixel_buffer_t *previous_frame_buffer, *current_frame_buffer;

        if (progress_animation->is_hidden)
                return;

        number_of_frames = ply_array_get_size (progress_animation->frames);

        if (number_of_frames == 0)
                return;

        frame_number = progress_animation->percent_done * (number_of_frames - 1);

        if (progress_animation->previous_frame_number != frame_number &&
            progress_animation->transition != PLY_PROGRESS_ANIMATION_TRANSITION_NONE &&
            progress_animation->transition_duration > 0.0) {
                progress_animation->is_transitioning = true;
                progress_animation->transition_start_time = ply_get_timestamp ();
        }

        frames = (ply_image_t *const *) ply_array_get_pointer_elements (progress_animation->frames);

        progress_animation->frame_area.x = progress_animation->area.x;
        progress_animation->frame_area.y = progress_animation->area.y;
        current_frame_buffer = ply_image_get_buffer (frames[frame_number]);

        if (progress_animation->is_transitioning) {
                double now;
                double fade_percentage;
                double fade_out_opacity;
                int width, height;
                uint32_t *faded_data;
                now = ply_get_timestamp ();

                fade_percentage = (now - progress_animation->transition_start_time) / progress_animation->transition_duration;

                if (fade_percentage >= 1.0)
                        progress_animation->is_transitioning = false;
                fade_percentage = CLAMP (fade_percentage, 0.0, 1.0);

                if (progress_animation->transition == PLY_PROGRESS_ANIMATION_TRANSITION_MERGE_FADE) {
                        width = MAX (ply_image_get_width (frames[frame_number]), ply_image_get_width (frames[frame_number - 1]));
                        height = MAX (ply_image_get_height (frames[frame_number]), ply_image_get_height (frames[frame_number - 1]));
                        progress_animation->frame_area.width = width;
                        progress_animation->frame_area.height = height;

                        ply_pixel_buffer_free (progress_animation->last_rendered_frame);
                        progress_animation->last_rendered_frame = ply_pixel_buffer_new (width, height);
                        faded_data = ply_pixel_buffer_get_argb32_data (progress_animation->last_rendered_frame);

                        image_fade_merge (frames[frame_number - 1], frames[frame_number], fade_percentage, width, height, faded_data);
                } else {
                        previous_frame_buffer = ply_image_get_buffer (frames[frame_number - 1]);
                        if (progress_animation->transition == PLY_PROGRESS_ANIMATION_TRANSITION_FADE_OVER) {
                                ply_pixel_buffer_free (progress_animation->last_rendered_frame);
                                progress_animation->last_rendered_frame = ply_pixel_buffer_new (ply_image_get_width (frames[frame_number - 1]),
                                                                                                ply_image_get_height (frames[frame_number - 1]));
                                ply_pixel_buffer_fill_with_buffer (progress_animation->last_rendered_frame,
                                                                   previous_frame_buffer,
                                                                   0,
                                                                   0);
                        } else {
                                fade_out_opacity = 1.0 - fade_percentage;
                                ply_pixel_buffer_fill_with_buffer_at_opacity (progress_animation->last_rendered_frame,
                                                                              previous_frame_buffer,
                                                                              0,
                                                                              0,
                                                                              fade_out_opacity);
                        }

                        ply_pixel_buffer_fill_with_buffer_at_opacity (progress_animation->last_rendered_frame,
                                                                      current_frame_buffer,
                                                                      0,
                                                                      0,
                                                                      fade_percentage);

                        width = MAX (ply_image_get_width (frames[frame_number]), ply_image_get_width (frames[frame_number - 1]));
                        height = MAX (ply_image_get_height (frames[frame_number]), ply_image_get_height (frames[frame_number - 1]));
                        progress_animation->frame_area.width = width;
                        progress_animation->frame_area.height = height;
                }
        } else {
                ply_pixel_buffer_free (progress_animation->last_rendered_frame);
                progress_animation->frame_area.width = ply_image_get_width (frames[frame_number]);
                progress_animation->frame_area.height = ply_image_get_height (frames[frame_number]);
                progress_animation->last_rendered_frame = ply_pixel_buffer_new (progress_animation->frame_area.width,
                                                                                progress_animation->frame_area.height);

                ply_pixel_buffer_fill_with_buffer (progress_animation->last_rendered_frame,
                                                   current_frame_buffer,
                                                   0,
                                                   0);
        }

        progress_animation->previous_frame_number = frame_number;

        ply_pixel_display_draw_area (progress_animation->display,
                                     progress_animation->frame_area.x,
                                     progress_animation->frame_area.y,
                                     progress_animation->frame_area.width,
                                     progress_animation->frame_area.height);
}