Ejemplo n.º 1
0
int color_alloc_colors(void *c, const palette_t *palette,
                       unsigned long *col_return)
{
    color_list_t *color_new, *color_to_alloc, *color_no_alloc,
    *color_alloced_owner, *color_without_owner;

    if (palette == NULL) {
        return 0; /* no palette yet, nothing to alloc. */
    }

    /* Convert the palette to a color list.  */
    color_create_empty_entry(&color_new);
    color_palette_to_list(color_new, c, palette);

    /* This splits `color_new' into two separate lists.  */
    color_create_empty_entry(&color_to_alloc);
    color_create_empty_entry(&color_no_alloc);
    color_compare_list(color_alloced, color_new, color_to_alloc,
                       color_no_alloc);

    /* Allocate only colors we do not have.  */
    if (color_alloc_new_colors(color_to_alloc) < 0) {
        color_free(color_new);
        color_free(color_to_alloc);
        color_free(color_no_alloc);
        return -1;
    }

    /* Remove the current owner from allocated colors list.  */
    color_remove_owner_from_list(color_alloced, c);

    /* Add the owner to remaining colors if necessary.  */
    color_add_owner_from_other_list(color_alloced, color_no_alloc);

    /* Add the newly allocated colors to the allocated colors list.  */
    color_copy_list(color_alloced, color_to_alloc);

    /* Copy valid colors (with owner) to new list.  */
    color_create_empty_entry(&color_alloced_owner);
    color_copy_list_with_owner(color_alloced_owner, color_alloced);

    color_fill_pixel_return(color_alloced_owner, color_new, col_return, c);

    /* Copy invalid colors (without owner) to new list.  */
    color_create_empty_entry(&color_without_owner);
    color_copy_list_without_owner(color_without_owner, color_alloced);
    color_free_old_colors(color_without_owner);

    /* Throw away old list and temp lists.  */
    color_free(color_alloced);
    color_free(color_new);
    color_free(color_to_alloc);
    color_free(color_no_alloc);
    color_free(color_without_owner);

    /* The new list.  */
    color_alloced = color_alloced_owner;

    return 0;
}
Ejemplo n.º 2
0
/****************************************************************************
  Called when the client first starts to free any allocated colors.
****************************************************************************/
void theme_color_system_free(struct theme_color_system *colors)
{
  int i;

  for (i = 0; i < (THEME_COLOR_LAST - COLOR_LAST); i++) {
    if (colors->colors[i].color) {
      color_free(colors->colors[i].color);
    }
  }
  
  free(colors);
}
Ejemplo n.º 3
0
void test_color () {
  printf ("test/color result: ");

  Color *color = color_new (0x11, 0x22, 0x33);

  assert (color_get_red (color) == 0x11);
  assert (color_get_green (color) == 0x22);
  assert (color_get_blue (color) == 0x33);

  color_free (color);

  printf ("success\n");
}
Ejemplo n.º 4
0
/****************************************************************************
  Called when the client first starts to free any allocated colors.
****************************************************************************/
void color_system_free(struct color_system *colors)
{
  int i;

  for (i = 0; i < COLOR_LAST; i++) {
    if (colors->colors[i].color) {
      color_free(colors->colors[i].color);
    }
  }
  for (i = 0; i < colors->num_player_colors; i++) {
    if (colors->player_colors[i].color) {
      color_free(colors->player_colors[i].color);
    }
  }
  free(colors->player_colors);
  for (i = 0; i < ARRAY_SIZE(colors->terrain_colors); i++) {
    if (colors->terrain_colors[i].color) {
      color_free(colors->terrain_colors[i].color);
    }
  }
  terrain_color_hash_destroy(colors->terrain_hash);
  free(colors);
}
Ejemplo n.º 5
0
void color_shutdown(void)
{
    color_free(color_alloced);
}