Tidy up
This commit is contained in:
parent
bdfc002e99
commit
302af6393d
|
@ -5,8 +5,8 @@ dependencies = [
|
||||||
"byteorder 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
"byteorder 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"flate2 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
"flate2 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"glfw 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"glfw 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"hyper 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
"hyper 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"image 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
"image 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rand 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rand 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -50,7 +50,7 @@ name = "bzip2-sys"
|
||||||
version = "0.1.3"
|
version = "0.1.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"gcc 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
"gcc 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gcc"
|
name = "gcc"
|
||||||
version = "0.3.14"
|
version = "0.3.17"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"advapi32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"advapi32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -170,7 +170,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hyper"
|
name = "hyper"
|
||||||
version = "0.6.13"
|
version = "0.6.14"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cookie 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
"cookie 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -191,7 +191,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "image"
|
name = "image"
|
||||||
version = "0.3.12"
|
version = "0.3.14"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
"byteorder 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -270,7 +270,7 @@ name = "miniz-sys"
|
||||||
version = "0.1.6"
|
version = "0.1.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"gcc 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
"gcc 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -317,7 +317,7 @@ name = "openssl-sys"
|
||||||
version = "0.6.5"
|
version = "0.6.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"gcc 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
"gcc 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"libressl-pnacl-sys 2.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libressl-pnacl-sys 2.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"pkg-config 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"pkg-config 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -13,8 +13,10 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::any::Any;
|
||||||
|
|
||||||
pub struct CVar<T: Sized + 'static> {
|
pub struct CVar<T: Sized + Any + 'static> {
|
||||||
pub name: &'static str,
|
pub name: &'static str,
|
||||||
pub ty: PhantomData<T>,
|
pub ty: PhantomData<T>,
|
||||||
pub description: &'static str,
|
pub description: &'static str,
|
||||||
|
@ -23,10 +25,6 @@ pub struct CVar<T: Sized + 'static> {
|
||||||
pub default: &'static Fn() -> T,
|
pub default: &'static Fn() -> T,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <T> CVar<T> {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Var for CVar<String> {}
|
impl Var for CVar<String> {}
|
||||||
|
|
||||||
pub trait Var {
|
pub trait Var {
|
||||||
|
@ -34,17 +32,32 @@ pub trait Var {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Console {
|
pub struct Console {
|
||||||
vars: Vec<Box<Var>>,
|
vars: HashMap<&'static str, Box<Var>>,
|
||||||
|
var_values: HashMap<&'static str, Box<Any>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Console {
|
impl Console {
|
||||||
pub fn new() -> Console {
|
pub fn new() -> Console {
|
||||||
Console {
|
Console {
|
||||||
vars: Vec::new(),
|
vars: HashMap::new(),
|
||||||
|
var_values: HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn register<T>(&mut self, var: CVar<T>) where CVar<T> : Var {
|
pub fn register<T: Sized + Any>(&mut self, var: CVar<T>) where CVar<T> : Var {
|
||||||
self.vars.push(Box::new(var));
|
if self.vars.contains_key(var.name) {
|
||||||
|
panic!("Key registered twice {}", var.name);
|
||||||
|
}
|
||||||
|
self.var_values.insert(var.name, Box::new((var.default)()));
|
||||||
|
self.vars.insert(var.name, Box::new(var));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get<T: Sized + Any>(&self, var: CVar<T>) -> &T where CVar<T> : Var {
|
||||||
|
// Should never fail
|
||||||
|
self.var_values.get(var.name).unwrap().downcast_ref::<T>().unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set<T: Sized + Any>(&mut self, var: CVar<T>, val: T) where CVar<T> : Var {
|
||||||
|
self.var_values.insert(var.name, Box::new(val));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -277,8 +277,8 @@ fn test_color_from() {
|
||||||
const LEGACY_CHAR: char = '§';
|
const LEGACY_CHAR: char = '§';
|
||||||
|
|
||||||
pub fn convert_legacy(c: &mut Component) {
|
pub fn convert_legacy(c: &mut Component) {
|
||||||
match c {
|
match *c {
|
||||||
&mut Component::Text(ref mut txt) => {
|
Component::Text(ref mut txt) => {
|
||||||
if let Some(ref mut extra) = txt.modifier.extra.as_mut() {
|
if let Some(ref mut extra) = txt.modifier.extra.as_mut() {
|
||||||
for e in extra.iter_mut() {
|
for e in extra.iter_mut() {
|
||||||
convert_legacy(e);
|
convert_legacy(e);
|
||||||
|
|
|
@ -312,7 +312,7 @@ impl Shader {
|
||||||
pub fn get_parameter(&self, param: ShaderParameter) -> i32 {
|
pub fn get_parameter(&self, param: ShaderParameter) -> i32 {
|
||||||
let mut ret : i32 = 0;
|
let mut ret : i32 = 0;
|
||||||
unsafe { gl::GetShaderiv(self.0, param, &mut ret); }
|
unsafe { gl::GetShaderiv(self.0, param, &mut ret); }
|
||||||
return ret;
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_info_log(&self) -> String {
|
pub fn get_info_log(&self) -> String {
|
||||||
|
@ -505,13 +505,13 @@ pub struct MappedBuffer {
|
||||||
impl Deref for MappedBuffer {
|
impl Deref for MappedBuffer {
|
||||||
type Target = Vec<u8>;
|
type Target = Vec<u8>;
|
||||||
|
|
||||||
fn deref<'a>(&'a self) -> &'a Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
&self.inner
|
&self.inner
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DerefMut for MappedBuffer {
|
impl DerefMut for MappedBuffer {
|
||||||
fn deref_mut<'a>(&'a mut self) -> &'a mut Self::Target {
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
&mut self.inner
|
&mut self.inner
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -353,7 +353,7 @@ pub struct LenPrefixed<L: Lengthable, V> {
|
||||||
|
|
||||||
impl <L: Lengthable, V: Default> LenPrefixed<L, V> {
|
impl <L: Lengthable, V: Default> LenPrefixed<L, V> {
|
||||||
fn new(data: Vec<V>) -> LenPrefixed<L, V> {
|
fn new(data: Vec<V>) -> LenPrefixed<L, V> {
|
||||||
return LenPrefixed {
|
LenPrefixed {
|
||||||
len: Default::default(),
|
len: Default::default(),
|
||||||
data: data,
|
data: data,
|
||||||
}
|
}
|
||||||
|
@ -374,7 +374,7 @@ impl <L: Lengthable, V: Serializable> Serializable for LenPrefixed<L, V> {
|
||||||
fn write_to(&self, buf: &mut io::Write) -> Result<(), io::Error> {
|
fn write_to(&self, buf: &mut io::Write) -> Result<(), io::Error> {
|
||||||
let len_data : L = L::from(self.data.len());
|
let len_data : L = L::from(self.data.len());
|
||||||
try!(len_data.write_to(buf));
|
try!(len_data.write_to(buf));
|
||||||
let ref data = self.data;
|
let data = &self.data;
|
||||||
for val in data {
|
for val in data {
|
||||||
try!(val.write_to(buf));
|
try!(val.write_to(buf));
|
||||||
}
|
}
|
||||||
|
@ -406,7 +406,7 @@ pub struct LenPrefixedBytes<L: Lengthable> {
|
||||||
|
|
||||||
impl <L: Lengthable> LenPrefixedBytes<L> {
|
impl <L: Lengthable> LenPrefixedBytes<L> {
|
||||||
fn new(data: Vec<u8>) -> LenPrefixedBytes<L> {
|
fn new(data: Vec<u8>) -> LenPrefixedBytes<L> {
|
||||||
return LenPrefixedBytes {
|
LenPrefixedBytes {
|
||||||
len: Default::default(),
|
len: Default::default(),
|
||||||
data: data,
|
data: data,
|
||||||
}
|
}
|
||||||
|
@ -621,18 +621,18 @@ impl convert::From<io::Error> for Error {
|
||||||
|
|
||||||
impl ::std::error::Error for Error {
|
impl ::std::error::Error for Error {
|
||||||
fn description(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
match self {
|
match *self {
|
||||||
&Error::Err(ref val) => &val[..],
|
Error::Err(ref val) => &val[..],
|
||||||
&Error::IOError(ref e) => e.description(),
|
Error::IOError(ref e) => e.description(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ::std::fmt::Display for Error {
|
impl ::std::fmt::Display for Error {
|
||||||
fn fmt(&self, f : &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
fn fmt(&self, f : &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||||
match self {
|
match *self {
|
||||||
&Error::Err(ref val) => write!(f, "protocol error: {}", val),
|
Error::Err(ref val) => write!(f, "protocol error: {}", val),
|
||||||
&Error::IOError(ref e) => e.fmt(f)
|
Error::IOError(ref e) => e.fmt(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,10 +39,9 @@ impl Atlas {
|
||||||
pub fn add(&mut self, width: usize, height: usize) -> Option<Rect> {
|
pub fn add(&mut self, width: usize, height: usize) -> Option<Rect> {
|
||||||
let mut priority = usize::max_value();
|
let mut priority = usize::max_value();
|
||||||
let mut target: Option<Rect> = None;
|
let mut target: Option<Rect> = None;
|
||||||
let mut index = 0;
|
|
||||||
let mut target_index = 0;
|
let mut target_index = 0;
|
||||||
// Search through and find the best fit for this texture
|
// Search through and find the best fit for this texture
|
||||||
for free in &self.free_space {
|
for (index, free) in self.free_space.iter().enumerate() {
|
||||||
if free.width >= width && free.height >= height {
|
if free.width >= width && free.height >= height {
|
||||||
let current_priority = (free.width - width) * (free.height - height);
|
let current_priority = (free.width - width) * (free.height - height);
|
||||||
if target.is_none() || current_priority < priority {
|
if target.is_none() || current_priority < priority {
|
||||||
|
@ -55,7 +54,6 @@ impl Atlas {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
index += 1;
|
|
||||||
}
|
}
|
||||||
if target.is_none() {
|
if target.is_none() {
|
||||||
return None;
|
return None;
|
||||||
|
|
|
@ -46,7 +46,7 @@ impl Renderer {
|
||||||
let version = { res.read().unwrap().version() };
|
let version = { res.read().unwrap().version() };
|
||||||
let tex = gl::Texture::new();
|
let tex = gl::Texture::new();
|
||||||
tex.bind(gl::TEXTURE_2D_ARRAY);
|
tex.bind(gl::TEXTURE_2D_ARRAY);
|
||||||
tex.image_3d(gl::TEXTURE_2D_ARRAY, 0, ATLAS_SIZE as u32, ATLAS_SIZE as u32, 1, gl::RGBA, gl::UNSIGNED_BYTE, &[0; ATLAS_SIZE*ATLAS_SIZE*1*4]);
|
tex.image_3d(gl::TEXTURE_2D_ARRAY, 0, ATLAS_SIZE as u32, ATLAS_SIZE as u32, 1, gl::RGBA, gl::UNSIGNED_BYTE, &[0; ATLAS_SIZE*ATLAS_SIZE*4]);
|
||||||
tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_MAG_FILTER, gl::NEAREST);
|
tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_MAG_FILTER, gl::NEAREST);
|
||||||
tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_MIN_FILTER, gl::NEAREST);
|
tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_MIN_FILTER, gl::NEAREST);
|
||||||
tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_WRAP_S, gl::CLAMP_TO_EDGE);
|
tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_WRAP_S, gl::CLAMP_TO_EDGE);
|
||||||
|
@ -122,7 +122,7 @@ impl Renderer {
|
||||||
tex.pending_uploads.clear();
|
tex.pending_uploads.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
for ani in self.textures.write().unwrap().animated_textures.iter_mut() {
|
for ani in &mut self.textures.write().unwrap().animated_textures {
|
||||||
if ani.remaining_time <= 0.0 {
|
if ani.remaining_time <= 0.0 {
|
||||||
ani.current_frame = (ani.current_frame + 1) % ani.frames.len();
|
ani.current_frame = (ani.current_frame + 1) % ani.frames.len();
|
||||||
ani.remaining_time += ani.frames[ani.current_frame].time as f64;
|
ani.remaining_time += ani.frames[ani.current_frame].time as f64;
|
||||||
|
@ -358,7 +358,7 @@ impl TextureManager {
|
||||||
|
|
||||||
fn find_free(&mut self, width: usize, height: usize) -> (i32, atlas::Rect) {
|
fn find_free(&mut self, width: usize, height: usize) -> (i32, atlas::Rect) {
|
||||||
let mut index = 0;
|
let mut index = 0;
|
||||||
for atlas in self.atlases.iter_mut() {
|
for atlas in &mut self.atlases {
|
||||||
if let Some(rect) = atlas.add(width, height) {
|
if let Some(rect) = atlas.add(width, height) {
|
||||||
return (index, rect);
|
return (index, rect);
|
||||||
}
|
}
|
||||||
|
@ -568,7 +568,7 @@ pub fn create_program(vertex: &str, fragment: &str) -> gl::Program {
|
||||||
panic!("Shader error: {}", v.get_info_log());
|
panic!("Shader error: {}", v.get_info_log());
|
||||||
} else {
|
} else {
|
||||||
let log = v.get_info_log();
|
let log = v.get_info_log();
|
||||||
if log.len() > 0 {
|
if !log.is_empty() {
|
||||||
println!("{}", log);
|
println!("{}", log);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -582,7 +582,7 @@ pub fn create_program(vertex: &str, fragment: &str) -> gl::Program {
|
||||||
panic!("Shader error: {}", f.get_info_log());
|
panic!("Shader error: {}", f.get_info_log());
|
||||||
} else {
|
} else {
|
||||||
let log = f.get_info_log();
|
let log = f.get_info_log();
|
||||||
if log.len() > 0 {
|
if !log.is_empty() {
|
||||||
println!("{}", log);
|
println!("{}", log);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -599,11 +599,9 @@ pub fn generate_element_buffer(size: usize) -> (Vec<u8>, gl::Type) {
|
||||||
let mut ty = gl::UNSIGNED_SHORT;
|
let mut ty = gl::UNSIGNED_SHORT;
|
||||||
let mut data = if (size/6)*4*3 >= u16::max_value() as usize {
|
let mut data = if (size/6)*4*3 >= u16::max_value() as usize {
|
||||||
ty = gl::UNSIGNED_INT;
|
ty = gl::UNSIGNED_INT;
|
||||||
let data = Vec::with_capacity(size*4);
|
Vec::with_capacity(size*4)
|
||||||
data
|
|
||||||
} else {
|
} else {
|
||||||
let data = Vec::with_capacity(size*2);
|
Vec::with_capacity(size*2)
|
||||||
data
|
|
||||||
};
|
};
|
||||||
for i in 0 .. size/6 {
|
for i in 0 .. size/6 {
|
||||||
for val in &[0, 1, 2, 2, 1, 3] {
|
for val in &[0, 1, 2, 2, 1, 3] {
|
||||||
|
|
|
@ -87,10 +87,8 @@ impl UIState {
|
||||||
|
|
||||||
let mut char_map = HashMap::new();
|
let mut char_map = HashMap::new();
|
||||||
let ascii_chars = "ÀÁÂÈÊËÍÓÔÕÚßãõğİıŒœŞşŴŵžȇ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜø£Ø׃áíóúñѪº¿®¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αβΓπΣσμτΦΘΩδ∞∅∈∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■";
|
let ascii_chars = "ÀÁÂÈÊËÍÓÔÕÚßãõğİıŒœŞşŴŵžȇ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜø£Ø׃áíóúñѪº¿®¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αβΓπΣσμτΦΘΩδ∞∅∈∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■";
|
||||||
let mut pos = 0u32;
|
for (pos, c) in ascii_chars.chars().enumerate() {
|
||||||
for c in ascii_chars.chars() {
|
char_map.insert(c, ::std::char::from_u32(pos as u32).unwrap());
|
||||||
char_map.insert(c, ::std::char::from_u32(pos).unwrap());
|
|
||||||
pos += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut state = UIState {
|
let mut state = UIState {
|
||||||
|
@ -206,7 +204,7 @@ impl UIState {
|
||||||
(sh as f32) / (self.page_height as f32)
|
(sh as f32) / (self.page_height as f32)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return p.relative(
|
p.relative(
|
||||||
(cx * 16 + info.0 as u32) as f32 / 256.0,
|
(cx * 16 + info.0 as u32) as f32 / 256.0,
|
||||||
(cy * 16) as f32 / 256.0,
|
(cy * 16) as f32 / 256.0,
|
||||||
(info.1 - info.0) as f32 / 256.0,
|
(info.1 - info.0) as f32 / 256.0,
|
||||||
|
@ -234,7 +232,7 @@ impl UIState {
|
||||||
return (((info.1 - info.0) as f64) / sw) * 16.0;
|
return (((info.1 - info.0) as f64) / sw) * 16.0;
|
||||||
}
|
}
|
||||||
let info = self.font_character_info[c as usize];
|
let info = self.font_character_info[c as usize];
|
||||||
return (info.1 - info.0) as f64;
|
(info.1 - info.0) as f64
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_font(&mut self) {
|
fn load_font(&mut self) {
|
||||||
|
@ -242,11 +240,11 @@ impl UIState {
|
||||||
if let Some(mut info) = res.open("minecraft", "font/glyph_sizes.bin") {
|
if let Some(mut info) = res.open("minecraft", "font/glyph_sizes.bin") {
|
||||||
let mut data = Vec::with_capacity(0x10000);
|
let mut data = Vec::with_capacity(0x10000);
|
||||||
info.read_to_end(&mut data).unwrap();
|
info.read_to_end(&mut data).unwrap();
|
||||||
for i in 0 .. self.font_character_info.len() {
|
for (i, info) in self.font_character_info.iter_mut().enumerate() {
|
||||||
// Top nibble - start position
|
// Top nibble - start position
|
||||||
// Bottom nibble - end position
|
// Bottom nibble - end position
|
||||||
self.font_character_info[i].0 = (data[i] >> 4) as i32;
|
info.0 = (data[i] >> 4) as i32;
|
||||||
self.font_character_info[i].1 = (data[i] & 0xF) as i32 + 1;
|
info.1 = (data[i] & 0xF) as i32 + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(mut val) = res.open("minecraft", "textures/font/ascii.png") {
|
if let Some(mut val) = res.open("minecraft", "textures/font/ascii.png") {
|
||||||
|
|
|
@ -51,6 +51,6 @@ impl Set {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(&mut self, i: usize) -> bool {
|
pub fn get(&mut self, i: usize) -> bool {
|
||||||
return (self.data[i>>6] & (1 << (i & 0x3F))) != 0
|
(self.data[i>>6] & (1 << (i & 0x3F))) != 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,13 +58,11 @@ impl Logo {
|
||||||
if line.is_empty() {
|
if line.is_empty() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let mut i = 0;
|
for (i, c) in line.chars().enumerate() {
|
||||||
for c in line.chars() {
|
|
||||||
i += 1;
|
|
||||||
if c == ' ' {
|
if c == ' ' {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let x = (i - 1) * 4;
|
let x = i * 4;
|
||||||
let y = row * 8;
|
let y = row * 8;
|
||||||
let (r, g, b) = if c == ':' {
|
let (r, g, b) = if c == ':' {
|
||||||
(255, 255, 255)
|
(255, 255, 255)
|
||||||
|
|
|
@ -39,27 +39,27 @@ macro_rules! element_impl {
|
||||||
($($name:ident),+) => (
|
($($name:ident),+) => (
|
||||||
impl Element {
|
impl Element {
|
||||||
fn get_click_funcs(&self) -> Vec<ClickFunc> {
|
fn get_click_funcs(&self) -> Vec<ClickFunc> {
|
||||||
match self {
|
match *self {
|
||||||
$(
|
$(
|
||||||
&Element::$name(ref val) => val.click_funcs.clone(),
|
Element::$name(ref val) => val.click_funcs.clone(),
|
||||||
)+
|
)+
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_hover_funcs(&self) -> Vec<HoverFunc> {
|
fn get_hover_funcs(&self) -> Vec<HoverFunc> {
|
||||||
match self {
|
match *self {
|
||||||
$(
|
$(
|
||||||
&Element::$name(ref val) => val.hover_funcs.clone(),
|
Element::$name(ref val) => val.hover_funcs.clone(),
|
||||||
)+
|
)+
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn should_call_hover(&mut self, new: bool) -> bool{
|
fn should_call_hover(&mut self, new: bool) -> bool{
|
||||||
match self {
|
match *self {
|
||||||
$(
|
$(
|
||||||
&mut Element::$name(ref mut val) => {
|
Element::$name(ref mut val) => {
|
||||||
let ret = val.hovered != new;
|
let ret = val.hovered != new;
|
||||||
val.hovered = new;
|
val.hovered = new;
|
||||||
ret
|
ret
|
||||||
|
@ -70,81 +70,81 @@ impl Element {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn should_draw(&self) -> bool {
|
fn should_draw(&self) -> bool {
|
||||||
match self {
|
match *self {
|
||||||
$(
|
$(
|
||||||
&Element::$name(ref val) => val.should_draw,
|
Element::$name(ref val) => val.should_draw,
|
||||||
)+
|
)+
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_parent(&self) -> Option<ElementRefInner> {
|
fn get_parent(&self) -> Option<ElementRefInner> {
|
||||||
match self {
|
match *self {
|
||||||
$(
|
$(
|
||||||
&Element::$name(ref val) => val.parent,
|
Element::$name(ref val) => val.parent,
|
||||||
)+
|
)+
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_attachment(&self) -> (VAttach, HAttach) {
|
fn get_attachment(&self) -> (VAttach, HAttach) {
|
||||||
match self {
|
match *self {
|
||||||
$(
|
$(
|
||||||
&Element::$name(ref val) => (val.v_attach, val.h_attach),
|
Element::$name(ref val) => (val.v_attach, val.h_attach),
|
||||||
)+
|
)+
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_offset(&self) -> (f64, f64) {
|
fn get_offset(&self) -> (f64, f64) {
|
||||||
match self {
|
match *self {
|
||||||
$(
|
$(
|
||||||
&Element::$name(ref val) => (val.x, val.y),
|
Element::$name(ref val) => (val.x, val.y),
|
||||||
)+
|
)+
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_size(&self) -> (f64, f64) {
|
fn get_size(&self) -> (f64, f64) {
|
||||||
match self {
|
match *self {
|
||||||
$(
|
$(
|
||||||
&Element::$name(ref val) => val.get_size(),
|
Element::$name(ref val) => val.get_size(),
|
||||||
)+
|
)+
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_dirty(&self) -> bool {
|
fn is_dirty(&self) -> bool {
|
||||||
match self {
|
match *self {
|
||||||
$(
|
$(
|
||||||
&Element::$name(ref val) => val.dirty,
|
Element::$name(ref val) => val.dirty,
|
||||||
)+
|
)+
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_dirty(&mut self, dirty: bool) {
|
fn set_dirty(&mut self, dirty: bool) {
|
||||||
match self {
|
match *self {
|
||||||
$(
|
$(
|
||||||
&mut Element::$name(ref mut val) => val.dirty = dirty,
|
Element::$name(ref mut val) => val.dirty = dirty,
|
||||||
)+
|
)+
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, renderer: &mut render::Renderer) {
|
fn update(&mut self, renderer: &mut render::Renderer) {
|
||||||
match self {
|
match *self {
|
||||||
$(
|
$(
|
||||||
&mut Element::$name(ref mut val) => val.update(renderer),
|
Element::$name(ref mut val) => val.update(renderer),
|
||||||
)+
|
)+
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw(&mut self, renderer: &mut render::Renderer, r: &Region, width: f64, height: f64, delta: f64) -> &Vec<u8>{
|
fn draw(&mut self, renderer: &mut render::Renderer, r: &Region, width: f64, height: f64, delta: f64) -> &Vec<u8>{
|
||||||
match self {
|
match *self {
|
||||||
$(
|
$(
|
||||||
&mut Element::$name(ref mut val) => val.draw(renderer, r, width, height, delta),
|
Element::$name(ref mut val) => val.draw(renderer, r, width, height, delta),
|
||||||
)+
|
)+
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
|
@ -459,8 +459,8 @@ impl Container {
|
||||||
|
|
||||||
pub trait UIElement {
|
pub trait UIElement {
|
||||||
fn wrap(self) -> Element;
|
fn wrap(self) -> Element;
|
||||||
fn unwrap_ref<'a>(&'a Element) -> &'a Self;
|
fn unwrap_ref(&Element) -> &Self;
|
||||||
fn unwrap_ref_mut<'a>(&'a mut Element) -> &'a mut Self;
|
fn unwrap_ref_mut(&mut Element) -> &mut Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! lazy_field {
|
macro_rules! lazy_field {
|
||||||
|
|
Loading…
Reference in New Issue