Foundation classes for a basic GUI implementing simple widgets and events
Dependents: TouchScreenGUIDemo
Widgets/BitmapWidget.cpp@12:63db16fea709, 2016-05-08 (annotated)
- Committer:
- duncanFrance
- Date:
- Sun May 08 14:42:08 2016 +0000
- Revision:
- 12:63db16fea709
- Parent:
- 9:616a9686d5db
- Child:
- 14:e6515b19f5a0
Update to handle dirty pixels and geometric change/damage
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 | 12:63db16fea709 | 3 | BitmapWidget::BitmapWidget(GraphicsContext *context) : Widget(context), _monochrome(false) |
duncanFrance | 4:27546fb8b670 | 4 | { |
duncanFrance | 4:27546fb8b670 | 5 | } |
duncanFrance | 4:27546fb8b670 | 6 | |
duncanFrance | 12:63db16fea709 | 7 | BitmapWidget::BitmapWidget(GraphicsContext *context, bool monochrome) : Widget(context), _monochrome(monochrome) |
duncanFrance | 9:616a9686d5db | 8 | { |
duncanFrance | 9:616a9686d5db | 9 | } |
duncanFrance | 9:616a9686d5db | 10 | |
duncanFrance | 4:27546fb8b670 | 11 | void BitmapWidget::setMonochrome(bool enabled) |
duncanFrance | 4:27546fb8b670 | 12 | { |
duncanFrance | 4:27546fb8b670 | 13 | _monochrome = enabled; |
duncanFrance | 12:63db16fea709 | 14 | dirty(); |
duncanFrance | 4:27546fb8b670 | 15 | } |
duncanFrance | 4:27546fb8b670 | 16 | |
duncanFrance | 4:27546fb8b670 | 17 | bool BitmapWidget::isMonochrome() |
duncanFrance | 4:27546fb8b670 | 18 | { |
duncanFrance | 4:27546fb8b670 | 19 | return _monochrome; |
duncanFrance | 4:27546fb8b670 | 20 | } |
duncanFrance | 4:27546fb8b670 | 21 | |
duncanFrance | 4:27546fb8b670 | 22 | |
duncanFrance | 12:63db16fea709 | 23 | void BitmapWidget::setBitmap(unsigned char* bitmap, int width, int height) |
duncanFrance | 4:27546fb8b670 | 24 | { |
duncanFrance | 4:27546fb8b670 | 25 | _bitmap = bitmap; |
duncanFrance | 12:63db16fea709 | 26 | // Adjust overall size so that the inner window fits the bitmap |
duncanFrance | 12:63db16fea709 | 27 | // Really we should just clip, but that's too hard for now |
duncanFrance | 12:63db16fea709 | 28 | setSize(((_padding + _borderWidth) * 2) + width, ((_padding + _borderWidth) * 2) + height); |
duncanFrance | 12:63db16fea709 | 29 | dirty(); |
duncanFrance | 4:27546fb8b670 | 30 | } |
duncanFrance | 4:27546fb8b670 | 31 | |
duncanFrance | 8:a460cabc85ac | 32 | void BitmapWidget::_draw() |
duncanFrance | 4:27546fb8b670 | 33 | { |
duncanFrance | 12:63db16fea709 | 34 | display()->setForeground(_fg); |
duncanFrance | 12:63db16fea709 | 35 | display()->setBackground(_bg); |
duncanFrance | 9:616a9686d5db | 36 | |
duncanFrance | 4:27546fb8b670 | 37 | if(_monochrome) { |
duncanFrance | 12:63db16fea709 | 38 | display()->Bitmap_FG_BG(_inner.x, _inner.y, _inner.width, _inner.height, _bitmap); |
duncanFrance | 4:27546fb8b670 | 39 | } else { |
duncanFrance | 12:63db16fea709 | 40 | display()->Bitmap(_inner.x, _inner.y, _inner.width, _inner.height, _bitmap); |
duncanFrance | 4:27546fb8b670 | 41 | } |
duncanFrance | 4:27546fb8b670 | 42 | } |