aboutsummaryrefslogtreecommitdiff
path: root/src/tool
diff options
context:
space:
mode:
Diffstat (limited to 'src/tool')
-rw-r--r--src/tool/deletion_tool.rs24
-rw-r--r--src/tool/icon_tool.rs9
-rw-r--r--src/tool/mod.rs23
-rw-r--r--src/tool/polygon_room_tool.rs15
-rw-r--r--src/tool/rect_room_tool.rs12
-rw-r--r--src/tool/selection_tool.rs24
-rw-r--r--src/tool/wall_tool.rs6
7 files changed, 82 insertions, 31 deletions
diff --git a/src/tool/deletion_tool.rs b/src/tool/deletion_tool.rs
index 5ff3e6a..afd916a 100644
--- a/src/tool/deletion_tool.rs
+++ b/src/tool/deletion_tool.rs
@@ -1,15 +1,26 @@
+//! A meta tool for selecting parts of a map and removing them in a single operation.
+//!
+//! The user can draw a rectangle, which currently must have it's side parallel to the x and y-axes
+//! of the world. With the first node placement, the mode is started, while the second placement would
+//! finish the process and delete all elements that are *completely* contained in the rectangle
+//! (partially contained items are not deleted) or abort it, in which case the selection is removed
+//! and nothing is deleted.
+
use super::Tool;
+use crate::colours::DEFAULT_COLOURS;
use crate::map::Map;
use crate::math::{Rect, Surface, Vec2};
use crate::transform::Transform;
-use crate::colours::DEFAULT_COLOURS;
use raylib::core::drawing::{RaylibDraw, RaylibDrawHandle};
+/// The deletion tool itself.
pub struct DeletionTool {
deletion_rect: Option<(Vec2<f64>, Vec2<f64>)>,
}
impl DeletionTool {
+ /// Create a new deletion tool, there should only be one deletion tool and it should be created
+ /// by the editor.
pub fn new() -> Self {
Self {
deletion_rect: None,
@@ -36,15 +47,8 @@ impl Tool for DeletionTool {
fn draw(&self, rld: &mut RaylibDrawHandle, transform: &Transform) {
if let Some((pos1, pos2)) = self.deletion_rect {
let rect_px = transform.rect_m_to_px(&Rect::bounding_rect(pos1, pos2));
- rld.draw_rectangle_rec(
- rect_px,
- DEFAULT_COLOURS.deletion_rect
- );
- rld.draw_rectangle_lines_ex(
- rect_px,
- 4,
- DEFAULT_COLOURS.deletion_rect_outline
- );
+ rld.draw_rectangle_rec(rect_px, DEFAULT_COLOURS.deletion_rect);
+ rld.draw_rectangle_lines_ex(rect_px, 4, DEFAULT_COLOURS.deletion_rect_outline);
}
}
diff --git a/src/tool/icon_tool.rs b/src/tool/icon_tool.rs
index 09b0ac1..c9e671e 100644
--- a/src/tool/icon_tool.rs
+++ b/src/tool/icon_tool.rs
@@ -1,3 +1,6 @@
+//! Tool for creating icons. For explanation of icons, please see
+//! [the icon module](crate::map::icon).
+
use crate::button::Button;
use crate::config::IconToolKeys;
use crate::map::icon_renderer::IconRenderer;
@@ -8,10 +11,8 @@ use crate::transform::Transform;
use raylib::core::drawing::RaylibDrawHandle;
use std::rc::Rc;
-pub const ICON_DIR: &str = "assets/icons";
-
+/// The icon tool itself.
pub struct IconTool {
- // TODO: support svg
keybindings: IconToolKeys,
/// Saves whether the IconTool is the currently active tool or not.
active: bool,
@@ -22,6 +23,8 @@ pub struct IconTool {
}
impl IconTool {
+ /// Create a new icon tool that renders icons with the provided icon renderer. There should only
+ /// be one instance of the tool for the program, which should be created in the editor.
pub fn new(keybindings: IconToolKeys, renderer: Rc<IconRenderer>) -> Self {
Self {
keybindings,
diff --git a/src/tool/mod.rs b/src/tool/mod.rs
index aeabf19..70534ac 100644
--- a/src/tool/mod.rs
+++ b/src/tool/mod.rs
@@ -1,3 +1,11 @@
+//! Tools, which are user interfaces that must be specifically selected in order to do something.
+//!
+//! As stated, a tool is not simply everything that helps a user do something, think of it more as a
+//! mode which must be elected by the user to perform a task on a specific object type or a class of
+//! objects. If instead the operation is defined by the state of the program, it is not a tool, since
+//! the user didn't explicitly ask for this function to be performed, but it is rather an option
+//! that's inherent to the situation the user finds themselves in.
+
pub mod deletion_tool;
pub mod icon_tool;
pub mod polygon_room_tool;
@@ -20,16 +28,31 @@ use raylib::core::drawing::RaylibDrawHandle;
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
#[repr(u8)]
+/// The types of tools available in graf karto. For information about the tool itself, please see the
+/// referenced Tool's documentation.
pub enum ToolType {
+ /// See [super::RectRoomTool] for information on this tool.
RectRoomTool,
+ /// See [super::PolygonRoomTool] for information on this tool.
PolygonRoomTool,
+ /// See [super::WallTool] for information on this tool.
WallTool,
+ /// See [super::IconTool] for information on this tool.
IconTool,
+ /// See [super::DeletionTool] for information on this tool.
DeletionTool,
+ /// See [super::SelectionTool] for information on this tool.
SelectionTool,
+ /// Not a real tool but used to know how many tools are available. New tools must be added
+ /// above this variant.
+ // TODO: Since we now use a hash map in the editor, check if this is still necessary at all.
NumTools,
}
+/// Base trait for tools. A tool is something that performs a specific action on one or more types of
+/// elements. It must be selected in order to be active. For this reason, the selection tool is a
+/// tool (it must be selected from the toolbox), but the dimension indicator for instance is not,
+/// since it is automatically updated when applicable.
pub trait Tool {
/// Code that needs to be called when this Tool is activated or reactivated goes here.
fn activate(&mut self) {}
diff --git a/src/tool/polygon_room_tool.rs b/src/tool/polygon_room_tool.rs
index 1b079d2..33daaf5 100644
--- a/src/tool/polygon_room_tool.rs
+++ b/src/tool/polygon_room_tool.rs
@@ -1,8 +1,10 @@
+//! Tool to create rooms in the shape of generic polygons.
+
use super::Tool;
+use crate::colours::DEFAULT_COLOURS;
use crate::map::Map;
use crate::math::{self, Polygon, PolygonError, Vec2};
use crate::transform::Transform;
-use crate::colours::DEFAULT_COLOURS;
use raylib::core::drawing::{RaylibDraw, RaylibDrawHandle};
struct UnfinishedPolygon {
@@ -10,6 +12,7 @@ struct UnfinishedPolygon {
pub working_corner: Vec2<f64>,
}
+/// The tool itself.
pub struct PolygonRoomTool {
unfinished_polygon: Option<UnfinishedPolygon>,
}
@@ -76,6 +79,8 @@ impl UnfinishedPolygon {
}
impl PolygonRoomTool {
+ /// Create a new polygon room tool. There should be only one instance and it should be created
+ /// in the editor.
pub fn new() -> Self {
Self {
unfinished_polygon: None,
@@ -103,7 +108,7 @@ impl Tool for PolygonRoomTool {
transform.point_m_to_px(&polygon.corners[0]),
transform.point_m_to_px(&polygon.working_corner),
transform.length_m_to_px(0.1) as f32,
- DEFAULT_COLOURS.room_selected
+ DEFAULT_COLOURS.room_selected,
);
} else if polygon.corners.len() == 2 {
// We have three valid corners, so we can draw a triangle.
@@ -111,7 +116,7 @@ impl Tool for PolygonRoomTool {
transform.point_m_to_px(&polygon.corners[0]),
transform.point_m_to_px(&polygon.corners[1]),
transform.point_m_to_px(&polygon.working_corner),
- DEFAULT_COLOURS.room_selected
+ DEFAULT_COLOURS.room_selected,
)
} else {
// A proper polygon can be drawn.
@@ -126,7 +131,7 @@ impl Tool for PolygonRoomTool {
transform.point_m_to_px(&triangle[0]),
transform.point_m_to_px(&triangle[1]),
transform.point_m_to_px(&triangle[2]),
- DEFAULT_COLOURS.room_selected
+ DEFAULT_COLOURS.room_selected,
)
}
} else if polygon.check_validity_completed().is_ok() {
@@ -138,7 +143,7 @@ impl Tool for PolygonRoomTool {
transform.point_m_to_px(&triangle[0]),
transform.point_m_to_px(&triangle[1]),
transform.point_m_to_px(&triangle[2]),
- DEFAULT_COLOURS.room_selected
+ DEFAULT_COLOURS.room_selected,
)
}
}
diff --git a/src/tool/rect_room_tool.rs b/src/tool/rect_room_tool.rs
index dfda495..7cb85bb 100644
--- a/src/tool/rect_room_tool.rs
+++ b/src/tool/rect_room_tool.rs
@@ -1,10 +1,15 @@
+//! The rectangle room tool is a specialised tool to create rooms of rectangular shape and with the
+//! sides of the room parallel to the x and y-axes. This is often useful, when a quick room creation
+//! is necessary and the shape of the room does not have to be very special.
+
use super::Tool;
+use crate::colours::DEFAULT_COLOURS;
use crate::map::Map;
use crate::math::{Rect, Vec2};
use crate::transform::Transform;
-use crate::colours::DEFAULT_COLOURS;
use raylib::core::drawing::{RaylibDraw, RaylibDrawHandle};
+/// The tool to create simple, rectangular rooms.
pub struct RectRoomTool {
/// The rectangle that is currently being drawn by the user. Once it is finished, it will be
/// pushed into the room_rects.
@@ -12,7 +17,8 @@ pub struct RectRoomTool {
}
impl RectRoomTool {
- /// Create a new room tool where no rooms have been drawn yet.
+ /// Create a new room tool where no rooms have been drawn yet. Should be created only once per
+ /// program instance and by the editor.
pub fn new() -> Self {
Self {
unfinished_rect: None,
@@ -35,7 +41,7 @@ impl Tool for RectRoomTool {
if let Some((pos1, pos2)) = self.unfinished_rect {
rld.draw_rectangle_rec(
transform.rect_m_to_px(&Rect::bounding_rect(pos1, pos2)),
- DEFAULT_COLOURS.room_selected
+ DEFAULT_COLOURS.room_selected,
);
}
}
diff --git a/src/tool/selection_tool.rs b/src/tool/selection_tool.rs
index 49efba9..c790734 100644
--- a/src/tool/selection_tool.rs
+++ b/src/tool/selection_tool.rs
@@ -1,15 +1,26 @@
+//! Selection of items on the map.
+//!
+//! When selecting items on the map, the editor goes into a different mode than when editing a
+//! specific kind of item. Actions that are available for specific types of items become
+//! unavailable, while other actions that make use of the properties to a wide range of items
+//! become available instead.
+//! For this reason, the selection tool can be thought of as a kind of meta tool over tools.
+
use super::Tool;
+use crate::colours::DEFAULT_COLOURS;
use crate::map::Map;
use crate::math::{Rect, Surface, Vec2};
use crate::transform::Transform;
use raylib::core::drawing::{RaylibDraw, RaylibDrawHandle};
-use crate::colours::DEFAULT_COLOURS;
+/// The selection tool makes it possible to select any item on the map when activated.
pub struct SelectionTool {
selection_rect: Option<(Vec2<f64>, Vec2<f64>)>,
}
impl SelectionTool {
+ /// Create a new selection tool. There should be only one such tool per program instance and it
+ /// should be created in the editor.
pub fn new() -> Self {
Self {
selection_rect: None,
@@ -31,15 +42,8 @@ impl Tool for SelectionTool {
fn draw(&self, rld: &mut RaylibDrawHandle, transform: &Transform) {
if let Some((pos1, pos2)) = self.selection_rect {
let rect_px = transform.rect_m_to_px(&Rect::bounding_rect(pos1, pos2));
- rld.draw_rectangle_rec(
- rect_px,
- DEFAULT_COLOURS.selection_rect
- );
- rld.draw_rectangle_lines_ex(
- rect_px,
- 4,
- DEFAULT_COLOURS.selection_rect_outline
- );
+ rld.draw_rectangle_rec(rect_px, DEFAULT_COLOURS.selection_rect);
+ rld.draw_rectangle_lines_ex(rect_px, 4, DEFAULT_COLOURS.selection_rect_outline);
}
}
diff --git a/src/tool/wall_tool.rs b/src/tool/wall_tool.rs
index b958799..123171c 100644
--- a/src/tool/wall_tool.rs
+++ b/src/tool/wall_tool.rs
@@ -1,3 +1,6 @@
+//! Tool to create walls. For information about walls, see also
+//! [the wall module](crate::map::wall).
+
use super::Tool;
use crate::map::Map;
use crate::math::{LineSegment, Vec2};
@@ -5,11 +8,14 @@ use crate::transform::Transform;
use raylib::core::drawing::{RaylibDraw, RaylibDrawHandle};
use raylib::ffi::{Color, Vector2};
+/// The wall tool to create solid barriers a player usually cannot cross.
pub struct WallTool {
unfinished_wall: Option<LineSegment<f64>>,
}
impl WallTool {
+ /// Create a new wall tool. There should only be one wall tool per program instance, which should
+ /// be created inside of the editor.
pub fn new() -> Self {
Self {
unfinished_wall: None,