From d7e9c3cc46d616c2fcd1a6e9f73adbb79c6570b4 Mon Sep 17 00:00:00 2001 From: Arne Dußin Date: Mon, 21 Dec 2020 01:22:15 +0100 Subject: Add previously missing docs where appropriate --- src/map/icon_renderer.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/map/icon_renderer.rs') 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() } -- cgit v1.2.3-70-g09d2