Skip to content

Commit b1b8b41

Browse files
committed
init
1 parent 856b4dc commit b1b8b41

5 files changed

Lines changed: 55 additions & 15 deletions

File tree

src/app_state.rs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::canvas::{CanvasTransform, Uniforms};
2-
use crate::drawing::{DrawingElement, Tool};
2+
use crate::drawing::{DrawingElement, Style, Tool};
33
use crate::state::{
4-
Canvas, GeometryBuffers, GpuContext, InputState, TextInput, UiBuffers,
5-
UiScreenBuffers, UiScreenUniforms, UserInputState::Idle,
4+
Canvas, GeometryBuffers, GpuContext, InputState, TextInput, UiBuffers, UiScreenBuffers,
5+
UiScreenUniforms, UserInputState::Idle,
66
};
77
use crate::text_renderer::TextRenderer;
88
use crate::ui::UiRenderer;
@@ -34,6 +34,7 @@ pub struct State {
3434
pub elements: Vec<DrawingElement>,
3535
pub current_tool: Tool,
3636
pub current_color: [f32; 4],
37+
pub current_style: Style,
3738
pub stroke_width: f32,
3839

3940
pub ui_renderer: UiRenderer,
@@ -44,7 +45,7 @@ pub struct State {
4445
impl State {
4546
pub async fn new(window: Arc<Window>) -> State {
4647
let mut size = window.inner_size();
47-
48+
4849
#[cfg(target_arch = "wasm32")]
4950
{
5051
if size.width == 0 || size.height == 0 {
@@ -195,9 +196,7 @@ impl State {
195196

196197
let ui_shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
197198
label: Some("UI Shader"),
198-
source: wgpu::ShaderSource::Wgsl(
199-
include_str!("../data/shaders/ui_shader.wgsl").into(),
200-
),
199+
source: wgpu::ShaderSource::Wgsl(include_str!("../data/shaders/ui_shader.wgsl").into()),
201200
});
202201

203202
let ui_uniform_bind_group_layout =
@@ -311,18 +310,26 @@ impl State {
311310
};
312311

313312
let ui_renderer = UiRenderer::new();
314-
let text_renderer = TextRenderer::new(&gpu.device, &gpu.queue, surface_format, &uniform_bind_group_layout, &ui_uniform_bind_group_layout);
313+
let text_renderer = TextRenderer::new(
314+
&gpu.device,
315+
&gpu.queue,
316+
surface_format,
317+
&uniform_bind_group_layout,
318+
&ui_uniform_bind_group_layout,
319+
);
315320

316321
let ui_screen_uniforms = UiScreenUniforms {
317322
screen_size: [size.width as f32, size.height as f32],
318323
_padding: [0.0, 0.0],
319324
};
320325

321-
let ui_screen_uniform_buffer = gpu.device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
322-
label: Some("UI Screen Uniform Buffer"),
323-
contents: bytemuck::cast_slice(&[ui_screen_uniforms]),
324-
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
325-
});
326+
let ui_screen_uniform_buffer =
327+
gpu.device
328+
.create_buffer_init(&wgpu::util::BufferInitDescriptor {
329+
label: Some("UI Screen Uniform Buffer"),
330+
contents: bytemuck::cast_slice(&[ui_screen_uniforms]),
331+
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
332+
});
326333

327334
let ui_screen_bind_group = gpu.device.create_bind_group(&wgpu::BindGroupDescriptor {
328335
layout: &ui_uniform_bind_group_layout,
@@ -338,6 +345,8 @@ impl State {
338345
bind_group: ui_screen_bind_group,
339346
};
340347

348+
let current_style = Style::Solid;
349+
341350
Self {
342351
window,
343352
size,
@@ -349,15 +358,16 @@ impl State {
349358
typing,
350359
elements: Vec::new(),
351360
current_tool: Tool::Pen,
352-
current_color: [0.0, 0.0, 0.0, 1.0],
361+
current_color: [0.0, 0.0, 0.0, 1.0],
353362
stroke_width: 2.0,
354363
ui_renderer,
355364
text_renderer,
356365
ui_screen,
366+
current_style,
357367
}
358368
}
359369

360370
pub fn window(&self) -> &Arc<Window> {
361371
&self.window
362372
}
363-
}
373+
}

src/drawing.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ pub enum Tool {
1111
Select,
1212
}
1313

14+
#[derive(Debug, Clone, Copy, PartialEq)]
15+
pub enum Style {
16+
Dotted,
17+
Solid,
18+
}
19+
1420
#[derive(Debug, Clone, Copy, PartialEq)]
1521
pub enum BoxState {
1622
Idle,
@@ -31,6 +37,7 @@ pub enum DrawingElement {
3137
color: [f32; 4],
3238
width: f32,
3339
rough_style: Option<crate::rough::RoughOptions>,
40+
style: Style,
3441
},
3542
Rectangle {
3643
position: [f32; 2],
@@ -39,6 +46,7 @@ pub enum DrawingElement {
3946
fill: bool,
4047
stroke_width: f32,
4148
rough_style: Option<crate::rough::RoughOptions>,
49+
style: Style,
4250
},
4351
Circle {
4452
center: [f32; 2],
@@ -47,6 +55,7 @@ pub enum DrawingElement {
4755
fill: bool,
4856
stroke_width: f32,
4957
rough_style: Option<crate::rough::RoughOptions>,
58+
style: Style,
5059
},
5160
Diamond {
5261
position: [f32; 2],
@@ -55,13 +64,15 @@ pub enum DrawingElement {
5564
fill: bool,
5665
stroke_width: f32,
5766
rough_style: Option<crate::rough::RoughOptions>,
67+
style: Style,
5868
},
5969
Arrow {
6070
start: [f32; 2],
6171
end: [f32; 2],
6272
color: [f32; 4],
6373
width: f32,
6474
rough_style: Option<crate::rough::RoughOptions>,
75+
style: Style,
6576
},
6677
Text {
6778
position: [f32; 2],

src/event_handler.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ impl State {
480480
fill: false,
481481
stroke_width: self.stroke_width,
482482
rough_style: Some(rough_options),
483+
style: self.current_style,
483484
})
484485
} else {
485486
None
@@ -510,6 +511,7 @@ impl State {
510511
fill: false,
511512
stroke_width: self.stroke_width,
512513
rough_style: Some(rough_options),
514+
style: self.current_style,
513515
})
514516
} else {
515517
None
@@ -538,6 +540,7 @@ impl State {
538540
color: self.current_color,
539541
width: self.stroke_width,
540542
rough_style: Some(rough_options),
543+
style: self.current_style,
541544
})
542545
} else {
543546
None
@@ -566,6 +569,7 @@ impl State {
566569
color: self.current_color,
567570
width: self.stroke_width,
568571
rough_style: Some(rough_options),
572+
style: self.current_style,
569573
})
570574
} else {
571575
None
@@ -596,6 +600,7 @@ impl State {
596600
fill: false,
597601
stroke_width: self.stroke_width,
598602
rough_style: Some(rough_options),
603+
style: self.current_style,
599604
})
600605
} else {
601606
None
@@ -638,6 +643,7 @@ impl State {
638643
fill: false,
639644
stroke_width: self.stroke_width,
640645
rough_style: None,
646+
style: self.current_style,
641647
});
642648
}
643649
}
@@ -658,6 +664,7 @@ impl State {
658664
fill: false,
659665
stroke_width: self.stroke_width,
660666
rough_style: None,
667+
style: self.current_style,
661668
});
662669
}
663670
}
@@ -676,6 +683,7 @@ impl State {
676683
],
677684
width: self.stroke_width,
678685
rough_style: None,
686+
style: self.current_style,
679687
});
680688
}
681689
}
@@ -694,6 +702,7 @@ impl State {
694702
],
695703
width: self.stroke_width,
696704
rough_style: None,
705+
style: self.current_style,
697706
});
698707
}
699708
}
@@ -715,6 +724,7 @@ impl State {
715724
fill: false,
716725
stroke_width: self.stroke_width,
717726
rough_style: None,
727+
style: self.current_style,
718728
});
719729
}
720730
}
@@ -769,6 +779,7 @@ impl State {
769779
fill,
770780
stroke_width,
771781
rough_style,
782+
style,
772783
} => {
773784
let half_width = size[0] / 2.0;
774785
let half_height = size[1] / 2.0;

src/update_logic.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ impl State {
153153
fill,
154154
stroke_width,
155155
rough_style,
156+
style,
156157
} => {
157158
if let Some(rough_options) = rough_style {
158159
let mut generator = crate::rough::RoughGenerator::new(rough_options.seed);
@@ -258,6 +259,7 @@ impl State {
258259
fill,
259260
stroke_width,
260261
rough_style,
262+
style,
261263
} => {
262264
if let Some(rough_options) = rough_style {
263265
let mut generator = crate::rough::RoughGenerator::new(rough_options.seed);
@@ -371,6 +373,7 @@ impl State {
371373
fill,
372374
stroke_width,
373375
rough_style,
376+
style,
374377
} => {
375378
if let Some(rough_options) = rough_style {
376379
let mut generator = crate::rough::RoughGenerator::new(rough_options.seed);
@@ -475,6 +478,7 @@ impl State {
475478
color,
476479
width,
477480
rough_style,
481+
style,
478482
} => {
479483
if let Some(rough_options) = rough_style {
480484
let mut generator = crate::rough::RoughGenerator::new(rough_options.seed);
@@ -619,6 +623,7 @@ impl State {
619623
color,
620624
width,
621625
rough_style,
626+
style,
622627
} => {
623628
if let Some(rough_options) = rough_style {
624629
let mut generator = crate::rough::RoughGenerator::new(rough_options.seed);

todo.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@
2121
- Brush Styles
2222
- Dotted
2323
- Solid
24+
25+
- Refactor
26+
- A lot of shared functionality that can be refactored into functions to reduce LOC

0 commit comments

Comments
 (0)