Skip to content

Commit

Permalink
refactor: Use painter.getPosition method
Browse files Browse the repository at this point in the history
  • Loading branch information
warxander committed Nov 13, 2023
1 parent 1370f38 commit 7842e2b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
8 changes: 2 additions & 6 deletions src/core/painter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,8 @@ export class Painter {
this.setMouseCursor(MouseCursor.Grab);
}

getX(): number {
return this.position.x;
}

getY(): number {
return this.position.y;
getPosition(): Vector2 {
return this.position;
}

beginRow() {
Expand Down
4 changes: 2 additions & 2 deletions src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ export function getContext(): IContext {
},

getPosition(): [number, number] {
const painter = context.getPainter();
return [painter.getX(), painter.getY()];
const position = context.getPainter().getPosition();
return [position.x, position.y];
},

setPosition(x: number, y: number) {
Expand Down
4 changes: 2 additions & 2 deletions src/items/slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ export function slider(min: number, value: number, max: number, w: number): ISli
if (
(input.isKeyDown(InputKey.LeftMouseButton) || input.isKeyPressed(InputKey.LeftMouseButton)) &&
new Rect(
new Vector2(painter.getX() - sliderStyle.tickMarkSize.x / 2, painter.getY()),
new Vector2(painter.getPosition().x - sliderStyle.tickMarkSize.x / 2, painter.getPosition().y),
new Vector2(w + sliderStyle.tickMarkSize.x, h)
).contains(input.getMousePosition())
)
newValue = Math.min(
max,
Math.max(min, min + ((input.getMousePosition().x - painter.getX()) / w) * (max + min))
Math.max(min, min + ((input.getMousePosition().x - painter.getPosition().x) / w) * (max + min))
);

const sh = (h - sliderStyle.height) / 2;
Expand Down

0 comments on commit 7842e2b

Please sign in to comment.