Main Page | Namespace List | Class List | Directories | File List | Namespace Members | Class Members | File Members

PasswordPanel.cc

Go to the documentation of this file.
00001 /*
00002  * Metroid Password Generator
00003  * Copyright (C) 2005 emuWorks
00004  * http://games.technoplaza.net/
00005  *
00006  * This file is part of Metroid Password Generator.
00007  *
00008  * Metroid Password Generator is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * Metroid Password Generator is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with Metroid Password Generator; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00021  */
00022  
00023 // $Id: PasswordPanel.cc,v 1.2 2005/09/27 09:06:12 technoplaza Exp $
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         // offset display at (8,8)
00069         wxPoint pos(START_X, START_Y);
00070         
00071         // two rows
00072         for (int row = 0; row < 2; ++row) {
00073             // of 12 password character
00074             for (int col = 0; col < 12; ++col) {
00075                 // separated in the middle with a space
00076                 if (col == 6) {
00077                     pos.x += CHAR_WIDTH;
00078                 }
00079                 
00080                 // (row * 12) + col = [0, 23]
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 

Generated on Fri Sep 30 04:56:20 2005 for Metroid Password Generator by  doxygen 1.4.2