Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkApplicationCursor.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkApplicationCursor.h"
18 #include <mitkLogMacros.h>
19 
20 #include <iostream>
21 
22 mitk::ApplicationCursorImplementation *mitk::ApplicationCursor::m_Implementation = nullptr;
23 
24 namespace mitk
25 {
28  {
29  static ApplicationCursor *m_Instance = nullptr;
30  if (!m_Instance)
31  {
32  m_Instance = new ApplicationCursor();
33  }
34 
35  return m_Instance;
36  }
37 
39  {
40  m_Implementation = implementation;
41  }
42 
43  void ApplicationCursor::PushCursor(std::istream &cursor, int hotspotX, int hotspotY)
44  {
45  if (m_Implementation)
46  {
47  m_Implementation->PushCursor(cursor, hotspotX, hotspotY);
48  }
49  else
50  {
51  MITK_ERROR << "in mitk::ApplicationCursor::PushCursor(): no implementation registered." << std::endl;
52  throw std::logic_error("No implementation registered for mitk::ApplicationCursor.");
53  }
54  }
55 
56  void ApplicationCursor::PushCursor(const char *XPM[], int hotspotX, int hotspotY)
57  {
58  if (m_Implementation)
59  {
60  m_Implementation->PushCursor(XPM, hotspotX, hotspotY);
61  }
62  else
63  {
64  MITK_ERROR << "in mitk::ApplicationCursor::PushCursor(): no implementation registered." << std::endl;
65  throw std::logic_error("No implementation registered for mitk::ApplicationCursor.");
66  }
67  }
68 
70  {
71  if (m_Implementation)
72  {
73  m_Implementation->PopCursor();
74  }
75  else
76  {
77  MITK_ERROR << "in mitk::ApplicationCursor::PopCursor(): no implementation registered." << std::endl;
78  throw std::logic_error("No implementation registered for mitk::ApplicationCursor.");
79  }
80  }
81 
83  {
84  if (m_Implementation)
85  {
86  return m_Implementation->GetCursorPosition();
87  }
88  else
89  {
90  MITK_ERROR << "in mitk::ApplicationCursor::GetCursorPosition(): no implementation registered." << std::endl;
91  throw std::logic_error("No implementation registered for mitk::ApplicationCursor.");
92  }
93  }
94 
96  {
97  if (m_Implementation)
98  {
99  m_Implementation->SetCursorPosition(p);
100  }
101  else
102  {
103  MITK_ERROR << "in mitk::ApplicationCursor::SetCursorPosition(): no implementation registered." << std::endl;
104  throw std::logic_error("No implementation registered for mitk::ApplicationCursor.");
105  }
106  }
107 
108 } // namespace
void SetCursorPosition(const Point2I &)
Set absolute mouse position on screen.
Allows to override the application's cursor.
virtual void SetCursorPosition(const Point2I &)=0
Set absolute mouse position on screen.
#define MITK_ERROR
Definition: mitkLogMacros.h:24
DataCollection - Class to facilitate loading/accessing structured data.
static void RegisterImplementation(ApplicationCursorImplementation *implementation)
To be called by a toolkit specific ApplicationCursorImplementation.
Toolkit specific implementation of mitk::ApplicationCursor.
void PopCursor()
Restore the previous cursor.
static ApplicationCursor * GetInstance()
This class is a singleton.
void PushCursor(const char *XPM[], int hotspotX=-1, int hotspotY=-1)
Change the current application cursor.
ApplicationCursor()
Purposely hidden - singleton.
virtual void PushCursor(const char *XPM[], int hotspotX, int hotspotY)=0
Change the current application cursor.
virtual const Point2I GetCursorPosition()=0
Get absolute mouse position on screen.
virtual void PopCursor()=0
Restore the previous cursor.