| 1 | /* File: gui_sketch_texture.h; Copyright and License: see below */ |
| 2 | |
| 3 | #ifndef GUI_SKETCH_TEXTURE_H |
| 4 | #define GUI_SKETCH_TEXTURE_H |
| 5 | |
| 6 | /* public file for the doxygen documentation: */ |
| 7 | /*! |
| 8 | * \file |
| 9 | * \brief provides types and functions that were still there in GTK 4.0.0 |
| 10 | * but deprecated later on and so had to be replaced by more modern concepts |
| 11 | */ |
| 12 | |
| 13 | #include "u8/u8_error.h" |
| 14 | #include "gui_gtk.h" |
| 15 | |
| 16 | /*! |
| 17 | * \brief constants of gui_sketch_texture_t |
| 18 | */ |
| 19 | enum gui_sketch_texture_enum { |
| 20 | GUI_SKETCH_TEXTURE_MAX_WIDTH = 80, /*!< maximum width of an icon to be drawn */ |
| 21 | GUI_SKETCH_TEXTURE_MAX_HEIGHT = 80, /*!< maximum height of an icon to be drawn */ |
| 22 | GUI_SKETCH_TEXTURE_BYTES_PER_PIXEL = 4, /*!< number of bits per pixel */ |
| 23 | }; |
| 24 | |
| 25 | /*! |
| 26 | * \brief attributes of the gui_sketch_texture_t |
| 27 | */ |
| 28 | struct gui_sketch_texture_struct { |
| 29 | cairo_surface_t *surface; /*!< cairo drawing surface wrapping a data buffer */ |
| 30 | unsigned int memory_fence_1; /* a memory fence to detect if gdk or cairo have been used in an unforseen way */ |
| 31 | unsigned char buf[ GUI_SKETCH_TEXTURE_MAX_WIDTH * GUI_SKETCH_TEXTURE_MAX_HEIGHT * GUI_SKETCH_TEXTURE_BYTES_PER_PIXEL ]; |
| 32 | /*!< buffer to download a texture into a cairo drawing surface */ |
| 33 | unsigned int memory_fence_2; /* a memory fence to detect if gdk or cairo have been used in an unforseen way */ |
| 34 | }; |
| 35 | |
| 36 | typedef struct gui_sketch_texture_struct gui_sketch_texture_t; |
| 37 | |
| 38 | /*! |
| 39 | * \brief initializes the gui_sketch_texture |
| 40 | * |
| 41 | * \param this_ pointer to own object attributes |
| 42 | */ |
| 43 | static inline void gui_sketch_texture_init( gui_sketch_texture_t *this_ ); |
| 44 | |
| 45 | /*! |
| 46 | * \brief destroys the gui_sketch_texture |
| 47 | * |
| 48 | * \param this_ pointer to own object attributes |
| 49 | */ |
| 50 | static inline void gui_sketch_texture_destroy( gui_sketch_texture_t *this_ ); |
| 51 | |
| 52 | /*! |
| 53 | * \brief draws the icon |
| 54 | * |
| 55 | * \param this_ pointer to own object attributes |
| 56 | * \param icon the icon to draw |
| 57 | * \param left left coordinate |
| 58 | * \param top top coordinate |
| 59 | * \param cr cairo drawing context |
| 60 | * \return U8_ERROR_NONE in case of success, |
| 61 | * U8_ERROR_EDGE_CASE_PARAM if the icon could not be drawn (overlap to surface boundary) |
| 62 | */ |
| 63 | static inline u8_error_t gui_sketch_texture_draw( gui_sketch_texture_t *this_, |
| 64 | GdkTexture *icon, |
| 65 | double left, |
| 66 | double top, |
| 67 | cairo_t *cr |
| 68 | ); |
| 69 | |
| 70 | #include "sketch/gui_sketch_texture.inl" |
| 71 | |
| 72 | #endif /* GUI_SKETCH_TEXTURE_H */ |
| 73 | |
| 74 | |
| 75 | /* |
| 76 | Copyright 2024-2026 Andreas Warnke |
| 77 | |
| 78 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 79 | you may not use this file except in compliance with the License. |
| 80 | You may obtain a copy of the License at |
| 81 | |
| 82 | http://www.apache.org/licenses/LICENSE-2.0 |
| 83 | |
| 84 | Unless required by applicable law or agreed to in writing, software |
| 85 | distributed under the License is distributed on an "AS IS" BASIS, |
| 86 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 87 | See the License for the specific language governing permissions and |
| 88 | limitations under the License. |
| 89 | */ |