Foundation classes for a basic GUI implementing simple widgets and events
Dependents: TouchScreenGUIDemo
Widgets/BitmapWidget.cpp@18:d849f3ada858, 2016-05-28 (annotated)
- Committer:
- duncanFrance
- Date:
- Sat May 28 14:50:14 2016 +0000
- Revision:
- 18:d849f3ada858
- Parent:
- 16:e9a771ecfdbe
Moved the event queue into the EventDispatcher; Improved event handling across Window/Widget
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
duncanFrance | 4:27546fb8b670 | 1 | #include "BitmapWidget.h" |
duncanFrance | 4:27546fb8b670 | 2 | |
duncanFrance | 16:e9a771ecfdbe | 3 | BitmapWidget::BitmapWidget(GraphicsContext *context) : |
duncanFrance | 16:e9a771ecfdbe | 4 | Widget(context), _monochrome(false), _bitmapWidth(0), _bitmapHeight(0) |
duncanFrance | 4:27546fb8b670 | 5 | { |
duncanFrance | 4:27546fb8b670 | 6 | } |
duncanFrance | 4:27546fb8b670 | 7 | |
duncanFrance | 16:e9a771ecfdbe | 8 | BitmapWidget::BitmapWidget(GraphicsContext *context, bool monochrome) : |
duncanFrance | 16:e9a771ecfdbe | 9 | Widget(context), _monochrome(monochrome), _bitmapWidth(0), _bitmapHeight(0) |
duncanFrance | 9:616a9686d5db | 10 | { |
duncanFrance | 9:616a9686d5db | 11 | } |
duncanFrance | 9:616a9686d5db | 12 | |
duncanFrance | 4:27546fb8b670 | 13 | void BitmapWidget::setMonochrome(bool enabled) |
duncanFrance | 4:27546fb8b670 | 14 | { |
duncanFrance | 4:27546fb8b670 | 15 | _monochrome = enabled; |
duncanFrance | 12:63db16fea709 | 16 | dirty(); |
duncanFrance | 4:27546fb8b670 | 17 | } |
duncanFrance | 4:27546fb8b670 | 18 | |
duncanFrance | 4:27546fb8b670 | 19 | bool BitmapWidget::isMonochrome() |
duncanFrance | 4:27546fb8b670 | 20 | { |
duncanFrance | 4:27546fb8b670 | 21 | return _monochrome; |
duncanFrance | 4:27546fb8b670 | 22 | } |
duncanFrance | 4:27546fb8b670 | 23 | |
duncanFrance | 4:27546fb8b670 | 24 | |
duncanFrance | 14:e6515b19f5a0 | 25 | void BitmapWidget::setBitmap(unsigned char const * bitmap, int width, int height) |
duncanFrance | 4:27546fb8b670 | 26 | { |
duncanFrance | 14:e6515b19f5a0 | 27 | _bitmap = (unsigned char*)bitmap; |
duncanFrance | 16:e9a771ecfdbe | 28 | _bitmapWidth = width; |
duncanFrance | 16:e9a771ecfdbe | 29 | _bitmapHeight = height; |
duncanFrance | 12:63db16fea709 | 30 | // Adjust overall size so that the inner window fits the bitmap |
duncanFrance | 12:63db16fea709 | 31 | // Really we should just clip, but that's too hard for now |
duncanFrance | 16:e9a771ecfdbe | 32 | setSize(((_padding + _borderWidth) * 2) + _bitmapWidth, ((_padding + _borderWidth) * 2) + _bitmapHeight); |
duncanFrance | 16:e9a771ecfdbe | 33 | dirty(); |
duncanFrance | 16:e9a771ecfdbe | 34 | } |
duncanFrance | 16:e9a771ecfdbe | 35 | |
duncanFrance | 16:e9a771ecfdbe | 36 | void BitmapWidget::setBorder(int width, uint16_t color) |
duncanFrance | 16:e9a771ecfdbe | 37 | { |
duncanFrance | 16:e9a771ecfdbe | 38 | Widget::setBorder(width, color); |
duncanFrance | 16:e9a771ecfdbe | 39 | setSize(((_padding + _borderWidth) * 2) + _bitmapWidth, ((_padding + _borderWidth) * 2) + _bitmapHeight); |
duncanFrance | 12:63db16fea709 | 40 | dirty(); |
duncanFrance | 4:27546fb8b670 | 41 | } |
duncanFrance | 4:27546fb8b670 | 42 | |
duncanFrance | 8:a460cabc85ac | 43 | void BitmapWidget::_draw() |
duncanFrance | 4:27546fb8b670 | 44 | { |
duncanFrance | 15:e69fd74d42e4 | 45 | Widget::_draw(); |
duncanFrance | 9:616a9686d5db | 46 | |
duncanFrance | 4:27546fb8b670 | 47 | if(_monochrome) { |
duncanFrance | 15:e69fd74d42e4 | 48 | int fg = display()->getForeground(); |
duncanFrance | 15:e69fd74d42e4 | 49 | int bg = display()->getBackground(); |
duncanFrance | 15:e69fd74d42e4 | 50 | display()->setForeground(_fg); |
duncanFrance | 15:e69fd74d42e4 | 51 | display()->setBackground(_bg); |
duncanFrance | 15:e69fd74d42e4 | 52 | |
duncanFrance | 12:63db16fea709 | 53 | display()->Bitmap_FG_BG(_inner.x, _inner.y, _inner.width, _inner.height, _bitmap); |
duncanFrance | 15:e69fd74d42e4 | 54 | |
duncanFrance | 15:e69fd74d42e4 | 55 | display()->setForeground(fg); |
duncanFrance | 15:e69fd74d42e4 | 56 | display()->setBackground(bg); |
duncanFrance | 4:27546fb8b670 | 57 | } else { |
duncanFrance | 12:63db16fea709 | 58 | display()->Bitmap(_inner.x, _inner.y, _inner.width, _inner.height, _bitmap); |
duncanFrance | 4:27546fb8b670 | 59 | } |
duncanFrance | 4:27546fb8b670 | 60 | } |