comparison Framework/Scene2D/InfoPanelSceneLayer.cpp @ 584:434ceeb0bcab

layers: InfoPanel, Polyline, Texture
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 19 Apr 2019 17:36:00 +0200
parents
children 2d8ab34c8c91
comparison
equal deleted inserted replaced
583:f9ac154c5a63 584:434ceeb0bcab
1 /**
2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License
9 * as published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21
22 #include "InfoPanelSceneLayer.h"
23
24 #include <Core/Images/Image.h>
25 #include <Core/OrthancException.h>
26
27 namespace OrthancStone
28 {
29 InfoPanelSceneLayer::InfoPanelSceneLayer(const Orthanc::ImageAccessor& texture,
30 BitmapAnchor anchor,
31 bool isLinearInterpolation) :
32 texture_(Orthanc::Image::Clone(texture)),
33 anchor_(anchor),
34 isLinearInterpolation_(isLinearInterpolation)
35 {
36 if (texture_->GetFormat() != Orthanc::PixelFormat_RGBA32 &&
37 texture_->GetFormat() != Orthanc::PixelFormat_RGB24)
38 {
39 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
40 }
41 }
42
43
44 void InfoPanelSceneLayer::ComputeAnchorLocation(int& x,
45 int& y,
46 BitmapAnchor anchor,
47 unsigned int textureWidth,
48 unsigned int textureHeight,
49 unsigned int canvasWidth,
50 unsigned int canvasHeight)
51 {
52 int tw = static_cast<int>(textureWidth);
53 int th = static_cast<int>(textureHeight);
54 int cw = static_cast<int>(canvasWidth);
55 int ch = static_cast<int>(canvasHeight);
56
57 switch (anchor)
58 {
59 case BitmapAnchor_TopLeft:
60 case BitmapAnchor_CenterLeft:
61 case BitmapAnchor_BottomLeft:
62 x = 0;
63 break;
64
65 case BitmapAnchor_TopCenter:
66 case BitmapAnchor_Center:
67 case BitmapAnchor_BottomCenter:
68 x = (cw - tw) / 2;
69 break;
70
71 case BitmapAnchor_TopRight:
72 case BitmapAnchor_CenterRight:
73 case BitmapAnchor_BottomRight:
74 x = cw - tw;
75 break;
76
77 default:
78 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
79 }
80
81 switch (anchor)
82 {
83 case BitmapAnchor_TopLeft:
84 case BitmapAnchor_TopCenter:
85 case BitmapAnchor_TopRight:
86 y = 0;
87 break;
88
89 case BitmapAnchor_CenterLeft:
90 case BitmapAnchor_Center:
91 case BitmapAnchor_CenterRight:
92 y = (ch - th) / 2;
93 break;
94
95 case BitmapAnchor_BottomLeft:
96 case BitmapAnchor_BottomCenter:
97 case BitmapAnchor_BottomRight:
98 y = ch - th;
99 break;
100
101 default:
102 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
103 }
104 }
105 }