Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing to remove note name filters. #230

Closed
wants to merge 8 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 43 additions & 41 deletions neothesia-core/src/render/keyboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,48 +124,50 @@ impl KeyboardRenderer {
}
}

#[profiling::function]
fn rebuild_text_cache(&mut self, font_system: &mut glyphon::FontSystem) {
let range_start = self.layout.range.start() as usize;
for key in self.layout.keys.iter().filter(|key| key.note_id() == 0) {
let x = self.pos.x + key.x();
let y = self.pos.y;

let w = key.width();
let h = key.height();

let size = w * 0.7;

let oct_number = (key.id() + range_start) / 12;

let mut buffer = glyphon::Buffer::new(font_system, glyphon::Metrics::new(size, size));
buffer.set_size(font_system, Some(w), Some(h));
buffer.set_wrap(font_system, glyphon::Wrap::None);
buffer.set_text(
font_system,
&format!("C{}", oct_number as i8 - 1),
glyphon::Attrs::new().family(glyphon::Family::SansSerif),
glyphon::Shaping::Basic,
);
buffer.lines[0].set_align(Some(glyphon::cosmic_text::Align::Center));
buffer.shape_until_scroll(font_system, false);

self.text_cache.push(super::text::TextArea {
buffer,
left: x,
top: y + h - size * 1.2,
scale: 1.0,
bounds: glyphon::TextBounds {
left: x.round() as i32,
top: y.round() as i32,
right: x.round() as i32 + w.round() as i32,
bottom: y.round() as i32 + h.round() as i32,
},
default_color: glyphon::Color::rgb(153, 153, 153),
});
}
#[profiling::function]
fn rebuild_text_cache(&mut self, font_system: &mut glyphon::FontSystem) {
let range_start = self.layout.range.start() as usize;
for key in self.layout.keys.iter() {
let x = self.pos.x + key.x();
let y = self.pos.y;

let w = key.width();
let h = key.height();

let size = w * 0.7;

let note_names = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"];
let note_index = (key.id() + range_start) % 12;
let note_name = note_names[note_index];
let oct_number = (key.id() + range_start) / 12;

let mut buffer = glyphon::Buffer::new(font_system, glyphon::Metrics::new(size, size));
buffer.set_size(font_system, Some(w), Some(h));
buffer.set_wrap(font_system, glyphon::Wrap::None);
buffer.set_text(
font_system,
&format!("{}{}", note_name, oct_number as i8 - 1),
glyphon::Attrs::new().family(glyphon::Family::SansSerif),
glyphon::Shaping::Basic,
);
buffer.lines[0].set_align(Some(glyphon::cosmic_text::Align::Center));
buffer.shape_until_scroll(font_system, false);

self.text_cache.push(super::text::TextArea {
buffer,
left: x,
top: y + h - size * 1.2,
scale: 1.0,
bounds: glyphon::TextBounds {
left: x.round() as i32,
top: y.round() as i32,
right: x.round() as i32 + w.round() as i32,
bottom: y.round() as i32 + h.round() as i32,
},
default_color: glyphon::Color::rgb(153, 153, 153),
});
}

}
#[profiling::function]
pub fn update(&mut self, quads: &mut QuadPipeline, layer: usize, text: &mut TextRenderer) {
if self.cache.is_empty() {
Expand Down