From 5a7314d137d33559e12c3d143756d3f971fc49bb Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Sun, 8 Dec 2019 12:46:56 -0800 Subject: [PATCH] Add color rewriting and stroke support for SVG images. Cut over more images, discovering some break... --- ezgui/src/drawing.rs | 19 +++++++++++++ ezgui/src/svg.rs | 41 ++++++++++++++++++++--------- ezgui/src/widgets/button.rs | 11 +++++--- ezgui/src/widgets/no_op.rs | 10 +++++++ game/assets/pregame/back.png | Bin 2433 -> 0 bytes game/assets/pregame/back.svg | 5 ++++ game/assets/pregame/challenges.svg | 8 ++++++ game/assets/pregame/logo.svg | 14 ++++++++++ game/assets/pregame/quit.png | Bin 1804 -> 0 bytes game/assets/pregame/quit.svg | 5 ++++ game/assets/pregame/tutorial.png | Bin 2649 -> 0 bytes game/assets/pregame/tutorial.svg | 6 +++++ game/assets/speed/pause.png | Bin 1051 -> 0 bytes game/assets/speed/pause.svg | 3 +++ game/assets/speed/resume.png | Bin 808 -> 0 bytes game/assets/speed/resume.svg | 3 +++ game/assets/speed/slow_down.png | Bin 148 -> 0 bytes game/assets/speed/slow_down.svg | 3 +++ game/assets/speed/speed_up.png | Bin 240 -> 0 bytes game/assets/speed/speed_up.svg | 3 +++ game/assets/speed/sunrise.png | Bin 662 -> 0 bytes game/assets/speed/sunrise.svg | 12 +++++++++ game/assets/speed/sunset.png | Bin 510 -> 0 bytes game/assets/speed/sunset.svg | 12 +++++++++ game/src/challenges.rs | 4 +-- game/src/managed.rs | 12 +-------- game/src/pregame.rs | 14 +++++----- game/src/sandbox/speed.rs | 26 +++++++----------- game/src/ui.rs | 9 ------- 29 files changed, 160 insertions(+), 60 deletions(-) delete mode 100644 game/assets/pregame/back.png create mode 100644 game/assets/pregame/back.svg create mode 100644 game/assets/pregame/challenges.svg create mode 100644 game/assets/pregame/logo.svg delete mode 100644 game/assets/pregame/quit.png create mode 100644 game/assets/pregame/quit.svg delete mode 100644 game/assets/pregame/tutorial.png create mode 100644 game/assets/pregame/tutorial.svg delete mode 100644 game/assets/speed/pause.png create mode 100644 game/assets/speed/pause.svg delete mode 100644 game/assets/speed/resume.png create mode 100644 game/assets/speed/resume.svg delete mode 100644 game/assets/speed/slow_down.png create mode 100644 game/assets/speed/slow_down.svg delete mode 100644 game/assets/speed/speed_up.png create mode 100644 game/assets/speed/speed_up.svg delete mode 100644 game/assets/speed/sunrise.png create mode 100644 game/assets/speed/sunrise.svg delete mode 100644 game/assets/speed/sunset.png create mode 100644 game/assets/speed/sunset.svg diff --git a/ezgui/src/drawing.rs b/ezgui/src/drawing.rs index 4632c63402..14d08ca3ae 100644 --- a/ezgui/src/drawing.rs +++ b/ezgui/src/drawing.rs @@ -1,4 +1,5 @@ use crate::assets::Assets; +use crate::svg; use crate::widgets::ContextMenu; use crate::{ text, Canvas, Color, EventCtx, HorizontalAlignment, Key, ScreenDims, ScreenPt, ScreenRectangle, @@ -411,6 +412,24 @@ impl GeomBatch { } ScreenDims::new(bounds.max_x - bounds.min_x, bounds.max_y - bounds.min_y) } + + // Slightly weird use case, but hotswap colors. + pub fn rewrite_color(&mut self, from: Color, to: Color) { + for (c, _) in self.list.iter_mut() { + if *c == from { + *c = to; + } + } + } + + // TODO Weird API... + pub fn add_svg(&mut self, filename: &str, dx: f64, dy: f64) { + let mut batch = GeomBatch::new(); + svg::add_svg(&mut batch, filename); + for (color, poly) in batch.consume() { + self.push(color, poly.translate(dx, dy)); + } + } } // Something that's been sent to the GPU already. diff --git a/ezgui/src/svg.rs b/ezgui/src/svg.rs index e1fef16a9b..30154efad0 100644 --- a/ezgui/src/svg.rs +++ b/ezgui/src/svg.rs @@ -6,15 +6,21 @@ use lyon::math::Point; use lyon::path::PathEvent; use lyon::tessellation; use lyon::tessellation::geometry_builder::{simple_builder, VertexBuffers}; -use lyon::tessellation::FillVertex; +use lyon::tessellation::{FillVertex, StrokeVertex}; const TOLERANCE: f32 = 0.01; -// No offset. Returns the button bounds. +// Code here adapted from +// https://github.com/nical/lyon/blob/b5c87c9a22dccfab24daa1947419a70915d60914/examples/wgpu_svg/src/main.rs. + +// No offset. I'm not exactly sure how the simplification in usvg works, but this doesn't support +// transforms or strokes or text, just fills. Luckily, all of the files exported from Figma so far +// work just fine. pub fn add_svg(batch: &mut GeomBatch, filename: &str) -> Bounds { let mut fill_tess = tessellation::FillTessellator::new(); let mut stroke_tess = tessellation::StrokeTessellator::new(); - let mut mesh_per_color: VecMap> = VecMap::new(); + let mut fill_mesh_per_color: VecMap> = VecMap::new(); + let mut stroke_mesh_per_color: VecMap> = VecMap::new(); let svg_tree = usvg::Tree::from_file(&filename, &usvg::Options::default()).unwrap(); for node in svg_tree.root().descendants() { @@ -23,31 +29,40 @@ pub fn add_svg(batch: &mut GeomBatch, filename: &str) -> Bounds { if let Some(ref fill) = p.fill { let color = convert_color(&fill.paint, fill.opacity.value()); - let geom = mesh_per_color.mut_or_insert(color, VertexBuffers::new); + let geom = fill_mesh_per_color.mut_or_insert(color, VertexBuffers::new); fill_tess .tessellate_path( convert_path(p), &tessellation::FillOptions::tolerance(TOLERANCE), &mut simple_builder(geom), ) - .unwrap(); + .expect(&format!("Couldn't tesellate something from {}", filename)); } if let Some(ref stroke) = p.stroke { - panic!("aww we have a stroke {:?}", stroke); let (color, stroke_opts) = convert_stroke(stroke); - let geom: &mut VertexBuffers = - mesh_per_color.mut_or_insert(color, VertexBuffers::new); - /*stroke_tess.tessellate_path( - convert_path(p), - &stroke_opts, - &mut simple_builder(geom)).unwrap();*/ + let geom = stroke_mesh_per_color.mut_or_insert(color, VertexBuffers::new); + stroke_tess + .tessellate_path(convert_path(p), &stroke_opts, &mut simple_builder(geom)) + .unwrap(); } } } let mut bounds = Bounds::new(); - for (color, mesh) in mesh_per_color.consume() { + for (color, mesh) in fill_mesh_per_color.consume() { + let poly = Polygon::precomputed( + mesh.vertices + .into_iter() + .map(|v| Pt2D::new(v.position.x as f64, v.position.y as f64)) + .collect(), + mesh.indices.into_iter().map(|idx| idx as usize).collect(), + None, + ); + bounds.union(poly.get_bounds()); + batch.push(color, poly); + } + for (color, mesh) in stroke_mesh_per_color.consume() { let poly = Polygon::precomputed( mesh.vertices .into_iter() diff --git a/ezgui/src/widgets/button.rs b/ezgui/src/widgets/button.rs index 8d1266a950..0a77f438a0 100644 --- a/ezgui/src/widgets/button.rs +++ b/ezgui/src/widgets/button.rs @@ -168,19 +168,24 @@ impl Button { Button::new(normal, hovered, key, "", bg) } - pub fn rectangle_svg(filename: &str, key: Option, ctx: &EventCtx) -> Button { + pub fn rectangle_svg( + filename: &str, + tooltip: &str, + key: Option, + ctx: &EventCtx, + ) -> Button { let mut normal = GeomBatch::new(); let bounds = svg::add_svg(&mut normal, filename); - // TODO Rewrite colors let mut hovered = GeomBatch::new(); svg::add_svg(&mut hovered, filename); + hovered.rewrite_color(Color::WHITE, Color::ORANGE); Button::new( DrawBoth::new(ctx, normal, Vec::new()), DrawBoth::new(ctx, hovered, Vec::new()), key, - "", + tooltip, bounds.get_rectangle(), ) } diff --git a/ezgui/src/widgets/no_op.rs b/ezgui/src/widgets/no_op.rs index e774fde929..3a9fdc6a7d 100644 --- a/ezgui/src/widgets/no_op.rs +++ b/ezgui/src/widgets/no_op.rs @@ -1,4 +1,5 @@ use crate::layout::Widget; +use crate::svg; use crate::{DrawBoth, EventCtx, GeomBatch, GfxCtx, ScreenDims, ScreenPt, Text}; // Just draw something. A widget just so layouting works. @@ -18,6 +19,15 @@ impl JustDraw { } } + pub fn svg(filename: &str, ctx: &EventCtx) -> JustDraw { + let mut batch = GeomBatch::new(); + svg::add_svg(&mut batch, filename); + JustDraw { + draw: DrawBoth::new(ctx, batch, vec![]), + top_left: ScreenPt::new(0.0, 0.0), + } + } + pub fn text(text: Text, ctx: &EventCtx) -> JustDraw { JustDraw { draw: DrawBoth::new(ctx, GeomBatch::new(), vec![(text, ScreenPt::new(0.0, 0.0))]), diff --git a/game/assets/pregame/back.png b/game/assets/pregame/back.png deleted file mode 100644 index e7e15a43b1c93b3550369bd8df9292df26e64c61..0000000000000000000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rXoCz-Iz_?~yb|E~t_k zxpc!QNta4GKTF#XX7)U;6wF6Guv!UKC58I6W_AGhrlcR@D&7|sslS)8P|^h@=L}bh zGz?cck;bJyW``q5WAKOBJJtGyFtgo~){|VhezBzCW>&gV`3Jy9JgNub_SRb|sR@^C z-i=#su?JVYI|5g^-@X~nxxjmIYr6ohBm3qzUd-%1Ns|HJrlli*2P9o!X1>T_u}B)H z+P2S?rlG{{Qjctla+KXfdKU%y@wu2b{UvQK=4B?*7-P5W9ctzFWZ96y{;j2LE1F|4 zvuDk0StV`sah{~ZS}3`wl&>u5VKaL*r>!RZX_QVbV3ZDMz*X1xD9r2-E`Jqrl^4q; zkdM-%6L)=_O~9<^!*6FY{=GypyMFCNuAQ&6Xp)@kS=#P-U@GCN@T$Yi{*M19)z0@N zozwnLZBX?*w&JSP&yU%F(ifm;0oIji`~JZ7xp61WY!h%cZZpo;%IrgzVrIW2yy43L zph*S%kV6d*%0H(%EVp6fZb^TY+x+rJa$)TWN+=7GbiAb3JbHs$Yo&NiLnIyY*w~^# zVpMLfa5Jotr0tR(lC)CN`(tbr_ES2MzIsXPQ}pd&N&PbII9j7d(MWm| z?kRRUE*dxp_v3GE!0W)i4#z9FAHb{X^?v^cjVG7ptr1lT00000NkvXXu0mjfJItqb diff --git a/game/assets/pregame/back.svg b/game/assets/pregame/back.svg new file mode 100644 index 0000000000..ff0be5c205 --- /dev/null +++ b/game/assets/pregame/back.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/game/assets/pregame/challenges.svg b/game/assets/pregame/challenges.svg new file mode 100644 index 0000000000..6809dee9e2 --- /dev/null +++ b/game/assets/pregame/challenges.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/game/assets/pregame/logo.svg b/game/assets/pregame/logo.svg new file mode 100644 index 0000000000..477c8e651c --- /dev/null +++ b/game/assets/pregame/logo.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/game/assets/pregame/quit.png b/game/assets/pregame/quit.png deleted file m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h##;2ZKhkr-$JMcGfI4~MG6`wTV@?<-Z9m)A~rGpk1zVDn{+4l2lU?-g)>y87~ zN_r7^3-}2b#6KpE1;zs>0@nby;IpH2Vmq*=%l_t}ijyIzAuWicBP0#vxQ{AWK1^JT z`gHBC89o$2%aN;6sSj(uo6-ky&J6*xfx1ngT#Rp}s^nw*oVuu~WhTM~3Gxmw9slT4 z3zD2xR{~XiS@&JwYUkX(ipuXBnJQC1#c0tWLDm4L;75`Mg9ek}oEreH0Pe!~4a#5} zK3T?e=iJVc%B(jEoN!GI>4N}BI#kj{lJ1qXTGAgm?yDCL>T?Ve(^yG!Bt0)_FlYI{ zN?IZRX@$`_e;2jyb9DW9jcSrtN`XJ1Qx(a5or%wjJ3iUQ0VDAvS3}9ayYQ{f05IsB z`=g?G9Dc;=Y(fCw9qwsyFJ@}96Yy!Rlwin316)&n;icU4C1u-I~Zep~>Wr7&t zsH+%l@tGh-|EaqeZE>0)M*oOKjJA053i4Q}SdGY$G%pr0+G5Tt$n?-L89(G8Y9Xd86F8(vON`8stJ;3?+S(dASXJec{ uBma5gY54g`Yn^kom=S9jhG7^+Q~4M1?sg9=yY;jH0000 + + + + diff --git a/game/assets/pregame/tutorial.png b/game/assets/pregame/tutorial.png deleted file mode 100644 index 27d1b78c911987cbff35765b65c8ab446a17a39d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2649 zcmb_ec~lZu7Y8vMM8U!)&27duOtTUbrv%G2D+{$US1d)X&_G2~amzGI&C#KSF&8qI znXqvex1=;FbICGXK*h=(S6on1KbUjoocVjs_s+TRo_Ftk_x|4R-Sf`7i#uzpthiGV z001c4owRb4>U^mb{{WWGT{j!6r3yki=@JY8z?x+Oe4r20000!Bc2+0O-+VI74@l9v zpv9S=#a5_>La$wSDxo>LWk0QWdAt~Y`PZiww?4~nt^D{|MbGPy%8>uB{;G%O)720^ zZ8QFY$oIfK+kfkbuCA4RD&z{=z_`q$JJi{~FJQtG|D<7Yux7I+cyut_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QrsJrTrCPQFc_8Q%x4gJE&*qer^4omHb&wK*`~ekb76 zqs%cca>gUl*I+UhN!qZ6DIr31bW`<#gHk<84nG4Ph+l#{-OR=5&EoXyYAJ={-bml zHsoL+@0!v|{T7CLhnEvm$}S5P6v&8PQ~@&}l*xQ08er{6({8&oyN@+rvcEtu3+@2U zwBh^?2ByqbY4XTwlF?E3vc}vhxule!>m;+gl{4Y&DWj@A4)k*&HgREJ2O%-B-yVta z&Fe?9m8tS!HASuRGo^#B{77@VG^NeBOw&?Lu|05_r6E}lzusG + + + + + diff --git a/game/assets/speed/pause.png b/game/assets/speed/pause.png deleted file mode 100644 index e51daaf951a64e4bcfb89638e2a8b18740f823d2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1051 zcmV+$1mydPP)o9IkN#0$s=BA*^j#3vG`Rr8knH zufFn1y=|KS%SZ=4(kfI&nzG;Nmr-HxPx=h~{&hN?zcxA4fysIcm$}rqusk&T<}9uh zjrBGV`R<#Hn8dVFoYwdE_akhqUX(oZ>kYBcoVjFK`cIVpjEm-cTrCn`fQ26FiXcUx zbPctp(BwqeCg-VM!Dn-Zqy}+o)KAS0IpUUhx^dzbow3;`M;xwkqLoKYguhi#Iuora zGW%qRoBIw}f8(SzBzgs>s&9I|<$DtrpURd1-7mi9UgEI$ShfV{?)aX2iHpUzHVE%= zFhkrDuOrzKVDSv`bU{mDvv{JFBd(;fVNjMs6Dm7q>a}jEt#O1P*#5m(JHRpQANt`3aiy6P>mY1jTIxSCGApNMvZKcbbPxLPN z%xgek&k%S*|F0twM(TaB_czzA{D11z;l-S1v?dl8E znrJ?;uVbA7C=1^+r(ShYtL^fN7gwnMaNRtpn+je4aKp5{%PSwuNVCa=(hfTq_zz(O Vg~Z!&kzxP<002ovPDHLkV1fsJ + + diff --git a/game/assets/speed/resume.png b/game/assets/speed/resume.png deleted file mode 100644 index 096d1004e969c6ce2c15d3b3b11db2879b9dfc04..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 808 zcmV+@1K0eCP)JD0Al@M91oj4QCpc#UrxV+4ptxD8sv0EGGHAHZxRGKSz=nICr|3Xq+o-t{F)HInjtcI=Ut3|*SG&~ zX95_i2jCq~5z=dPGmFNa@p?nV<`vX{cO((tX-P+HZ<_?*jSqtHHB^Kj1*wGclY_2~ zIXY+nbk74v4>^b!TSG%cMqmY6;BmQZ5_F250dHf+%SUUV6Y9?->OGVMfo?6CvP%`+ z(ycC+An2rEXYBCuNvnNyGYp4G)D1_>X73I%5Xt^$-tR)tyjP|U3$va5o4QoF`ISjY}G-b4B?VD2yz>6IeKzVK8NG>B@ z_x%40)|nd}p*}Qa^y>J?`SG$TUStwsNP5&i2cNCe!&5Or>)cfa4r5n;;Yf5b$6mkl z{icYGp*nF!V2f!O0+|x}_gG=7O$nmIx^G7GS9+C#IA9)nEWEU>{Wj3<1nqaJZbxuC m!{1QpZQzG~4|~QL8TbcIU->r=>YE<`0000 + + diff --git a/game/assets/speed/slow_down.png b/game/assets/speed/slow_down.png deleted file mode 100644 index a0da2e4aa37153ed748a97b8ab1f21f8d3f9fec6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 148 zcmeAS@N?(olHy`uVBq!ia0vp^LLkh+1|-AI^@Rf|&H|6fVg?3oVGw3ym^DWNDCp+t z;uvDl`}TaG=m7%`=Zglu3zSZsE9oM>8PwgwIXW7gm?J6HW$ph>A`00-DI+>FVdQ&MBb@0Ayn@djJ3c diff --git a/game/assets/speed/slow_down.svg b/game/assets/speed/slow_down.svg new file mode 100644 index 0000000000..1a99ede140 --- /dev/null +++ b/game/assets/speed/slow_down.svg @@ -0,0 +1,3 @@ + + + diff --git a/game/assets/speed/speed_up.png b/game/assets/speed/speed_up.png deleted file mode 100644 index f4f64162b648d7e9b878f35f6e0a867dc1f23c44..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 240 zcmeAS@N?(olHy`uVBq!ia0vp^LLkh+1|-AI^@Rf|&H|6fVg?3oVGw3ym^DWND9BhG zEQlj88gMMsC{TY*!W$d#)2tjLQs+75gBjIt55cX`tc}kDJiI6Xztf&ez)>P z diff --git a/game/assets/speed/speed_up.svg b/game/assets/speed/speed_up.svg new file mode 100644 index 0000000000..0f1645abba --- /dev/null +++ b/game/assets/speed/speed_up.svg @@ -0,0 +1,3 @@ + + + diff --git a/game/assets/speed/sunrise.png b/game/assets/speed/sunrise.png deleted file mode 100644 index aafee10aa515ff2a0c317722e5a2003011d53a89..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 662 zcmV;H0%`q;P)P000dL1^@s6T&~6L00009a7bBm000XU z000XU0RWnu7ytkQNJ&INR5*>5Qb9-*VHEz}KeO4aJDQ{=w(iadk!3~Y66K{jbcrOo z1ce2a*NCut9Ri_4U=V=>1yP3%<*kb#dZ{Q1jcs?GWYbj=7uIceW;flP|8+=2)>8 z3D-Hs|dG*j{E`NV*Zqft(vtaZvp^Jce z1}_jW&cG^MBL2mpC2)In0Y0|C9TY~S4GYCg4wZjexJOIP;m?Z2L`jw>Gx zT_T@)jAZFCNE~4(eUf=Vx0CNFf)W7aEVElMUxCEO#Y}mywQIJxB6I+(-Xdm)mGTQA zl|FKL(7%8BgXjFx@kZUT%%MUee34T@Z7r9b2sPv_<5V`@w(d-GvGB=!qHWmggx6h{ zAKDpqIrDc}Oi}B9r`43ImQ#>&OhV~d$5jHX_)bIOdyV3zE4h_DjCzTDnw^`E1dTCB w@nBOC0_#k;$Exzko@}c&$cjS%;E783ADPSfrpW~7asU7T07*qoM6N<$g6du{aR2}S diff --git a/game/assets/speed/sunrise.svg b/game/assets/speed/sunrise.svg new file mode 100644 index 0000000000..d5fdcf460e --- /dev/null +++ b/game/assets/speed/sunrise.svg @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/game/assets/speed/sunset.png b/game/assets/speed/sunset.png deleted file mode 100644 index 4603d0ab4ae9d2311e3ffb3891633cb8ba6dd740..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 510 zcmVP000dL1^@s6T&~6L00009a7bBm000XU z000XU0RWnu7ytkO0drDELIAGL9O(c600d`2O+f$vv5yPd%7(j%_yoe@Ds0A3?HgDVAz{J}hCof!C$K7mqs$KU4TSgr=wyup z3jOzSmC`pzaHss}jJKcD3CXd@fGWDjYoN=GDc zhk(7w81fV!VF!FX10*Smsc#-DwXnBI^UWv(lgyaX58HLYV4cl5BepB8FP+zAU8Dbb z(4m>E@`Gcr#uDrDDM8d-B*kjWv4criQc)P~BEp9tQ6yB71T`Pwep!LQYfZfrqt;N< zdSX@1qK~Pe@Uz7VaE(n>(I}=q#1LD1Q%w&REedD5@Bje}h@o=OHFn*xT!>VJzD-UN zM$ZseKDI%Cy>M6z2iUk1kI*9zC^CpEf?$VZzeUocD^5(Od;kCd07*qoM6N<$g7O*B AbN~PV diff --git a/game/assets/speed/sunset.svg b/game/assets/speed/sunset.svg new file mode 100644 index 0000000000..db803c6efe --- /dev/null +++ b/game/assets/speed/sunset.svg @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/game/src/challenges.rs b/game/src/challenges.rs index f928336324..439eb667d8 100644 --- a/game/src/challenges.rs +++ b/game/src/challenges.rs @@ -111,9 +111,9 @@ pub fn challenges_picker(ctx: &EventCtx) -> Box { col.push(ManagedWidget::Row( LayoutStyle::Neutral, vec![ - ManagedWidget::img_button_no_bg( + ManagedWidget::svg_button( ctx, - "assets/pregame/back.png", + "assets/pregame/back.svg", "back", hotkey(Key::Escape), Box::new(|_, _| Some(Transition::Pop)), diff --git a/game/src/managed.rs b/game/src/managed.rs index 23a9f5caa1..71be56ef08 100644 --- a/game/src/managed.rs +++ b/game/src/managed.rs @@ -54,23 +54,13 @@ impl ManagedWidget { } pub fn svg_button( - ctx: &EventCtx, - filename: &str, - hotkey: Option, - onclick: Callback, - ) -> ManagedWidget { - let btn = Button::rectangle_svg(filename, hotkey, ctx); - ManagedWidget::Btn(btn, onclick) - } - - pub fn img_button_no_bg( ctx: &EventCtx, filename: &str, tooltip: &str, hotkey: Option, onclick: Callback, ) -> ManagedWidget { - let btn = Button::rectangle_img_no_bg(filename, tooltip, hotkey, ctx); + let btn = Button::rectangle_svg(filename, tooltip, hotkey, ctx); ManagedWidget::Btn(btn, onclick) } diff --git a/game/src/pregame.rs b/game/src/pregame.rs index 4d8774e517..432d89fd4a 100644 --- a/game/src/pregame.rs +++ b/game/src/pregame.rs @@ -75,9 +75,9 @@ pub fn main_menu(ctx: &EventCtx, ui: &UI) -> Box { col.push(ManagedWidget::Row( LayoutStyle::Neutral, vec![ - ManagedWidget::img_button_no_bg( + ManagedWidget::svg_button( ctx, - "assets/pregame/quit.png", + "assets/pregame/quit.svg", "quit", hotkey(Key::Escape), Box::new(|_, _| { @@ -101,15 +101,17 @@ pub fn main_menu(ctx: &EventCtx, ui: &UI) -> Box { col.push(ManagedWidget::Row( LayoutStyle::Centered, vec![ - ManagedWidget::img_button( + ManagedWidget::svg_button( ctx, - "assets/pregame/tutorial.png", + "assets/pregame/tutorial.svg", + "Tutorial", hotkey(Key::T), Box::new(|ctx, _| Some(Transition::Push(Box::new(TutorialMode::new(ctx))))), ), ManagedWidget::svg_button( ctx, "assets/pregame/sandbox.svg", + "Sandbox mode", hotkey(Key::S), Box::new(|ctx, ui| { Some(Transition::Push(Box::new(SandboxMode::new( @@ -158,9 +160,9 @@ pub fn main_menu(ctx: &EventCtx, ui: &UI) -> Box { fn about(ctx: &EventCtx) -> Box { let mut row = Vec::new(); - row.push(ManagedWidget::img_button_no_bg( + row.push(ManagedWidget::svg_button( ctx, - "assets/pregame/back.png", + "assets/pregame/back.svg", "back", hotkey(Key::Escape), Box::new(|_, _| Some(Transition::Pop)), diff --git a/game/src/sandbox/speed.rs b/game/src/sandbox/speed.rs index bade12d369..ac222f9e60 100644 --- a/game/src/sandbox/speed.rs +++ b/game/src/sandbox/speed.rs @@ -62,14 +62,12 @@ impl SpeedControls { Text::from(Line("00:00").size(12).roboto()).no_bg(), ScreenPt::new(25.0, 97.0), )); - let (sunrise_color, sunrise_rect) = ctx.canvas.texture_rect("assets/speed/sunrise.png"); - batch.push(sunrise_color, sunrise_rect.translate(94.0, 94.0)); + batch.add_svg("assets/speed/sunrise.svg", 94.0, 94.0); txt.push(( Text::from(Line("12:00").size(12).roboto()).no_bg(), ScreenPt::new(153.0, 97.0), )); - let (sunset_color, sunset_rect) = ctx.canvas.texture_rect("assets/speed/sunset.png"); - batch.push(sunset_color, sunset_rect.translate(220.0, 94.0)); + batch.add_svg("assets/speed/sunset.svg", 220.0, 94.0); txt.push(( Text::from(Line("24:00").size(12).roboto()).no_bg(), ScreenPt::new(280.0, 97.0), @@ -94,15 +92,11 @@ impl SpeedControls { }; // Row 1 - let resume_btn = Button::rectangle_img_no_bg( - "assets/speed/resume.png", - "resume", - hotkey(Key::Space), - ctx, - ) - .at(ScreenPt::new(23.0, 14.0)); + let resume_btn = + Button::rectangle_svg("assets/speed/resume.svg", "resume", hotkey(Key::Space), ctx) + .at(ScreenPt::new(23.0, 14.0)); let pause_btn = - Button::rectangle_img_no_bg("assets/speed/pause.png", "pause", hotkey(Key::Space), ctx) + Button::rectangle_svg("assets/speed/pause.svg", "pause", hotkey(Key::Space), ctx) .at(ScreenPt::new(23.0, 14.0)); let jump_to_time_btn = Button::rectangle_img_no_bg( @@ -140,15 +134,15 @@ impl SpeedControls { speed_slider.set_percent(ctx, (speed_cap / 1.0).powf(-1.0 / std::f64::consts::E)); speed_slider.set_pos(ScreenPt::new(92.0, 134.0)); - let slow_down_btn = Button::rectangle_img_no_bg( - "assets/speed/slow_down.png", + let slow_down_btn = Button::rectangle_svg( + "assets/speed/slow_down.svg", "slow down", hotkey(Key::LeftBracket), ctx, ) .at(ScreenPt::new(245.0, 129.0)); - let speed_up_btn = Button::rectangle_img_no_bg( - "assets/speed/speed_up.png", + let speed_up_btn = Button::rectangle_svg( + "assets/speed/speed_up.svg", "speed up", hotkey(Key::RightBracket), ctx, diff --git a/game/src/ui.rs b/game/src/ui.rs index 0fb961259a..f803ea6471 100644 --- a/game/src/ui.rs +++ b/game/src/ui.rs @@ -26,20 +26,11 @@ impl UI { let primary = ctx.loading_screen("load map", |ctx, mut timer| { ctx.set_textures( vec![ - ("assets/pregame/back.png", TextureType::Stretch), ("assets/pregame/challenges.png", TextureType::Stretch), - ("assets/pregame/quit.png", TextureType::Stretch), - ("assets/pregame/tutorial.png", TextureType::Stretch), ("assets/pregame/logo.png", TextureType::Stretch), ("assets/speed/jump_to_time.png", TextureType::Stretch), ("assets/speed/large_step.png", TextureType::Stretch), - ("assets/speed/pause.png", TextureType::Stretch), - ("assets/speed/resume.png", TextureType::Stretch), - ("assets/speed/slow_down.png", TextureType::Stretch), ("assets/speed/small_step.png", TextureType::Stretch), - ("assets/speed/speed_up.png", TextureType::Stretch), - ("assets/speed/sunrise.png", TextureType::Stretch), - ("assets/speed/sunset.png", TextureType::Stretch), ("assets/ui/edit_bike.png", TextureType::Stretch), ("assets/ui/edit_bus.png", TextureType::Stretch), ("assets/ui/edit_construction.png", TextureType::Stretch),