DUDS
Distributed Update of Data from Something
SimulatedBppDisplay.cpp
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 
13 #include <duds/general/Errors.hpp>
14 #include <iostream>
15 
16 namespace duds { namespace hardware { namespace devices { namespace displays {
17 
19 
22 ) : duds::hardware::display::BppGraphicDisplay(id)
23 { } // all done above
24 
26  // range check on display size
27  if (id.empty()) {
30  );
31  }
32  frmbuf.resize(id);
33  bottom = false;
34 }
35 
37  if (bottom) {
38  // return cursor to top
39  std::cout << "\033[" << height() + 2 << 'A';
40  }
41  bottom = true;
42  // output border
43  std::cout << '*';
44  for (int w = width(); w > 0; --w) {
45  std::cout << '-';
46  }
47  std::cout << "*\n";
48  // output image
49  for (int h = 0; h < height(); ++h) {
50  // start border
51  std::cout << '|';
52  // initialize pointer to the start of the line
54  // setup the mask for the bit to check
56  // go through the whole width
57  for (int w = width(); w > 0; --w) {
58  // check for set pixel
59  if (*pb & mask) {
60  std::cout << 'X';
61  } else {
62  std::cout << ' ';
63  }
64  // advance to next pixel
65  mask <<= 1;
66  // gone past the end of the pixel block?
67  if (!mask) {
68  // advance to the next block
69  mask = 1;
70  ++pb;
71  }
72  }
73  // end border
74  std::cout << "|\n";
75  }
76  // output border
77  std::cout << '*';
78  for (int w = width(); w > 0; --w) {
79  std::cout << '-';
80  }
81  std::cout << '*' << std::endl;
82 }
83 
84 } } } }
std::uintptr_t PixelBlock
The type used to hold pixel values, one bit per pixel.
Definition: BppImage.hpp:326
boost::error_info< struct Info_ImageDimensions, ImageDimensions > ImageErrorDimensions
Image dimensions relevant to the error.
Definition: BppImage.hpp:293
int height() const
Returns the height of the frame buffer.
const PixelBlock * bufferLine(int py) const
Returns a pointer to the start of the given line.
Definition: BppImage.cpp:175
SimulatedBppDisplay()
Creates the object with an invalid display size.
Stores the dimensions of an image.
Definition: BppImage.hpp:125
The specified display size is unsupported, or there is a display size mismatch.
int width() const
Returns the width of the frame buffer.
void resize(const duds::ui::graphics::ImageDimensions &newdim)
Changes the size of the image.
Definition: BppImage.cpp:123
bool bottom
True after rendering a frame to denote output is at the bottom of the frame.
duds::ui::graphics::BppImage frmbuf
The frame buffer.
virtual void outputFrame(const duds::ui::graphics::BppImage *img)
Writes out only the changed portions of the image to the display, and updates the image in frmbuf to ...
BppGraphicDisplay()=default
Construct with an empty frame buffer.
void configure(const duds::ui::graphics::ImageDimensions &id)
Initializes the object to a usable state.
General errors.
#define DUDS_THROW_EXCEPTION(x)
Works like BOOST_THROW_EXCEPTION, but includes a stack trace if DUDS_ERRORS_VERBOSE is defined...
Definition: Errors.hpp:48
An image that uses a single bit to represent the state of each pixel; a black or white picture...
Definition: BppImage.hpp:321