00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifdef HAVE_CONFIG_H
00026 #include <config.h>
00027 #endif
00028
00029 #include <wx/wxprec.h>
00030
00031 #ifndef WX_PRECOMP
00032 #include <wx/wx.h>
00033 #endif
00034
00035 #include <wx/dcbuffer.h>
00036
00037 #include "model/Password.hh"
00038 #include "res/alphabet.xpm"
00039 #include "view/PasswordPanel.hh"
00040
00041 using namespace mpg;
00042
00043 PasswordPanel::PasswordPanel() : alphabet(alphabet_xpm), password(0) {}
00044
00045 wxPoint PasswordPanel::getLetterPos(wxChar letter) const {
00046 int index = Password::ALPHABET.Find(letter);
00047
00048 return wxPoint(((index % CHARS_PER_ROW) * CHAR_WIDTH * 2),
00049 ((index / CHARS_PER_ROW) * CHAR_HEIGHT * 2));
00050 }
00051
00052 void PasswordPanel::onPaint(wxPaintEvent &) {
00053 wxBufferedPaintDC dc(this);
00054
00055 dc.SetBackground(wxBrush(GetBackgroundColour()));
00056 dc.Clear();
00057
00058 if (password) {
00059 wxMemoryDC xpm;
00060 xpm.SelectObject(alphabet);
00061 const wxString &encoded = password->getEncoded();
00062
00063
00064 wxPoint pos(START_X, START_Y);
00065
00066
00067 for (int row = 0; row < 2; ++row) {
00068
00069 for (int col = 0; col < 12; ++col) {
00070
00071 if (col == 6) {
00072 pos.x += CHAR_WIDTH;
00073 }
00074
00075
00076 wxPoint letter = getLetterPos(encoded[(row * 12) + col]);
00077 dc.Blit(pos.x, pos.y, CHAR_WIDTH, CHAR_HEIGHT,
00078 &xpm, letter.x, letter.y);
00079
00080 pos.x += CHAR_WIDTH;
00081 }
00082
00083 pos.x = START_X;
00084 pos.y = START_Y + (2 * CHAR_HEIGHT);
00085 }
00086 }
00087 }
00088
00089 IMPLEMENT_DYNAMIC_CLASS(PasswordPanel, wxPanel)
00090
00091 BEGIN_EVENT_TABLE(PasswordPanel, wxPanel)
00092 EVT_ERASE_BACKGROUND(PasswordPanel::onEraseBackground)
00093 EVT_PAINT(PasswordPanel::onPaint)
00094 END_EVENT_TABLE()
00095