Skip to content

Commit

Permalink
Procedurally generate the toolbar buttons/icons
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitris Zervas <[email protected]>
  • Loading branch information
dzervas committed May 25, 2024
1 parent c0e0106 commit ad31bfc
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 21 deletions.
4 changes: 1 addition & 3 deletions applications/web/src/routes/(CADmium)/MainDisplay.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div
class="bg-white {$sketchTool === 'Line' || $sketchTool === 'Circle' || $sketchTool === 'Rectangle'
? 'cursor-crosshair'
: ''}"
class="bg-white {$sketchTool !== 'Select' ? 'cursor-crosshair' : ''}"
style="width:{viewportWidth}px; height:{height}px"
on:mousedown={(e) => {
if ($selectingFor.length > 0) {
Expand Down
4 changes: 0 additions & 4 deletions applications/web/src/routes/(CADmium)/PassiveSketch.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
import Face from "./Face.svelte"
import { LineMaterial } from "three/addons/lines/LineMaterial.js"
import { LineGeometry } from "three/addons/lines/LineGeometry.js"
import NewLineTool from "./tools/Line.svelte"
import NewCircleTool from "./tools/Circle.svelte"
import NewRectangleTool from "./tools/Rectangle.svelte"
import SelectTool from "./tools/Select.svelte"
import type {
ArcTuple,
CircleTuple,
Expand Down
4 changes: 2 additions & 2 deletions applications/web/src/routes/(CADmium)/Sketch.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { LineMaterial } from "three/examples/jsm/lines/LineMaterial.js"
import PassiveSketch from "./PassiveSketch.svelte"
import { currentlySelected, previewGeometry, sketchTool } from "shared/stores"
import type { PlaneRealized, SketchTuple } from "shared/types"
import type { PlaneRealized, SketchTuple, ToolType } from "shared/types"
// prettier-ignore
const log = (function () { const context = "[Sketch.svelte]"; const color="gray"; return Function.prototype.bind.call(console.log, console, `%c${context}`, `font-weight:bold;color:${color};`)})()
Expand All @@ -18,7 +18,7 @@
solidSelectedMaterial: LineMaterial,
collisionLineMaterial: LineMaterial
function setTool(tool: string): void {
function setTool(tool: ToolType): void {
$sketchTool = tool
$currentlySelected = []
$previewGeometry = []
Expand Down
28 changes: 17 additions & 11 deletions applications/web/src/routes/(CADmium)/ToolBar.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<script>
<script lang="ts">
import {
currentlySelected,
currentlyMousedOver,
Expand All @@ -9,15 +9,15 @@
workbench,
hiddenSketches
} from "shared/stores"
import * as AllTools from "./tools";
import { newExtrusion, newSketchOnPlane } from "shared/projectUtils"
import { base } from "$app/paths"
import type { ToolType } from "shared/types"
// prettier-ignore
const log = (function () { const context = "[ToolBar.svelte]"; const color="gray"; return Function.prototype.bind.call(console.log, console, `%c${context}`, `font-weight:bold;color:${color};`)})()
let solving = false
// todo ask Matt why is this a no-op?
const solveSketch = () => {}
const createNewExtrusion = () => {
newExtrusion()
// set that as the current feature being edited
Expand All @@ -28,7 +28,6 @@
newSketchOnPlane()
$featureIndex = $workbench.history.length - 1
}
const stepSketch = () => {}
const debugging = false
const actions = [
Expand All @@ -42,13 +41,20 @@
// { alt: 'plane', src: '/actions/plane_min.svg' }
]
const sketchActions = [
{ alt: "solve", src: `${base}/actions/solve_min.svg`, text: "Solve", handler: solveSketch },
{ alt: "step", src: `${base}/actions/step_min.svg`, text: "Step", handler: stepSketch },
{ alt: "line", src: `${base}/actions/line.svg`, handler: () => ($sketchTool = "Line") },
{ alt: "circle", src: `${base}/actions/circle.svg`, handler: () => ($sketchTool = "Circle") },
{ alt: "rectangle", src: `${base}/actions/rectangle.svg`, handler: () => ($sketchTool = "Rectangle") }
]
interface SketchActionType {
alt: string
src: string
text: string
// tooltip: string // TODO
handler: () => void
}
const sketchActions: SketchActionType[] = Object.keys(AllTools).filter(toolName => toolName !== "Select").map((toolName: string): SketchActionType => ({
alt: toolName,
src: `${base}/actions/${toolName.toLowerCase()}.svg`,
text: toolName,
handler: () => ($sketchTool = (toolName as ToolType))
}))
</script>

<div class="col-span-2 flex flex-none items-center gap-1 bg-gray-100 h-[45px] select-none">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
interface ToolComponentInstance {
name: string
// component: (new (...args: any[]) => AllTools.ToolComponentType)
component: AllTools.ToolComponentType
}
Expand All @@ -31,6 +30,10 @@
})
}))
export function getToolNames(): ToolType[] {
return instances.map(i => i.name as ToolType)
}
export function meshMouseMove(event: Event, data: Vector2) {
const inst = instances.find(i => i.name === $sketchTool)
inst !== undefined && inst.component.mouseMove(event, data)
Expand All @@ -41,3 +44,7 @@
inst !== undefined && inst.component.click(event, data)
}
</script>

<div
id="tool-instance"
></div>
58 changes: 58 additions & 0 deletions applications/web/static/actions/arc.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ad31bfc

Please sign in to comment.