Overte C++ Documentation
CursorManager.h
1 //
2 // Created by Bradley Austin Davis on 2015/06/08
3 // Copyright 2015 High Fidelity, Inc.
4 //
5 // Distributed under the Apache License, Version 2.0.
6 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
7 //
8 
9 #pragma once
10 #include <stdint.h>
11 #include <DependencyManager.h>
12 
13 #include <GLMHelpers.h>
14 
15 namespace Cursor {
16  enum class Source {
17  MOUSE,
18  UNKNOWN,
19  };
20 
21  enum Icon {
22  SYSTEM,
23  DEFAULT,
24  LINK,
25  GRAB,
26  ARROW,
27  RETICLE,
28 
29  // Add new system cursors here
30 
31  // User cursors will have ids over this value
32  USER_BASE = 0xFF,
33  };
34  class Instance {
35  public:
36  virtual Source getType() const = 0;
37  virtual void setIcon(uint16_t icon);
38  virtual uint16_t getIcon() const;
39  private:
40  uint16_t _icon;
41  };
42 
43  class MouseInstance : public Instance {
44  Source getType() const override {
45  return Source::MOUSE;
46  }
47  };
48 
49  class Manager : public QObject, public Dependency {
50  SINGLETON_DEPENDENCY
51 
52  Manager();
53  Manager(const Manager& other) = delete;
54  public:
55  static Manager& instance();
56  uint8_t getCount();
57  float getScale();
58  void setScale(float scale);
59  Instance* getCursor(uint8_t index = 0);
60  uint16_t registerIcon(const QString& path);
61  QList<uint16_t> registeredIcons() const;
62  const QString& getIconImage(uint16_t icon);
63 
64  static QMap<uint16_t, QString> ICON_NAMES;
65  static Icon lookupIcon(const QString& name);
66  static const QString& getIconName(const Icon& icon);
67  private:
68  MouseInstance mouseInstance;
69  float _scale{ 1.0f };
70  QMap<uint16_t, QString> ICONS;
71  };
72 }
73 
74