Skip to content

Commit

Permalink
feat(floor-creator, frontend): show element angle
Browse files Browse the repository at this point in the history
  • Loading branch information
Smrtnyk committed Dec 27, 2024
1 parent 3e7cce5 commit bc698fe
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/floor-creator/src/elements/Bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,12 @@ export class Bar extends Group implements FloorEditorElement {
this.canvas?.requestRenderAll();
}

setAngle(angle: number): void {
this.angle = angle;
this.setCoords();
this.canvas?.requestRenderAll();
}

getBaseFill(): string {
return this.barBody.get("fill") as string;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/floor-creator/src/elements/Cloakroom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ export class Cloakroom extends Group implements FloorEditorElement {
this.canvas?.requestRenderAll();
}

setAngle(angle: number): void {
this.angle = angle;
this.setCoords();
this.canvas?.requestRenderAll();
}

getBaseFill(): string {
return this.counterBody.get("fill") as string;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/floor-creator/src/elements/DJBooth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ export class DJBooth extends Group implements FloorEditorElement {
this.canvas?.requestRenderAll();
}

setAngle(angle: number): void {
this.angle = angle;
this.setCoords();
this.canvas?.requestRenderAll();
}

getBaseFill(): string {
return "";
}
Expand Down
6 changes: 6 additions & 0 deletions packages/floor-creator/src/elements/Door.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ export class Door extends Group implements FloorEditorElement {
this.canvas?.requestRenderAll();
}

setAngle(angle: number): void {
this.angle = angle;
this.setCoords();
this.canvas?.requestRenderAll();
}

flip(): void {
// Store the current bounding rectangle before flipping
const boundingRectBefore = this.getBoundingRect();
Expand Down
6 changes: 6 additions & 0 deletions packages/floor-creator/src/elements/EditableShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ export class EditableShape extends Group implements FloorEditorElement {
this.canvas?.requestRenderAll();
}

setAngle(angle: number): void {
this.angle = angle;
this.setCoords();
this.canvas?.requestRenderAll();
}

setBaseFill(val: string): void {
this.shape.set("fill", val);
this.canvas?.requestRenderAll();
Expand Down
6 changes: 6 additions & 0 deletions packages/floor-creator/src/elements/Sofa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ export class Sofa extends Group implements FloorEditorElement {
this.canvas?.requestRenderAll();
}

setAngle(angle: number): void {
this.angle = angle;
this.setCoords();
this.canvas?.requestRenderAll();
}

getBaseFill(): string {
return this.sofaBase.get("fill") as string;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/floor-creator/src/elements/Stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ export class Stage extends Group implements FloorEditorElement {
this.canvas?.requestRenderAll();
}

setAngle(angle: number): void {
this.angle = angle;
this.setCoords();
this.canvas?.requestRenderAll();
}

getBaseFill(): string {
return "";
}
Expand Down
6 changes: 6 additions & 0 deletions packages/floor-creator/src/elements/Table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ export abstract class Table extends Group implements FloorEditorElement {
this.canvas?.requestRenderAll();
}

setAngle(angle: number): void {
this.angle = angle;
this.setCoords();
this.canvas?.requestRenderAll();
}

private handleScaling(): void {
this.enforceMinimumDimensions();
this.adjustTextScaling();
Expand Down
6 changes: 6 additions & 0 deletions packages/floor-creator/src/elements/Wall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ export class Wall extends Group implements FloorEditorElement {
this.canvas?.requestRenderAll();
}

setAngle(angle: number): void {
this.angle = angle;
this.setCoords();
this.canvas?.requestRenderAll();
}

changeToOutlinedMode(): void {
this.wallRect.set({
// Makes the background transparent
Expand Down
1 change: 1 addition & 0 deletions packages/floor-creator/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface FloorEditorElement extends FabricObject {
changeToFilledMode?(): void;

setDimensions(width: number, height: number): void;
setAngle(angle: number): void;
nextDesign?(): void;
}

Expand Down
16 changes: 16 additions & 0 deletions packages/frontend/src/components/Floor/FloorEditorTopControls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,32 @@ const getElementHeight = computed(function () {
? Math.round(selectedFloorElement.height * selectedFloorElement.scaleY)
: 0;
});
const getElementAngle = computed(() => (selectedFloorElement ? selectedFloorElement.angle : 0));
const localWidth = ref(getElementWidth.value);
const localHeight = ref(getElementHeight.value);
const localAngle = ref(getElementAngle.value);
const elementColor = ref(selectedFloorElement?.getBaseFill?.() ?? "");
watch(
() => selectedFloorElement,
function (newEl) {
localWidth.value = newEl ? Math.round(newEl.width * newEl.scaleX) : 0;
localHeight.value = newEl ? Math.round(newEl.height * newEl.scaleY) : 0;
localAngle.value = newEl ? newEl.angle : 0;
if (newEl?.getBaseFill) {
elementColor.value = newEl.getBaseFill();
}
},
{ immediate: true, deep: true },
);
watch(localAngle, (newAngle) => {
if (!selectedFloorElement) return;
selectedFloorElement.setAngle(newAngle);
});
watch(localWidth, function (newWidth) {
if (!selectedFloorElement) {
return;
Expand Down Expand Up @@ -120,6 +130,12 @@ onMounted(function () {
<div class="col-2">
<q-input rounded v-model.number="localHeight" standout type="number" label="Height" />
</div>

<!-- Angle Control -->
<div class="col-2">
<q-input rounded v-model.number="localAngle" standout type="number" label="Angle°" />
</div>

<div class="col-3" v-if="isTable(selectedFloorElement)">
<q-input
:debounce="500"
Expand Down

0 comments on commit bc698fe

Please sign in to comment.