|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | + |
| 3 | +#include <scratchcpp/monitor.h> |
| 4 | +#include <scratchcpp/block.h> |
| 5 | +#include <scratchcpp/sprite.h> |
| 6 | + |
| 7 | +#include "monitor_p.h" |
| 8 | + |
| 9 | +using namespace libscratchcpp; |
| 10 | + |
| 11 | +/*! Constructs Monitor. */ |
| 12 | +Monitor::Monitor(const std::string &id, const std::string &opcode) : |
| 13 | + Entity(id), |
| 14 | + impl(spimpl::make_unique_impl<MonitorPrivate>(opcode)) |
| 15 | +{ |
| 16 | +} |
| 17 | + |
| 18 | +/*! Returns the monitor's mode. */ |
| 19 | +Monitor::Mode Monitor::mode() const |
| 20 | +{ |
| 21 | + return impl->mode; |
| 22 | +} |
| 23 | + |
| 24 | +/*! Sets the monitor's mode. */ |
| 25 | +void Monitor::setMode(Mode mode) |
| 26 | +{ |
| 27 | + impl->mode = mode; |
| 28 | +} |
| 29 | + |
| 30 | +/*! Returns the block used to get the monitor's value. */ |
| 31 | +std::shared_ptr<Block> Monitor::block() const |
| 32 | +{ |
| 33 | + return impl->block; |
| 34 | +} |
| 35 | + |
| 36 | +/*! Convenience method which calls block()->target(). */ |
| 37 | +Sprite *Monitor::sprite() const |
| 38 | +{ |
| 39 | + return dynamic_cast<Sprite *>(impl->block->target()); |
| 40 | +} |
| 41 | + |
| 42 | +/*! Convenience method which calls block()->setTarget(). */ |
| 43 | +void Monitor::setSprite(Sprite *sprite) |
| 44 | +{ |
| 45 | + impl->block->setTarget(sprite); |
| 46 | +} |
| 47 | + |
| 48 | +/*! Convenience method which calls block()->opcode(). */ |
| 49 | +const std::string &Monitor::opcode() const |
| 50 | +{ |
| 51 | + return impl->block->opcode(); |
| 52 | +} |
| 53 | + |
| 54 | +/*! Returns the monitor's width. */ |
| 55 | +unsigned int Monitor::width() const |
| 56 | +{ |
| 57 | + return impl->width; |
| 58 | +} |
| 59 | + |
| 60 | +/*! Sets the monitor's width. */ |
| 61 | +void Monitor::setWidth(unsigned int width) |
| 62 | +{ |
| 63 | + impl->width = width; |
| 64 | +} |
| 65 | + |
| 66 | +/*! Returns the monitor's height. */ |
| 67 | +unsigned int Monitor::height() const |
| 68 | +{ |
| 69 | + return impl->height; |
| 70 | +} |
| 71 | + |
| 72 | +/*! Sets the monitor's height. */ |
| 73 | +void Monitor::setHeight(unsigned int height) |
| 74 | +{ |
| 75 | + impl->height = height; |
| 76 | +} |
| 77 | + |
| 78 | +/*! Returns the monitor's x-coordinate. */ |
| 79 | +int Monitor::x() const |
| 80 | +{ |
| 81 | + return impl->x; |
| 82 | +} |
| 83 | + |
| 84 | +/*! Sets the monitor's x-coordinate. */ |
| 85 | +void Monitor::setX(int x) |
| 86 | +{ |
| 87 | + impl->x = x; |
| 88 | +} |
| 89 | + |
| 90 | +/*! Returns the monitor's y-coordinate. */ |
| 91 | +int Monitor::y() const |
| 92 | +{ |
| 93 | + return impl->y; |
| 94 | +} |
| 95 | + |
| 96 | +/*! Sets the monitor's y-coordinate. */ |
| 97 | +void Monitor::setY(int y) |
| 98 | +{ |
| 99 | + impl->y = y; |
| 100 | +} |
| 101 | + |
| 102 | +/*! Returns true if the monitor is visible. */ |
| 103 | +bool Monitor::visible() const |
| 104 | +{ |
| 105 | + return impl->visible; |
| 106 | +} |
| 107 | + |
| 108 | +/*! Sets whether the monitor is visible or not. */ |
| 109 | +void Monitor::setVisible(bool visible) |
| 110 | +{ |
| 111 | + impl->visible = visible; |
| 112 | +} |
| 113 | + |
| 114 | +/*! Returns the minimum value of the monitor's slider. */ |
| 115 | +double Monitor::sliderMin() const |
| 116 | +{ |
| 117 | + return impl->sliderMin; |
| 118 | +} |
| 119 | + |
| 120 | +/*! Sets the minimum value of the monitor's slider. */ |
| 121 | +void Monitor::setSliderMin(double sliderMin) |
| 122 | +{ |
| 123 | + impl->sliderMin = sliderMin; |
| 124 | +} |
| 125 | + |
| 126 | +/*! Returns the maximum value of the monitor's slider. */ |
| 127 | +double Monitor::sliderMax() const |
| 128 | +{ |
| 129 | + return impl->sliderMax; |
| 130 | +} |
| 131 | + |
| 132 | +/*! Sets the maximum value of the monitor's slider. */ |
| 133 | +void Monitor::setSliderMax(double sliderMax) |
| 134 | +{ |
| 135 | + impl->sliderMax = sliderMax; |
| 136 | +} |
| 137 | + |
| 138 | +/*! Returns true if the monitor's slider allows only integer values. */ |
| 139 | +bool Monitor::discrete() const |
| 140 | +{ |
| 141 | + return impl->discrete; |
| 142 | +} |
| 143 | + |
| 144 | +/*! Sets whether the monitor's slider allows only integer values. */ |
| 145 | +void Monitor::setDiscrete(bool discrete) |
| 146 | +{ |
| 147 | + impl->discrete = discrete; |
| 148 | +} |
0 commit comments