changeset 367:face7b7008de am-2

line and circle measure tools are now compatible with WebAssembly
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 01 Nov 2018 12:09:11 +0100
parents a7de01c8fd29
children 557c8ff1db5c
files Applications/Samples/SimpleViewer/MainWidgetInteractor.cpp Applications/Samples/SimpleViewerApplicationSingleFile.h Framework/Layers/LineMeasureTracker.cpp Framework/Layers/LineMeasureTracker.h
diffstat 4 files changed, 22 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/Samples/SimpleViewer/MainWidgetInteractor.cpp	Thu Nov 01 11:55:45 2018 +0100
+++ b/Applications/Samples/SimpleViewer/MainWidgetInteractor.cpp	Thu Nov 01 12:09:11 2018 +0100
@@ -38,7 +38,8 @@
     {
       if (application_.GetCurrentTool() == SimpleViewerApplication::Tools_LineMeasure)
       {
-        return new LineMeasureTracker(statusBar, dynamic_cast<LayerWidget&>(widget).GetSlice(), x, y, 255, 0, 0, 10);
+        return new LineMeasureTracker(statusBar, dynamic_cast<LayerWidget&>(widget).GetSlice(),
+                                      x, y, 255, 0, 0, application_.GetFont());
       }
       else if (application_.GetCurrentTool() == SimpleViewerApplication::Tools_CircleMeasure)
       {
--- a/Applications/Samples/SimpleViewerApplicationSingleFile.h	Thu Nov 01 11:55:45 2018 +0100
+++ b/Applications/Samples/SimpleViewerApplicationSingleFile.h	Thu Nov 01 12:09:11 2018 +0100
@@ -124,7 +124,8 @@
           {
             if (application_.currentTool_ == Tools_LineMeasure)
             {
-              return new LineMeasureTracker(statusBar, dynamic_cast<LayerWidget&>(widget).GetSlice(), x, y, 255, 0, 0, 10);
+              return new LineMeasureTracker(statusBar, dynamic_cast<LayerWidget&>(widget).GetSlice(),
+                                            x, y, 255, 0, 0, application_.GetFont());
             }
             else if (application_.currentTool_ == Tools_CircleMeasure)
             {
--- a/Framework/Layers/LineMeasureTracker.cpp	Thu Nov 01 11:55:45 2018 +0100
+++ b/Framework/Layers/LineMeasureTracker.cpp	Thu Nov 01 12:09:11 2018 +0100
@@ -21,8 +21,6 @@
 
 #include "LineMeasureTracker.h"
 
-#include "../Viewport/CairoFont.h"
-
 #include <stdio.h>
 
 namespace OrthancStone
@@ -34,14 +32,14 @@
                                          uint8_t red,
                                          uint8_t green,
                                          uint8_t blue,
-                                         unsigned int fontSize) :
+                                         const Orthanc::Font& font) :
     statusBar_(statusBar),
     slice_(slice),
     x1_(x),
     y1_(y),
     x2_(x),
     y2_(y),
-    fontSize_(fontSize)
+    font_(font)
   {
     color_[0] = red;
     color_[1] = green;
@@ -60,13 +58,13 @@
     cairo_line_to(cr, x2_, y2_);
     cairo_stroke(cr);
 
-    if (fontSize_ != 0)
+    if (y2_ - y1_ < 0)
     {
-      cairo_move_to(cr, x2_, y2_ - static_cast<double>(fontSize_) / zoom);
-#if ORTHANC_ENABLE_NATIVE==1 // text rendering currently fails in wasm
-      CairoFont font("sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
-      font.Draw(context, FormatLength(), static_cast<double>(fontSize_) / zoom);
-#endif
+      context.DrawText(font_, FormatLength(), x2_, y2_ - 5, BitmapAnchor_BottomCenter);
+    }
+    else
+    {
+      context.DrawText(font_, FormatLength(), x2_, y2_ + 5, BitmapAnchor_TopCenter);
     }
   }
     
--- a/Framework/Layers/LineMeasureTracker.h	Thu Nov 01 11:55:45 2018 +0100
+++ b/Framework/Layers/LineMeasureTracker.h	Thu Nov 01 12:09:11 2018 +0100
@@ -31,14 +31,15 @@
   class LineMeasureTracker : public IWorldSceneMouseTracker
   {
   private:
-    IStatusBar*         statusBar_;
-    CoordinateSystem3D  slice_;
-    double              x1_;
-    double              y1_;
-    double              x2_;
-    double              y2_;
-    uint8_t             color_[3];
-    unsigned int        fontSize_;
+    IStatusBar*           statusBar_;
+    CoordinateSystem3D    slice_;
+    double                x1_;
+    double                y1_;
+    double                x2_;
+    double                y2_;
+    uint8_t               color_[3];
+    unsigned int          fontSize_;
+    const Orthanc::Font&  font_;
 
   public:
     LineMeasureTracker(IStatusBar* statusBar,
@@ -48,7 +49,7 @@
                        uint8_t red,
                        uint8_t green,
                        uint8_t blue,
-                       unsigned int fontSize);
+                       const Orthanc::Font& font);
 
     virtual bool HasRender() const
     {