Mercurial > hg > orthanc-stone
changeset 366:a7de01c8fd29 am-2
new enum BitmapAnchor
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 01 Nov 2018 11:55:45 +0100 |
parents | ef31240a73f6 |
children | face7b7008de |
files | Applications/Samples/SimpleViewerApplicationSingleFile.h Framework/Layers/CircleMeasureTracker.cpp Framework/StoneEnumerations.cpp Framework/StoneEnumerations.h Framework/Viewport/CairoContext.cpp Framework/Viewport/CairoContext.h |
diffstat | 6 files changed, 104 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/Applications/Samples/SimpleViewerApplicationSingleFile.h Wed Oct 31 18:10:29 2018 +0100 +++ b/Applications/Samples/SimpleViewerApplicationSingleFile.h Thu Nov 01 11:55:45 2018 +0100 @@ -172,6 +172,14 @@ widget.FitContent(); break; + case 'l': + application_.currentTool_ = Tools_LineMeasure; + break; + + case 'c': + application_.currentTool_ = Tools_CircleMeasure; + break; + default: break; }
--- a/Framework/Layers/CircleMeasureTracker.cpp Wed Oct 31 18:10:29 2018 +0100 +++ b/Framework/Layers/CircleMeasureTracker.cpp Thu Nov 01 11:55:45 2018 +0100 @@ -71,8 +71,7 @@ cairo_stroke(cr); cairo_restore(cr); - //context.SetSourceColor(0, 255, 0); - context.DrawText(font_, FormatRadius(), x, y); + context.DrawText(font_, FormatRadius(), x, y, BitmapAnchor_Center); }
--- 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); + } + } }
--- a/Framework/StoneEnumerations.h Wed Oct 31 18:10:29 2018 +0100 +++ b/Framework/StoneEnumerations.h Thu Nov 01 11:55:45 2018 +0100 @@ -102,6 +102,19 @@ SopClassUid_RTDose }; + enum BitmapAnchor + { + BitmapAnchor_BottomLeft, + BitmapAnchor_BottomCenter, + BitmapAnchor_BottomRight, + BitmapAnchor_CenterLeft, + BitmapAnchor_Center, + BitmapAnchor_CenterRight, + BitmapAnchor_TopLeft, + BitmapAnchor_TopCenter, + BitmapAnchor_TopRight + }; + bool StringToSopClassUid(SopClassUid& result, const std::string& source); @@ -110,4 +123,10 @@ ImageWindowing windowing, float defaultCenter, float defaultWidth); + + void ComputeAnchorTranslation(double& deltaX /* out */, + double& deltaY /* out */, + BitmapAnchor anchor, + unsigned int bitmapWidth, + unsigned int bitmapHeight); }
--- a/Framework/Viewport/CairoContext.cpp Wed Oct 31 18:10:29 2018 +0100 +++ b/Framework/Viewport/CairoContext.cpp Thu Nov 01 11:55:45 2018 +0100 @@ -100,7 +100,7 @@ cairo_image_surface_get_data(surface_)); } - void Fill(cairo_t* cr, + void Blit(cairo_t* cr, double x, double y) { @@ -114,8 +114,10 @@ void CairoContext::DrawText(const Orthanc::Font& font, const std::string& text, double x, - double y) + double y, + BitmapAnchor anchor) { + // Render a bitmap containing the text unsigned int width, height; font.ComputeTextExtent(width, height, text); @@ -125,6 +127,11 @@ surface.GetAccessor(accessor); font.Draw(accessor, text, 0, 0, 255); + // Correct the text location given the anchor location + double deltaX, deltaY; + ComputeAnchorTranslation(deltaX, deltaY, anchor, width, height); + + // Cancel zoom/rotation before blitting the text onto the surface double pixelX = x; double pixelY = y; cairo_user_to_device(context_, &pixelX, &pixelY); @@ -132,8 +139,8 @@ cairo_save(context_); cairo_identity_matrix(context_); - surface.Fill(context_, pixelX, pixelY); - + // Blit the text bitmap + surface.Blit(context_, pixelX + deltaX, pixelY + deltaY); cairo_restore(context_); } }
--- a/Framework/Viewport/CairoContext.h Wed Oct 31 18:10:29 2018 +0100 +++ b/Framework/Viewport/CairoContext.h Thu Nov 01 11:55:45 2018 +0100 @@ -22,6 +22,7 @@ #pragma once #include "CairoSurface.h" +#include "../StoneEnumerations.h" #include <Core/Images/Font.h> @@ -69,6 +70,7 @@ void DrawText(const Orthanc::Font& font, const std::string& text, double x, - double y); + double y, + BitmapAnchor anchor); }; }