surface_cache.h (2244B)
1 /* 2 * Copyright (c) 2022-2024 lumidify <nobody@lumidify.org> 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #ifndef LTK_SURFACE_CACHE_H 18 #define LTK_SURFACE_CACHE_H 19 20 #include "graphics.h" 21 22 /* FIXME: It would probably be much better to just have a named cache 23 and then pass a single surface around while drawing other widgets */ 24 /* FIXME: some sort of "locking" for surfaces so they temporarily can't 25 be reassigned? (e.g. when drawing widget hierarchy) */ 26 27 typedef struct ltk_surface_cache ltk_surface_cache; 28 typedef struct ltk_surface_cache_key ltk_surface_cache_key; 29 30 ltk_surface_cache *ltk_surface_cache_create(ltk_renderwindow *renderwindow); 31 void ltk_surface_cache_destroy(ltk_surface_cache *cache); 32 ltk_surface_cache_key *ltk_surface_cache_get_named_key(ltk_surface_cache *cache, int widget_type, int id, int min_w, int min_h); 33 ltk_surface_cache_key *ltk_surface_cache_get_unnamed_key(ltk_surface_cache *cache, int min_w, int min_h); 34 35 /* WARNING: DO NOT RESIZE SURFACES MANUALLY, ALWAYS USE ltk_surface_cache_request_surface_size! */ 36 void ltk_surface_cache_request_surface_size(ltk_surface_cache_key *key, int min_w, int min_h); 37 /* -> just sets to invalid and changes min_* so appropriate size is taken next time */ 38 /* -> cannot assume anything about the contents afterwards! */ 39 40 /* returns 1 if key was valid, i.e. surface was already assigned, 0 otherwise */ 41 int ltk_surface_cache_get_surface(ltk_surface_cache_key *key, ltk_surface **s_ret); 42 43 void ltk_surface_cache_release_key(ltk_surface_cache_key *key); 44 45 #endif /* LTK_SURFACE_CACHE_H */