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 BEGIN_EVENT_TABLE(PasswordPanel, wxPanel)
00044 EVT_ERASE_BACKGROUND(PasswordPanel::onEraseBackground)
00045 EVT_PAINT(PasswordPanel::onPaint)
00046 END_EVENT_TABLE()
00047
00048 PasswordPanel::PasswordPanel() : alphabet(alphabet_xpm), password(NULL) {}
00049
00050 wxPoint PasswordPanel::getLetterPos(wxChar letter) const {
00051 int index = Password::ALPHABET.Find(letter);
00052
00053 return wxPoint(((index % CHARS_PER_ROW) * CHAR_WIDTH * 2),
00054 ((index / CHARS_PER_ROW) * CHAR_HEIGHT * 2));
00055 }
00056
00057 void PasswordPanel::onPaint(wxPaintEvent &) {
00058 wxBufferedPaintDC dc(this);
00059
00060 dc.SetBackground(wxBrush(GetBackgroundColour()));
00061 dc.Clear();
00062
00063 if (password) {
00064 wxMemoryDC xpm;
00065 xpm.SelectObject(alphabet);
00066 const wxString &encoded = password->getEncoded();
00067
00068
00069 wxPoint pos(START_X, START_Y);
00070
00071
00072 for (int row = 0; row < 2; ++row) {
00073
00074 for (int col = 0; col < 12; ++col) {
00075
00076 if (col == 6) {
00077 pos.x += CHAR_WIDTH;
00078 }
00079
00080
00081 wxPoint letter = getLetterPos(encoded[(row * 12) + col]);
00082 dc.Blit(pos.x, pos.y, CHAR_WIDTH, CHAR_HEIGHT,
00083 &xpm, letter.x, letter.y);
00084
00085 pos.x += CHAR_WIDTH;
00086 }
00087
00088 pos.x = START_X;
00089 pos.y = START_Y + (2 * CHAR_HEIGHT);
00090 }
00091 }
00092 }
00093
00094 IMPLEMENT_DYNAMIC_CLASS(PasswordPanel, wxPanel)
00095