diff Framework/StoneEnumerations.cpp @ 366:a7de01c8fd29 am-2

new enum BitmapAnchor
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 01 Nov 2018 11:55:45 +0100
parents 5412adf19980
children b70e9be013e4
line wrap: on
line diff
--- a/Framework/StoneEnumerations.cpp	Wed Oct 31 18:10:29 2018 +0100
+++ b/Framework/StoneEnumerations.cpp	Thu Nov 01 11:55:45 2018 +0100
@@ -72,4 +72,66 @@
         throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
     }
   }
+
+  
+  void ComputeAnchorTranslation(double& deltaX,
+                                double& deltaY,
+                                BitmapAnchor anchor,
+                                unsigned int bitmapWidth,
+                                unsigned int bitmapHeight)
+  {
+    double dw = static_cast<double>(bitmapWidth);
+    double dh = static_cast<double>(bitmapHeight);
+
+    switch (anchor)
+    {
+      case BitmapAnchor_TopLeft:
+        deltaX = 0;
+        deltaY = 0;
+        break;
+        
+      case BitmapAnchor_TopCenter:
+        deltaX = -dw / 2.0;
+        deltaY = 0;
+        break;
+        
+      case BitmapAnchor_TopRight:
+        deltaX = -dw;
+        deltaY = 0;
+        break;
+        
+      case BitmapAnchor_CenterLeft:
+        deltaX = 0;
+        deltaY = -dh / 2.0;
+        break;
+        
+      case BitmapAnchor_Center:
+        deltaX = -dw / 2.0;
+        deltaY = -dh / 2.0;
+        break;
+        
+      case BitmapAnchor_CenterRight:
+        deltaX = -dw;
+        deltaY = -dh / 2.0;
+        break;
+        
+      case BitmapAnchor_BottomLeft:
+        deltaX = 0;
+        deltaY = -dh;
+        break;
+        
+      case BitmapAnchor_BottomCenter:
+        deltaX = -dw / 2.0;
+        deltaY = -dh;
+        break;
+        
+      case BitmapAnchor_BottomRight:
+        deltaX = -dw;
+        deltaY = -dh;
+        break;
+        
+      default:
+        throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
+    }    
+  }
 }