Skip to content

Instantly share code, notes, and snippets.

@ermiry
Created January 3, 2020 22:13
Show Gist options
  • Save ermiry/d27ee3dd2f7f0c48ca4d4a795c1a49db to your computer and use it in GitHub Desktop.
Save ermiry/d27ee3dd2f7f0c48ca4d4a795c1a49db to your computer and use it in GitHub Desktop.
#include "cengine/renderer.h"
#include "cengine/ui/image.h"
void cimage_like_image_create (const char *filename,
SDL_Texture *overlay_texture, SDL_Texture *selected_texture) {
if (filename && overlay_texture && selected_texture) {
Renderer *main_renderer = renderer_get_by_name ("main");
Image *image = ui_image_create_static (0, 0, main_renderer);
// sets the image to be displayed at the center of the screen
ui_image_set_pos (image, NULL, UI_POS_MIDDLE_CENTER, main_renderer);
// sets the real image to be loaded from a file, like a jpg
ui_image_set_sprite (image, main_renderer, filename);
// sets a white outline for the image
ui_image_set_ouline_colour (image, RGBA_WHITE);
ui_image_set_outline_scale (image, 2, 2);
// you need to set this to enable image actions
ui_image_toggle_active (image);
// sets reerences to overlay and selected textures
ui_image_set_overlay_ref (image, overlay_texture);
ui_image_set_selected_ref (image, selected_texture);
// actions to be executed on single and double click
ui_image_set_action (image, app_ui_image_select, NULL);
ui_image_set_double_click_action (image, app_ui_image_display_in_window, NULL);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment