Automate écran capacitif
Dependencies: BSP_DISCO_F469NI LCD_DISCO_F469NI SeeedStudioTFTv2 TFT_fonts mbed
Fork of DISCO-F469NI_LCD_demo by
F469_GUI/Label.cpp@2:2182df2d7810, 2017-03-31 (annotated)
- Committer:
- SquirrelGod
- Date:
- Fri Mar 31 15:36:26 2017 +0000
- Revision:
- 2:2182df2d7810
Programme ?cran capacitif
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
SquirrelGod | 2:2182df2d7810 | 1 | //----------------------------------------------------------- |
SquirrelGod | 2:2182df2d7810 | 2 | // Label class |
SquirrelGod | 2:2182df2d7810 | 3 | // |
SquirrelGod | 2:2182df2d7810 | 4 | // 2016/04/24, Copyright (c) 2016 MIKAMI, Naoki |
SquirrelGod | 2:2182df2d7810 | 5 | //----------------------------------------------------------- |
SquirrelGod | 2:2182df2d7810 | 6 | |
SquirrelGod | 2:2182df2d7810 | 7 | #include "Label.hpp" |
SquirrelGod | 2:2182df2d7810 | 8 | |
SquirrelGod | 2:2182df2d7810 | 9 | namespace Mikami |
SquirrelGod | 2:2182df2d7810 | 10 | { |
SquirrelGod | 2:2182df2d7810 | 11 | // Constructor |
SquirrelGod | 2:2182df2d7810 | 12 | Label::Label(uint16_t x, uint16_t y, |
SquirrelGod | 2:2182df2d7810 | 13 | const string str, TextAlignMode mode, sFONT &fonts, |
SquirrelGod | 2:2182df2d7810 | 14 | uint32_t textColor, uint32_t backColor) |
SquirrelGod | 2:2182df2d7810 | 15 | : GuiBase(x, y, fonts, textColor, backColor), |
SquirrelGod | 2:2182df2d7810 | 16 | MODE_(mode), STR_(str) |
SquirrelGod | 2:2182df2d7810 | 17 | { |
SquirrelGod | 2:2182df2d7810 | 18 | length_ = str.length(); |
SquirrelGod | 2:2182df2d7810 | 19 | lcd_.SetBackColor(backColor); |
SquirrelGod | 2:2182df2d7810 | 20 | lcd_.SetTextColor(textColor); |
SquirrelGod | 2:2182df2d7810 | 21 | lcd_.SetFont(&fonts); |
SquirrelGod | 2:2182df2d7810 | 22 | DrawString(PosX(x), y, str); |
SquirrelGod | 2:2182df2d7810 | 23 | } |
SquirrelGod | 2:2182df2d7810 | 24 | |
SquirrelGod | 2:2182df2d7810 | 25 | void Label::Draw(const string str, uint32_t textColor) |
SquirrelGod | 2:2182df2d7810 | 26 | { |
SquirrelGod | 2:2182df2d7810 | 27 | // Erase previously-drawn string |
SquirrelGod | 2:2182df2d7810 | 28 | lcd_.SetTextColor(BACK_COLOR_); |
SquirrelGod | 2:2182df2d7810 | 29 | length_ = (length_ > str.length()) ? length_ : str.length(); |
SquirrelGod | 2:2182df2d7810 | 30 | lcd_.FillRect(PosX(X_), Y_, FONTS_->Width*length_+1, FONTS_->Height); |
SquirrelGod | 2:2182df2d7810 | 31 | |
SquirrelGod | 2:2182df2d7810 | 32 | // Draw new string |
SquirrelGod | 2:2182df2d7810 | 33 | length_ = str.length(); |
SquirrelGod | 2:2182df2d7810 | 34 | lcd_.SetFont(FONTS_); |
SquirrelGod | 2:2182df2d7810 | 35 | lcd_.SetTextColor(textColor); |
SquirrelGod | 2:2182df2d7810 | 36 | DrawString(PosX(X_), Y_, str); |
SquirrelGod | 2:2182df2d7810 | 37 | } |
SquirrelGod | 2:2182df2d7810 | 38 | |
SquirrelGod | 2:2182df2d7810 | 39 | uint16_t Label::PosX(uint16_t x) |
SquirrelGod | 2:2182df2d7810 | 40 | { |
SquirrelGod | 2:2182df2d7810 | 41 | if (MODE_ == LEFT) return x; |
SquirrelGod | 2:2182df2d7810 | 42 | else |
SquirrelGod | 2:2182df2d7810 | 43 | { |
SquirrelGod | 2:2182df2d7810 | 44 | if (MODE_ == CENTER) |
SquirrelGod | 2:2182df2d7810 | 45 | return x - length_*FONTS_->Width/2; |
SquirrelGod | 2:2182df2d7810 | 46 | else |
SquirrelGod | 2:2182df2d7810 | 47 | return x - length_*FONTS_->Width; |
SquirrelGod | 2:2182df2d7810 | 48 | } |
SquirrelGod | 2:2182df2d7810 | 49 | } |
SquirrelGod | 2:2182df2d7810 | 50 | } |