diff options
| author | Arne Dußin | 2020-12-21 01:22:15 +0100 |
|---|---|---|
| committer | Arne Dußin | 2020-12-21 21:15:55 +0100 |
| commit | d7e9c3cc46d616c2fcd1a6e9f73adbb79c6570b4 (patch) | |
| tree | e5633f4d3b18472922c943d759e9f58722ba4405 /src/map/icon_renderer.rs | |
| parent | 48f321a80970ebeb8374072b1d2e0a4d297aa348 (diff) | |
| download | graf_karto-d7e9c3cc46d616c2fcd1a6e9f73adbb79c6570b4.tar.gz graf_karto-d7e9c3cc46d616c2fcd1a6e9f73adbb79c6570b4.zip | |
Add previously missing docs where appropriate
Diffstat (limited to 'src/map/icon_renderer.rs')
| -rw-r--r-- | src/map/icon_renderer.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/map/icon_renderer.rs b/src/map/icon_renderer.rs index fb81e24..eef053d 100644 --- a/src/map/icon_renderer.rs +++ b/src/map/icon_renderer.rs @@ -1,3 +1,6 @@ +//! Since the same icon may be used very often on a map, it becomes impracticalto let every icon have +//! it's own texture data saved, which is why a texture manager type of struct is used for it instead. + use crate::math::Vec2; use raylib::core::texture::Texture2D; use raylib::{RaylibHandle, RaylibThread}; @@ -5,6 +8,7 @@ use ron::de::from_reader; use serde::Deserialize; use std::fs::{self, File}; +/// The directory containing all files related to icons. pub const ICON_DIR: &str = "assets/icons"; #[derive(Deserialize)] @@ -16,11 +20,15 @@ pub(super) struct IconFileInfo { pub pixels_per_m: f64, } +/// Manager for all icon texture or rendering data. pub struct IconRenderer { texture_data: Vec<(Texture2D, IconFileInfo)>, } impl IconRenderer { + /// Create a new icon renderer. This loads all textures and information for icons that is needed + /// to draw them to the screen. Usually, there should be only one IconRenderer, or at least one + /// renderer per directory and program instance. pub fn new(rl: &mut RaylibHandle, rlt: &RaylibThread) -> Self { /* Read all available icons from the icon directory. SVGs do not need any special scale * file, but pixel-based file formats require a RON-file declaring what the scale of the @@ -67,10 +75,16 @@ impl IconRenderer { Self { texture_data } } + /// Get the data needed to render an icon of type `icon_id`. + /// + /// # Panics + /// If the `icon_id` does not describe a valid icon (is out of bounds), there is no data to be + /// accessed and the function panics. pub(super) fn get(&self, icon_id: usize) -> &(Texture2D, IconFileInfo) { &self.texture_data[icon_id] } + /// The number of icons registered in this icon-renderer. pub fn num_icons(&self) -> usize { self.texture_data.len() } |
