PasswordPanel.cc

Go to the documentation of this file.
00001 /*
00002  * Metroid Password Generator
00003  * Copyright (C) 2005,2007-2008 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.4 2008/12/17 00:23:12 jdratlif 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 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         // offset display at (8,8)
00064         wxPoint pos(START_X, START_Y);
00065         
00066         // two rows
00067         for (int row = 0; row < 2; ++row) {
00068             // of 12 password character
00069             for (int col = 0; col < 12; ++col) {
00070                 // separated in the middle with a space
00071                 if (col == 6) {
00072                     pos.x += CHAR_WIDTH;
00073                 }
00074                 
00075                 // (row * 12) + col = [0, 23]
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 

Generated on Tue Dec 16 20:16:57 2008 for Metroid Password Generator by  doxygen 1.5.4