2019-02-16 03:01:42 +00:00
|
|
|
// TODO: figure out proper way to propagate events down to the ui
|
2019-01-30 12:11:34 +00:00
|
|
|
|
|
|
|
// Library
|
|
|
|
use image::DynamicImage;
|
2019-02-12 04:14:55 +00:00
|
|
|
use conrod_core::{
|
|
|
|
Ui as CrUi,
|
|
|
|
UiBuilder,
|
|
|
|
UiCell,
|
2019-02-23 02:41:52 +00:00
|
|
|
text::{
|
|
|
|
Font,
|
|
|
|
GlyphCache,
|
|
|
|
font::Id as FontId,
|
|
|
|
},
|
2019-02-12 04:14:55 +00:00
|
|
|
image::{Map, Id as ImgId},
|
2019-02-16 03:01:42 +00:00
|
|
|
widget::{Id as WidgId, id::Generator},
|
|
|
|
render::Primitive,
|
|
|
|
event::Input,
|
2019-03-03 23:55:07 +00:00
|
|
|
input::{touch::Touch, Widget, Motion},
|
2019-02-12 04:14:55 +00:00
|
|
|
};
|
2019-03-03 23:55:07 +00:00
|
|
|
use vek::*;
|
2019-01-30 12:11:34 +00:00
|
|
|
|
|
|
|
// Crate
|
|
|
|
use crate::{
|
|
|
|
Error,
|
|
|
|
render::{
|
|
|
|
RenderError,
|
|
|
|
Renderer,
|
|
|
|
Model,
|
2019-02-23 02:41:52 +00:00
|
|
|
Mesh,
|
2019-01-30 12:11:34 +00:00
|
|
|
Texture,
|
|
|
|
UiPipeline,
|
2019-02-23 02:41:52 +00:00
|
|
|
UiMode,
|
|
|
|
push_ui_quad_to_mesh,
|
2019-03-04 07:28:16 +00:00
|
|
|
push_ui_tri_to_mesh,
|
2019-01-30 12:11:34 +00:00
|
|
|
},
|
2019-02-16 03:01:42 +00:00
|
|
|
window::Window,
|
2019-01-30 12:11:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum UiError {
|
|
|
|
RenderError(RenderError),
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Cache {
|
|
|
|
blank_texture: Texture<UiPipeline>,
|
2019-02-23 02:41:52 +00:00
|
|
|
glyph_cache: GlyphCache<'static>,
|
|
|
|
glyph_cache_tex: Texture<UiPipeline>,
|
2019-01-30 12:11:34 +00:00
|
|
|
}
|
|
|
|
|
2019-02-16 03:01:42 +00:00
|
|
|
// TODO: Should functions be returning UiError instead of Error?
|
2019-01-30 12:11:34 +00:00
|
|
|
impl Cache {
|
|
|
|
pub fn new(renderer: &mut Renderer) -> Result<Self, Error> {
|
2019-02-23 03:16:12 +00:00
|
|
|
let (w, h) = renderer.get_resolution().into_tuple();
|
2019-02-23 02:41:52 +00:00
|
|
|
const SCALE_TOLERANCE: f32 = 0.1;
|
|
|
|
const POSITION_TOLERANCE: f32 = 0.1;
|
|
|
|
|
2019-01-30 12:11:34 +00:00
|
|
|
Ok(Self {
|
|
|
|
blank_texture: renderer.create_texture(&DynamicImage::new_rgba8(1, 1))?,
|
2019-02-23 02:41:52 +00:00
|
|
|
glyph_cache: GlyphCache::builder()
|
|
|
|
.dimensions(w as u32, h as u32)
|
|
|
|
.scale_tolerance(SCALE_TOLERANCE)
|
|
|
|
.position_tolerance(POSITION_TOLERANCE)
|
|
|
|
.build(),
|
|
|
|
glyph_cache_tex: renderer.create_dynamic_texture((w, h).into())?,
|
2019-01-30 12:11:34 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
pub fn blank_texture(&self) -> &Texture<UiPipeline> { &self.blank_texture }
|
2019-02-23 02:41:52 +00:00
|
|
|
pub fn glyph_cache_tex(&self) -> &Texture<UiPipeline> { &self.glyph_cache_tex }
|
|
|
|
pub fn glyph_cache_mut_and_tex(&mut self) -> (&mut GlyphCache<'static>, &Texture<UiPipeline>) { (&mut self.glyph_cache, &self.glyph_cache_tex) }
|
2019-01-30 12:11:34 +00:00
|
|
|
}
|
|
|
|
|
2019-02-23 02:41:52 +00:00
|
|
|
pub enum DrawCommand {
|
|
|
|
Image(Model<UiPipeline>, ImgId),
|
|
|
|
// Text and non-textured geometry
|
|
|
|
Plain(Model<UiPipeline>),
|
2019-02-16 03:01:42 +00:00
|
|
|
}
|
|
|
|
|
2019-03-03 23:55:07 +00:00
|
|
|
// How to scale the ui
|
|
|
|
pub enum ScaleMode {
|
|
|
|
// Scale against physical size
|
|
|
|
Absolute(f64),
|
|
|
|
// Use the dpi factor provided by the windowing system (i.e. use logical size)
|
|
|
|
DpiFactor,
|
|
|
|
// Scale based on the window's physical size, but maintain aspect ratio of widgets
|
|
|
|
// Contains width and height of the "default" window size (ie where there should be no scaling)
|
|
|
|
RelativeToWindow(Vec2<f64>),
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Scale {
|
|
|
|
// Type of scaling to use
|
|
|
|
mode: ScaleMode,
|
|
|
|
// Current dpi factor
|
|
|
|
dpi_factor: f64,
|
|
|
|
// Current logical window size
|
|
|
|
window_dims: Vec2<f64>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Scale {
|
|
|
|
fn new(window: &Window, mode: ScaleMode) -> Self {
|
|
|
|
let window_dims = window.logical_size();
|
|
|
|
let dpi_factor = window.renderer().get_resolution().x as f64 / window_dims.x;
|
|
|
|
Scale {
|
|
|
|
mode,
|
|
|
|
dpi_factor,
|
|
|
|
window_dims,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Change the scaling mode
|
|
|
|
pub fn scaling_mode(&mut self, mode: ScaleMode) {
|
|
|
|
self.mode = mode;
|
|
|
|
}
|
|
|
|
// Calculate factor to transform from logical coordinates to our scaled coordinates
|
|
|
|
fn scale_factor(&self) -> f64 {
|
|
|
|
match self.mode {
|
|
|
|
ScaleMode::Absolute(scale) => scale / self.dpi_factor,
|
|
|
|
ScaleMode::DpiFactor => 1.0,
|
|
|
|
ScaleMode::RelativeToWindow(dims) => (self.window_dims.x / dims.x).min(self.window_dims.y / dims.y),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Updates internal window size (and/or dpi_factor)
|
|
|
|
fn window_resized(&mut self, new_dims: Vec2<f64>, renderer: &Renderer) {
|
|
|
|
self.dpi_factor = renderer.get_resolution().x as f64 / new_dims.x;
|
|
|
|
self.window_dims = new_dims;
|
|
|
|
}
|
|
|
|
// Get scaled window size
|
|
|
|
fn scaled_window_size(&self) -> Vec2<f64> {
|
|
|
|
self.window_dims / self.scale_factor()
|
|
|
|
}
|
|
|
|
// Transform point from logical to scaled coordinates
|
|
|
|
fn scale_point(&self, point: Vec2<f64>) -> Vec2<f64> {
|
|
|
|
point / self.scale_factor()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-30 12:11:34 +00:00
|
|
|
pub struct Ui {
|
2019-02-12 04:14:55 +00:00
|
|
|
ui: CrUi,
|
|
|
|
image_map: Map<Texture<UiPipeline>>,
|
2019-01-30 12:11:34 +00:00
|
|
|
cache: Cache,
|
2019-02-23 03:16:12 +00:00
|
|
|
// Draw commands for the next render
|
2019-02-23 02:41:52 +00:00
|
|
|
draw_commands: Vec<DrawCommand>,
|
2019-03-03 23:55:07 +00:00
|
|
|
// Stores new window size for updating scaling
|
|
|
|
window_resized: Option<Vec2<f64>>,
|
|
|
|
// Scaling of the ui
|
|
|
|
scale: Scale,
|
2019-01-30 12:11:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Ui {
|
2019-02-16 03:01:42 +00:00
|
|
|
pub fn new(window: &mut Window) -> Result<Self, Error> {
|
2019-03-03 23:55:07 +00:00
|
|
|
let scale = Scale::new(window, ScaleMode::Absolute(1.0));
|
|
|
|
let win_dims = scale.scaled_window_size().into_array();
|
2019-01-30 12:11:34 +00:00
|
|
|
Ok(Self {
|
2019-03-03 23:55:07 +00:00
|
|
|
ui: UiBuilder::new(win_dims).build(),
|
2019-02-12 04:14:55 +00:00
|
|
|
image_map: Map::new(),
|
2019-02-16 03:01:42 +00:00
|
|
|
cache: Cache::new(window.renderer_mut())?,
|
2019-03-03 23:55:07 +00:00
|
|
|
window_resized: None,
|
2019-02-23 02:41:52 +00:00
|
|
|
draw_commands: vec![],
|
2019-03-03 23:55:07 +00:00
|
|
|
scale,
|
2019-01-30 12:11:34 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-03-03 23:55:07 +00:00
|
|
|
// Set the scaling mode of the ui
|
|
|
|
pub fn scaling_mode(&mut self, mode: ScaleMode) {
|
|
|
|
self.scale.scaling_mode(mode);
|
|
|
|
// Give conrod the new size
|
|
|
|
let (w, h) = self.scale.scaled_window_size().into_tuple();
|
|
|
|
self.ui.handle_event(Input::Resize(w, h));
|
|
|
|
}
|
|
|
|
|
2019-02-12 04:14:55 +00:00
|
|
|
pub fn new_image(&mut self, renderer: &mut Renderer, image: &DynamicImage) -> Result<ImgId, Error> {
|
|
|
|
Ok(self.image_map.insert(renderer.create_texture(image)?))
|
|
|
|
}
|
|
|
|
|
2019-02-23 02:41:52 +00:00
|
|
|
pub fn new_font(&mut self, font: Font) -> FontId {
|
|
|
|
self.ui.fonts.insert(font)
|
|
|
|
}
|
|
|
|
|
2019-02-16 03:01:42 +00:00
|
|
|
pub fn id_generator(&mut self) -> Generator {
|
|
|
|
self.ui.widget_id_generator()
|
2019-02-12 04:14:55 +00:00
|
|
|
}
|
|
|
|
|
2019-02-16 03:01:42 +00:00
|
|
|
pub fn set_widgets(&mut self) -> UiCell {
|
|
|
|
self.ui.set_widgets()
|
2019-02-12 04:14:55 +00:00
|
|
|
}
|
|
|
|
|
2019-02-16 03:01:42 +00:00
|
|
|
pub fn handle_event(&mut self, event: Input) {
|
2019-03-03 23:55:07 +00:00
|
|
|
match event {
|
|
|
|
Input::Resize(w, h) => self.window_resized = Some(Vec2::new(w, h)),
|
|
|
|
Input::Touch(touch) => self.ui.handle_event(
|
|
|
|
Input::Touch(Touch {
|
|
|
|
xy: self.scale.scale_point(touch.xy.into()).into_array(),
|
|
|
|
..touch
|
|
|
|
})
|
|
|
|
),
|
|
|
|
Input::Motion(motion) => self.ui.handle_event(
|
|
|
|
Input::Motion( match motion {
|
|
|
|
Motion::MouseCursor { x, y } => {
|
|
|
|
let (x, y) = self.scale.scale_point(Vec2::new(x, y)).into_tuple();
|
|
|
|
Motion::MouseCursor { x, y }
|
|
|
|
}
|
|
|
|
Motion::MouseRelative { x, y } => {
|
|
|
|
let (x, y) = self.scale.scale_point(Vec2::new(x, y)).into_tuple();
|
|
|
|
Motion::MouseRelative { x, y }
|
|
|
|
}
|
|
|
|
Motion::Scroll { x, y } => {
|
|
|
|
let (x, y) = self.scale.scale_point(Vec2::new(x, y)).into_tuple();
|
|
|
|
Motion::Scroll { x, y }
|
|
|
|
}
|
|
|
|
_ => motion,
|
|
|
|
})
|
|
|
|
),
|
|
|
|
_ => self.ui.handle_event(event),
|
|
|
|
}
|
2019-02-16 03:01:42 +00:00
|
|
|
}
|
2019-02-12 04:14:55 +00:00
|
|
|
|
2019-02-16 03:01:42 +00:00
|
|
|
pub fn widget_input(&self, id: WidgId) -> Widget {
|
|
|
|
self.ui.widget_input(id)
|
2019-01-30 12:11:34 +00:00
|
|
|
}
|
|
|
|
|
2019-02-16 03:01:42 +00:00
|
|
|
pub fn maintain(&mut self, renderer: &mut Renderer) {
|
|
|
|
let ref mut ui = self.ui;
|
2019-03-03 23:55:07 +00:00
|
|
|
// Regenerate draw commands and associated models only if the ui changed
|
2019-02-16 03:01:42 +00:00
|
|
|
if let Some(mut primitives) = ui.draw_if_changed() {
|
2019-02-23 02:41:52 +00:00
|
|
|
self.draw_commands.clear();
|
|
|
|
let mut mesh = Mesh::new();
|
|
|
|
|
|
|
|
let mut current_img = None;
|
|
|
|
|
|
|
|
// Switches to the `Plain` state and completes the previous `Command` if not already in the
|
|
|
|
// `Plain` state.
|
|
|
|
macro_rules! switch_to_plain_state {
|
|
|
|
() => {
|
|
|
|
if let Some(image_id) = current_img.take() {
|
|
|
|
self.draw_commands.push(DrawCommand::Image(renderer.create_model(&mesh).unwrap(), image_id));
|
|
|
|
mesh.clear();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-02-12 04:14:55 +00:00
|
|
|
while let Some(prim) = primitives.next() {
|
2019-02-23 02:41:52 +00:00
|
|
|
// TODO: Use scizzor
|
|
|
|
let Primitive {kind, scizzor, id, rect} = prim;
|
2019-03-04 07:28:16 +00:00
|
|
|
// Functions for converting for conrod scalar coords to GL vertex coords (-1.0 to 1.0)
|
|
|
|
let vx = |x: f64| (x / ui.win_w * 2.0) as f32;
|
|
|
|
let vy = |y: f64| (y / ui.win_h * 2.0) as f32;
|
2019-02-23 03:16:12 +00:00
|
|
|
|
2019-02-23 02:41:52 +00:00
|
|
|
use conrod_core::render::PrimitiveKind;
|
2019-02-12 04:14:55 +00:00
|
|
|
match kind {
|
2019-02-23 02:41:52 +00:00
|
|
|
// TODO: use source_rect
|
2019-02-12 04:14:55 +00:00
|
|
|
PrimitiveKind::Image { image_id, color, source_rect } => {
|
2019-02-23 02:41:52 +00:00
|
|
|
|
|
|
|
// Switch to the `Image` state for this image if we're not in it already.
|
|
|
|
let new_image_id = image_id;
|
|
|
|
match current_img {
|
|
|
|
// If we're already in the drawing mode for this image, we're done.
|
|
|
|
Some(image_id) if image_id == new_image_id => (),
|
|
|
|
// If we were in the `Plain` drawing state, switch to Image drawing state.
|
|
|
|
None => {
|
|
|
|
self.draw_commands.push(DrawCommand::Plain(renderer.create_model(&mesh).unwrap()));
|
|
|
|
mesh.clear();
|
|
|
|
current_img = Some(new_image_id);
|
|
|
|
}
|
|
|
|
// If we were drawing a different image, switch state to draw *this* image.
|
|
|
|
Some(image_id) => {
|
|
|
|
self.draw_commands.push(DrawCommand::Image(renderer.create_model(&mesh).unwrap(), image_id));
|
|
|
|
mesh.clear();
|
|
|
|
current_img = Some(new_image_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let color = color.unwrap_or(conrod_core::color::WHITE).to_fsa();
|
|
|
|
|
2019-02-28 00:37:47 +00:00
|
|
|
// Transform the source rectangle into uv coordinates
|
|
|
|
let (image_w, image_h) = self.image_map
|
|
|
|
.get(&image_id)
|
|
|
|
.expect("Image does not exist in image map")
|
|
|
|
.get_dimensions()
|
|
|
|
.map(|e| e as f64)
|
|
|
|
.into_tuple();
|
|
|
|
let (uv_l, uv_r, uv_t, uv_b) = match source_rect {
|
2019-02-23 02:41:52 +00:00
|
|
|
Some(src_rect) => {
|
|
|
|
let (l, r, b, t) = src_rect.l_r_b_t();
|
|
|
|
((l / image_w) as f32,
|
|
|
|
(r / image_w) as f32,
|
|
|
|
(b / image_h) as f32,
|
|
|
|
(t / image_h) as f32)
|
|
|
|
}
|
|
|
|
None => (0.0, 1.0, 0.0, 1.0),
|
2019-02-28 00:37:47 +00:00
|
|
|
};
|
2019-02-23 02:41:52 +00:00
|
|
|
// Convert from conrod Scalar range to GL range -1.0 to 1.0.
|
2019-02-28 00:37:47 +00:00
|
|
|
let (l, r, b, t) = rect.l_r_b_t();
|
2019-03-04 07:28:16 +00:00
|
|
|
let (l, r, b, t) = (vx(l), vx(r), vy(b), vy(t));
|
2019-02-23 02:41:52 +00:00
|
|
|
push_ui_quad_to_mesh(
|
|
|
|
&mut mesh,
|
|
|
|
[l, t , r, b],
|
|
|
|
[uv_l, uv_t, uv_r, uv_b],
|
|
|
|
color,
|
|
|
|
UiMode::Image,
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
PrimitiveKind::Text { color, text, font_id } => {
|
|
|
|
switch_to_plain_state!();
|
|
|
|
// Get screen width
|
|
|
|
let (screen_w, screen_h) = renderer.get_resolution().map(|e| e as f32).into_tuple();
|
|
|
|
// Calculate dpi factor
|
|
|
|
let dpi_factor = screen_w / ui.win_w as f32;
|
|
|
|
|
|
|
|
let positioned_glyphs = text.positioned_glyphs(dpi_factor);
|
|
|
|
let (glyph_cache, cache_tex) = self.cache.glyph_cache_mut_and_tex();
|
|
|
|
// Queue the glyphs to be cached
|
|
|
|
for glyph in positioned_glyphs {
|
|
|
|
glyph_cache.queue_glyph(font_id.index(), glyph.clone());
|
|
|
|
}
|
|
|
|
|
|
|
|
glyph_cache.cache_queued(|rect, data| {
|
|
|
|
let offset = [rect.min.x as u16, rect.min.y as u16];
|
|
|
|
let size = [rect.width() as u16, rect.height() as u16];
|
|
|
|
|
|
|
|
let new_data = data.iter().map(|x| [255, 255, 255, *x]).collect::<Vec<[u8; 4]>>();
|
|
|
|
|
|
|
|
renderer.update_texture(cache_tex, offset, size, &new_data);
|
|
|
|
}).unwrap();
|
|
|
|
|
|
|
|
// TODO: consider gamma....
|
|
|
|
let color = color.to_fsa();
|
|
|
|
|
|
|
|
for g in positioned_glyphs {
|
|
|
|
if let Ok(Some((uv_rect, screen_rect))) = glyph_cache.rect_for(font_id.index(), g) {
|
|
|
|
let (uv_l, uv_r, uv_t, uv_b) = (
|
|
|
|
uv_rect.min.x,
|
|
|
|
uv_rect.max.x,
|
|
|
|
uv_rect.min.y,
|
|
|
|
uv_rect.max.y,
|
|
|
|
);
|
|
|
|
let (l, t, r, b) = (
|
|
|
|
(screen_rect.min.x as f32 / screen_w - 0.5) * 2.0,
|
|
|
|
(screen_rect.min.y as f32 / screen_h - 0.5) * -2.0,
|
|
|
|
(screen_rect.max.x as f32 / screen_w - 0.5) * 2.0,
|
|
|
|
(screen_rect.max.y as f32 / screen_h - 0.5) * -2.0,
|
|
|
|
);
|
|
|
|
push_ui_quad_to_mesh(
|
|
|
|
&mut mesh,
|
|
|
|
[l, t , r, b],
|
|
|
|
[uv_l, uv_t, uv_r, uv_b],
|
|
|
|
color,
|
|
|
|
UiMode::Text,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-02-12 04:14:55 +00:00
|
|
|
}
|
2019-03-04 07:28:16 +00:00
|
|
|
PrimitiveKind::Rectangle { color } => {
|
|
|
|
// TODO: consider gamma/linear conversion....
|
|
|
|
let color = color.to_fsa();
|
|
|
|
// Don't draw a transparent rectangle (they exist)
|
|
|
|
if color[3] == 0.0 {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch_to_plain_state!();
|
|
|
|
|
|
|
|
// Convert from conrod Scalar range to GL range -1.0 to 1.0.
|
|
|
|
let (l, r, b, t) = rect.l_r_b_t();
|
|
|
|
let (l, r, b, t) = (vx(l), vx(r), vy(b), vy(t));
|
|
|
|
push_ui_quad_to_mesh(
|
|
|
|
&mut mesh,
|
|
|
|
[l, t , r, b],
|
|
|
|
[0.0, 0.0, 0.0, 0.0],
|
|
|
|
color,
|
|
|
|
UiMode::Geometry,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
PrimitiveKind::TrianglesSingleColor { color, triangles } => {
|
|
|
|
// Don't draw transparent triangle or switch state if there are actually no triangles
|
|
|
|
let color: [f32; 4] = color.into();
|
|
|
|
if triangles.is_empty() || color[3] == 0.0 {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch_to_plain_state!();
|
|
|
|
|
|
|
|
for tri in triangles {
|
|
|
|
// TODO: this code is repeated above, put it in a single location
|
|
|
|
let triangle = [
|
|
|
|
[vx(tri[2][0]), vy(tri[2][1])],
|
|
|
|
[vx(tri[1][0]), vy(tri[1][1])],
|
|
|
|
[vx(tri[0][0]), vy(tri[0][1])],
|
|
|
|
];
|
|
|
|
push_ui_tri_to_mesh(
|
|
|
|
&mut mesh,
|
|
|
|
triangle,
|
|
|
|
[[0.0; 2]; 3],
|
|
|
|
[1.0, 1.0, 1.0, 1.0],
|
|
|
|
UiMode::Geometry,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-02-16 03:01:42 +00:00
|
|
|
_ => {}
|
|
|
|
// TODO: Add these
|
|
|
|
//PrimitiveKind::Other {..} => {println!("primitive kind other with id {:?}", id);}
|
|
|
|
//PrimitiveKind::TrianglesMultiColor {..} => {println!("primitive kind multicolor with id {:?}", id);}
|
2019-02-12 04:14:55 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-23 02:41:52 +00:00
|
|
|
// Enter the final command.
|
|
|
|
match current_img {
|
|
|
|
None =>
|
|
|
|
self.draw_commands.push(DrawCommand::Plain(renderer.create_model(&mesh).unwrap())),
|
|
|
|
Some(image_id) =>
|
|
|
|
self.draw_commands.push(DrawCommand::Image(renderer.create_model(&mesh).unwrap(), image_id)),
|
|
|
|
}
|
2019-03-03 23:55:07 +00:00
|
|
|
|
|
|
|
// Handle window resizing
|
|
|
|
if let Some(new_dims) = self.window_resized.take() {
|
|
|
|
self.scale.window_resized(new_dims, renderer);
|
|
|
|
let (w, h) = self.scale.scaled_window_size().into_tuple();
|
|
|
|
self.ui.handle_event(Input::Resize(w, h));
|
|
|
|
}
|
2019-02-12 04:14:55 +00:00
|
|
|
}
|
2019-01-30 12:11:34 +00:00
|
|
|
}
|
2019-02-16 03:01:42 +00:00
|
|
|
|
|
|
|
pub fn render(&self, renderer: &mut Renderer) {
|
2019-02-23 02:41:52 +00:00
|
|
|
for draw_command in self.draw_commands.iter() {
|
|
|
|
match draw_command {
|
|
|
|
DrawCommand::Image(model, image_id) => {
|
|
|
|
let tex = self.image_map.get(&image_id).expect("Image does not exist in image map");
|
|
|
|
renderer.render_ui_element(&model, &tex);
|
|
|
|
},
|
|
|
|
DrawCommand::Plain(model) => {
|
|
|
|
let tex = self.cache.glyph_cache_tex();
|
|
|
|
renderer.render_ui_element(&model, &tex);
|
|
|
|
},
|
2019-02-16 03:01:42 +00:00
|
|
|
}
|
2019-02-23 02:41:52 +00:00
|
|
|
}
|
2019-02-16 03:01:42 +00:00
|
|
|
}
|
2019-01-30 12:11:34 +00:00
|
|
|
}
|