Skip to content

Commit

Permalink
Update to match new asset server
Browse files Browse the repository at this point in the history
  • Loading branch information
AlisCode committed Oct 21, 2020
1 parent 6fc2573 commit 13d0753
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
6 changes: 3 additions & 3 deletions crates/bevy_text/src/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl<'a> Drawable for TextDrawer<'a> {
fn draw(&mut self, draw: &mut Draw, context: &mut DrawContext) -> Result<(), DrawError> {
context.set_pipeline(
draw,
bevy_sprite::SPRITE_SHEET_PIPELINE_HANDLE,
&bevy_sprite::SPRITE_SHEET_PIPELINE_HANDLE,
&PipelineSpecialization {
sample_count: self.msaa.samples,
..Default::default()
Expand All @@ -179,13 +179,13 @@ impl<'a> Drawable for TextDrawer<'a> {

let render_resource_context = &**context.render_resource_context;
if let Some(RenderResourceId::Buffer(quad_vertex_buffer)) = render_resource_context
.get_asset_resource(bevy_sprite::QUAD_HANDLE, mesh::VERTEX_BUFFER_ASSET_INDEX)
.get_asset_resource(&bevy_sprite::QUAD_HANDLE, mesh::VERTEX_BUFFER_ASSET_INDEX)
{
draw.set_vertex_buffer(0, quad_vertex_buffer, 0);
}
let mut indices = 0..0;
if let Some(RenderResourceId::Buffer(quad_index_buffer)) = render_resource_context
.get_asset_resource(bevy_sprite::QUAD_HANDLE, mesh::INDEX_BUFFER_ASSET_INDEX)
.get_asset_resource(&bevy_sprite::QUAD_HANDLE, mesh::INDEX_BUFFER_ASSET_INDEX)
{
draw.set_index_buffer(quad_index_buffer, 0);
if let Some(buffer_info) = render_resource_context.get_buffer_info(quad_index_buffer) {
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_text/src/font_atlas_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use bevy_math::Vec2;
use bevy_render::texture::Texture;
use bevy_sprite::TextureAtlas;
use bevy_utils::HashMap;
use bevy_type_registry::TypeUuid;

type FontSizeKey = FloatOrd;

Expand Down Expand Up @@ -103,7 +104,7 @@ impl FontAtlasSet {
.find_map(|atlas| {
atlas
.get_glyph_index(glyph_id)
.map(|glyph_index| (glyph_index, atlas.texture_atlas))
.map(|glyph_index| (glyph_index, atlas.texture_atlas.clone_weak()))
})
.map(|(glyph_index, texture_atlas)| GlyphAtlasInfo {
texture_atlas,
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_text/src/glyph_brush.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ impl GlyphBrush {
let mut vertices = Vec::new();
for glyph in glyphs {
println!("processing a glyph: {:?}", glyph);
let handle = self.handles[glyph.font_id.0];
let handle_font_atlas = Handle::<FontAtlasSet>::from(handle.id);
let handle = &self.handles[glyph.font_id.0];
let handle_font_atlas: Handle<FontAtlasSet> = handle.as_weak();
let font_atlas_set = font_atlas_set_storage
.get_or_insert_with(handle_font_atlas, || FontAtlasSet::default());
let position = glyph.glyph.position;
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_text/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ impl Default for TextPipeline {
impl TextPipeline {
pub fn measure(
&mut self,
font_handle: &Handle<Font>,
font_handle: Handle<Font>,
font_storage: &Assets<Font>,
text: &str,
size: f32,
bounds: Size,
) -> Result<Vec2, TextError> {
let font = font_storage.get(font_handle).ok_or(TextError::NoSuchFont)?;
let font = font_storage.get(font_handle.clone()).ok_or(TextError::NoSuchFont)?;
let font_id = self.get_or_insert_font_id(font_handle, font);

let section = glyph_brush_layout::SectionText {
Expand All @@ -56,23 +56,23 @@ impl TextPipeline {
todo!()
}

pub fn get_or_insert_font_id(&mut self, handle: &Handle<Font>, font: &Font) -> FontId {
pub fn get_or_insert_font_id(&mut self, handle: Handle<Font>, font: &Font) -> FontId {
self.map_font_id
.entry(*handle)
.entry(handle.clone())
.or_insert(self.brush.add_font(handle.clone(), font.font.clone()))
.clone()
}

pub fn queue_text(
&mut self,
font_handle: &Handle<Font>,
font_handle: Handle<Font>,
font_storage: &Assets<Font>,
text: &str,
size: f32,
bounds: Size,
screen_position: Vec2,
) -> Result<(), TextError> {
let font = font_storage.get(font_handle).ok_or(TextError::NoSuchFont)?;
let font = font_storage.get(font_handle.clone()).ok_or(TextError::NoSuchFont)?;
let font_id = self.get_or_insert_font_id(font_handle, font);

println!("the font id is {:?}", font_id);
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ui/src/widget/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ pub fn text_system(
}
*/
println!("Queing text : {}", &text.value);
let screen_position = trans.translation();
let screen_position = trans.translation;
if let Err(e) = text_pipeline.queue_text(
&text.font,
text.font.clone(),
&fonts,
&text.value,
text.style.font_size,
Expand Down

0 comments on commit 13d0753

Please sign in to comment.