From a5943ae8b445a79f78b0b26035c4e55a0e927f52 Mon Sep 17 00:00:00 2001 From: Charles Date: Sat, 6 Jun 2020 17:23:54 +0200 Subject: Initial commit --- .gitignore | 1 + Cargo.lock | 54 +++++++++++++++++++++++++++ Cargo.toml | 12 ++++++ font/FiraMono-Bold.ttf | Bin 0 -> 200840 bytes font/FiraMono-Medium.ttf | Bin 0 -> 168316 bytes font/FiraMono-Regular.ttf | Bin 0 -> 169464 bytes font/OFL.txt | 93 ++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 50 +++++++++++++++++++++++++ 8 files changed, 210 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 font/FiraMono-Bold.ttf create mode 100644 font/FiraMono-Medium.ttf create mode 100644 font/FiraMono-Regular.ttf create mode 100644 font/OFL.txt create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..78fcd3c --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,54 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49" + +[[package]] +name = "rutikmer" +version = "0.1.0" +dependencies = [ + "sdl2", +] + +[[package]] +name = "sdl2" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6693f362118c0cd32858fe33a14d74cc3111bbc3a7de1aee88e5289fd9289f97" +dependencies = [ + "bitflags", + "lazy_static", + "libc", + "sdl2-sys", +] + +[[package]] +name = "sdl2-sys" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "575db20c45cce6565d4ece46509288ded53f5571dc89e4af165a562eb0eeec26" +dependencies = [ + "cfg-if", + "libc", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..d373e5e --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "rutikmer" +version = "0.1.0" +authors = ["Charles "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies.sdl2] +version = "0.34.0" +default-features = false +features = ["ttf"] diff --git a/font/FiraMono-Bold.ttf b/font/FiraMono-Bold.ttf new file mode 100644 index 0000000..db6f63f Binary files /dev/null and b/font/FiraMono-Bold.ttf differ diff --git a/font/FiraMono-Medium.ttf b/font/FiraMono-Medium.ttf new file mode 100644 index 0000000..892c124 Binary files /dev/null and b/font/FiraMono-Medium.ttf differ diff --git a/font/FiraMono-Regular.ttf b/font/FiraMono-Regular.ttf new file mode 100644 index 0000000..3910f17 Binary files /dev/null and b/font/FiraMono-Regular.ttf differ diff --git a/font/OFL.txt b/font/OFL.txt new file mode 100644 index 0000000..1ba1596 --- /dev/null +++ b/font/OFL.txt @@ -0,0 +1,93 @@ +Copyright (c) 2012-2013, The Mozilla Corporation and Telefonica S.A. + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..6c9d2ee --- /dev/null +++ b/src/main.rs @@ -0,0 +1,50 @@ +use std::time::SystemTime; +use sdl2::ttf; +use sdl2::event::Event; +use sdl2::keyboard::Keycode; +use sdl2::pixels::Color; + +fn main() { + let sdl = sdl2::init().unwrap(); + let video_subsys = sdl.video().unwrap(); + let ttf = ttf::init().unwrap(); + let font = ttf.load_font("font/FiraMono-Regular.ttf", 40).unwrap(); + + let window = video_subsys + .window("rutikmer", 640, 480) + .build() + .unwrap(); + + let mut timming = false; + let mut time_start = SystemTime::now(); + + let mut canvas = window.into_canvas().build().unwrap(); + let texture_creator = canvas.texture_creator(); + + let mut event_pump = sdl.event_pump().unwrap(); + 'running: loop { + for e in event_pump.poll_iter() { + match e { + Event::Quit {..} | Event::KeyDown { keycode: Some(Keycode::Escape), .. } => break 'running, + Event::KeyDown { keycode: Some(Keycode::Space), .. } => { + timming = !timming; + if timming { + time_start = SystemTime::now(); + } + }, + _ => {} + } + } + + canvas.set_draw_color(if !timming { Color::RGB(0, 0, 0) } else { Color::RGB(30, 150, 30) }); + canvas.clear(); + if timming { + let surface = font.render(&time_start.elapsed().unwrap().as_millis().to_string()) + .solid(Color::RGB(255, 255, 255)) + .unwrap(); + let tex = texture_creator.create_texture_from_surface(&surface).unwrap(); + canvas.copy(&tex, None, None).unwrap(); + } + canvas.present(); + } +} -- cgit