Exemple #1
0
GFont simply_res_add_custom_font(SimplyRes *self, uint32_t id) {
  SimplyFont *font = malloc(sizeof(*font));
  if (!font) {
    return NULL;
  }

  ResHandle handle = resource_get_handle(id);
  if (!handle) {
    return NULL;
  }

  GFont custom_font = fonts_load_custom_font(handle);
  if (!custom_font) {
    free(font);
    return NULL;
  }

  font->font = custom_font;

  list1_prepend(&self->fonts, &font->node);

  window_stack_schedule_top_window_render();

  return font->font;
}
Exemple #2
0
GBitmap *simply_res_add_image(SimplyRes *self, uint32_t id, int16_t width, int16_t height, uint32_t *pixels) {
  SimplyImage *image = (SimplyImage*) list1_find(self->images, id_filter, (void*)(uintptr_t) id);
  if (image) {
    free(image->bitmap.addr);
    image->bitmap.addr = NULL;
  } else {
    image = malloc(sizeof(*image));
    if (!image) {
      return NULL;
    }
    *image = (SimplyImage) { .id = id };
    list1_prepend(&self->images, &image->node);
  }

  uint16_t row_size_bytes = (1 + (width - 1) / 32) * 4;
  size_t pixels_size = height * row_size_bytes;
  image->bitmap = (GBitmap) {
    .row_size_bytes = row_size_bytes,
    .bounds.size = { width, height },
  };

  image->bitmap.addr = malloc(pixels_size);
  memcpy(image->bitmap.addr, pixels, pixels_size);

  window_stack_schedule_top_window_render();

  return &image->bitmap;
}

void simply_res_remove_image(SimplyRes *self, uint32_t id) {
  SimplyImage *image = (SimplyImage*) list1_find(self->images, id_filter, (void*)(uintptr_t) id);
  if (image) {
    destroy_image(self, image);
  }
}
Exemple #3
0
static void add_image(SimplyRes *self, SimplyImage *image) {
  list1_prepend(&self->images, &image->node);

  setup_image(image);

  window_stack_schedule_top_window_render();
}
Exemple #4
0
GBitmap *simply_res_add_bundled_image(SimplyRes *self, uint32_t id) {
  SimplyImage *image = malloc(sizeof(*image));
  if (!image) {
    return NULL;
  }

  GBitmap *bitmap = gbitmap_create_with_resource(id);
  if (!bitmap) {
    free(image);
    return NULL;
  }

  *image = (SimplyImage) {
    .id = id,
    .bitmap = *bitmap,
  };

  list1_prepend(&self->images, &image->node);

  window_stack_schedule_top_window_render();

  return &image->bitmap;
}
Exemple #5
0
static void handle_card_image_packet(Simply *simply, Packet *data) {
  CardImagePacket *packet = (CardImagePacket*) data;
  simply->ui->ui_layer.imagefields[MIN(NumUiImagefields - 1, packet->index)] = packet->image;
  window_stack_schedule_top_window_render();
}