xref: /haiku/src/apps/icon-o-matic/transformable/CanvasTransformBox.cpp (revision 820dca4df6c7bf955c46e8f6521b9408f50b2900)
1 /*
2  * Copyright 2006-2009, 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 
14 // constructor
15 CanvasTransformBox::CanvasTransformBox(CanvasView* view)
16 	:
17 	TransformBox(view, BRect(0.0, 0.0, 1.0, 1.0)),
18 
19 	fCanvasView(view),
20 	fParentTransform()
21 {
22 }
23 
24 
25 // destructor
26 CanvasTransformBox::~CanvasTransformBox()
27 {
28 }
29 
30 
31 // TransformFromCanvas
32 void
33 CanvasTransformBox::TransformFromCanvas(BPoint& point) const
34 {
35 	fParentTransform.InverseTransform(&point);
36 	fCanvasView->ConvertFromCanvas(&point);
37 }
38 
39 
40 // TransformToCanvas
41 void
42 CanvasTransformBox::TransformToCanvas(BPoint& point) const
43 {
44 	fCanvasView->ConvertToCanvas(&point);
45 	fParentTransform.Transform(&point);
46 }
47 
48 
49 // ZoomLevel
50 float
51 CanvasTransformBox::ZoomLevel() const
52 {
53 	return fCanvasView->ZoomLevel();
54 }
55 
56 
57 // ViewSpaceRotation
58 double
59 CanvasTransformBox::ViewSpaceRotation() const
60 {
61 	Transformable t(*this);
62 	t.Multiply(fParentTransform);
63 	return t.rotation() * 180.0 / M_PI;
64 }
65