mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-22 06:48:43 -06:00
why doesnt it work
This commit is contained in:
parent
da4a686100
commit
e75693926a
|
@ -2,11 +2,20 @@
|
|||
|
||||
in vec2 position;
|
||||
out vec2 uv;
|
||||
uniform vec2 ui_view;
|
||||
uniform vec2 element_position;
|
||||
uniform vec2 element_size;
|
||||
uniform mat4 ui_view;
|
||||
uniform mat3 transform;
|
||||
|
||||
//not sure if mat4(i) does the same thing
|
||||
mat4 extend(mat3 i) {
|
||||
mat4 o;
|
||||
o[0] = vec4(i[0].xyz, 0);
|
||||
o[1] = vec4(i[1].xyz, 0);
|
||||
o[2] = vec4(i[2].xyz, 0);
|
||||
o[3] = vec4(0, 0, 0, 1);
|
||||
return o;
|
||||
}
|
||||
|
||||
void main() {
|
||||
uv = position;
|
||||
gl_Position = vec4(ui_view * (element_position + (position * element_size)), 0.0, 1.0);
|
||||
gl_Position = ui_view * extend(transform) * vec4(position, 0., 1.);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use shipyard::{Component, Unique, Workload, IntoWorkload, AllStoragesView, AllStoragesViewMut};
|
||||
use glam::{Vec2, Vec4, vec2};
|
||||
use crate::color::color_hex;
|
||||
use glam::{Vec2, Vec4, Mat3, vec2, Mat4};
|
||||
use crate::{color::color_hex, transform::Transform2d};
|
||||
|
||||
pub mod text_widget;
|
||||
pub mod progressbar;
|
||||
|
@ -9,26 +9,11 @@ use progressbar::{render_progressbars, ProgressbarComponent};
|
|||
|
||||
//TODO compute gui scale on window resize
|
||||
#[derive(Unique, Clone, Copy, Debug)]
|
||||
pub struct GuiViewScale(pub Vec2);
|
||||
pub struct GuiView(pub Mat4);
|
||||
|
||||
#[derive(Component, Clone, Copy, Debug, Default)]
|
||||
pub struct GuiComponent;
|
||||
|
||||
#[derive(Component, Clone, Copy, Debug)]
|
||||
#[track(All)]
|
||||
pub struct GuiTransform {
|
||||
pub position: Vec2,
|
||||
pub scale: Vec2,
|
||||
}
|
||||
impl Default for GuiTransform {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
position: Vec2::ZERO,
|
||||
scale: Vec2::ONE,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component, Clone, Copy, Debug)]
|
||||
pub struct PrimaryColor(pub Vec4);
|
||||
impl Default for PrimaryColor {
|
||||
|
@ -54,7 +39,7 @@ pub fn render_gui() -> Workload {
|
|||
pub fn init_gui(
|
||||
storages: AllStoragesView,
|
||||
) {
|
||||
storages.add_unique(GuiViewScale(Vec2::ONE));
|
||||
storages.add_unique(GuiView(Mat4::orthographic_rh_gl(0.0, 1.0, 1.0, 0.0, 0.0, 1.0)));
|
||||
}
|
||||
|
||||
pub fn gui_testing(
|
||||
|
@ -62,10 +47,11 @@ pub fn gui_testing(
|
|||
) {
|
||||
storages.add_entity((
|
||||
GuiComponent,
|
||||
GuiTransform {
|
||||
position: Vec2::ZERO,
|
||||
scale: vec2(1.0, 0.05),
|
||||
},
|
||||
Transform2d(Mat3::from_scale_angle_translation(
|
||||
vec2(0.25, 0.05),
|
||||
0.,
|
||||
vec2(0.5, 0.)
|
||||
)),
|
||||
ProgressbarComponent {
|
||||
progress: 0.5
|
||||
},
|
||||
|
|
|
@ -5,9 +5,9 @@ use crate::{
|
|||
rendering::{
|
||||
RenderTarget,
|
||||
primitives::rect::RectPrimitive
|
||||
},
|
||||
}, transform::Transform2d,
|
||||
};
|
||||
use super::{GuiComponent, GuiTransform, PrimaryColor, SecondaryColor, GuiViewScale};
|
||||
use super::{GuiComponent, PrimaryColor, SecondaryColor, GuiView};
|
||||
|
||||
#[derive(Component, Debug, Clone, Copy, Default)]
|
||||
pub struct ProgressbarComponent {
|
||||
|
@ -18,9 +18,9 @@ pub fn render_progressbars(
|
|||
mut target: NonSendSync<UniqueViewMut<RenderTarget>>,
|
||||
rect: NonSendSync<UniqueView<RectPrimitive>>,
|
||||
program: NonSendSync<UniqueView<ProgressbarShaderPrefab>>,
|
||||
view: UniqueView<GuiViewScale>,
|
||||
view: UniqueView<GuiView>,
|
||||
components: View<GuiComponent>,
|
||||
transforms: View<GuiTransform>,
|
||||
transforms: View<Transform2d>,
|
||||
progressbars: View<ProgressbarComponent>,
|
||||
primary: View<PrimaryColor>,
|
||||
secondary: View<SecondaryColor>,
|
||||
|
@ -34,9 +34,8 @@ pub fn render_progressbars(
|
|||
&rect.1,
|
||||
&program.0,
|
||||
&uniform! {
|
||||
element_position: transform.position.to_array(),
|
||||
element_size: transform.scale.to_array(),
|
||||
ui_view: view.0.to_array(),
|
||||
transform: transform.0.to_cols_array_2d(),
|
||||
ui_view: view.0.to_cols_array_2d(),
|
||||
progress: progress.progress,
|
||||
color: pri.unwrap_or_default().0.to_array(),
|
||||
bg_color: sec.unwrap_or_default().0.to_array(),
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
use shipyard::Component;
|
||||
use glam::{Mat4, Vec2};
|
||||
use glam::{Mat4, Mat3};
|
||||
|
||||
#[derive(Component, Clone, Copy, Debug, Default)]
|
||||
#[track(All)]
|
||||
pub struct Transform(pub Mat4);
|
||||
|
||||
#[derive(Component, Clone, Copy, Debug, Default)]
|
||||
#[track(All)]
|
||||
pub struct Transform2d(pub Mat3);
|
||||
|
|
Loading…
Reference in a new issue