Debian Codegraph @

src/theme.rs

raw symbols SCIP
1 /*
2 * Copyright 2020-2024 Andrey Kutejko <[email protected]>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
16 *
17 * For more details see the file COPYING.
18 */
19
20 use craterust-analyzer cargo gnome-robots 50.0.0 crate/::animationrust-analyzer cargo gnome-robots 50.0.0 animation/::{selfrust-analyzer cargo gnome-robots 50.0.0 animation/, Animationrust-analyzer cargo gnome-robots 50.0.0 animation/Animation#, InfiniteAnimationrust-analyzer cargo gnome-robots 50.0.0 animation/InfiniteAnimation#};
21 use craterust-analyzer cargo gnome-robots 50.0.0 crate/::arenarust-analyzer cargo gnome-robots 50.0.0 arena/::ObjectTyperust-analyzer cargo gnome-robots 50.0.0 arena/ObjectType#;
22 use craterust-analyzer cargo gnome-robots 50.0.0 crate/::imagerust-analyzer cargo gnome-robots 50.0.0 image/::Imagerust-analyzer cargo gnome-robots 50.0.0 image/Image#;
23 use gtkrust-analyzer cargo gtk4 0.11.1 crate/::{glibrust-analyzer cargo glib 0.22.3 crate/, glibrust-analyzer cargo glib 0.22.3 crate/::subclassrust-analyzer cargo glib 0.22.3 subclass/::preluderust-analyzer cargo glib 0.22.3 subclass/prelude/::*, graphenerust-analyzer cargo graphene-rs 0.22.0 crate/, gskrust-analyzer cargo gsk4 0.11.1 crate/, preluderust-analyzer cargo gtk4 0.11.1 prelude/::*};
24 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#;
25 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#;
26 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::{Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#};
27
28 pub const PLAYER_ANIMATION_FRAMESrust-analyzer cargo gnome-robots 50.0.0 theme/PLAYER_ANIMATION_FRAMES.: Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#<usize> = 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#4;
29 pub const PLAYER_DEAD_ANIMATION_FRAMESrust-analyzer cargo gnome-robots 50.0.0 theme/PLAYER_DEAD_ANIMATION_FRAMES.: Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#<usize> = 4..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#5;
30 pub const ROBOT1_ANIMATION_FRAMESrust-analyzer cargo gnome-robots 50.0.0 theme/ROBOT1_ANIMATION_FRAMES.: Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#<usize> = 5..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#9;
31 pub const ROBOT2_ANIMATION_FRAMESrust-analyzer cargo gnome-robots 50.0.0 theme/ROBOT2_ANIMATION_FRAMES.: Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#<usize> = 9..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#13;
32 pub const HEAP_ANIMATION_FRAMESrust-analyzer cargo gnome-robots 50.0.0 theme/HEAP_ANIMATION_FRAMES.: Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#<usize> = 13..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#14;
33 pub const FRAMES_COUNTrust-analyzer cargo gnome-robots 50.0.0 theme/FRAMES_COUNT.: usize = 14;
34
35 mod imprust-analyzer cargo gnome-robots 50.0.0 theme/imp/ {
36 use superrust-analyzer cargo gnome-robots 50.0.0 theme/::*;
37 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/::OnceCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/once/OnceCell#;
38
39 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(glibrust-analyzer cargo glib 0.22.3 crate/::Propertiesrust-analyzer cargo glib-macros 0.22.2 Properties:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)]
40 #[properties(wrapper_type = superrust-analyzer cargo gnome-robots 50.0.0 theme/::Themerust-analyzer cargo gnome-robots 50.0.0 theme/Theme#)]
41 pub struct Themerust-analyzer cargo gnome-robots 50.0.0 theme/imp/Theme# {
42 pub imagerust-analyzer cargo gnome-robots 50.0.0 theme/imp/Theme#image.: OnceCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/once/OnceCell#<Imagerust-analyzer cargo gnome-robots 50.0.0 image/Image#>,
43 #[propertyrust-analyzer cargo glib-macros 0.22.2 property:(get, construct_onlyrust-analyzer cargo glib 0.22.3 param_spec/ParamSpecBuilderExt#construct_only().)]
44 pub pathrust-analyzer cargo gnome-robots 50.0.0 theme/imp/Theme#path.: OnceCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/once/OnceCell#<PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#>,
45 #[propertyrust-analyzer cargo glib-macros 0.22.2 property:(get, construct_onlyrust-analyzer cargo glib 0.22.3 param_spec/ParamSpecBuilderExt#construct_only().)]
46 pub namerust-analyzer cargo gnome-robots 50.0.0 theme/imp/Theme#name.: OnceCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/once/OnceCell#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
47 }
48
49 #[glibrust-analyzer cargo glib 0.22.3 crate/::object_subclassrust-analyzer cargo glib-macros 0.22.2 object_subclass:]
50 impl ObjectSubclassrust-analyzer cargo glib 0.22.3 subclass/types/ObjectSubclass# for Themerust-analyzer cargo gnome-robots 50.0.0 theme/imp/Theme# {
51 const NAMErust-analyzer cargo gnome-robots 50.0.0 theme/imp/impl#[Theme][ObjectSubclass]NAME.: &'static str = "RobotsTheme";
52 type Typerust-analyzer cargo gnome-robots 50.0.0 theme/imp/impl#[Theme][ObjectSubclass]Type# = superrust-analyzer cargo gnome-robots 50.0.0 theme/::Themerust-analyzer cargo gnome-robots 50.0.0 theme/Theme#;
53 type ParentTyperust-analyzer cargo gnome-robots 50.0.0 theme/imp/impl#[Theme][ObjectSubclass]ParentType# = glibrust-analyzer cargo glib 0.22.3 crate/::Objectrust-analyzer cargo glib 0.22.3 object/Object#;
54 }
55
56 #[glibrust-analyzer cargo glib 0.22.3 crate/::derived_propertiesrust-analyzer cargo glib-macros 0.22.2 derived_properties:]
57 impl ObjectImplrust-analyzer cargo glib 0.22.3 subclass/object/ObjectImpl# for Themerust-analyzer cargo gnome-robots 50.0.0 theme/imp/Theme# {}
58 }
59
60 glibrust-analyzer cargo glib 0.22.3 crate/::wrapperrust-analyzer cargo glib 0.22.3 wrapper/wrapper!! {
61 pub struct Themerust-analyzer cargo gnome-robots 50.0.0 theme/Theme#(ObjectSubclass<imprust-analyzer cargo gnome-robots 50.0.0 theme/imp/::Themerust-analyzer cargo gnome-robots 50.0.0 theme/imp/Theme#>);
62 }
63
64 impl Themerust-analyzer cargo gnome-robots 50.0.0 theme/Theme# {
65 pub fn from_filerust-analyzer cargo gnome-robots 50.0.0 theme/impl#[Theme]from_file().(path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo gnome-robots 50.0.0 theme/impl#[Theme], Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
66 let image = Imagerust-analyzer cargo gnome-robots 50.0.0 image/Image#::from_filerust-analyzer cargo gnome-robots 50.0.0 image/impl#[Image]from_file().(path)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
67 let name = path
68 .file_stemrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]file_stem().()
69 .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().("Bad file name")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
70 .to_string_lossyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_string_lossy().()
71 .replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().("_", " ");
72 let this: Selfrust-analyzer cargo gnome-robots 50.0.0 theme/impl#[Theme] = glibrust-analyzer cargo glib 0.22.3 crate/::Objectrust-analyzer cargo glib 0.22.3 object/Object#::builderrust-analyzer cargo glib 0.22.3 object/impl#[Object]builder().()
73 .propertyrust-analyzer cargo glib 0.22.3 object/impl#[`ObjectBuilder<'a, O>`]property().("path", path)
74 .propertyrust-analyzer cargo glib 0.22.3 object/impl#[`ObjectBuilder<'a, O>`]property().("name", name)
75 .buildrust-analyzer cargo glib 0.22.3 object/impl#[`ObjectBuilder<'a, O>`]build().();
76 this.imprust-analyzer cargo glib 0.22.3 subclass/types/impl#[T][ObjectSubclassIsExt]imp().().imagerust-analyzer cargo gnome-robots 50.0.0 theme/imp/Theme#image..setrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/once/impl#[`OnceCell<T>`]set().(image).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
77 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(this)
78 }
79
80 pub fn draw_objectrust-analyzer cargo gnome-robots 50.0.0 theme/impl#[Theme]draw_object().(
81 &self,
82 r#type: ObjectTyperust-analyzer cargo gnome-robots 50.0.0 arena/ObjectType#,
83 frame_no: usize,
84 snapshot: &gtkrust-analyzer cargo gtk4 0.11.1 crate/::Snapshotrust-analyzer cargo gtk4 0.11.1 auto/snapshot/Snapshot#,
85 rect: &graphenerust-analyzer cargo graphene-rs 0.22.0 crate/::Rectrust-analyzer cargo graphene-rs 0.22.0 auto/rect/Rect#,
86 renderer: &gskrust-analyzer cargo gsk4 0.11.1 crate/::Rendererrust-analyzer cargo gsk4 0.11.1 auto/renderer/Renderer#,
87 ) {
88 let tile_no = match r#type {
89 ObjectTyperust-analyzer cargo gnome-robots 50.0.0 arena/ObjectType#::Playerrust-analyzer cargo gnome-robots 50.0.0 arena/ObjectType#Player# => frame_indexrust-analyzer cargo gnome-robots 50.0.0 theme/frame_index().(PLAYER_ANIMATION_FRAMESrust-analyzer cargo gnome-robots 50.0.0 theme/PLAYER_ANIMATION_FRAMES., frame_no),
90 ObjectTyperust-analyzer cargo gnome-robots 50.0.0 arena/ObjectType#::Robot1rust-analyzer cargo gnome-robots 50.0.0 arena/ObjectType#Robot1# => frame_indexrust-analyzer cargo gnome-robots 50.0.0 theme/frame_index().(ROBOT1_ANIMATION_FRAMESrust-analyzer cargo gnome-robots 50.0.0 theme/ROBOT1_ANIMATION_FRAMES., frame_no),
91 ObjectTyperust-analyzer cargo gnome-robots 50.0.0 arena/ObjectType#::Robot2rust-analyzer cargo gnome-robots 50.0.0 arena/ObjectType#Robot2# => frame_indexrust-analyzer cargo gnome-robots 50.0.0 theme/frame_index().(ROBOT2_ANIMATION_FRAMESrust-analyzer cargo gnome-robots 50.0.0 theme/ROBOT2_ANIMATION_FRAMES., frame_no),
92 ObjectTyperust-analyzer cargo gnome-robots 50.0.0 arena/ObjectType#::Heaprust-analyzer cargo gnome-robots 50.0.0 arena/ObjectType#Heap# => frame_indexrust-analyzer cargo gnome-robots 50.0.0 theme/frame_index().(HEAP_ANIMATION_FRAMESrust-analyzer cargo gnome-robots 50.0.0 theme/HEAP_ANIMATION_FRAMES., frame_no),
93 ObjectTyperust-analyzer cargo gnome-robots 50.0.0 arena/ObjectType#::Nonerust-analyzer cargo gnome-robots 50.0.0 arena/ObjectType#None# => return,
94 };
95
96 snapshot.push_cliprust-analyzer cargo gtk4 0.11.1 auto/snapshot/SnapshotExt#push_clip().(rect);
97
98 snapshot.saverust-analyzer cargo gtk4 0.11.1 auto/snapshot/SnapshotExt#save().();
99 let frame_offset = (tile_no as i32) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Mul<Self>`]mul().(rect.widthrust-analyzer cargo graphene-rs 0.22.0 auto/rect/impl#[Rect]width().() as i32);
100 let texture_width = (rect.widthrust-analyzer cargo graphene-rs 0.22.0 auto/rect/impl#[Rect]width().() as i32) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Mul<Self>`]mul().(FRAMES_COUNTrust-analyzer cargo gnome-robots 50.0.0 theme/FRAMES_COUNT. as i32);
101 let texture_height = rect.heightrust-analyzer cargo graphene-rs 0.22.0 auto/rect/impl#[Rect]height().() as i32;
102 let image = self.imprust-analyzer cargo glib 0.22.3 subclass/types/impl#[T][ObjectSubclassIsExt]imp().().imagerust-analyzer cargo gnome-robots 50.0.0 theme/imp/Theme#image..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/once/impl#[`OnceCell<T>`]get().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
103 match image.scaledrust-analyzer cargo gnome-robots 50.0.0 image/impl#[Image]scaled().(texture_width, texture_height, renderer) {
104 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(texture) => {
105 snapshot.translaterust-analyzer cargo gtk4 0.11.1 auto/snapshot/SnapshotExt#translate().(&graphenerust-analyzer cargo graphene-rs 0.22.0 crate/::Pointrust-analyzer cargo graphene-rs 0.22.0 auto/point/Point#::newrust-analyzer cargo graphene-rs 0.22.0 point/impl#[Point]new().(
106 rect.xrust-analyzer cargo graphene-rs 0.22.0 auto/rect/impl#[Rect]x().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub().frame_offset as f32,
107 rect.yrust-analyzer cargo graphene-rs 0.22.0 auto/rect/impl#[Rect]y().(),
108 ));
109 texture.snapshotrust-analyzer cargo gdk4 0.11.1 auto/paintable/PaintableExt#snapshot().(snapshot, texture_width as f64, texture_height as f64);
110 }
111 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error) => {
112 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("Failed to get a scaled texture: {error}");
113 }
114 }
115 snapshot.restorerust-analyzer cargo gtk4 0.11.1 auto/snapshot/SnapshotExt#restore().();
116
117 snapshot.poprust-analyzer cargo gtk4 0.11.1 auto/snapshot/SnapshotExt#pop().();
118 }
119 }
120
121 fn frame_indexrust-analyzer cargo gnome-robots 50.0.0 theme/frame_index().(range: Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#<usize>, frame_no: usize) -> usize {
122 range.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#start. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().frame_no rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().range.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator#len().()
123 }
124
125 pub fn player_animationrust-analyzer cargo gnome-robots 50.0.0 theme/player_animation().() -> impl InfiniteAnimationrust-analyzer cargo gnome-robots 50.0.0 animation/InfiniteAnimation# {
126 animationrust-analyzer cargo gnome-robots 50.0.0 animation/::sequencerust-analyzer cargo gnome-robots 50.0.0 animation/sequence().(PLAYER_ANIMATION_FRAMESrust-analyzer cargo gnome-robots 50.0.0 theme/PLAYER_ANIMATION_FRAMES.)
127 .limitrust-analyzer cargo gnome-robots 50.0.0 animation/Animation#limit().(1)
128 .repeatrust-analyzer cargo gnome-robots 50.0.0 animation/Animation#repeat().(20)
129 .thenrust-analyzer cargo gnome-robots 50.0.0 animation/Animation#then().(animationrust-analyzer cargo gnome-robots 50.0.0 animation/::bouncerust-analyzer cargo gnome-robots 50.0.0 animation/bounce().(PLAYER_ANIMATION_FRAMESrust-analyzer cargo gnome-robots 50.0.0 theme/PLAYER_ANIMATION_FRAMES.).repeatrust-analyzer cargo gnome-robots 50.0.0 animation/Animation#repeat().(2))
130 .foreverrust-analyzer cargo gnome-robots 50.0.0 animation/Animation#forever().()
131 }
132
133 pub fn player_dead_animationrust-analyzer cargo gnome-robots 50.0.0 theme/player_dead_animation().() -> impl InfiniteAnimationrust-analyzer cargo gnome-robots 50.0.0 animation/InfiniteAnimation# {
134 animationrust-analyzer cargo gnome-robots 50.0.0 animation/::bouncerust-analyzer cargo gnome-robots 50.0.0 animation/bounce().(PLAYER_DEAD_ANIMATION_FRAMESrust-analyzer cargo gnome-robots 50.0.0 theme/PLAYER_DEAD_ANIMATION_FRAMES.).foreverrust-analyzer cargo gnome-robots 50.0.0 animation/Animation#forever().()
135 }
136
137 pub fn robot1_animationrust-analyzer cargo gnome-robots 50.0.0 theme/robot1_animation().() -> impl InfiniteAnimationrust-analyzer cargo gnome-robots 50.0.0 animation/InfiniteAnimation# {
138 animationrust-analyzer cargo gnome-robots 50.0.0 animation/::sequencerust-analyzer cargo gnome-robots 50.0.0 animation/sequence().(ROBOT1_ANIMATION_FRAMESrust-analyzer cargo gnome-robots 50.0.0 theme/ROBOT1_ANIMATION_FRAMES.).foreverrust-analyzer cargo gnome-robots 50.0.0 animation/Animation#forever().()
139 }
140
141 pub fn robot2_animationrust-analyzer cargo gnome-robots 50.0.0 theme/robot2_animation().() -> impl InfiniteAnimationrust-analyzer cargo gnome-robots 50.0.0 animation/InfiniteAnimation# {
142 animationrust-analyzer cargo gnome-robots 50.0.0 animation/::sequencerust-analyzer cargo gnome-robots 50.0.0 animation/sequence().(ROBOT2_ANIMATION_FRAMESrust-analyzer cargo gnome-robots 50.0.0 theme/ROBOT2_ANIMATION_FRAMES.).foreverrust-analyzer cargo gnome-robots 50.0.0 animation/Animation#forever().()
143 }