xref: /haiku/src/apps/icon-o-matic/transformable/CanvasTransformBox.cpp (revision 1acbe440b8dd798953bec31d18ee589aa3f71b73)
1 /*
2  * Copyright 2006, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Stephan Aßmus <superstippi@gmx.de>
7  */
8 
9 #include "CanvasTransformBox.h"
10 
11 #include "CanvasView.h"
12 
13 // constructor
14 CanvasTransformBox::CanvasTransformBox(CanvasView* view)
15 	: TransformBox(view, BRect(0.0, 0.0, 1.0, 1.0)),
16 
17 	  fCanvasView(view),
18 	  fParentTransform()
19 {
20 }
21 
22 // destructor
23 CanvasTransformBox::~CanvasTransformBox()
24 {
25 }
26 
27 // TransformFromCanvas
28 void
29 CanvasTransformBox::TransformFromCanvas(BPoint& point) const
30 {
31 	fParentTransform.InverseTransform(&point);
32 	fCanvasView->ConvertFromCanvas(&point);
33 }
34 
35 // TransformToCanvas
36 void
37 CanvasTransformBox::TransformToCanvas(BPoint& point) const
38 {
39 	fCanvasView->ConvertToCanvas(&point);
40 	fParentTransform.Transform(&point);
41 }
42 
43 // ZoomLevel
44 float
45 CanvasTransformBox::ZoomLevel() const
46 {
47 	return fCanvasView->ZoomLevel();
48 }
49 
50 // ViewSpaceRotation
51 double
52 CanvasTransformBox::ViewSpaceRotation() const
53 {
54 	Transformable t(*this);
55 	t.Multiply(fParentTransform);
56 	return t.rotation() * 180.0 / PI;
57 }
58