2016-11-30 17:41:21 +01:00
|
|
|
|
#define MEMSIZE 4096 * 1024 * 2
|
2021-06-22 14:28:03 +02:00
|
|
|
|
#define NO_DLL_INIT
|
2016-11-30 17:43:20 +01:00
|
|
|
|
#include "../lib/strings.h"
|
|
|
|
|
#include "../lib/gui.h"
|
|
|
|
|
#include "../lib/obj/box_lib.h"
|
2012-11-26 16:26:15 +01:00
|
|
|
|
|
2015-09-07 17:01:43 +02:00
|
|
|
|
#ifdef LANG_RUS
|
2021-06-22 14:28:03 +02:00
|
|
|
|
#define WINDOW_TITLE "<22><><EFBFBD><EFBFBD><EFBFBD>ਪ 2.4"
|
2015-09-07 17:01:43 +02:00
|
|
|
|
#define DICTIONARY_LOADED "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>㦥<EFBFBD>"
|
|
|
|
|
#define WORD_NOT_FOUND "<22><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <><E1ABAE><EFBFBD><EFBFBD>"
|
2016-10-30 23:47:57 +01:00
|
|
|
|
#define ERROR "<22>訡<EFBFBD><E8A8A1> #%d"
|
2015-09-07 17:01:43 +02:00
|
|
|
|
#else
|
2021-06-22 14:28:03 +02:00
|
|
|
|
#define WINDOW_TITLE "Dictionary v2.4"
|
2015-09-07 17:01:43 +02:00
|
|
|
|
#define DICTIONARY_LOADED "Dictionary loaded"
|
|
|
|
|
#define WORD_NOT_FOUND "Word isn't found in the dictionary"
|
2016-10-30 23:47:57 +01:00
|
|
|
|
#define ERROR "Error #%d"
|
2021-06-22 14:28:03 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#define TEXT_ENG_RUS "ENG\26RUS"
|
|
|
|
|
#define TEXT_RUS_ENG "RUS\26ENG"
|
|
|
|
|
#define TEXT_RU2EN "ENG RUS"
|
|
|
|
|
#define TEXT_EN2RU "RUS ENG"
|
|
|
|
|
|
|
|
|
|
unsigned char speaker[23*40*3]= FROM "speaker.raw";
|
2012-11-26 16:26:15 +01:00
|
|
|
|
|
2015-09-07 17:01:43 +02:00
|
|
|
|
proc_info Form;
|
2021-06-22 14:28:03 +02:00
|
|
|
|
char search_word[256], translate_result[4096];
|
2016-11-05 11:13:29 +01:00
|
|
|
|
#define TOPH 45
|
2021-06-22 14:28:03 +02:00
|
|
|
|
#define PRONOUNCED_FILE "/tmp0/1/pronounced.txt"
|
2022-07-10 11:46:29 +02:00
|
|
|
|
#define SPEECH_PATH "/kolibrios/speech/speech"
|
2021-06-22 14:28:03 +02:00
|
|
|
|
dword speaker_id;
|
2015-09-07 17:01:43 +02:00
|
|
|
|
|
2016-11-30 17:41:21 +01:00
|
|
|
|
unsigned char eng_rus[] = FROM "eng_rus.dict""\0";
|
|
|
|
|
unsigned char rus_eng[] = FROM "rus_eng.dict""\0";
|
|
|
|
|
dword io_buffer_data;
|
|
|
|
|
|
2015-09-07 17:01:43 +02:00
|
|
|
|
#define ENG_RUS 0
|
|
|
|
|
#define RUS_ENG 1
|
|
|
|
|
int active_dict=2;
|
2013-03-11 19:16:24 +01:00
|
|
|
|
|
2021-06-22 14:28:03 +02:00
|
|
|
|
#define BTN_CHANGE_LANGUAGE 10
|
|
|
|
|
#define BTN_SPEAKER 11
|
2012-11-26 16:26:15 +01:00
|
|
|
|
|
2021-06-22 14:28:03 +02:00
|
|
|
|
char edit_text[256];
|
|
|
|
|
edit_box edit1 = {0,13,13,0xffffff,0x94AECE,0xffffff,0xffffff,
|
|
|
|
|
0x10000000,248,#edit_text,0,ed_focus+ed_always_focus};
|
2012-11-26 16:26:15 +01:00
|
|
|
|
|
|
|
|
|
void main()
|
|
|
|
|
{
|
2021-06-22 14:28:03 +02:00
|
|
|
|
int btnid;
|
2015-07-29 22:43:05 +02:00
|
|
|
|
load_dll(boxlib, #box_lib_init,0);
|
2015-09-07 17:01:43 +02:00
|
|
|
|
OpenDictionary(ENG_RUS);
|
2021-06-22 14:28:03 +02:00
|
|
|
|
if (param) {
|
2016-11-30 17:41:21 +01:00
|
|
|
|
strcpy(#edit_text, #param);
|
2021-06-22 14:28:03 +02:00
|
|
|
|
edit_box_set_text stdcall (#edit1, #param);
|
2012-11-26 16:26:15 +01:00
|
|
|
|
Translate();
|
|
|
|
|
}
|
2021-06-22 14:28:03 +02:00
|
|
|
|
@SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
|
|
|
|
|
loop() switch(@WaitEvent())
|
2012-11-26 16:26:15 +01:00
|
|
|
|
{
|
|
|
|
|
case evMouse:
|
|
|
|
|
edit_box_mouse stdcall (#edit1);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case evButton:
|
2021-06-22 14:28:03 +02:00
|
|
|
|
btnid = @GetButtonID();
|
|
|
|
|
if (btnid==01) ExitProcess();
|
|
|
|
|
if (btnid==BTN_CHANGE_LANGUAGE) {
|
|
|
|
|
if (active_dict == ENG_RUS) {
|
|
|
|
|
OpenDictionary(RUS_ENG);
|
|
|
|
|
} else {
|
|
|
|
|
OpenDictionary(ENG_RUS);
|
|
|
|
|
}
|
2016-10-30 23:47:57 +01:00
|
|
|
|
DrawLangButtons();
|
2012-11-26 16:26:15 +01:00
|
|
|
|
}
|
2021-06-22 14:28:03 +02:00
|
|
|
|
if (btnid==BTN_SPEAKER) {
|
|
|
|
|
if (GetProcessSlot(speaker_id)!=0) {
|
|
|
|
|
KillProcess(speaker_id);
|
|
|
|
|
pause(50);
|
|
|
|
|
} else {
|
|
|
|
|
if (CreateFile(strlen(#translate_result)+1, #translate_result, PRONOUNCED_FILE)!=0) break;
|
|
|
|
|
pause(50);
|
|
|
|
|
speaker_id = RunProgram(SPEECH_PATH, PRONOUNCED_FILE);
|
|
|
|
|
}
|
|
|
|
|
SpeakerDraw();
|
|
|
|
|
}
|
2012-11-26 16:26:15 +01:00
|
|
|
|
break;
|
|
|
|
|
|
2021-06-22 14:28:03 +02:00
|
|
|
|
case evKey:
|
|
|
|
|
@GetKey();
|
2015-09-07 17:01:43 +02:00
|
|
|
|
edit_box_key stdcall(#edit1);
|
|
|
|
|
Translate();
|
2012-11-26 16:26:15 +01:00
|
|
|
|
break;
|
|
|
|
|
|
2021-06-22 14:28:03 +02:00
|
|
|
|
case evReDraw:
|
2020-04-18 01:52:24 +02:00
|
|
|
|
sc.get();
|
|
|
|
|
DefineAndDrawWindow(215,120,500,350,0x73,sc.work,WINDOW_TITLE,0);
|
2015-09-07 17:01:43 +02:00
|
|
|
|
GetProcessInfo(#Form, SelfInfo);
|
2021-06-26 09:59:13 +02:00
|
|
|
|
if (Form.status_window&ROLLED_UP) break;
|
2015-09-07 17:01:43 +02:00
|
|
|
|
if (Form.height<140) { MoveSize(OLD,OLD,OLD,140); break; }
|
|
|
|
|
if (Form.width<400) { MoveSize(OLD,OLD,400,OLD); break; }
|
2020-04-18 01:52:24 +02:00
|
|
|
|
DrawBar(0, 0, Form.cwidth, TOPH, sc.work); //top bg
|
2022-01-09 07:36:16 +01:00
|
|
|
|
DrawBar(0, TOPH, Form.cwidth, 1, sc.line);
|
2021-06-22 14:28:03 +02:00
|
|
|
|
edit1.width = Form.cwidth-edit1.left-edit1.left - 116;
|
2015-09-07 17:01:43 +02:00
|
|
|
|
edit_box_draw stdcall(#edit1);
|
2016-11-05 11:13:29 +01:00
|
|
|
|
DrawWideRectangle(edit1.left-2, edit1.top-2, edit1.width+3, 25, 2, 0xffffff);
|
2022-01-09 07:36:16 +01:00
|
|
|
|
DrawRectangle(edit1.left-3, edit1.top-3, edit1.width+4, 26, sc.line);
|
2015-09-07 17:01:43 +02:00
|
|
|
|
DrawTranslation();
|
|
|
|
|
DrawLangButtons();
|
2021-06-22 14:28:03 +02:00
|
|
|
|
}
|
2012-11-26 16:26:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-09-07 17:01:43 +02:00
|
|
|
|
void DrawLangButtons()
|
2012-11-26 16:26:15 +01:00
|
|
|
|
{
|
2016-10-30 23:47:57 +01:00
|
|
|
|
dword direction;
|
2021-06-22 14:28:03 +02:00
|
|
|
|
int y = edit1.top+3;
|
|
|
|
|
DrawBar(Form.cwidth-111, y, 100, 25, sc.work);
|
|
|
|
|
DefineButton(Form.cwidth-79, y-4, 20, 20, BTN_CHANGE_LANGUAGE, sc.button);
|
2021-11-16 01:28:47 +01:00
|
|
|
|
WriteText(Form.cwidth-73, y-1, 10000001b, sc.button_text, "\26");
|
2021-06-22 14:28:03 +02:00
|
|
|
|
if (active_dict == ENG_RUS) {
|
|
|
|
|
direction = TEXT_RU2EN;
|
|
|
|
|
} else {
|
|
|
|
|
direction = TEXT_EN2RU;
|
|
|
|
|
}
|
|
|
|
|
WriteText(Form.cwidth-111, y, 0x90, sc.work_text, direction);
|
2012-11-26 16:26:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Translate()
|
|
|
|
|
{
|
2021-06-22 14:28:03 +02:00
|
|
|
|
dword tr_start, tr_end;
|
2015-09-07 17:01:43 +02:00
|
|
|
|
|
2016-11-30 17:41:21 +01:00
|
|
|
|
sprintf(#search_word, "\10%s\13", #edit_text);
|
2012-11-26 16:26:15 +01:00
|
|
|
|
strupr(#search_word);
|
2015-09-07 17:01:43 +02:00
|
|
|
|
|
2016-11-30 17:41:21 +01:00
|
|
|
|
if (!edit_text) goto _TR_END;
|
2015-09-07 17:01:43 +02:00
|
|
|
|
|
2021-06-22 14:28:03 +02:00
|
|
|
|
tr_start = strstr(io_buffer_data, #search_word);
|
|
|
|
|
if (!tr_start) {
|
2015-09-07 17:01:43 +02:00
|
|
|
|
strcpy(#translate_result, WORD_NOT_FOUND);
|
2021-06-22 14:28:03 +02:00
|
|
|
|
} else {
|
|
|
|
|
tr_start = strchr(tr_start, '"') + 1;
|
|
|
|
|
tr_end = strchr(tr_start, '"');
|
|
|
|
|
strlcpy(#translate_result, tr_start, tr_end - tr_start);
|
2012-11-26 16:26:15 +01:00
|
|
|
|
}
|
2015-09-07 17:01:43 +02:00
|
|
|
|
_TR_END:
|
|
|
|
|
strcpy(#search_word, #search_word+1);
|
|
|
|
|
DrawTranslation();
|
2012-11-26 16:26:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-09-07 17:01:43 +02:00
|
|
|
|
void OpenDictionary(dword dict_id)
|
2013-03-11 19:16:24 +01:00
|
|
|
|
{
|
2015-09-07 17:01:43 +02:00
|
|
|
|
if (dict_id==active_dict) return;
|
|
|
|
|
active_dict = dict_id;
|
2016-11-30 17:41:21 +01:00
|
|
|
|
if (active_dict==ENG_RUS)
|
2013-03-11 19:16:24 +01:00
|
|
|
|
{
|
2016-11-30 17:41:21 +01:00
|
|
|
|
io_buffer_data=#eng_rus;
|
|
|
|
|
strcpy(#search_word, TEXT_ENG_RUS);
|
2015-02-18 21:49:48 +01:00
|
|
|
|
}
|
2016-11-30 17:41:21 +01:00
|
|
|
|
if (active_dict==RUS_ENG)
|
2015-02-18 21:49:48 +01:00
|
|
|
|
{
|
2016-11-30 17:41:21 +01:00
|
|
|
|
io_buffer_data=#rus_eng;
|
|
|
|
|
strcpy(#search_word, TEXT_RUS_ENG);
|
2013-03-11 19:16:24 +01:00
|
|
|
|
}
|
2016-11-30 17:41:21 +01:00
|
|
|
|
strcpy(#translate_result, DICTIONARY_LOADED);
|
2015-09-07 17:01:43 +02:00
|
|
|
|
DrawTranslation();
|
2013-03-11 19:16:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-11-26 16:26:15 +01:00
|
|
|
|
void DrawTranslation()
|
|
|
|
|
{
|
2015-09-07 17:01:43 +02:00
|
|
|
|
int y_pos=TOPH+1;
|
2012-11-26 16:26:15 +01:00
|
|
|
|
char draw_buf[4096];
|
2020-03-25 01:18:19 +01:00
|
|
|
|
strlcpy(#draw_buf, #translate_result, sizeof(draw_buf)-1);
|
2012-11-26 16:26:15 +01:00
|
|
|
|
|
2020-04-13 23:08:28 +02:00
|
|
|
|
DrawBar(0, y_pos, Form.cwidth, Form.cheight - y_pos, 0xFFFFFF);
|
2012-11-26 16:26:15 +01:00
|
|
|
|
strttl(#draw_buf);
|
2015-09-07 17:01:43 +02:00
|
|
|
|
WriteTextB(10+1, y_pos+8, 10000001b, 0x800080, #search_word);
|
2016-10-30 23:47:57 +01:00
|
|
|
|
|
2016-11-05 11:13:29 +01:00
|
|
|
|
DrawTextViewArea(10, y_pos+31, Form.cwidth-20, Form.cheight-30,
|
2016-10-30 23:47:57 +01:00
|
|
|
|
#draw_buf, -1, 0x000000);
|
2021-06-22 14:28:03 +02:00
|
|
|
|
|
|
|
|
|
SpeakerDraw();
|
2012-11-26 16:26:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-22 14:28:03 +02:00
|
|
|
|
void SpeakerDraw()
|
|
|
|
|
{
|
|
|
|
|
dword x = Form.cwidth-38;
|
|
|
|
|
dword y = Form.cheight-32;
|
|
|
|
|
if (active_dict == RUS_ENG)
|
|
|
|
|
{
|
|
|
|
|
DeleteButton(15);
|
|
|
|
|
DrawBar(x,y,23,20,0xFFFFFF);
|
|
|
|
|
} else {
|
|
|
|
|
DefineHiddenButton(x-5, y-5, 23+10, 20+9, BTN_SPEAKER);
|
|
|
|
|
if (!GetProcessSlot(speaker_id)) {
|
2022-01-09 07:36:16 +01:00
|
|
|
|
PutImage(x, y, 23,20, #speaker);
|
2021-06-22 14:28:03 +02:00
|
|
|
|
} else {
|
2022-01-09 07:36:16 +01:00
|
|
|
|
PutImage(x, y, 23,20, 23*20*3+#speaker);
|
2021-06-22 14:28:03 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-11-26 16:26:15 +01:00
|
|
|
|
|
|
|
|
|
stop:
|