Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of SimpleGUI by
BitmapWidget.cpp
00001 #include "BitmapWidget.h" 00002 00003 BitmapWidget::BitmapWidget(GraphicsContext *context) : 00004 Widget(context), _monochrome(false), _bitmapWidth(0), _bitmapHeight(0) 00005 { 00006 } 00007 00008 BitmapWidget::BitmapWidget(GraphicsContext *context, bool monochrome) : 00009 Widget(context), _monochrome(monochrome), _bitmapWidth(0), _bitmapHeight(0) 00010 { 00011 } 00012 00013 void BitmapWidget::setMonochrome(bool enabled) 00014 { 00015 _monochrome = enabled; 00016 dirty(); 00017 } 00018 00019 bool BitmapWidget::isMonochrome() 00020 { 00021 return _monochrome; 00022 } 00023 00024 00025 void BitmapWidget::setBitmap(unsigned char const * bitmap, int width, int height) 00026 { 00027 _bitmap = (unsigned char*)bitmap; 00028 _bitmapWidth = width; 00029 _bitmapHeight = height; 00030 // Adjust overall size so that the inner window fits the bitmap 00031 // Really we should just clip, but that's too hard for now 00032 setSize(((_padding + _borderWidth) * 2) + _bitmapWidth, ((_padding + _borderWidth) * 2) + _bitmapHeight); 00033 dirty(); 00034 } 00035 00036 void BitmapWidget::setBorder(int width, uint16_t color) 00037 { 00038 Widget::setBorder(width, color); 00039 setSize(((_padding + _borderWidth) * 2) + _bitmapWidth, ((_padding + _borderWidth) * 2) + _bitmapHeight); 00040 dirty(); 00041 } 00042 00043 void BitmapWidget::_draw() 00044 { 00045 Widget::_draw(); 00046 00047 if(_monochrome) { 00048 int fg = display()->getForeground(); 00049 int bg = display()->getBackground(); 00050 display()->setForeground(_fg); 00051 display()->setBackground(_bg); 00052 00053 display()->Bitmap_FG_BG(_inner.x, _inner.y, _inner.width, _inner.height, _bitmap); 00054 00055 display()->setForeground(fg); 00056 display()->setBackground(bg); 00057 } else { 00058 display()->Bitmap(_inner.x, _inner.y, _inner.width, _inner.height, _bitmap); 00059 } 00060 }
Generated on Tue Jul 12 2022 22:27:14 by
