DUDS
Distributed Update of Data from Something
BppPositionIndicator.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the DUDS project. It is subject to the BSD-style
3  * license terms in the LICENSE file found in the top-level directory of this
4  * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5  * No part of DUDS, including this file, may be copied, modified, propagated,
6  * or distributed except according to the terms contained in the LICENSE file.
7  *
8  * Copyright (C) 2020 Jeff Jackowski
9  */
10 #ifndef BPPPOSITIONINDICATOR_HPP
11 #define BPPPOSITIONINDICATOR_HPP
12 
14 #include <boost/exception/info.hpp>
15 
16 namespace duds { namespace ui { namespace graphics {
17 
21 struct BppPositionIndicatorError : virtual std::exception, virtual boost::exception { };
22 
28 
34 
39 
43 typedef boost::error_info<struct Info_IndicatorMinimumSize, std::uint16_t>
45 
49 typedef boost::error_info<struct Info_IndicatorRange, std::uint16_t>
51 
91  std::uint16_t rng;
95  std::uint16_t minSize = 4;
100  bool bstate = false;
107  int position(int pos, int len) const;
108 public:
120  BppPositionIndicator() = default;
133  std::uint16_t minMarkerSize,
134  bool backgroundState = false
135  ) : minSize(minMarkerSize), bstate(backgroundState) { }
151  const ImageLocation &indicatorPos,
152  const ImageDimensions &indicatorDim,
153  std::uint16_t minMarkerSize = 4,
154  bool backgroundState = false
155  );
159  const ImageLocation &position() const {
160  return ipos;
161  }
165  void position(const ImageLocation &pos) {
166  ipos = pos;
167  }
171  const ImageDimensions &dimensions() const {
172  return idim;
173  }
183  void dimensions(const ImageDimensions &dim);
187  std::uint16_t minMarkerSize() const {
188  return minSize;
189  }
197  void minMarkerSize(std::uint16_t size);
202  bool backgroundState() const {
203  return bstate;
204  }
210  void backgroundState(bool s) {
211  bstate = s;
212  }
217  bool markerState() const {
218  return !bstate;
219  }
225  void markerState(bool s) {
226  bstate = !s;
227  }
232  std::uint16_t range() const {
233  return rng + 1;
234  }
243  void range(std::uint16_t r);
248  std::uint16_t maxPosition() const {
249  return rng;
250  }
256  void maxPosition(std::uint16_t p) {
257  rng = p;
258  }
262  bool horizontal() const {
263  return idim.w > idim.h;
264  }
268  bool vertical() const {
269  return idim.h >= idim.w;
270  }
293  void render(BppImage *dest, int start, int end = 0);
316  void render(const BppImageSptr &dest, int start, int end = 0) {
317  render(dest.get(), start, end);
318  }
319 };
320 
321 } } }
322 
323 #endif // #ifndef BPPPOSITIONINDICATOR_HPP
ImageDimensions idim
The size of the indicator.
ImageLocation ipos
The location to render the indicator.
void backgroundState(bool s)
Changes the pixel state used for the background of the indicator.
BppPositionIndicator(std::uint16_t minMarkerSize, bool backgroundState=false)
Makes a new indicator with its position and dimensions left uninitialized.
Stores a location within an image.
Definition: BppImage.hpp:33
void render(const BppImageSptr &dest, int start, int end=0)
Renders the indicator with the marker showing the given position.
void maxPosition(std::uint16_t p)
Returns the maximum position that will be represented by the indicator.
bool markerState() const
Returns the pixel state used for the position marker of the indicator.
Stores the dimensions of an image.
Definition: BppImage.hpp:125
boost::error_info< struct Info_IndicatorMinimumSize, std::uint16_t > PositionMarkMinimumSize
Error attribute with the length of the position mark in pixels.
std::shared_ptr< BppImage > BppImageSptr
Definition: BppImage.hpp:1777
const ImageDimensions & dimensions() const
Returns the dimensions (size) of the rendered indicator.
bool backgroundState() const
Returns the pixel state used for the background of the indicator.
The base class for errors from the BppPositionIndicator.
An attempt was made to set the range to zero.
boost::error_info< struct Info_IndicatorRange, std::uint16_t > IndicatorRange
Error attribute with the range of positions for a position indicator.
bool horizontal() const
True when the indicator&#39;s marker will move horizontally.
void position(const ImageLocation &pos)
Changes the upper left position where the indictor will be drawn.
std::uint16_t maxPosition() const
Returns the maximum position that will be represented by the indicator.
An attempt was made to set the dimensions to a size that is too small to fit the position mark with e...
void markerState(bool s)
Changes the pixel state used for the position marker of the indicator.
An attempt was made to set a minimum marker size that is less than one, or that is too large to fit w...
std::uint16_t minMarkerSize() const
Returns the minimum size of the position marker in pixels.
std::uint16_t range() const
Returns the range of positions that will be represented by the indicator.
bool vertical() const
True when the indicator&#39;s marker will move vertically.
General graphics related code.
Definition: HD44780.hpp:15
std::uint16_t rng
The range of position values that may be used.
const ImageLocation & position() const
Returns the upper left position where the indictor will be drawn.
An image that uses a single bit to represent the state of each pixel; a black or white picture...
Definition: BppImage.hpp:321
A generalized position indicator that can be used to render a simple scroll bar, progress bar...