Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OrbGame
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
4
Issues
4
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
redox-os
OrbGame
Commits
6f180743
Commit
6f180743
authored
Jul 22, 2020
by
Florian Blasius
🤘
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
OrbTk update.
parent
5261e3d6
Pipeline
#8080
failed with stages
in 3 minutes and 37 seconds
Changes
9
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
401 additions
and
397 deletions
+401
-397
Cargo.lock
Cargo.lock
+265
-284
README.md
README.md
+2
-2
crates/api/src/render_object/tile_map.rs
crates/api/src/render_object/tile_map.rs
+8
-6
crates/utils/src/camera.rs
crates/utils/src/camera.rs
+37
-31
examples/dungeon.rs
examples/dungeon.rs
+50
-69
examples/minimal.rs
examples/minimal.rs
+2
-2
res/dungeon/dungeon_theme.ron
res/dungeon/dungeon_theme.ron
+34
-0
src/lib.rs
src/lib.rs
+1
-1
src/prelude.rs
src/prelude.rs
+2
-2
No files found.
Cargo.lock
View file @
6f180743
This diff is collapsed.
Click to expand it.
README.md
View file @
6f180743
...
...
@@ -33,11 +33,11 @@ use orbgame::prelude::*;
fn
main
()
{
Game
::
new
()
.window
(|
ctx
|
{
Window
::
create
()
Window
::
new
()
.title
(
"OrbGame - minimal example"
)
.position
((
100.0
,
100.0
))
.size
(
420.0
,
730.0
)
.child
(
TextBlock
::
create
()
.text
(
"OrbGame"
)
.build
(
ctx
))
.child
(
TextBlock
::
new
()
.text
(
"OrbGame"
)
.build
(
ctx
))
.build
(
ctx
)
})
.run
();
...
...
crates/api/src/render_object/tile_map.rs
View file @
6f180743
...
...
@@ -19,16 +19,16 @@ impl TileMapRenderObject {
)
{
let
mut
y
=
y
as
i32
;
let
stride
=
image
.width
();
let
mut
offset
=
clip
.y
.mul_add
(
stride
,
clip
.x
)
as
usize
;
let
mut
offset
=
clip
.y
()
.mul_add
(
stride
,
clip
.x
()
)
as
usize
;
let
last_offset
=
cmp
::
min
(
((
clip
.y
+
clip
.height
)
.mul_add
(
stride
,
clip
.x
))
as
usize
,
((
clip
.y
()
+
clip
.height
())
.mul_add
(
stride
,
clip
.x
()
))
as
usize
,
image
.data
()
.len
(),
);
while
offset
<
last_offset
{
let
next_offset
=
offset
+
stride
as
usize
;
for
i
in
0
..
clip
.width
as
usize
{
for
i
in
0
..
clip
.width
()
as
usize
{
let
index
=
(
x
as
f64
+
y
as
f64
*
render_target
.width
())
.floor
()
as
usize
+
i
;
render_target
.data_mut
()[
index
]
=
image
.data
()[
offset
+
i
];
}
...
...
@@ -74,7 +74,7 @@ impl RenderObject for TileMapRenderObject {
for
l
in
0
..
map
.layer_count
{
let
mut
render_target
=
RenderTarget
::
new
(
bounds
.width
()
as
u32
,
bounds
.height
as
u32
);
RenderTarget
::
new
(
bounds
.width
()
as
u32
,
bounds
.height
()
as
u32
);
// add 1 to prevent missing tiles at the borders
let
mut
end_column
=
end_column
+
1
;
...
...
@@ -109,8 +109,10 @@ impl RenderObject for TileMapRenderObject {
&
mut
render_target
,
image
,
Rectangle
::
new
(
tile_c
as
f64
*
map
.tile_size
()
as
f64
,
tile_r
as
f64
*
map
.tile_size
()
as
f64
,
Point
::
new
(
tile_c
as
f64
*
map
.tile_size
()
as
f64
,
tile_r
as
f64
*
map
.tile_size
()
as
f64
,
),
map
.tile_size
as
f64
,
map
.tile_size
as
f64
,
),
...
...
crates/utils/src/camera.rs
View file @
6f180743
...
...
@@ -16,37 +16,37 @@ impl CameraBuilder {
/// Inserts a x.
pub
fn
x
(
mut
self
,
x
:
f64
)
->
Self
{
self
.rect.
x
=
x
;
self
.rect
.
set_x
(
x
)
;
self
}
/// Inserts a y.
pub
fn
y
(
mut
self
,
y
:
f64
)
->
Self
{
self
.rect.
y
=
y
;
self
.rect
.
set_y
(
y
)
;
self
}
/// Inserts a width.
pub
fn
width
(
mut
self
,
width
:
f64
)
->
Self
{
self
.rect.
width
=
width
;
self
.rect
.
set_width
(
width
)
;
self
}
/// Inserts a height.
pub
fn
height
(
mut
self
,
height
:
f64
)
->
Self
{
self
.rect.
height
=
height
;
self
.rect
.
set_height
(
height
)
;
self
}
/// Inserts a max_width.
pub
fn
max_width
(
mut
self
,
max_width
:
f64
)
->
Self
{
self
.maximum.
x
=
max_width
;
self
.maximum
.
set_x
(
max_width
)
;
self
}
/// Inserts a max_height.
pub
fn
max_height
(
mut
self
,
max_height
:
f64
)
->
Self
{
self
.maximum.
y
=
max_height
;
self
.maximum
.
set_y
(
max_height
)
;
self
}
...
...
@@ -95,64 +95,63 @@ impl Camera {
/// Gets x.
pub
fn
x
(
&
self
)
->
f64
{
self
.rect.x
self
.rect
.x
()
}
/// Sets x.
pub
fn
set_x
(
&
mut
self
,
x
:
f64
)
{
self
.rect.
x
=
x
;
self
.rect
.
set_y
(
x
)
;
}
/// Gets y.
pub
fn
y
(
&
self
)
->
f64
{
self
.rect.y
self
.rect
.y
()
}
/// Sets y.
pub
fn
set_y
(
&
mut
self
,
y
:
f64
)
{
self
.rect.
y
=
y
;
self
.rect
.
set_y
(
y
)
;
}
/// Gets position.
pub
fn
position
(
&
self
)
->
(
f64
,
f64
)
{
(
self
.rect.x
,
self
.rect.y
)
(
self
.rect
.x
(),
self
.rect
.y
()
)
}
/// Sets position.
pub
fn
set_position
(
&
mut
self
,
x
:
f64
,
y
:
f64
)
{
self
.rect.
x
=
x
;
self
.rect.
y
=
y
;
self
.rect
.
set_x
(
x
)
;
self
.rect
.
set_y
(
y
)
;
}
/// Gets with.
pub
fn
width
(
&
self
)
->
f64
{
self
.rect.width
self
.rect
.width
()
}
/// Sets width.
pub
fn
set_width
(
&
mut
self
,
width
:
f64
)
{
self
.rect.
width
=
width
;
self
.rect
.
set_width
(
width
)
;
}
/// Gets height.
pub
fn
height
(
&
self
)
->
f64
{
self
.rect.height
self
.rect
.height
()
}
/// Sets height.
pub
fn
set_height
(
&
mut
self
,
height
:
f64
)
{
self
.rect.
height
=
height
;
self
.rect
.
set_height
(
height
)
;
}
/// Gets size.
pub
fn
size
(
&
self
)
->
(
f64
,
f64
)
{
(
self
.rect.width
,
self
.rect.height
)
(
self
.rect
.width
(),
self
.rect
.height
()
)
}
/// Sets size.
pub
fn
set_size
(
&
mut
self
,
width
:
f64
,
height
:
f64
)
{
self
.rect.width
=
width
;
self
.rect.height
=
height
;
self
.rect
.set_size
(
width
,
height
);
}
/// Gets maximum.
...
...
@@ -162,8 +161,8 @@ impl Camera {
/// Sets maximum.
pub
fn
set_maximum
(
&
mut
self
,
x
:
f64
,
y
:
f64
)
{
self
.maximum.
x
=
x
;
self
.maximum.
y
=
y
;
self
.maximum
.
set_x
(
x
)
;
self
.maximum
.
set_y
(
y
)
;
}
/// Gets speed.
...
...
@@ -178,14 +177,18 @@ impl Camera {
/// Moves the camera.
pub
fn
mov
(
&
mut
self
,
delta
:
f64
,
dir_x
:
f64
,
dir_y
:
f64
)
{
self
.rect.x
+=
(
dir_x
as
f64
*
self
.speed
as
f64
*
delta
)
as
f64
;
self
.rect.y
+=
(
dir_y
as
f64
*
self
.speed
as
f64
*
delta
)
as
f64
;
self
.rect
.set_x
(
self
.rect
.x
()
+
(
dir_x
as
f64
*
self
.speed
as
f64
*
delta
)
as
f64
);
self
.rect
.set_y
(
self
.rect
.y
()
+
(
dir_y
as
f64
*
self
.speed
as
f64
*
delta
)
as
f64
);
let
zero
:
f64
=
0.0
;
// adjust to respect the render_camera
self
.rect.x
=
zero
.max
(
self
.rect.x
.min
(
self
.maximum.x
));
self
.rect.y
=
zero
.max
(
self
.rect.y
.min
(
self
.maximum.y
));
self
.rect
.set_x
(
zero
.max
(
self
.rect
.x
()
.min
(
self
.maximum
.x
())));
self
.rect
.set_y
(
zero
.max
(
self
.rect
.y
()
.min
(
self
.maximum
.y
())));
}
// pub fn follow(&mut self, entity: &mut Entity) {
...
...
@@ -287,7 +290,7 @@ mod tests {
#[test]
fn
test_mov
()
{
let
mut
camera
=
Camera
::
new
(
Rectangle
::
new
(
0.0
,
0.0
,
10.0
,
10.0
),
Rectangle
::
new
(
Point
::
new
(
0.0
,
0.0
)
,
10.0
,
10.0
),
Point
::
new
(
100.0
,
50.0
),
);
camera
.mov
(
0.2
,
-
10.0
,
-
10.0
);
...
...
@@ -295,14 +298,14 @@ mod tests {
assert_eq!
(
0.0
,
camera
.y
());
camera
=
Camera
::
new
(
Rectangle
::
new
(
0.0
,
0.0
,
10.0
,
10.0
),
Rectangle
::
new
(
Point
::
new
(
0.0
,
0.0
)
,
10.0
,
10.0
),
Point
::
new
(
100.0
,
50.0
),
);
camera
.mov
(
1.0
,
200.0
,
200.0
);
assert_eq!
(
100.0
,
camera
.x
());
assert_eq!
(
50.0
,
camera
.y
());
camera
=
Camera
::
new
(
Rectangle
::
new
(
0.0
,
0.0
,
10.0
,
10.0
),
Rectangle
::
new
(
Point
::
new
(
0.0
,
0.0
)
,
10.0
,
10.0
),
Point
::
new
(
100.0
,
50.0
),
);
camera
.mov
(
1.0
,
-
10.0
,
200.0
);
...
...
@@ -316,8 +319,11 @@ mod tests {
assert_eq!
(
6.0
,
Camera
::
create
()
.y
(
6.0
)
.build
()
.y
());
assert_eq!
(
7.0
,
Camera
::
create
()
.width
(
7.0
)
.build
()
.width
());
assert_eq!
(
8.0
,
Camera
::
create
()
.height
(
8.0
)
.build
()
.height
());
assert_eq!
(
9.0
,
Camera
::
create
()
.max_width
(
9.0
)
.build
()
.maximum
()
.x
);
assert_eq!
(
10.0
,
Camera
::
create
()
.max_height
(
10.0
)
.build
()
.maximum
()
.y
);
assert_eq!
(
9.0
,
Camera
::
create
()
.max_width
(
9.0
)
.build
()
.maximum
()
.x
());
assert_eq!
(
10.0
,
Camera
::
create
()
.max_height
(
10.0
)
.build
()
.maximum
()
.y
()
);
assert_eq!
(
11.0
,
Camera
::
create
()
.speed
(
11.0
)
.build
()
.speed
());
}
}
examples/dungeon.rs
View file @
6f180743
use
orbgame
::
prelude
::
*
;
use
orbgame
::
theme
::
DEFAULT_THEME_CSS
;
use
orbgame
::{
prelude
::
*
,
theme
::{
COLORS_RON
,
DARK_THEME_RON
,
FONTS_RON
},
theming
::
config
::
ThemeConfig
,
};
use
std
::{
cell
::
RefCell
,
rc
::
Rc
};
static
DUNGEON_
THEME
:
&
'static
str
=
include_str!
(
"../res/dungeon/theme.css
"
);
static
DUNGEON_
EXT
:
&
'static
str
=
include_str!
(
"../res/dungeon/dungeon_theme.ron
"
);
fn
get_theme
()
->
ThemeValue
{
ThemeValue
::
create_from_css
(
DEFAULT_THEME_CSS
)
.extension_css
(
DUNGEON_THEME
)
.build
()
fn
theme
()
->
Theme
{
Theme
::
from_config
(
ThemeConfig
::
from
(
DARK_THEME_RON
)
.extend
(
ThemeConfig
::
from
(
DUNGEON_EXT
))
.extend
(
ThemeConfig
::
from
(
COLORS_RON
))
.extend
(
ThemeConfig
::
from
(
FONTS_RON
)),
)
}
#[derive(Copy,
Clone)]
...
...
@@ -29,49 +35,29 @@ impl MapViewState {
impl
State
for
MapViewState
{
fn
update
(
&
mut
self
,
_
:
&
mut
Registry
,
ctx
:
&
mut
Context
<
'_
>
)
{
if
let
Some
(
action
)
=
self
.action
{
if
let
Some
(
window_id
)
=
ctx
.parent_entity_by_element
(
"window"
)
{
match
action
{
MapViewAction
::
OpenMenu
=>
{
ctx
.push_event_by_entity
(
GameEvent
::
OpenMenu
,
window_id
);
}
match
action
{
MapViewAction
::
OpenMenu
=>
{
ctx
.push_event_by_window
(
GameEvent
::
OpenMenu
);
}
}
self
.action
=
None
;
}
// workaround
if
let
Some
(
old_focused_element
)
=
ctx
.window
()
.get
::
<
Global
>
(
"global"
)
.focused_widget
{
if
old_focused_element
==
ctx
.entity
{
return
;
}
let
mut
old_focused_element
=
ctx
.get_widget
(
old_focused_element
);
old_focused_element
.set
(
"focused"
,
false
);
old_focused_element
.update_theme_by_state
(
false
);
}
ctx
.window
()
.get_mut
::
<
Global
>
(
"global"
)
.focused_widget
=
Some
(
ctx
.entity
);
ctx
.widget
()
.set
(
"focused"
,
true
);
ctx
.widget
()
.update_theme_by_state
(
false
);
}
}
widget!
(
MapView
<
MapViewState
>
:
KeyDownHandler
{
focused
:
bool
});
widget!
(
MapView
<
MapViewState
>
:
KeyDownHandler
);
impl
Template
for
MapView
{
fn
template
(
self
,
id
:
Entity
,
ctx
:
&
mut
BuildContext
)
->
Self
{
self
.name
(
"MapView"
)
.focused
(
false
)
.child
(
Container
::
create
()
.
element
(
"container"
)
Container
::
new
()
.
style
(
"container"
)
.child
(
Grid
::
create
()
Grid
::
new
()
.child
(
TileMap
::
create
()
TileMap
::
new
()
.camera
(
CameraBuilder
::
new
()
.x
(
0.0
)
...
...
@@ -87,9 +73,9 @@ impl Template for MapView {
.build
(
ctx
),
)
.child
(
TextBlock
::
create
()
TextBlock
::
new
()
.text
(
"Press ESC to open menu"
)
.v
ertical_alignment
(
"bottom"
)
.v
_align
(
"bottom"
)
.margin
(
4.0
)
.build
(
ctx
),
)
...
...
@@ -128,14 +114,12 @@ impl MenuViewState {
impl
State
for
MenuViewState
{
fn
update
(
&
mut
self
,
_
:
&
mut
Registry
,
ctx
:
&
mut
Context
<
'_
>
)
{
if
let
Some
(
action
)
=
self
.action
{
if
let
Some
(
window_id
)
=
ctx
.parent_entity_by_element
(
"window"
)
{
match
action
{
MenuAction
::
Start
=>
{
ctx
.push_event_by_entity
(
GameEvent
::
StartGame
,
window_id
);
}
MenuAction
::
Quit
=>
{
ctx
.push_event_by_entity
(
GameEvent
::
Quit
,
window_id
);
}
match
action
{
MenuAction
::
Start
=>
{
ctx
.push_event_by_window
(
GameEvent
::
StartGame
);
}
MenuAction
::
Quit
=>
{
ctx
.push_event_by_window
(
GameEvent
::
Quit
);
}
}
...
...
@@ -151,30 +135,27 @@ widget!(
impl
Template
for
MenuView
{
fn
template
(
self
,
id
:
Entity
,
ctx
:
&
mut
BuildContext
)
->
Self
{
self
.name
(
"MenuView"
)
.child
(
Grid
::
create
()
.element
(
"grid"
)
.class
(
"start"
)
Grid
::
new
()
.style
(
"start"
)
.child
(
Container
::
create
()
Container
::
new
()
.padding
(
16.0
)
.min_width
(
120.0
)
.element
(
"container"
)
.class
(
"menu"
)
.vertical_alignment
(
"center"
)
.horizontal_alignment
(
"center"
)
.style
(
"menu"
)
.v_align
(
"center"
)
.h_align
(
"center"
)
.child
(
Stack
::
create
()
Stack
::
new
()
.child
(
TextBlock
::
create
()
.element
(
"textblock"
)
.class
(
"h1"
)
TextBlock
::
new
()
.style
(
"header"
)
.text
(
"Dungeon"
)
.h
orizontal_alignment
(
"Center"
)
.h
_align
(
"Center"
)
.build
(
ctx
),
)
.child
(
Button
::
create
()
.
class
(
"
single_content"
)
Button
::
new
()
.
style
(
"button_
single_content"
)
.margin
((
0.0
,
16.0
,
0.0
,
0.0
))
.text
(
"Start Game"
)
.on_click
(
move
|
states
,
_
|
{
...
...
@@ -186,8 +167,8 @@ impl Template for MenuView {
.build
(
ctx
),
)
.child
(
Button
::
create
()
.
class
(
"
single_content"
)
Button
::
new
()
.
style
(
"button_
single_content"
)
.margin
((
0.0
,
8.0
,
0.0
,
0.0
))
.text
(
"Quit"
)
.on_click
(
move
|
states
,
_
|
{
...
...
@@ -290,7 +271,7 @@ impl State for GameViewState {
}
}
widget!
(
GameView
<
GameViewState
>
{
selector
:
Selector
}
);
widget!
(
GameView
<
GameViewState
>
);
impl
GameView
{
fn
on_game_event
<
H
:
Fn
(
&
mut
StatesContext
,
&
GameEvent
)
->
bool
+
'static
>
(
...
...
@@ -308,14 +289,14 @@ impl Template for GameView {
self
.name
(
"GameView"
)
.id
(
"game_view"
)
.child
(
Grid
::
create
()
Grid
::
new
()
.child
(
MapView
::
create
()
MapView
::
new
()
.id
(
"map_view"
)
.visibility
(
"collapsed"
)
.build
(
ctx
),
)
.child
(
MenuView
::
create
()
.id
(
"menu_view"
)
.build
(
ctx
))
.child
(
MenuView
::
new
()
.id
(
"menu_view"
)
.build
(
ctx
))
.build
(
ctx
),
)
.on_game_event
(
move
|
states
,
e
|
{
...
...
@@ -327,13 +308,13 @@ impl Template for GameView {
fn
main
()
{
Game
::
new
()
.theme
(
theme
())
.window
(|
ctx
|
{
Window
::
create
()
Window
::
new
()
.title
(
"OrbGame - dungeon example"
)
.position
((
100.0
,
100.0
))
.size
(
800.0
,
600.0
)
.theme
(
get_theme
())
.child
(
GameView
::
create
()
.build
(
ctx
))
.child
(
GameView
::
new
()
.build
(
ctx
))
.build
(
ctx
)
})
.run
();
...
...
examples/minimal.rs
View file @
6f180743
...
...
@@ -3,11 +3,11 @@ use orbgame::prelude::*;
fn
main
()
{
Game
::
new
()
.window
(|
ctx
|
{
Window
::
create
()
Window
::
new
()
.title
(
"OrbGame - minimal example"
)
.position
((
100.0
,
100.0
))
.size
(
420.0
,
730.0
)
.child
(
TextBlock
::
create
()
.text
(
"OrbGame"
)
.build
(
ctx
))
.child
(
TextBlock
::
new
()
.text
(
"OrbGame"
)
.build
(
ctx
))
.build
(
ctx
)
})
.run
();
...
...
res/dungeon/dungeon_theme.ron
0 → 100644
View file @
6f180743
Theme (
styles: {
"window": (
properties: {
"background": "#25131a",
},
),
"menu": (
properties: {
"background": "#6e4a48",
"border_brush": "#472b43",
"border_radius": 2,
"border_width": 2
}
),
"button": (
base: "base",
properties: {
"height": 36,
"foreground": "$WHITE",
"icon_brush": "$WHITE",
"background": "#895a45",
"border_radius": 2,
"border_width": 4,
"border_brush": "#3d253b"
},
states: {
"pressed": {
"background": "#724736",
},
},
),
},
)
src/lib.rs
View file @
6f180743
pub
use
orbgame_api
::
prelude
as
api
;
pub
use
orbgame_utils
::
prelude
as
utils
;
pub
use
orbgame_widgets
::
prelude
as
widgets
;
pub
use
orbtk
::
css_engine
;
pub
use
orbtk
::
proc_macros
;
pub
use
orbtk
::
render
;
pub
use
orbtk
::
shell
;
pub
use
orbtk
::
theme
;
pub
use
orbtk
::
theming
;
pub
use
orbtk
::
tree
;
pub
use
shell
::
initialize
;
...
...
src/prelude.rs
View file @
6f180743
...
...
@@ -8,11 +8,11 @@ pub use std::{
pub
use
crate
::{
api
::
*
,
css_engine
::{
Selector
as
SelectorValue
,
SelectorRelation
,
Theme
as
ThemeValue
,
ThemeBuilder
},
proc_macros
::
*
,
render
,
shell
::
Key
,
theme
::{
colors
,
default_theme
,
fonts
,
light_theme
,
vector_graphics
::
material_font_icons
},
theme
::{
colors
,
dark_theme
,
fonts
,
light_theme
,
vector_graphics
::
material_icons_font
},
theming
::
prelude
::
*
,
tree
::
*
,
utils
::
*
,
widgets
::
*
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment