wolfrpg_map_parser/command/picture_command/
options.rs

1#[cfg(feature = "serde")]
2use serde::{Serialize, Deserialize};
3use crate::command::picture_command::anchor::Anchor;
4use crate::command::picture_command::blending_method::BlendingMethod;
5use crate::command::picture_command::display_operation::DisplayOperation;
6use crate::command::picture_command::display_type::DisplayType;
7use crate::command::picture_command::zoom::Zoom;
8
9#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10#[derive(PartialEq, Clone)]
11pub struct Options {
12    display_operation: DisplayOperation,
13    display_type: DisplayType,
14    blending_method: BlendingMethod,
15    anchor: Anchor,
16    position_relative: bool,
17    zoom: Zoom,
18    range: bool,
19    link_to_scroll: bool,
20    free_transform: bool,
21}
22
23impl Options {
24    pub fn new(options: u32) -> Self {
25        Self {
26            display_operation: DisplayOperation::new((options & 0xff) as u8),
27            display_type: DisplayType::new((options & 0xff) as u8),
28            blending_method: BlendingMethod::new(((options >> 8) & 0x0f) as u8),
29            anchor: Anchor::new((((options >> 8) & 0xf0) >> 4) as u8),
30            position_relative: ((options >> 16) & 0b00000001) != 0,
31            zoom: Zoom::new((((options >> 16) & 0xf0) >> 4) as u8),
32            range:          (options >> 24) & 0b00000001 != 0,
33            link_to_scroll: (options >> 24) & 0b00000010 != 0,
34            free_transform: (options >> 24) & 0b00000100 != 0
35        }
36    }
37
38    pub fn display_operation(&self) -> &DisplayOperation {
39        &self.display_operation
40    }
41
42    pub fn display_type(&self) -> &DisplayType {
43        &self.display_type
44    }
45
46    pub fn blending_method(&self) -> &BlendingMethod {
47        &self.blending_method
48    }
49
50    pub fn anchor(&self) -> &Anchor {
51        &self.anchor
52    }
53
54    pub fn position_relative(&self) -> bool {
55        self.position_relative
56    }
57
58    pub fn zoom(&self) -> &Zoom {
59        &self.zoom
60    }
61
62    pub fn range(&self) -> bool {
63        self.range
64    }
65
66    pub fn link_to_scroll(&self) -> bool {
67        self.link_to_scroll
68    }
69
70    pub fn free_transform(&self) -> bool {
71        self.free_transform
72    }
73}