about summary refs log tree commit diff
path: root/src/block/extension/graphiccontrol.rs
diff options
context:
space:
mode:
authorGenny <gen@nyble.dev>2021-03-10 02:44:45 -0600
committerGenny <gen@nyble.dev>2021-03-10 02:44:45 -0600
commitfa403b904c8596d8d1731d7f8bfafa6c0145e3dd (patch)
treeb1c0b89da9f51f35b7984a30d9c249788922bb9a /src/block/extension/graphiccontrol.rs
parent743888ae0c1038a92f4a0b64709a313eba70c887 (diff)
downloadgifed-fa403b904c8596d8d1731d7f8bfafa6c0145e3dd.tar.gz
gifed-fa403b904c8596d8d1731d7f8bfafa6c0145e3dd.zip
Implement, roughly, extensions, animation, and looping
Diffstat (limited to 'src/block/extension/graphiccontrol.rs')
-rw-r--r--src/block/extension/graphiccontrol.rs59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/block/extension/graphiccontrol.rs b/src/block/extension/graphiccontrol.rs
new file mode 100644
index 0000000..46f44fa
--- /dev/null
+++ b/src/block/extension/graphiccontrol.rs
@@ -0,0 +1,59 @@
+pub struct GraphicControl {
+	pub(crate) packed: u8,
+	pub(crate) delay_time: u16,
+	pub(crate) transparency_index: u8
+}
+
+impl GraphicControl {
+	pub fn new(disposal_method: DisposalMethod, user_input_flag: bool, transparency_flag: bool, delay_time: u16, transparency_index: u8) -> Self {
+		let mut ret = Self {
+			packed: 0,
+			delay_time,
+			transparency_index
+		};
+
+		ret.disposal_method(disposal_method);
+		ret.user_input(user_input_flag);
+		ret.transparency(transparency_flag);
+
+		ret
+	}
+
+	pub fn disposal_method(&mut self, method: DisposalMethod) {
+		match method {
+			DisposalMethod::Clear => self.packed &= 0b111_000_1_1,
+			DisposalMethod::DoNotDispose => self.packed |= 0b000_100_0_0,
+			DisposalMethod::RestoreBackground => self.packed |= 0b000_010_0_0,
+			DisposalMethod::RestorePrevious => self.packed |= 0b000_110_0_0
+		};
+	}
+
+	pub fn user_input(&mut self, flag: bool) {
+		if flag {
+			self.packed |= 0b000_000_1_0;
+		} else {
+			self.packed &= 0b111_111_0_1;
+		}
+	}
+
+	pub fn transparency(&mut self, flag: bool) {
+		if flag {
+			self.packed |= 0b000_000_0_1;
+		} else {
+			self.packed &= 0b111_111_1_0;
+		}
+	}
+
+	pub fn delay_time(&mut self, hundreths: u16) {
+		self.delay_time = hundreths;
+	}
+
+	//TODO: Transparency index setter
+}
+
+pub enum DisposalMethod {
+	Clear,
+	DoNotDispose,
+	RestoreBackground,
+	RestorePrevious
+}
\ No newline at end of file