practiceMenu.cpp

00001 /*
00002   タイピング練習メニュー
00003   Satofumi KAMIMURA
00004   $Id$
00005 */
00006 
00007 #include "practiceMenu.h"
00008 #include "practiceMenuUnicode.h"
00009 #include "nettyping.h"
00010 #include "firstMenuUnicode.h"
00011 #include "typingPractice.h"
00012 
00013 
00014 PracticeMenu::PracticeMenu(void)
00015   : title(NULL), user_name(NULL),
00016     type_normal(NULL), memorize_normal(NULL), back_normal(NULL),
00017     type_focused(NULL), memorize_focused(NULL), back_focused(NULL),
00018     practice_num_cmb(NULL) {
00019 }
00020 
00021 
00022 PracticeMenu::~PracticeMenu(void) {
00023   deleteObject();
00024 }
00025 
00026 
00027 void PracticeMenu::deleteObject(void) {
00028   delete type_normal;
00029   delete memorize_normal;
00030   delete back_normal;
00031   delete type_focused;
00032   delete memorize_focused;
00033   delete back_focused;
00034 
00035   delete user_name;
00036   delete title;
00037 }
00038 
00039 
00040 void PracticeMenu::recreate(void) {
00041   win->lock();
00042   win->clear(ForeDepth);
00043   deleteObject();
00044   Initialize(0, NULL);
00045   win->unlock();
00046 }
00047 
00048 
00049 int PracticeMenu::Initialize(int argc, char *argv[]) {
00050   win->clear(ForeDepth);
00051 
00052   // タイトル文字
00053   title = new DrawSurface(ttf->createText(FirstMenu_title, TitleSize,
00054                                          Fore, Back), true);
00055   win->add((new LabelComponent(title))
00056            ->setPosition(Grid(win->w/2, 120), Middle | Center), ForeDepth);
00057 
00058   // メニュー
00059   type_normal = new DrawSurface(ttf->createText(PracticeMenu_type, NormalSize,
00060                                                Normal, Back), true);
00061   memorize_normal =
00062     new DrawSurface(ttf->createText(PracticeMenu_memorize,
00063                                    NormalSize, Normal, Back),true);
00064   back_normal = new DrawSurface(ttf->createText(PracticeMenu_back, NormalSize,
00065                                                Normal, Back), true);
00066   type_focused = new DrawSurface(ttf->createText(PracticeMenu_type, NormalSize,
00067                                                 Focused, Back), true);
00068   memorize_focused =
00069     new DrawSurface(ttf->createText(PracticeMenu_memorize, NormalSize,
00070                                    Focused, Back),true);
00071   back_focused = new DrawSurface(ttf->createText(PracticeMenu_back, NormalSize,
00072                                                 Focused, Back), true);
00073 
00074   type_btn = new ButtonComponent(type_normal);
00075   memorize_btn = new ButtonComponent(memorize_normal);
00076   back_btn = new ButtonComponent(back_normal);
00077   type_btn->setFocusedSurface(type_focused);
00078   memorize_btn->setFocusedSurface(memorize_focused);
00079   back_btn->setFocusedSurface(back_focused);
00080 
00081   menu = new MenuComponent();
00082   menu->add(type_btn);
00083   menu->add(memorize_btn);
00084   menu->add(back_btn);
00085   menu->setOffset(Rect(0, NormalSize + 8));
00086 
00087   menu->addIcon(new LabelComponent(icon));
00088   menu->setIconOffset(Rect(-icon->w -4, -(icon->h - NormalSize)/2));
00089   menu->activate(true);
00090   menu->setPosition(Grid(win->w/2 +16, win->h/2 -32), Center | Top);
00091   win->add(menu, ForeDepth);
00092 
00093   // 選択ユーザ名
00094   user_name =
00095     new DrawSurface(ttf->createText(property->user->name.c_str(), SmallSize,
00096                                     Black, Back), true);
00097   win->add((new LabelComponent(user_name))
00098            ->setPosition(Grid(win->w -16, 16), Right | Top), ForeDepth);
00099 
00100   // 出題数のコンボボックス
00101   practice_num_cmb = new ComboBoxComponent(*ttf);
00102   practice_num_cmb->setColor(Black, Pink, White, Blue);
00103   practice_num_cmb->add(PracticeMenu_6);
00104   practice_num_cmb->add(PracticeMenu_12);
00105   practice_num_cmb->add(PracticeMenu_25);
00106   practice_num_cmb->add(PracticeMenu_50);
00107   practice_num_cmb->add(PracticeMenu_100);
00108   practice_num_cmb->setFontSize(SmallSize);
00109   practice_num_cmb->activate(true);
00110   practice_num_cmb->
00111     setNowIndex(getPracticeNumIndex(property->user->practice_num));
00112   practice_num_cmb->setPosition(Grid(win->w -16, 16 + NormalSize), Right|Top);
00113   win->add(practice_num_cmb, ForeDepth);
00114 
00115   return 0;
00116 }
00117 
00118 
00119 void PracticeMenu::setFocus(bool menu_focused) {
00120   if (menu_focused) {
00121     practice_num_cmb->endFocus();
00122     menu->beginFocus();
00123 
00124   } else {
00125     menu->endFocus();
00126     practice_num_cmb->beginFocus();
00127   }
00128 }
00129 
00130 
00131 int PracticeMenu::MainLoop(void) {
00132 
00133   bool menu_focused = true;
00134   bool quit = false;
00135   do {
00136     win->lock();
00137     if (menu->isDecided()) {
00138       int index = menu->getNowIndex();
00139       win->unlock();
00140       if (index == 0) {
00141         // 下の句タイピング
00142         TypingPractice typing;
00143         typing.run(0, NULL);
00144         recreate();
00145 
00146       } else if (index == 1) {
00147         // 決まり字タイピング
00148         // !!!
00149         recreate();
00150 
00151       } else if (index == 2) {
00152         // 戻る
00153         quit = true;
00154       }
00155       win->lock();
00156     }
00157     UserInput::userInput_t ui = UserInput::getInputed();
00158 
00159     // フォーカス管理
00160     if (ui.isPressedCode(SDLK_TAB)) {
00161       menu_focused = !menu_focused;
00162       setFocus(menu_focused);
00163     }
00164 
00165     if (practice_num_cmb->isDecided()) {
00166       property->user->practice_num =
00167         getPracticeNum(practice_num_cmb->getNowIndex());
00168       menu_focused = true;
00169       setFocus(menu_focused);
00170     }
00171 
00172     if (ui.isPressedCode(SDLK_ESCAPE)) {
00173       if (menu_focused) {
00174         quit = true;
00175       } else {
00176         menu_focused = true;
00177         setFocus(menu_focused);
00178       }
00179     }
00180     quit |= ui.quit;
00181     win->unlock();
00182 
00183     SDL_Delay(10);
00184   } while (!quit);
00185 
00186   return 0;
00187 }
00188 

Generated on Mon Apr 13 22:52:03 2009 by  doxygen 1.5.7.1