Added the kanamemo & traydict side projects to repository

Originally committed to SVN as r436.
This commit is contained in:
Rodrigo Braz Monteiro 2006-06-29 23:14:54 +00:00
parent 818377243d
commit 4a2c0dbbfa
32 changed files with 3783 additions and 0 deletions

BIN
kanamemo/game_display.cpp Normal file

Binary file not shown.

100
kanamemo/game_display.h Normal file
View file

@ -0,0 +1,100 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include <wx/wxprec.h>
#include <vector>
//////////////
// Prototypes
class KanaTable;
class KanaEntry;
class SwitchUserDialog;
class GamePanel;
//////////////////////
// Game display class
class GameDisplay : public wxWindow {
friend class SwitchUserDialog;
private:
wxStatusBar *statusBar;
const KanaEntry *current;
const KanaEntry *previous;
int curn;
int curTable;
int lastTable;
std::vector<int> scores[2];
bool enabled[2];
wxMenuItem *menuCheck[2];
int status;
int levelUp;
wxString lastEntry;
wxString playerName;
void OnPaint(wxPaintEvent &event);
void OnClick(wxMouseEvent &event);
void Reset();
int GetNAtLevel(int level,int table);
void UpdateStatusBar();
public:
bool autoLevel;
bool isOn;
int level[2];
KanaTable *table;
GamePanel *panel;
GameDisplay(wxWindow *parent);
~GameDisplay();
void ResetTable(int id);
void GetNextKana();
void EnterRomaji(wxString romaji);
void EnableTable(int table,bool enable);
void SetLevel(int table,int level);
void EnableGame(bool enable);
void Save();
void Load();
DECLARE_EVENT_TABLE();
};

109
kanamemo/game_panel.cpp Normal file
View file

@ -0,0 +1,109 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include "game_panel.h"
#include "game_display.h"
///////////////
// Constructor
GamePanel::GamePanel(wxWindow *parent,GameDisplay *dsp)
: wxPanel (parent,-1,wxDefaultPosition,wxDefaultSize,wxRAISED_BORDER)
{
// Set display
display = dsp;
// Controls
enterField = new wxTextCtrl(this,Enter_Box,_T(""),wxDefaultPosition,wxSize(50,-1),wxTE_PROCESS_ENTER);
enterField->SetMaxLength(3);
enterField->SetToolTip(_T("Enter the hepburn romaji for the kana you see here and press the Enter key or the enter button to accept. Type '?' for the answer."));
wxButton *enterButton = new wxButton(this,Enter_Button,_T("Enter"),wxDefaultPosition,wxSize(60,-1));
enterButton->SetToolTip(_T("Enter text. (Pressing the enter key on the keyboard will also work)"));
wxButton *questionButton = new wxButton(this,Question_Button,_T("?"),wxDefaultPosition,wxSize(30,-1));
questionButton->SetToolTip(_T("Shows the correct hepburn romaji for the shown kana."));
// Sizers
wxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
wxSizer *topSizer = new wxBoxSizer(wxHORIZONTAL);
topSizer->AddStretchSpacer(1);
topSizer->Add(new wxStaticText(this,-1,_T("Enter hepburn romaji:")),0,wxALIGN_CENTER | wxRIGHT,8);
topSizer->Add(enterField,0,wxALIGN_CENTER | wxRIGHT,2);
topSizer->Add(enterButton,0,0,0);
topSizer->Add(questionButton,0,0,0);
topSizer->AddStretchSpacer(1);
mainSizer->Add(topSizer,1,wxEXPAND,0);
mainSizer->Add(new wxStaticText(this,-1,_T("Copyright © 2006 - Rodrigo Braz Monteiro. All rights reserved.")),0,wxALIGN_CENTER | wxALL,5);
mainSizer->SetSizeHints(this);
SetSizer(mainSizer);
}
//////////////
// Destructor
GamePanel::~GamePanel() {
}
///////////////
// Event table
BEGIN_EVENT_TABLE(GamePanel,wxPanel)
EVT_BUTTON(Enter_Button,OnEnterPress)
EVT_BUTTON(Question_Button,OnQuestionPress)
EVT_TEXT_ENTER(Enter_Box,OnEnterPress)
END_EVENT_TABLE()
/////////////////
// Enter pressed
void GamePanel::OnEnterPress(wxCommandEvent &event) {
wxString value = enterField->GetValue();
if (!value.IsEmpty()) {
display->EnterRomaji(value);
enterField->Clear();
}
enterField->SetFocus();
}
////////////////////
// Question pressed
void GamePanel::OnQuestionPress(wxCommandEvent &event) {
display->EnterRomaji(_T("?"));
enterField->Clear();
enterField->SetFocus();
}

72
kanamemo/game_panel.h Normal file
View file

@ -0,0 +1,72 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include <wx/wxprec.h>
//////////////
// Prototypes
class GameDisplay;
///////////////
// Panel class
class GamePanel : public wxPanel {
private:
GameDisplay *display;
void OnEnterPress(wxCommandEvent &event);
void OnQuestionPress(wxCommandEvent &event);
public:
wxTextCtrl *enterField;
GamePanel(wxWindow *parent,GameDisplay *dsp);
~GamePanel();
DECLARE_EVENT_TABLE();
};
///////
// IDs
enum {
Enter_Box = 2500,
Enter_Button,
Question_Button
};

166
kanamemo/game_window.cpp Normal file
View file

@ -0,0 +1,166 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include "game_window.h"
#include "game_display.h"
#include "game_panel.h"
#include "version.h"
#include "level.h"
#include "switch_user.h"
///////////////
// Constructor
GameWindow::GameWindow()
: GameWindowBase(NULL,-1,GetVersionString(),wxDefaultPosition,wxDefaultSize,wxMINIMIZE_BOX | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN)
{
// Menu bar
menu = new wxMenuBar();
SetMenuBar(menu);
SetIcon(wxICON(wxicon));
// File menu
wxMenu *fileMenu = new wxMenu;
//fileMenu->Append(Menu_File_New,_T("&New Player"),_T(""));
fileMenu->Append(Menu_File_Load,_T("&Switch User..."),_T(""));
fileMenu->Append(Menu_File_Exit,_T("E&xit"),_T(""));
menu->Append(fileMenu,_T("&File"));
// Options menu
wxMenu *optionsMenu = new wxMenu;
optionsMenu->Append(Menu_Options_Hiragana,_T("Hiragana"),_T(""),wxITEM_CHECK);
optionsMenu->Append(Menu_Options_Katakana,_T("Katakana"),_T(""),wxITEM_CHECK);
optionsMenu->Append(Menu_Options_Level,_T("Set Level..."),_T(""));
menu->Append(optionsMenu,_T("&Options"));
// Status bar
wxStatusBar *bar = CreateStatusBar(3,0);
int widths[] = { 85, -1, -1 };
bar->SetStatusWidths(3,widths);
// Subwindows
display = new GameDisplay(this);
panel = new GamePanel(this,display);
display->panel = panel;
// Sizer
wxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
mainSizer->Add(display,1,wxEXPAND,0);
mainSizer->Add(panel,0,wxEXPAND,0);
mainSizer->SetSizeHints(this);
SetSizer(mainSizer);
// Prompt user for name
Show();
SwitchUserDialog user(display);
user.ShowModal();
if (!display->isOn) Destroy();
}
//////////////
// Destructor
GameWindow::~GameWindow() {
}
///////////////
// Event table
BEGIN_EVENT_TABLE(GameWindow,GameWindowBase)
EVT_CLOSE(GameWindow::OnClose)
EVT_MENU(Menu_File_Exit,GameWindow::OnFileExit)
EVT_MENU(Menu_File_New,GameWindow::OnFileNew)
EVT_MENU(Menu_File_Load,GameWindow::OnFileLoad)
EVT_MENU(Menu_Options_Hiragana,GameWindow::OnOptionsHiragana)
EVT_MENU(Menu_Options_Katakana,GameWindow::OnOptionsKatakana)
EVT_MENU(Menu_Options_Level,GameWindow::OnOptionsLevel)
END_EVENT_TABLE()
///////////////
// Close event
void GameWindow::OnClose(wxCloseEvent &event) {
Destroy();
}
////////
// Exit
void GameWindow::OnFileExit(wxCommandEvent &event) {
Close();
}
//////////////
// New player
void GameWindow::OnFileNew(wxCommandEvent &event) {
}
///////////////
// Load player
void GameWindow::OnFileLoad(wxCommandEvent &event) {
display->Save();
SwitchUserDialog user(display);
user.ShowModal();
}
///////////////////
// Toggle hiragana
void GameWindow::OnOptionsHiragana(wxCommandEvent &event) {
display->EnableTable(0,event.IsChecked());
display->Save();
}
///////////////////
// Toggle katakana
void GameWindow::OnOptionsKatakana(wxCommandEvent &event) {
display->EnableTable(1,event.IsChecked());
display->Save();
}
////////////////////
// Difficulty Level
void GameWindow::OnOptionsLevel(wxCommandEvent &event) {
LevelWindow level(this,display);
level.ShowModal();
display->Save();
}

86
kanamemo/game_window.h Normal file
View file

@ -0,0 +1,86 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include <wx/wxprec.h>
//////////////
// Prototypes
class GameDisplay;
class GamePanel;
///////////
// Typedef
typedef wxFrame GameWindowBase;
/////////////////////
// Game window class
class GameWindow : public GameWindowBase {
private:
GameDisplay *display;
GamePanel *panel;
wxMenuBar *menu;
void OnClose(wxCloseEvent &event);
void OnFileExit(wxCommandEvent &event);
void OnFileNew(wxCommandEvent &event);
void OnFileLoad(wxCommandEvent &event);
void OnOptionsHiragana(wxCommandEvent &event);
void OnOptionsKatakana(wxCommandEvent &event);
void OnOptionsLevel(wxCommandEvent &event);
public:
GameWindow();
~GameWindow();
DECLARE_EVENT_TABLE();
};
////////////////////
// Menu identifiers
enum {
Menu_File_Exit = 2000,
Menu_File_New,
Menu_File_Load,
Menu_Options_Hiragana,
Menu_Options_Katakana,
Menu_Options_Level
};

BIN
kanamemo/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

294
kanamemo/kana_table.cpp Normal file
View file

@ -0,0 +1,294 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include "kana_table.h"
///////////////
// Constructor
KanaTable::KanaTable() {
level = 0;
groups[0] = 0;
groups[1] = 0;
BeginGroup();
Insert(L"",L"",L"a");
Insert(L"",L"",L"i");
Insert(L"",L"",L"u");
Insert(L"",L"",L"e");
Insert(L"",L"",L"o");
BeginGroup();
Insert(L"",L"",L"ka");
Insert(L"",L"",L"ki");
Insert(L"",L"",L"ku");
Insert(L"",L"",L"ke");
Insert(L"",L"",L"ko");
BeginGroup();
Insert(L"",L"",L"sa");
Insert(L"",L"",L"shi");
Insert(L"",L"",L"su");
Insert(L"",L"",L"se");
Insert(L"",L"",L"so");
BeginGroup();
Insert(L"",L"",L"ta");
Insert(L"",L"",L"chi");
Insert(L"",L"",L"tsu");
Insert(L"",L"",L"te");
Insert(L"",L"",L"to");
BeginGroup();
Insert(L"",L"",L"na");
Insert(L"",L"",L"ni");
Insert(L"",L"",L"nu");
Insert(L"",L"",L"ne");
Insert(L"",L"",L"no");
BeginGroup();
Insert(L"",L"",L"ha");
Insert(L"",L"",L"hi");
Insert(L"",L"",L"fu");
Insert(L"",L"",L"he");
Insert(L"",L"",L"ho");
BeginGroup();
Insert(L"",L"",L"ma");
Insert(L"",L"",L"mi");
Insert(L"",L"",L"mu");
Insert(L"",L"",L"me");
Insert(L"",L"",L"mo");
BeginGroup();
Insert(L"",L"",L"ya");
Insert(L"",L"",L"yu");
Insert(L"",L"",L"yo");
BeginGroup();
Insert(L"",L"",L"ra");
Insert(L"",L"",L"ri");
Insert(L"",L"",L"ru");
Insert(L"",L"",L"re");
Insert(L"",L"",L"ro");
BeginGroup();
Insert(L"",L"",L"wa");
Insert(L"",L"",L"wo");
BeginGroup();
level--;
Insert(L"",L"",L"n");
BeginGroup();
Insert(L"",L"",L"ga");
Insert(L"",L"",L"gi");
Insert(L"",L"",L"gu");
Insert(L"",L"",L"ge");
Insert(L"",L"",L"go");
BeginGroup();
Insert(L"",L"",L"za");
Insert(L"",L"",L"ji");
Insert(L"",L"",L"zu");
Insert(L"",L"",L"ze");
Insert(L"",L"",L"zo");
BeginGroup();
Insert(L"",L"",L"da");
Insert(L"",L"",L"ji");
Insert(L"",L"",L"zu");
Insert(L"",L"",L"de");
Insert(L"",L"",L"do");
BeginGroup();
Insert(L"",L"",L"ba");
Insert(L"",L"",L"bi");
Insert(L"",L"",L"bu");
Insert(L"",L"",L"be");
Insert(L"",L"",L"bo");
BeginGroup();
Insert(L"",L"",L"pa");
Insert(L"",L"",L"pi");
Insert(L"",L"",L"pu");
Insert(L"",L"",L"pe");
Insert(L"",L"",L"po");
BeginGroup();
Insert(L"きゃ",L"キャ",L"kya");
Insert(L"きゅ",L"キュ",L"kyu");
Insert(L"きょ",L"キョ",L"kyo");
BeginGroup();
Insert(L"しゃ",L"シャ",L"sha");
Insert(L"しゅ",L"シュ",L"shu");
Insert(L"しょ",L"ショ",L"sho");
BeginGroup();
Insert(L"ちゃ",L"チャ",L"cha");
Insert(L"ちゅ",L"チュ",L"chu");
Insert(L"ちょ",L"チョ",L"cho");
BeginGroup();
Insert(L"にゃ",L"ニャ",L"nya");
Insert(L"にゅ",L"ニュ",L"nyu");
Insert(L"にょ",L"ニョ",L"nyo");
BeginGroup();
Insert(L"ひゃ",L"ヒャ",L"hya");
Insert(L"ひゅ",L"ヒュ",L"hyu");
Insert(L"ひょ",L"ヒョ",L"hyo");
BeginGroup();
Insert(L"みゃ",L"ミャ",L"mya");
Insert(L"みゅ",L"ミュ",L"myu");
Insert(L"みょ",L"ミョ",L"myo");
BeginGroup();
Insert(L"りゃ",L"リャ",L"rya");
Insert(L"りゅ",L"リュ",L"ryu");
Insert(L"りょ",L"リョ",L"ryo");
BeginGroup();
Insert(L"ぎゃ",L"ギャ",L"gya");
Insert(L"ぎゅ",L"ギュ",L"gyu");
Insert(L"ぎょ",L"ギョ",L"gyo");
BeginGroup();
Insert(L"じゃ",L"ジャ",L"ja");
Insert(L"じゅ",L"ジュ",L"ju");
Insert(L"じょ",L"ジョ",L"jo");
BeginGroup();
Insert(L"ぢゃ",L"ヂャ",L"ja");
Insert(L"ぢゅ",L"ヂュ",L"ju");
Insert(L"ぢょ",L"ヂョ",L"jo");
BeginGroup();
Insert(L"びゃ",L"ビャ",L"bya");
Insert(L"びゅ",L"ビュ",L"byu");
Insert(L"びょ",L"ビョ",L"byo");
BeginGroup();
Insert(L"ぴゃ",L"ピャ",L"pya");
Insert(L"ぴゅ",L"ピュ",L"pyu");
Insert(L"ぴょ",L"ピョ",L"pyo");
BeginGroup();
Insert(L"",L"ファ",L"fa");
Insert(L"",L"フィ",L"fi");
Insert(L"",L"フェ",L"fe");
Insert(L"",L"フォ",L"fo");
BeginGroup();
Insert(L"",L"ヴァ",L"va");
Insert(L"",L"ヴィ",L"vi");
Insert(L"",L"",L"vu");
Insert(L"",L"ヴェ",L"ve");
Insert(L"",L"ヴォ",L"vo");
}
//////////////
// Destructor
KanaTable::~KanaTable() {
}
///////////////
// Begin group
void KanaTable::BeginGroup() {
curGroup = _T("");
level++;
}
//////////
// Insert
void KanaTable::Insert(wchar_t *hira,wchar_t *kata,wchar_t *hep) {
#ifdef _UNICODE
KanaEntry entry(hira,kata,hep);
if (curGroup.IsEmpty()) curGroup = hep;
entry.group = curGroup;
entry.level = level;
if (!entry.hiragana.IsEmpty() && level > groups[0]) groups[0] = level;
if (!entry.katakana.IsEmpty() && level > groups[1]) groups[1] = level;
entries.push_back(entry);
#endif
}
/////////////////////
// Number of entries
int KanaTable::GetNumberEntries(int level) const {
if (level == -1) return entries.size();
else {
int count = 0;
int n = entries.size();
for (int i=0;i<n;i++) {
if (entries[i].level <= level) count++;
}
return count;
}
}
////////////////////////
// Get a specific entry
const KanaEntry &KanaTable::GetEntry(int i) const {
return entries.at(i);
}
//////////////////////////
// Find a specific romaji
const KanaEntry *KanaTable::FindByRomaji(wxString romaji) const {
int n = entries.size();
for (int i=0;i<n;i++) {
if (entries[i].hepburn == romaji) return &entries[i];
}
return NULL;
}
/////////////////////////////////////////////
// Get number of levels for a specific table
int KanaTable::GetLevels(int table) const {
return groups[table];
}

80
kanamemo/kana_table.h Normal file
View file

@ -0,0 +1,80 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include <vector>
#include <wx/wxprec.h>
///////////////////////////
// Hiragana/katakana entry
class KanaEntry {
public:
wxString hiragana;
wxString katakana;
wxString hepburn;
wxString group;
int level;
KanaEntry(wxString hira,wxString kata,wxString hep) {
hiragana = hira;
katakana = kata;
hepburn = hep;
}
};
///////////////////////////
// Hiragana/Katakana table
class KanaTable {
private:
std::vector<KanaEntry> entries;
void Insert(wchar_t *hira,wchar_t *kata,wchar_t *hep);
void BeginGroup();
wxString curGroup;
int groups[2];
int level;
public:
KanaTable();
~KanaTable();
int GetNumberEntries(int level=-1) const;
int GetLevels(int table) const;
const KanaEntry &GetEntry(int i) const;
const KanaEntry *FindByRomaji(wxString romaji) const;
};

117
kanamemo/level.cpp Normal file
View file

@ -0,0 +1,117 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include "level.h"
#include "game_display.h"
#include "kana_table.h"
///////////////
// Constructor
LevelWindow::LevelWindow(wxWindow *parent,GameDisplay *dsp)
: wxDialog(parent,-1,_T("Set Level"),wxDefaultPosition,wxDefaultSize)
{
// Set display
display = dsp;
// Sliders
int levelHira = display->level[0];
int levelKata = display->level[1];
int maxLevelHira = display->table->GetLevels(0);
int maxLevelKata = display->table->GetLevels(1);
hiraSlider = new wxSlider(this,-1,levelHira,1,maxLevelHira,wxDefaultPosition,wxSize(200,-1));
kataSlider = new wxSlider(this,-1,levelKata,1,maxLevelKata,wxDefaultPosition,wxSize(200,-1));
// Checkbox
autoLevelCheck = new wxCheckBox(this,-1,_T("Automatically level up"));
autoLevelCheck->SetValue(display->autoLevel);
// Sizers
wxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
wxSizer *sizer1 = new wxStaticBoxSizer(wxVERTICAL,this,_T("Hiragana and Katakana"));
wxSizer *sizer2 = new wxFlexGridSizer(2,2,5,5);
wxSizer *sizer3 = new wxBoxSizer(wxHORIZONTAL);
// Insert controls
sizer2->Add(new wxStaticText(this,-1,_T("Hiragana")),0,wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxRIGHT,5);
sizer2->Add(hiraSlider,1,wxEXPAND,0);
sizer2->Add(new wxStaticText(this,-1,_T("Katakana")),0,wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxRIGHT,5);
sizer2->Add(kataSlider,1,wxEXPAND,0);
// Sizer layout
sizer1->Add(sizer2,1,wxEXPAND,0);
sizer1->Add(autoLevelCheck,0,wxALIGN_LEFT | wxTOP,5);
sizer3->AddStretchSpacer(1);
sizer3->Add(new wxButton(this,wxID_OK),0,0,0);
sizer3->Add(new wxButton(this,wxID_CANCEL),0,0,0);
mainSizer->Add(sizer1,1,wxEXPAND | wxALL,5);
mainSizer->Add(sizer3,0,wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM,5);
mainSizer->SetSizeHints(this);
SetSizer(mainSizer);
}
//////////////
// Destructor
LevelWindow::~LevelWindow() {
}
///////////////
// Event table
BEGIN_EVENT_TABLE(LevelWindow,wxDialog)
EVT_BUTTON(wxID_OK,LevelWindow::OnOK)
EVT_BUTTON(wxID_CANCEL,LevelWindow::OnCancel)
END_EVENT_TABLE()
//////
// OK
void LevelWindow::OnOK(wxCommandEvent &event) {
display->autoLevel = autoLevelCheck->GetValue();
display->SetLevel(0,hiraSlider->GetValue());
display->SetLevel(1,kataSlider->GetValue());
Destroy();
}
//////////
// Cancel
void LevelWindow::OnCancel(wxCommandEvent &event) {
Destroy();
}

65
kanamemo/level.h Normal file
View file

@ -0,0 +1,65 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include <wx/wxprec.h>
//////////////
// Prototypes
class GameDisplay;
/////////////////////
// Game window class
class LevelWindow : public wxDialog {
private:
GameDisplay *display;
wxSlider *hiraSlider;
wxSlider *kataSlider;
wxCheckBox *autoLevelCheck;
void OnOK(wxCommandEvent &event);
void OnCancel(wxCommandEvent &event);
public:
LevelWindow(wxWindow *parent,GameDisplay *dsp);
~LevelWindow();
DECLARE_EVENT_TABLE();
};

115
kanamemo/main.cpp Normal file
View file

@ -0,0 +1,115 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include <wx/wxprec.h>
#include <wx/filename.h>
#include "main.h"
#include "game_window.h"
/////////////////
// Implement app
IMPLEMENT_APP(KanaMemo)
//////////////
// Initialize
bool KanaMemo::OnInit() {
// Configuration
SetAppName(_T("KanaMemo"));
srand((unsigned)time(NULL));
// Get path
GetFullPath(argv[0]);
GetFolderName();
// Create the window
GameWindow *window = new GameWindow();
window->Show();
// Initialization OK
return true;
}
/////////////////////////////
// Gets and stores full path
void KanaMemo::GetFullPath(wxString arg) {
if (wxIsAbsolutePath(arg)) {
fullPath = arg;
return;
}
// Is it a relative path?
wxString currentDir(wxFileName::GetCwd());
if (currentDir.Last() != wxFILE_SEP_PATH) currentDir += wxFILE_SEP_PATH;
wxString str = currentDir + arg;
if (wxFileExists(str)) {
fullPath = str;
return;
}
// OK, it's neither an absolute path nor a relative path.
// Search PATH.
wxPathList pathList;
pathList.AddEnvList(_T("PATH"));
str = pathList.FindAbsoluteValidPath(arg);
if (!str.IsEmpty()) {
fullPath = str;
return;
}
fullPath = _T("");
return;
}
///////////////////////////////////
// Gets folder name from full path
void KanaMemo::GetFolderName () {
folderName = _T("");
wxFileName path(fullPath);
folderName += path.GetPath(wxPATH_GET_VOLUME);
folderName += _T("/");
}
///////////
// Statics
wxString KanaMemo::folderName;
wxString KanaMemo::fullPath;

47
kanamemo/main.h Normal file
View file

@ -0,0 +1,47 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
//////////////
// Main class
class KanaMemo : public wxApp {
public:
bool OnInit();
void GetFullPath(wxString arg);
void GetFolderName();
static wxString folderName;
static wxString fullPath;
};

3
kanamemo/res.rc Normal file
View file

@ -0,0 +1,3 @@
wxicon ICON "icon.ico"
#include "wx/msw/wx.rc"

178
kanamemo/switch_user.cpp Normal file
View file

@ -0,0 +1,178 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include <wx/filename.h>
#include <wx/dir.h>
#include <stdio.h>
#include "switch_user.h"
#include "game_display.h"
#include "main.h"
///////////////
// Constructor
SwitchUserDialog::SwitchUserDialog(GameDisplay *dspl)
: wxDialog(NULL,-1,_T("Select user..."),wxDefaultPosition,wxDefaultSize)
{
display = dspl;
// Sizers
wxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
wxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL);
wxSizer *listSizer = new wxStaticBoxSizer(wxVERTICAL,this,_T("Users:"));
// Load list
wxArrayString choices;
wxArrayString files;
wxDir::GetAllFiles(KanaMemo::folderName,&files,_T("*.usr"),wxDIR_FILES);
for (size_t i=0;i<files.Count();i++) {
wxFileName fname(files[i]);
choices.Add(fname.GetName());
}
// List sizer
listBox = new wxListBox(this,1337,wxDefaultPosition,wxSize(200,150),choices,wxLB_SINGLE | wxLB_SORT );
listSizer->Add(listBox,1,wxEXPAND,0);
// Button sizer
buttonSizer->AddStretchSpacer(1);
okButton = new wxButton(this,wxID_OK);
buttonSizer->Add(new wxButton(this,wxID_NEW),0,0,0);
buttonSizer->Add(okButton,0,0,0);
buttonSizer->Add(new wxButton(this,wxID_CANCEL),0,0,0);
// Main sizer
mainSizer->Add(listSizer,1,wxEXPAND | wxALL,5);
mainSizer->Add(buttonSizer,0,wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM,5);
mainSizer->SetSizeHints(this);
SetSizer(mainSizer);
// If list is empty, prompt for new user
if (listBox->GetCount() == 0) NewUser();
UpdateButtons();
}
//////////////
// Destructor
SwitchUserDialog::~SwitchUserDialog() {
}
///////////////
// Event table
BEGIN_EVENT_TABLE(SwitchUserDialog,wxDialog)
EVT_BUTTON(wxID_NEW,SwitchUserDialog::OnButtonCreate)
EVT_BUTTON(wxID_OK,SwitchUserDialog::OnButtonOK)
EVT_BUTTON(wxID_CANCEL,SwitchUserDialog::OnButtonCancel)
EVT_LISTBOX(1337, SwitchUserDialog::OnClickList)
EVT_LISTBOX_DCLICK(1337, SwitchUserDialog::OnDoubleClickList)
END_EVENT_TABLE()
//////////
// Create
void SwitchUserDialog::OnButtonCreate(wxCommandEvent &event) {
NewUser();
}
//////
// OK
void SwitchUserDialog::OnButtonOK(wxCommandEvent &event) {
Select();
}
//////////
// Cancel
void SwitchUserDialog::OnButtonCancel(wxCommandEvent &event) {
Destroy();
}
////////////
// New user
void SwitchUserDialog::NewUser() {
wxString userName = wxGetTextFromUser(_T("Enter the name of the new user:"),_T("New user"),_T(""),this);
if (!userName.IsEmpty()) {
// Create file
wxString path = KanaMemo::folderName + _T("/") + userName + _T(".usr");
FILE *fp = fopen(path.mb_str(wxConvLocal),"wb");
fclose(fp);
// Update stuff
listBox->Append(userName);
listBox->SetStringSelection(userName);
UpdateButtons();
}
}
////////////////
// List clicked
void SwitchUserDialog::OnClickList(wxCommandEvent &event) {
UpdateButtons();
}
///////////////////////
// List double clicked
void SwitchUserDialog::OnDoubleClickList(wxCommandEvent &event) {
Select();
}
//////////////////
// Update buttons
void SwitchUserDialog::UpdateButtons() {
okButton->Enable(!listBox->GetStringSelection().IsEmpty());
}
///////////////
// Select user
void SwitchUserDialog::Select() {
wxString user = listBox->GetStringSelection();
if (!user.IsEmpty()) {
display->playerName = user;
display->Load();
display->EnableGame(true);
Destroy();
}
}

71
kanamemo/switch_user.h Normal file
View file

@ -0,0 +1,71 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include <wx/wxprec.h>
//////////////
// Prototypes
class GameDisplay;
///////////////////////
// Switch users dialog
class SwitchUserDialog : public wxDialog {
private:
GameDisplay *display;
wxListBox *listBox;
wxButton *okButton;
void OnButtonCreate(wxCommandEvent &event);
void OnButtonOK(wxCommandEvent &event);
void OnButtonCancel(wxCommandEvent &event);
void OnClickList(wxCommandEvent &event);
void OnDoubleClickList(wxCommandEvent &event);
void NewUser();
void UpdateButtons();
void Select();
public:
SwitchUserDialog(GameDisplay *display);
~SwitchUserDialog();
DECLARE_EVENT_TABLE()
};

51
kanamemo/version.cpp Normal file
View file

@ -0,0 +1,51 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include "version.h"
////////////////////
// Version function
wxString GetVersionString() {
wxString final;
final = _T("KanaMemo v0.06");
#ifdef _DEBUG
final += _T(" DEBUG");
#endif
return final;
}

44
kanamemo/version.h Normal file
View file

@ -0,0 +1,44 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include <wx/wxprec.h>
////////////////////
// Version function
wxString GetVersionString();

228
traydict/dict_window.cpp Normal file
View file

@ -0,0 +1,228 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include <wx/wxprec.h>
#include <wx/taskbar.h>
#include "dict_window.h"
#include "systray.h"
#include "dictionary.h"
#include "main.h"
///////////////
// Constructor
DictWindow::DictWindow()
: wxFrame(NULL,-1,_T("TrayDict v0.06 - By Rodrigo Braz Monteiro"),wxDefaultPosition,wxSize(620,500),wxRESIZE_BORDER | wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN)
{
// Icons
SetIcon(wxICON(wxicon));
systray = new Systray(this);
// Menu bar
//menu = new wxMenuBar();
//SetMenuBar(menu);
// Status bar
//wxStatusBar *bar = CreateStatusBar(3,0);
//int widths[] = { 85, -1, -1 };
//bar->SetStatusWidths(3,widths);
// Panel
panel = new wxPanel(this);
// Controls
entry = new wxTextCtrl(panel,ENTRY_FIELD,_T(""),wxDefaultPosition,wxDefaultSize,wxTE_PROCESS_ENTER);
results = new wxTextCtrl(panel,-1,_T(""),wxDefaultPosition,wxSize(280,400),wxTE_RICH2 | wxTE_MULTILINE | wxTE_DONTWRAP | wxTE_READONLY);
wxButton *searchButton = new wxButton(panel,BUTTON_SEARCH,_T("Search"),wxDefaultPosition,wxSize(80,-1));
wxSizer *entrySizer = new wxBoxSizer(wxHORIZONTAL);
entrySizer->Add(entry,1,wxEXPAND | wxRIGHT,5);
entrySizer->Add(searchButton,0,wxEXPAND,0);
// Options
checkKanji = new wxCheckBox(panel,CHECK_KANJI,_T("Kanji"));
checkKana = new wxCheckBox(panel,CHECK_KANA,_T("Kana"));
checkRomaji = new wxCheckBox(panel,CHECK_ROMAJI,_T("Romaji"));
checkEnglish = new wxCheckBox(panel,CHECK_ENGLISH,_T("English"));
checkEdict = new wxCheckBox(panel,CHECK_ENGLISH,_T("EDICT"));
checkEnamdict = new wxCheckBox(panel,CHECK_ENGLISH,_T("ENAMDICT"));
checkCompdic = new wxCheckBox(panel,CHECK_ENGLISH,_T("COMPDIC"));
checkJplaces = new wxCheckBox(panel,CHECK_ENGLISH,_T("J_PLACES"));
checkKanji->SetValue(true);
checkKana->SetValue(true);
checkRomaji->SetValue(true);
checkEnglish->SetValue(true);
checkEdict->SetValue(true);
checkEnamdict->SetValue(false);
checkCompdic->SetValue(false);
checkJplaces->SetValue(false);
wxSizer *optionsSizer = new wxBoxSizer(wxHORIZONTAL);
optionsSizer->Add(new wxStaticText(panel,-1,_T("Display:")),0,wxCENTER | wxRIGHT,5);
optionsSizer->Add(checkKanji,0,wxCENTER | wxRIGHT,5);
optionsSizer->Add(checkKana,0,wxCENTER | wxRIGHT,5);
optionsSizer->Add(checkRomaji,0,wxCENTER | wxRIGHT,5);
optionsSizer->Add(checkEnglish,0,wxCENTER | wxRIGHT,20);
optionsSizer->Add(new wxStaticText(panel,-1,_T("Dictionary:")),0,wxCENTER | wxRIGHT,5);
optionsSizer->Add(checkEdict,0,wxCENTER | wxRIGHT,5);
optionsSizer->Add(checkEnamdict,0,wxCENTER | wxRIGHT,5);
optionsSizer->Add(checkCompdic,0,wxCENTER | wxRIGHT,5);
optionsSizer->Add(checkJplaces,0,wxCENTER | wxRIGHT,0);
optionsSizer->AddStretchSpacer(1);
// Main sizer
wxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
mainSizer->Add(entrySizer,0,wxEXPAND | wxALL,5);
mainSizer->Add(optionsSizer,0,wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM,5);
mainSizer->Add(results,1,wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM,5);
panel->SetSizer(mainSizer);
// Create dictionary files
if (false) {
Dictionary::Convert(TrayDict::folderName + _T("edict"),TrayDict::folderName + _T("edict.dic"));
Dictionary::Convert(TrayDict::folderName + _T("enamdict"),TrayDict::folderName + _T("enamdict.dic"));
Dictionary::Convert(TrayDict::folderName + _T("compdic"),TrayDict::folderName + _T("compdic.dic"));
Dictionary::Convert(TrayDict::folderName + _T("j_places"),TrayDict::folderName + _T("j_places.dic"));
}
// Load dictionary files
dict.push_back(new Dictionary(_T("edict"),checkEdict));
dict.push_back(new Dictionary(_T("enamdict"),checkEnamdict));
dict.push_back(new Dictionary(_T("compdic"),checkCompdic));
dict.push_back(new Dictionary(_T("j_places"),checkJplaces));
// Register hotkey
RegisterHotKey(HOTKEY_ID,wxMOD_WIN,'Z');
}
//////////////
// Destructor
DictWindow::~DictWindow() {
if (systray->IsOk()) {
systray->RemoveIcon();
}
delete systray;
for (size_t i=0;i<dict.size();i++) delete dict[i];
dict.clear();
}
/////////////////
// Go to systray
void DictWindow::GoToTray() {
if (systray->IsOk()) {
Hide();
}
}
///////////////
// Event table
BEGIN_EVENT_TABLE(DictWindow,wxFrame)
EVT_ICONIZE(DictWindow::OnIconize)
EVT_BUTTON(BUTTON_SEARCH,DictWindow::OnSearch)
EVT_TEXT_ENTER(ENTRY_FIELD,DictWindow::OnSearch)
EVT_HOTKEY(HOTKEY_ID,DictWindow::OnHotkey)
EVT_CLOSE(DictWindow::OnClose)
END_EVENT_TABLE()
/////////////////
// Iconize event
void DictWindow::OnIconize(wxIconizeEvent &event) {
if (event.Iconized()) {
GoToTray();
}
}
//////////////////
// Hotkey pressed
void DictWindow::OnHotkey(wxKeyEvent &event) {
if (IsShown()) GoToTray();
else systray->BringUp();
}
/////////////////////////
// Search button pressed
void DictWindow::OnSearch(wxCommandEvent &event) {
Search(entry->GetValue());
}
//////////
// Search
void DictWindow::Search(wxString text) {
// Prepare
int bitmask = (checkKanji->GetValue() ? 1 : 0) | (checkKana->GetValue() ? 2 : 0) | (checkRomaji->GetValue() ? 4 : 0) | (checkEnglish->GetValue() ? 8 : 0);
// Clear text
results->Clear();
entry->SetSelection(0,entry->GetValue().Length());
// Search each dictionary
for (size_t i=0;i<dict.size();i++) {
if (dict[i]->check->GetValue() && dict[i]->check->IsEnabled()) {
// Search
ResultSet res;
dict[i]->Search(res,text);
// Sort results by relevancy
res.results.sort();
// Print
res.Print(results,bitmask);
}
}
// Show start
results->ShowPosition(0);
results->SetSelection(0,0);
}
////////////////
// Close window
void DictWindow::OnClose(wxCloseEvent &event) {
if (event.CanVeto()) {
event.Veto();
GoToTray();
}
else Destroy();
}

95
traydict/dict_window.h Normal file
View file

@ -0,0 +1,95 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include <vector>
//////////////
// Prototypes
class Systray;
class Dictionary;
//////////////////////////
// Dictionary main window
class DictWindow : public wxFrame {
private:
wxMenuBar *menu;
wxTextCtrl *results;
Systray *systray;
std::vector<Dictionary*> dict;
void GoToTray();
void ComeFromTray();
void OnIconize(wxIconizeEvent &event);
void OnSearch(wxCommandEvent &event);
void OnHotkey(wxKeyEvent &event);
void OnClose(wxCloseEvent &event);
void Search(wxString text);
public:
wxTextCtrl *entry;
wxPanel *panel;
wxCheckBox *checkKanji;
wxCheckBox *checkKana;
wxCheckBox *checkRomaji;
wxCheckBox *checkEnglish;
wxCheckBox *checkEdict;
wxCheckBox *checkEnamdict;
wxCheckBox *checkCompdic;
wxCheckBox *checkJplaces;
DictWindow();
~DictWindow();
DECLARE_EVENT_TABLE();
};
///////
// IDs
enum {
BUTTON_SEARCH = 1200,
ENTRY_FIELD,
CHECK_KANJI,
CHECK_KANA,
CHECK_ROMAJI,
CHECK_ENGLISH,
HOTKEY_ID = 0x19E2 // Totally arbitrary
};

587
traydict/dictionary.cpp Normal file
View file

@ -0,0 +1,587 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include <wx/wxprec.h>
#include <wx/tokenzr.h>
#include <wx/filename.h>
#include <wx/zstream.h>
#include <wx/wfstream.h>
#include <stdio.h>
#include "dictionary.h"
#include "text_file_reader.h"
#include "main.h"
///////////////
// Constructor
Dictionary::Dictionary(wxString _name,wxCheckBox *_check) {
name = _name;
check = _check;
// Set file
wxString filename = TrayDict::folderName + _name + _T(".dic");
Load(filename);
// Set checkbox
wxFileName file(filename);
check->Enable(file.FileExists());
}
//////////////
// Destructor
Dictionary::~Dictionary() {
}
//////////
// Static
KanaTable Dictionary::kanatable;
////////
// Load
void Dictionary::Convert(wxString source,wxString dest) {
// Variables
const wchar_t *str = NULL;
short len;
DictEntry curEntry;
try {
// Open source file
TextFileReader file(source,_T("EUC-JP"));
// Open destination file
wxFileOutputStream out(dest);
wxBufferedOutputStream buf(out);
wxZlibOutputStream fp(buf,9,wxZLIB_GZIP);
// Skip first line
if (file.HasMoreLines()) file.ReadLineFromFile();
// Read lines
while (file.HasMoreLines()) {
// Get string
wxString string = file.ReadLineFromFile();
// Process string to account for lack of kana
if (!string.Contains(_T("["))) {
if (!string.Contains(_T("]"))) {
int pos = string.Find(_T(' '));
if (pos == -1) continue;
wxString temp = string;
string = temp.Left(pos) + _T(" []") + temp.Right(temp.Length() - pos);
}
else continue;
}
// Tokenize
wxStringTokenizer token(string,_T("[]"),wxTOKEN_RET_EMPTY);
// Kanji
if (token.HasMoreTokens()) {
curEntry.kanji = token.GetNextToken().Trim(false).Trim(true);
}
else continue;
// Kana & romaji
if (token.HasMoreTokens()) {
curEntry.kana = token.GetNextToken().Trim(false).Trim(true);
if (curEntry.kana.IsEmpty()) curEntry.kana = curEntry.kanji;
curEntry.romaji = kanatable.KanaToRomaji(curEntry.kana,0);
}
else continue;
// English
if (token.HasMoreTokens()) {
curEntry.english = token.GetNextToken().Trim(false).Trim(true);
curEntry.english = curEntry.english.Mid(1,curEntry.english.Length()-2);
}
else continue;
// Write kanji
str = curEntry.kanji.c_str();
len = wcslen(str);
fp.Write(&len,2);
fp.Write(str,len*2);
// Write kana
str = curEntry.kana.c_str();
len = wcslen(str);
fp.Write(&len,2);
fp.Write(str,len*2);
// Write romaji
str = curEntry.romaji.c_str();
len = wcslen(str);
fp.Write(&len,2);
fp.Write(str,len*2);
// Write english
str = curEntry.english.c_str();
len = wcslen(str);
fp.Write(&len,2);
fp.Write(str,len*2);
}
}
catch (...) {
wxMessageBox(_T("Could not find dictionary file: ") + source,_T("File not found!"),wxICON_ERROR);
}
}
////////
// Load
void Dictionary::Load(wxString filename) {
dictFile = filename;
}
//////////
// Search
void Dictionary::Search(ResultSet &results,wxString query) {
// Prepare results
int resCount = 0;
results.ownData = true;
results.dicName = name;
results.query = query;
query.Trim(true);
query.Trim(false);
// Determine query type
bool isJapanese = false;
for (size_t i=0;i<query.Length();i++) {
if (query[i] > 255) {
isJapanese = true;
break;
}
}
// Stopwatch
wxStopWatch stopwatch;
// Open file
wxInputStream *file;
wxFileInputStream filestream(dictFile);
wxBufferedInputStream buf(filestream);
wxZlibInputStream zstream(buf);
wxBufferedInputStream buf2(zstream);
file = &zstream;
// Buffer
wchar_t buffer[16384];
short len;
DictEntry *cur = NULL;
// Search for matches
while (!file->Eof()) {
// Prepare
bool addThis = false;
int rel = 0;
// Create data
if (!cur) cur = new DictEntry;
// Read kanji
file->Read(&len,2);
if (len < 0) return;
file->Read(buffer,2*len);
buffer[len] = 0;
cur->kanji = buffer;
// Read kana
file->Read(&len,2);
if (len < 0) return;
file->Read(buffer,2*len);
buffer[len] = 0;
cur->kana = buffer;
// Read romaji
file->Read(&len,2);
if (len < 0) return;
file->Read(buffer,2*len);
buffer[len] = 0;
cur->romaji = buffer;
// Read english
file->Read(&len,2);
if (len < 0) return;
file->Read(buffer,2*len);
buffer[len] = 0;
cur->english = buffer;
// Japanese query
if (isJapanese) {
// Matches kanji?
if (cur->kanji.Contains(query)) {
addThis = true;
rel = GetRelevancy(query,cur->kanji,cur->english.Contains(_T("(P)")));
}
// Matches kana?
else if (cur->kana.Contains(query)) {
addThis = true;
rel = GetRelevancy(query,cur->kana,cur->english.Contains(_T("(P)")));
}
}
// English/romaji query
else {
// Lowercase query
wxString lowQuery = query.Lower();
// Matches english?
if (cur->english.Lower().Contains(lowQuery)) {
addThis = true;
rel = GetRelevancy(lowQuery,cur->english,cur->english.Contains(_T("(P)")),true);
}
// Matches wapuro romaji?
if (cur->romaji.Contains(lowQuery)) {
addThis = true;
rel = GetRelevancy(lowQuery,cur->romaji,cur->english.Contains(_T("(P)")));
}
}
// Add entry
if (addThis) {
SearchResult res;
res.relevancy = rel;
res.entry = cur;
results.results.push_back(res);
cur = NULL;
}
}
// Delete cur
if (cur) delete cur;
// Time
stopwatch.Pause();
results.time = stopwatch.Time();
// Close file
}
/////////////////
// Get relevancy
int Dictionary::GetRelevancy(wxString substr,wxString _str,bool isPop,bool english) {
// Best score
int bestScore = 0;
// Generate list of strings
wxArrayString strings;
if (!english) strings.Add(_str.Lower());
else {
wxStringTokenizer tkn(_str.Lower(),_T("/"));
while (tkn.HasMoreTokens()) {
// Get token
wxString token = tkn.GetNextToken();
// Remove parenthesis
wxString temp;
bool inside = false;
bool gotOne = false;
for (size_t i=0;i<token.Length();i++) {
if (token[i] == _T('(')) {
inside = true;
gotOne = true;
}
if (!inside) temp += token[i];
if (token[i] == _T(')')) inside = false;
}
// Add a copy with parenthesis
if (gotOne) strings.Add(token);
// Trim & add
temp.Trim(true);
temp.Trim(false);
strings.Add(temp);
}
}
// Search in each match
for (size_t i=0;i<strings.Count();i++) {
// Get string
wxString str = strings[i];
if (!str.Contains(substr)) continue;
// Score
int score = 0;
if (isPop) score += 5000;
// Exact match, can't get better
if (substr == str) {
score += 10000;
}
else {
// Semi-exact match (to e.g. match "car shed" higher than "card" when looking for "car")
if (english) {
wxString temp1 = _T(" ") + str + _T(" ");
wxString temp2 = _T(" ") + substr + _T(" ");
if (temp1.Contains(temp2)) score += 5000;
}
// Calculate how much of a partial match it was
score += 1000 - (str.Length() - substr.Length())*1000/str.Length();
// Find match position
int start = str.Find(substr);
if (start == -1) throw 0;
int temp1 = (str.length() - start)*500/str.Length() + 1;
int temp2 = (start + substr.Length())*500/str.Length();
if (temp1 > temp2) score += temp1;
else score += temp2;
}
// Best score?
if (score > bestScore) bestScore = score;
}
return bestScore;
}
//////////////////////////
// Comparison for sorting
bool operator < (const SearchResult &a,const SearchResult &b) {
return (a.relevancy > b.relevancy);
}
/////////////////
// Compact entry
void DictEntry::Compact() {
kanji.Trim(true).Trim(false).Shrink();
kana.Trim(true).Trim(false).Shrink();
english.Trim(true).Trim(false).Shrink();
}
///////////////
// Constructor
ResultSet::ResultSet() {
ownData = false;
}
//////////////
// Destructor
ResultSet::~ResultSet() {
if (ownData) {
std::list<SearchResult>::iterator cur;
for (cur = results.begin(); cur != results.end();cur++) {
delete (*cur).entry;
}
}
}
///////////////////
// Print resultset
void ResultSet::Print(wxTextCtrl *target,int bitmask) {
// Get options
bool drawKanji = (bitmask & 1) != 0;
bool drawKana = (bitmask & 2) != 0;
bool drawRomaji = (bitmask & 4) != 0;
bool drawEnglish = (bitmask & 8) != 0;
// Fonts
wxFont font;
font.SetFaceName(_T("MS Mincho"));
font.SetPointSize(9);
wxFont font2;
font2.SetFaceName(_T("Tahoma"));
// Text attributes
wchar_t space = 0x3000;
wxString spaceStr = space;
wxTextAttr fontAttr;
fontAttr.SetFont(font);
wxTextAttr kanjiCol;
kanjiCol.SetFont(font);
kanjiCol.SetTextColour(wxColour(192,0,0));
wxTextAttr kanaCol;
kanaCol.SetTextColour(wxColour(0,0,192));
wxTextAttr romajiCol;
romajiCol.SetTextColour(wxColour(0,128,0));
wxTextAttr engCol;
engCol.SetFont(font2);
engCol.SetTextColour(wxColour(0,0,0));
wxTextAttr commonCol;
commonCol.SetTextColour(wxColour(0,128,128));
commonCol.SetFont(font2);
wxTextAttr sepCol;
sepCol.SetTextColour(wxColour(128,90,0));
wxTextAttr boldCol;
font2.SetWeight(wxBOLD);
boldCol.SetFont(font2);
wxTextAttr notBoldCol;
font2.SetWeight(wxNORMAL);
notBoldCol.SetFont(font);
// Find column widths
int kanjiWidth = 0;
int kanaWidth = 0;
int romajiWidth = 0;
std::list<SearchResult>::iterator cur;
DictEntry *entry;
int curLen;
int resPrinted = 0;
for (cur=results.begin();cur!=results.end();cur++) {
entry = cur->entry;
curLen = entry->kanji.Length();
if (curLen > kanjiWidth) kanjiWidth = curLen;
curLen = entry->kana.Length();
if (curLen > kanaWidth) kanaWidth = curLen;
wxString temp = Dictionary::kanatable.KanaToRomaji(entry->kana);
curLen = temp.Length() - temp.Freq(0x304);
if (curLen > romajiWidth) romajiWidth = curLen;
// Limit to 1000
resPrinted++;
if (resPrinted >= 1000) break;
}
// List number of results
target->SetDefaultStyle(boldCol);
int maxDisp = results.size();
if (maxDisp > 1000) maxDisp = 1000;
target->AppendText(wxString::Format(_T("Searched %s for \"%s\". Displaying %i matches. Search took %i ms.\n"),dicName.Upper().c_str(),query.c_str(),maxDisp,time));
target->SetDefaultStyle(notBoldCol);
target->SetDefaultStyle(fontAttr);
// Append to results
wxString curText;
resPrinted = 0;
for (cur=results.begin();cur!=results.end();cur++) {
entry = cur->entry;
// Write kanji
if (drawKanji) {
target->SetDefaultStyle(kanjiCol);
curText = entry->kanji;
curLen = kanjiWidth - curText.Length() + 1;
for (int i=0;i<curLen;i++) curText = curText + spaceStr;
target->AppendText(curText);
}
// Write kana
if (drawKana) {
target->SetDefaultStyle(kanaCol);
//curText = _T("[") + entry->kana + _T("]");
curText = entry->kana;
curLen = kanaWidth - curText.Length() + 1;
for (int i=0;i<curLen;i++) curText = curText + spaceStr;
target->AppendText(curText);
}
// Write romaji
if (drawRomaji) {
target->SetDefaultStyle(romajiCol);
curText = Dictionary::kanatable.KanaToRomaji(entry->kana);
curLen = romajiWidth - curText.Length() + curText.Freq(0x304) + 1;
for (int i=0;i<curLen;i++) curText = curText + _T(" ");
target->AppendText(curText);
}
// Write english
if (drawEnglish) {
// Search for grammatical class
wxString mainText;
int pos = entry->english.Find(_T(')'));
if (entry->english[0] == _T('(') && pos != -1) {
mainText = entry->english.Mid(pos+1);
mainText.Trim(false);
// Draw grammatical class
target->SetDefaultStyle(sepCol);
target->AppendText(entry->english.Left(pos+1) + _T(" "));
}
else mainText = entry->english;
target->SetDefaultStyle(engCol);
// Draw rest
target->SetDefaultStyle(engCol);
wxStringTokenizer tkn(mainText,_T("/"));
bool hadPrev = false;
while (tkn.HasMoreTokens()) {
// Popular entry
wxString token = tkn.GetNextToken();
if (token == _T("(P)")) {
target->SetDefaultStyle(commonCol);
target->AppendText(_T(" [Common]"));
target->SetDefaultStyle(engCol);
}
// Normal entry
else {
// Separator
if (hadPrev) {
target->SetDefaultStyle(sepCol);
target->AppendText(_T(" / "));
target->SetDefaultStyle(engCol);
}
// Append text
target->AppendText(token);
hadPrev = true;
}
}
}
// Line break
target->SetDefaultStyle(fontAttr);
target->AppendText(_T("\n"));
// Limit to 1000
resPrinted++;
if (resPrinted >= 1000) {
target->SetDefaultStyle(boldCol);
target->AppendText(wxString::Format(_T("Too many (%i) matches, stopping.\n"),results.size()));
break;
}
}
// Print two carriage returns
target->AppendText(_T("\n\n"));
}

102
traydict/dictionary.h Normal file
View file

@ -0,0 +1,102 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include <list>
#include "kana_table.h"
//////////////////////////
// Dictionary entry class
class DictEntry {
public:
wxString english;
wxString kanji;
wxString kana;
wxString romaji;
void Compact();
};
///////////
// Results
class SearchResult {
public:
DictEntry *entry;
int relevancy;
};
bool operator < (const SearchResult &a,const SearchResult &b);
//////////////
// Result set
class ResultSet {
public:
wxString query;
wxString dicName;
std::list<SearchResult> results;
void Print(wxTextCtrl *target,int bitmask);
bool ownData;
int time;
ResultSet();
~ResultSet();
};
////////////////////
// Dictionary class
class Dictionary {
private:
std::list<DictEntry> entries;
wxString dictFile;
wxString name;
public:
wxCheckBox *check;
static KanaTable kanatable;
static void Convert(wxString source,wxString dest);
void Load(wxString filename);
void Search(ResultSet &results,wxString query);
int GetRelevancy(wxString substr,wxString str,bool isPop,bool english=false);
Dictionary(wxString name,wxCheckBox *check);
~Dictionary();
};

BIN
traydict/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

432
traydict/kana_table.cpp Normal file
View file

@ -0,0 +1,432 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include "kana_table.h"
///////////////
// Constructor
KanaTable::KanaTable() {
level = 0;
groups[0] = 0;
groups[1] = 0;
BeginGroup();
Insert(L"",L"",L"a");
Insert(L"",L"",L"i");
Insert(L"",L"",L"u");
Insert(L"",L"",L"e");
Insert(L"",L"",L"o");
BeginGroup();
Insert(L"",L"",L"ka");
Insert(L"",L"",L"ki");
Insert(L"",L"",L"ku");
Insert(L"",L"",L"ke");
Insert(L"",L"",L"ko");
BeginGroup();
Insert(L"",L"",L"sa");
Insert(L"",L"",L"shi");
Insert(L"",L"",L"su");
Insert(L"",L"",L"se");
Insert(L"",L"",L"so");
BeginGroup();
Insert(L"",L"",L"ta");
Insert(L"",L"",L"chi");
Insert(L"",L"",L"tsu");
Insert(L"",L"",L"te");
Insert(L"",L"",L"to");
BeginGroup();
Insert(L"",L"",L"na");
Insert(L"",L"",L"ni");
Insert(L"",L"",L"nu");
Insert(L"",L"",L"ne");
Insert(L"",L"",L"no");
BeginGroup();
Insert(L"",L"",L"ha");
Insert(L"",L"",L"hi");
Insert(L"",L"",L"fu");
Insert(L"",L"",L"he");
Insert(L"",L"",L"ho");
BeginGroup();
Insert(L"",L"",L"ma");
Insert(L"",L"",L"mi");
Insert(L"",L"",L"mu");
Insert(L"",L"",L"me");
Insert(L"",L"",L"mo");
BeginGroup();
Insert(L"",L"",L"ya");
Insert(L"",L"",L"yu");
Insert(L"",L"",L"yo");
BeginGroup();
Insert(L"",L"",L"ra");
Insert(L"",L"",L"ri");
Insert(L"",L"",L"ru");
Insert(L"",L"",L"re");
Insert(L"",L"",L"ro");
BeginGroup();
Insert(L"",L"",L"wa");
Insert(L"",L"",L"wi");
Insert(L"",L"",L"we");
Insert(L"",L"",L"wo");
BeginGroup();
level--;
Insert(L"",L"",L"n");
BeginGroup();
Insert(L"",L"",L"ga");
Insert(L"",L"",L"gi");
Insert(L"",L"",L"gu");
Insert(L"",L"",L"ge");
Insert(L"",L"",L"go");
BeginGroup();
Insert(L"",L"",L"za");
Insert(L"",L"",L"ji");
Insert(L"",L"",L"zu");
Insert(L"",L"",L"ze");
Insert(L"",L"",L"zo");
BeginGroup();
Insert(L"",L"",L"da");
Insert(L"",L"",L"ji");
Insert(L"",L"",L"zu");
Insert(L"",L"",L"de");
Insert(L"",L"",L"do");
BeginGroup();
Insert(L"",L"",L"ba");
Insert(L"",L"",L"bi");
Insert(L"",L"",L"bu");
Insert(L"",L"",L"be");
Insert(L"",L"",L"bo");
BeginGroup();
Insert(L"",L"",L"pa");
Insert(L"",L"",L"pi");
Insert(L"",L"",L"pu");
Insert(L"",L"",L"pe");
Insert(L"",L"",L"po");
BeginGroup();
Insert(L"きゃ",L"キャ",L"kya");
Insert(L"きゅ",L"キュ",L"kyu");
Insert(L"きょ",L"キョ",L"kyo");
BeginGroup();
Insert(L"しゃ",L"シャ",L"sha");
Insert(L"しゅ",L"シュ",L"shu");
Insert(L"しょ",L"ショ",L"sho");
BeginGroup();
Insert(L"ちゃ",L"チャ",L"cha");
Insert(L"ちゅ",L"チュ",L"chu");
Insert(L"ちょ",L"チョ",L"cho");
BeginGroup();
Insert(L"にゃ",L"ニャ",L"nya");
Insert(L"にゅ",L"ニュ",L"nyu");
Insert(L"にょ",L"ニョ",L"nyo");
BeginGroup();
Insert(L"ひゃ",L"ヒャ",L"hya");
Insert(L"ひゅ",L"ヒュ",L"hyu");
Insert(L"ひょ",L"ヒョ",L"hyo");
BeginGroup();
Insert(L"みゃ",L"ミャ",L"mya");
Insert(L"みゅ",L"ミュ",L"myu");
Insert(L"みょ",L"ミョ",L"myo");
BeginGroup();
Insert(L"りゃ",L"リャ",L"rya");
Insert(L"りゅ",L"リュ",L"ryu");
Insert(L"りょ",L"リョ",L"ryo");
BeginGroup();
Insert(L"ぎゃ",L"ギャ",L"gya");
Insert(L"ぎゅ",L"ギュ",L"gyu");
Insert(L"ぎょ",L"ギョ",L"gyo");
BeginGroup();
Insert(L"じゃ",L"ジャ",L"ja");
Insert(L"じゅ",L"ジュ",L"ju");
Insert(L"じょ",L"ジョ",L"jo");
BeginGroup();
Insert(L"ぢゃ",L"ヂャ",L"ja");
Insert(L"ぢゅ",L"ヂュ",L"ju");
Insert(L"ぢょ",L"ヂョ",L"jo");
BeginGroup();
Insert(L"びゃ",L"ビャ",L"bya");
Insert(L"びゅ",L"ビュ",L"byu");
Insert(L"びょ",L"ビョ",L"byo");
BeginGroup();
Insert(L"ぴゃ",L"ピャ",L"pya");
Insert(L"ぴゅ",L"ピュ",L"pyu");
Insert(L"ぴょ",L"ピョ",L"pyo");
BeginGroup();
Insert(L"",L"ファ",L"fa");
Insert(L"",L"フィ",L"fi");
Insert(L"",L"フェ",L"fe");
Insert(L"",L"フォ",L"fo");
BeginGroup();
Insert(L"",L"ヴァ",L"va");
Insert(L"",L"ヴィ",L"vi");
Insert(L"",L"",L"vu");
Insert(L"",L"ヴェ",L"ve");
Insert(L"",L"ヴォ",L"vo");
Insert(L"",L"フュ",L"fyu");
BeginGroup();
Insert(L"",L"イェ",L"ye");
Insert(L"",L"ウィ",L"wi");
Insert(L"",L"ウェ",L"we");
Insert(L"",L"ウォ",L"wo");
BeginGroup();
Insert(L"",L"ヴャ",L"vya");
Insert(L"",L"ヴュ",L"vyu");
Insert(L"",L"ヴョ",L"vyo");
BeginGroup();
Insert(L"",L"シェ",L"she");
Insert(L"",L"ジェ",L"je");
Insert(L"",L"チェ",L"che");
BeginGroup();
Insert(L"",L"ティ",L"ti");
Insert(L"",L"テゥ",L"tu");
Insert(L"",L"テュ",L"tyu");
BeginGroup();
Insert(L"",L"ディ",L"di");
Insert(L"",L"デゥ",L"du");
Insert(L"",L"デゥ",L"dyu");
BeginGroup();
Insert(L"",L"ツァ",L"tsa");
Insert(L"",L"ツィ",L"tsi");
Insert(L"",L"ツェ",L"tse");
Insert(L"",L"ツォ",L"tso");
}
//////////////
// Destructor
KanaTable::~KanaTable() {
}
///////////////
// Begin group
void KanaTable::BeginGroup() {
curGroup = _T("");
level++;
}
//////////
// Insert
void KanaTable::Insert(wchar_t *hira,wchar_t *kata,wchar_t *hep) {
#ifdef _UNICODE
KanaEntry entry(hira,kata,hep);
if (curGroup.IsEmpty()) curGroup = hep;
entry.group = curGroup;
entry.level = level;
if (!entry.hiragana.IsEmpty() && level > groups[0]) groups[0] = level;
if (!entry.katakana.IsEmpty() && level > groups[1]) groups[1] = level;
entries.push_back(entry);
#endif
}
/////////////////////
// Number of entries
int KanaTable::GetNumberEntries(int level) const {
if (level == -1) return entries.size();
else {
int count = 0;
int n = entries.size();
for (int i=0;i<n;i++) {
if (entries[i].level <= level) count++;
}
return count;
}
}
////////////////////////
// Get a specific entry
const KanaEntry &KanaTable::GetEntry(int i) const {
return entries.at(i);
}
//////////////////////////
// Find a specific romaji
const KanaEntry *KanaTable::FindByRomaji(wxString romaji) const {
int n = entries.size();
for (int i=0;i<n;i++) {
if (entries[i].hepburn == romaji) return &entries[i];
}
return NULL;
}
////////////////////////
// Find a specific kana
const KanaEntry *KanaTable::FindByKana(wxString kana) const {
int n = entries.size();
for (int i=0;i<n;i++) {
if (entries[i].hiragana == kana) return &entries[i];
if (entries[i].katakana == kana) return &entries[i];
}
return NULL;
}
/////////////////////////////////////////////
// Get number of levels for a specific table
int KanaTable::GetLevels(int table) const {
return groups[table];
}
//////////////////////////
// Convert kana to romaji
wxString KanaTable::KanaToRomaji(wxString kana,int type) {
// Prepare
wxString lastSyl;
wxString final;
bool ltsu = false;
bool longVowel = false;
// Look up the entries
for (size_t i=0;i<kana.Length();i++) {
// Find syllable
const KanaEntry *cur;
cur = FindByKana(kana.Mid(i,2));
if (cur) i++;
else cur = FindByKana(kana.Mid(i,1));
// Check if it's little tsu or long vowel in katakana
if (!cur) {
if (kana.Mid(i,1) == _T("") || kana.Mid(i,1) == _T("") || kana.Mid(i,1) == _T("")) {
ltsu = true;
continue;
}
if (kana.Mid(i,1) == _T("") || kana.Mid(i,1) == _T("-")) {
longVowel = true;
}
}
// Append
if (cur || longVowel) {
bool vetoAdd = false;
// Hepburn
if (type == 1) {
if (longVowel) {
longVowel = false;
final += 0x304;
vetoAdd = true;
}
else {
// Check for need to add apostrophe
wxString fl;
if (lastSyl == _T("n")) {
fl = cur->hepburn.Left(1);
bool add = false;
if (fl == _T("y") || fl == _T("a") || fl == _T("e") || fl == _T("i") || fl == _T("o") || fl == _T("u")) add = true;
if (fl == _T("n") && cur->hiragana == _T("")) add = true;
if (add) final += _T("'");
}
// Check if it needs to add a macron
wxString last = lastSyl.Right(1);
wxString curV = cur->hepburn;
if ((last == _T("o") && curV == _T("u")) || (last == curV && last != lastSyl && last != _T("n"))) {
final += 0x304;
vetoAdd = true;
}
}
}
// Wapura
else {
if (longVowel) {
longVowel = false;
final += lastSyl.Right(1);
vetoAdd = true;
}
}
// Add syllable
if (!vetoAdd) {
// Little tsu
if (ltsu) {
ltsu = false;
final += cur->hepburn.Left(1);
}
// Standard
final += cur->hepburn;
}
// Set last
if (cur) lastSyl = cur->hepburn;
}
}
return final;
}

83
traydict/kana_table.h Normal file
View file

@ -0,0 +1,83 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include <vector>
#include <wx/wxprec.h>
///////////////////////////
// Hiragana/katakana entry
class KanaEntry {
public:
wxString hiragana;
wxString katakana;
wxString hepburn;
wxString group;
int level;
KanaEntry(wxString hira,wxString kata,wxString hep) {
hiragana = hira;
katakana = kata;
hepburn = hep;
}
};
///////////////////////////
// Hiragana/Katakana table
class KanaTable {
private:
std::vector<KanaEntry> entries;
void Insert(wchar_t *hira,wchar_t *kata,wchar_t *hep);
void BeginGroup();
wxString curGroup;
int groups[2];
int level;
public:
KanaTable();
~KanaTable();
int GetNumberEntries(int level=-1) const;
int GetLevels(int table) const;
const KanaEntry &GetEntry(int i) const;
const KanaEntry *FindByRomaji(wxString romaji) const;
const KanaEntry *FindByKana(wxString kana) const;
wxString KanaToRomaji(wxString kana,int type=1);
};

115
traydict/main.cpp Normal file
View file

@ -0,0 +1,115 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include <wx/wxprec.h>
#include <wx/filename.h>
#include "main.h"
#include "dict_window.h"
/////////////////
// Implement app
IMPLEMENT_APP(TrayDict)
//////////////
// Initialize
bool TrayDict::OnInit() {
// Configuration
SetAppName(_T("TrayDict"));
srand((unsigned)time(NULL));
// Get path
GetFullPath(argv[0]);
GetFolderName();
// Create the window
DictWindow *window = new DictWindow();
window->Show();
// Initialization OK
return true;
}
/////////////////////////////
// Gets and stores full path
void TrayDict::GetFullPath(wxString arg) {
if (wxIsAbsolutePath(arg)) {
fullPath = arg;
return;
}
// Is it a relative path?
wxString currentDir(wxFileName::GetCwd());
if (currentDir.Last() != wxFILE_SEP_PATH) currentDir += wxFILE_SEP_PATH;
wxString str = currentDir + arg;
if (wxFileExists(str)) {
fullPath = str;
return;
}
// OK, it's neither an absolute path nor a relative path.
// Search PATH.
wxPathList pathList;
pathList.AddEnvList(_T("PATH"));
str = pathList.FindAbsoluteValidPath(arg);
if (!str.IsEmpty()) {
fullPath = str;
return;
}
fullPath = _T("");
return;
}
///////////////////////////////////
// Gets folder name from full path
void TrayDict::GetFolderName () {
folderName = _T("");
wxFileName path(fullPath);
folderName += path.GetPath(wxPATH_GET_VOLUME);
folderName += _T("/");
}
///////////
// Statics
wxString TrayDict::folderName;
wxString TrayDict::fullPath;

47
traydict/main.h Normal file
View file

@ -0,0 +1,47 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
//////////////
// Main class
class TrayDict : public wxApp {
public:
bool OnInit();
void GetFullPath(wxString arg);
void GetFolderName();
static wxString folderName;
static wxString fullPath;
};

3
traydict/res.rc Normal file
View file

@ -0,0 +1,3 @@
wxicon ICON "icon.ico"
#include "wx/msw/wx.rc"

110
traydict/systray.cpp Normal file
View file

@ -0,0 +1,110 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include <wx/wxprec.h>
#include <wx/taskbar.h>
#include "systray.h"
#include "dict_window.h"
///////////////
// Constructor
Systray::Systray(wxFrame *mast) {
master = mast;
SetIcon(wxICON(wxicon),_T("TrayDict"));
}
//////////////
// Destructor
Systray::~Systray() {
}
///////////////
// Event table
BEGIN_EVENT_TABLE(Systray,wxTaskBarIcon)
EVT_TASKBAR_LEFT_UP(Systray::OnLeftClick)
EVT_MENU(SYSTRAY_OPEN,Systray::OnOpen)
EVT_MENU(SYSTRAY_EXIT,Systray::OnExit)
END_EVENT_TABLE()
//////////////
// Left click
void Systray::OnLeftClick(wxTaskBarIconEvent &event) {
if (master->IsShown()) master->Hide();
else BringUp();
}
////////
// Open
void Systray::OnOpen(wxCommandEvent &event) {
if (master->IsShown()) master->Hide();
else BringUp();
}
////////
// Exit
void Systray::OnExit(wxCommandEvent &event) {
master->Destroy();
}
/////////
// Popup
wxMenu* Systray::CreatePopupMenu() {
wxMenu *popup = new wxMenu();
if (master->IsShown()) popup->Append(SYSTRAY_OPEN,_T("Hide"));
else popup->Append(SYSTRAY_OPEN,_T("Show"));
popup->Append(SYSTRAY_EXIT,_T("Exit"));
return popup;
}
////////////
// Bring up
void Systray::BringUp() {
//if (IsOk()) RemoveIcon();
master->Show();
master->Restore();
master->Raise();
((DictWindow*)master)->entry->SetFocus();
}

68
traydict/systray.h Normal file
View file

@ -0,0 +1,68 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include <wx/taskbar.h>
//////////////////////
// Systray icon class
class Systray : public wxTaskBarIcon {
private:
wxFrame *master;
void OnLeftClick(wxTaskBarIconEvent &event);
void OnExit(wxCommandEvent &event);
void OnOpen(wxCommandEvent &event);
wxMenu* CreatePopupMenu();
public:
Systray(wxFrame *master);
~Systray();
void BringUp();
DECLARE_EVENT_TABLE();
};
///////
// IDs
enum {
SYSTRAY_EXIT = 1500,
SYSTRAY_OPEN
};

View file

@ -0,0 +1,238 @@
// Copyright (c) 2005, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include <fstream>
#include <algorithm>
#include <string>
#include "text_file_reader.h"
///////////////
// Constructor
TextFileReader::TextFileReader(wxString _filename,wxString enc,bool _trim) {
// Setup
open = false;
customConv = false;
trim = _trim;
filename = _filename;
// Open file
Open();
// Set encoding
encoding = enc;
if (encoding.IsEmpty()) encoding = GetEncoding(filename);
SetEncodingConfiguration();
}
//////////////
// Destructor
TextFileReader::~TextFileReader() {
Close();
// Clean up conversion
if (customConv) delete conv;
}
///////////////////////////
// Determine file encoding
wxString TextFileReader::GetEncoding(const wxString _filename) {
// Prepare
using namespace std;
unsigned char b[4];
for (int i=0;i<4;i++) b[i] = 0;
// Read four bytes from file
ifstream ifile;
ifile.open(_filename.mb_str(wxConvLocal));
if (!ifile.is_open()) {
return _T("unknown");
}
ifile.read((char*)b,4);
ifile.close();
// Try to get the byte order mark from them
if (b[0] == 0xEF && b[1] == 0xBB && b[2] == 0xBF) return _T("UTF-8");
else if (b[0] == 0xFF && b[1] == 0xFE && b[2] == 0x00 && b[3] == 0x00) return _T("UTF-32LE");
else if (b[0] == 0x00 && b[1] == 0x00 && b[2] == 0xFE && b[3] == 0xFF) return _T("UTF-32BE");
else if (b[0] == 0xFF && b[1] == 0xFE) return _T("UTF-16LE");
else if (b[0] == 0xFE && b[1] == 0xFF) return _T("UTF-16BE");
else if (b[0] == 0x2B && b[1] == 0x2F && b[2] == 0x76) return _T("UTF-7");
// Try to guess UTF-16
else if (b[0] == 0x00 && b[2] == 0x00) return _T("UTF-16BE");
else if (b[1] == 0x00 && b[3] == 0x00) return _T("UTF-16LE");
// Fallback to ascii
return _T("Local");
}
//////////////////////////////
// Set encoding configuration
void TextFileReader::SetEncodingConfiguration() {
// Set encoding configuration
swap = false;
Is16 = false;
customConv = false;
conv = NULL;
if (encoding == _T("UTF-8")) {
conv = new wxMBConvUTF8;
customConv = true;
}
else if (encoding == _T("UTF-16LE")) {
Is16 = true;
}
else if (encoding == _T("UTF-16BE")) {
Is16 = true;
swap = true;
}
else if (encoding == _T("UTF-7")) {
conv = new wxCSConv(encoding);
customConv = true;
}
else if (encoding == _T("Local")) {
conv = wxConvCurrent;
}
else {
conv = new wxCSConv(encoding);
customConv = true;
}
}
//////////////////////////
// Reads a line from file
wxString TextFileReader::ReadLineFromFile() {
Open();
wxString wxbuffer = _T("");
// Read UTF-16 line from file
if (Is16) {
char charbuffer[3];
charbuffer[2] = 0;
char aux;
wchar_t ch = 0;
int n = 0;
while (ch != L'\n' && !file.eof()) {
// Read two chars from file
file.read(charbuffer,2);
// Swap bytes for big endian
if (swap) {
aux = charbuffer[0];
charbuffer[0] = charbuffer[1];
charbuffer[1] = aux;
}
// Convert two chars into a widechar and append to string
ch = *((wchar_t*)charbuffer);
wxbuffer += ch;
n++;
}
}
// Read ASCII/UTF-8 line from file
else {
std::string buffer;
getline(file,buffer);
wxString lineresult(buffer.c_str(),*conv);
wxbuffer = lineresult;
}
// Remove line breaks
wxbuffer.Replace(_T("\r"),_T(""));
wxbuffer.Replace(_T("\n"),_T(""));
// Final string
wxString final = wxString(wxbuffer);
// Remove BOM
if (final[0] == 0xFEFF) {
final = final.Mid(1);
}
// Trim
if (trim) {
final.Trim(true);
final.Trim(false);
}
return final;
}
/////////////
// Open file
void TextFileReader::Open() {
if (open) return;
file.open(filename.mb_str(wxConvLocal),std::ios::in | std::ios::binary);
if (!file.is_open()) {
throw _T("Failed opening file.");
}
open = true;
}
//////////////
// Close file
void TextFileReader::Close() {
if (!open) return;
file.close();
open = false;
}
//////////////////////////////////
// Checks if there's more to read
bool TextFileReader::HasMoreLines() {
return (!file.eof());
}
////////////////////////////////
// Ensure that charset is valid
void TextFileReader::EnsureValid(wxString enc) {
if (enc == _T("unknown") || enc == _T("UTF-32BE") || enc == _T("UTF-32LE")) {
wxString error = _T("Character set ");
error += enc;
error += _T(" is not supported.");
throw error;
}
}

View file

@ -0,0 +1,77 @@
// Copyright (c) 2005, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
#ifndef TEXT_FILE_READER_H
#define TEXT_FILE_READER_H
///////////
// Headers
#include <wx/wxprec.h>
#include <wx/dynarray.h>
#include <fstream>
/////////
// Class
class TextFileReader {
private:
wxString filename;
wxString encoding;
std::ifstream file;
wxMBConv *conv;
bool Is16;
bool swap;
bool open;
bool customConv;
bool trim;
void Open();
void Close();
void SetEncodingConfiguration();
public:
TextFileReader(wxString filename,wxString encoding=_T(""),bool trim=true);
~TextFileReader();
wxString ReadLineFromFile();
bool HasMoreLines();
static void EnsureValid(const wxString encoding);
static wxString GetEncoding(const wxString filename);
};
#endif