2015-09-07 18:01:43 +03:00
|
|
|
|
#ifndef AUTOBUILD
|
|
|
|
|
#include "lang.h--"
|
|
|
|
|
#endif
|
|
|
|
|
|
2013-03-11 22:16:24 +04:00
|
|
|
|
#define MEMSIZE 0x8000
|
|
|
|
|
#include "..\lib\strings.h"
|
2015-09-07 18:01:43 +03:00
|
|
|
|
#include "..\lib\io.h"
|
2015-03-05 23:55:28 +03:00
|
|
|
|
#include "..\lib\gui.h"
|
|
|
|
|
#include "..\lib\obj\box_lib.h"
|
2012-11-26 19:26:15 +04:00
|
|
|
|
|
2013-03-11 22:16:24 +04:00
|
|
|
|
unsigned char speaker[23*40*3]= FROM "speaker.raw";
|
2012-11-26 19:26:15 +04:00
|
|
|
|
|
2015-09-07 18:01:43 +03:00
|
|
|
|
#ifdef LANG_RUS
|
|
|
|
|
#define WINDOW_TITLE "<22><><EFBFBD><EFBFBD><EFBFBD>ਪ 2.0"
|
|
|
|
|
#define DICTIONARY_NOT_FOUND "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"
|
|
|
|
|
#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>"
|
|
|
|
|
#define ERROR "<22>訡<EFBFBD><E8A8A1> #"
|
|
|
|
|
#else
|
|
|
|
|
#define WINDOW_TITLE "Dictionary v2.0"
|
|
|
|
|
#define DICTIONARY_NOT_FOUND "Dictionary not found"
|
|
|
|
|
#define DICTIONARY_LOADED "Dictionary loaded"
|
|
|
|
|
#define WORD_NOT_FOUND "Word isn't found in the dictionary"
|
|
|
|
|
#define ERROR "Error #"
|
|
|
|
|
#endif
|
2012-11-26 19:26:15 +04:00
|
|
|
|
|
2015-09-07 18:01:43 +03:00
|
|
|
|
proc_info Form;
|
|
|
|
|
char edword[256], search_word[256], translate_result[4096];
|
2013-10-09 22:10:23 +04:00
|
|
|
|
#define PRONOUNCED_FILE "/sys/pronounced.txt"
|
|
|
|
|
#define SPEECH_PATH "/kolibrios/media/speech/speech"
|
2015-09-07 18:01:43 +03:00
|
|
|
|
#define TOPH 44
|
|
|
|
|
|
|
|
|
|
#define TEXT_ENG_RUS "ENG\26RUS"
|
|
|
|
|
#define TEXT_RUS_ENG "RUS\26ENG"
|
|
|
|
|
#define ENG_RUS 0
|
|
|
|
|
#define RUS_ENG 1
|
|
|
|
|
int active_dict=2;
|
2013-03-11 22:16:24 +04:00
|
|
|
|
|
|
|
|
|
int mouse_dd, speaker_id;
|
2015-09-07 18:01:43 +03:00
|
|
|
|
edit_box edit1= {200,16,16,0xffffff,0x94AECE,0xffffff,0x94AECE,0,248,#edword,#mouse_dd,100000000000010b};
|
2012-11-26 19:26:15 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void main()
|
|
|
|
|
{
|
2015-09-07 18:01:43 +03:00
|
|
|
|
int id;
|
2015-07-29 23:43:05 +03:00
|
|
|
|
load_dll(boxlib, #box_lib_init,0);
|
2015-09-07 18:01:43 +03:00
|
|
|
|
OpenDictionary(ENG_RUS);
|
2012-11-26 19:26:15 +04:00
|
|
|
|
if (param)
|
|
|
|
|
{
|
|
|
|
|
strcpy(#edword, #param);
|
|
|
|
|
edit1.size=edit1.pos=strlen(#edword);
|
|
|
|
|
Translate();
|
|
|
|
|
}
|
|
|
|
|
SetEventMask(0x27);
|
|
|
|
|
loop()
|
|
|
|
|
{
|
|
|
|
|
switch(WaitEvent())
|
|
|
|
|
{
|
|
|
|
|
case evMouse:
|
|
|
|
|
edit_box_mouse stdcall (#edit1);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case evButton:
|
|
|
|
|
id=GetButtonID();
|
2015-09-07 18:01:43 +03:00
|
|
|
|
if (id==01) { KillProcess(speaker_id); ExitProcess(); }
|
|
|
|
|
if (id==10) { OpenDictionary(ENG_RUS); DrawLangButtons(); }
|
|
|
|
|
if (id==11) { OpenDictionary(RUS_ENG); DrawLangButtons(); }
|
2013-03-11 22:16:24 +04:00
|
|
|
|
if (id==15)
|
2012-11-26 19:26:15 +04:00
|
|
|
|
{
|
2013-03-11 22:16:24 +04:00
|
|
|
|
if (GetProcessSlot(speaker_id)!=0))
|
|
|
|
|
{
|
|
|
|
|
KillProcess(speaker_id);
|
|
|
|
|
pause(50);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (WriteFile(strlen(#translate_result)+1, #translate_result, PRONOUNCED_FILE)!=0) break;
|
|
|
|
|
pause(50);
|
|
|
|
|
speaker_id = RunProgram(SPEECH_PATH, PRONOUNCED_FILE);
|
|
|
|
|
}
|
2015-09-07 18:01:43 +03:00
|
|
|
|
SpeakerDraw();
|
2012-11-26 19:26:15 +04:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case evKey:
|
2015-09-07 18:01:43 +03:00
|
|
|
|
GetKeys();
|
|
|
|
|
EAX=key_ascii<<8;
|
|
|
|
|
edit_box_key stdcall(#edit1);
|
|
|
|
|
Translate();
|
2012-11-26 19:26:15 +04:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case evReDraw:
|
2015-09-07 18:01:43 +03:00
|
|
|
|
system.color.get();
|
|
|
|
|
DefineAndDrawWindow(215,120,400,250,0x73,system.color.work,WINDOW_TITLE);
|
|
|
|
|
GetProcessInfo(#Form, SelfInfo);
|
|
|
|
|
if (Form.status_window>2) break;
|
|
|
|
|
if (Form.height<140) { MoveSize(OLD,OLD,OLD,140); break; }
|
|
|
|
|
if (Form.width<400) { MoveSize(OLD,OLD,400,OLD); break; }
|
|
|
|
|
DrawBar(0, 0, Form.width-9, TOPH, system.color.work); //top bg
|
|
|
|
|
DrawBar(0, TOPH, Form.width-9, 1, system.color.work_graph);
|
|
|
|
|
edit1.width=Form.width-edit1.left-edit1.left-9 - 116;
|
|
|
|
|
edit_box_draw stdcall(#edit1);
|
|
|
|
|
DrawWideRectangle(edit1.left-2, edit1.top-2, edit1.width+3, 19, 2, 0xffffff);
|
|
|
|
|
DrawRectangle(edit1.left-3, edit1.top-3, edit1.width+4, 20, system.color.work_graph);
|
|
|
|
|
DrawTranslation();
|
|
|
|
|
DrawLangButtons();
|
2012-11-26 19:26:15 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-09-07 18:01:43 +03:00
|
|
|
|
void DrawLangButtons()
|
2012-11-26 19:26:15 +04:00
|
|
|
|
{
|
2015-09-07 18:01:43 +03:00
|
|
|
|
DrawCaptButton(Form.width-130, edit1.top-3, 50,19, 10, system.color.work_button, system.color.work_button_text, TEXT_ENG_RUS);
|
|
|
|
|
DrawCaptButton(Form.width-70, edit1.top-3, 50,19, 11, system.color.work_button, system.color.work_button_text, TEXT_RUS_ENG);
|
|
|
|
|
PutShadow(-active_dict*60 + Form.width-70, edit1.top-3, 50,19, 1, 2);
|
|
|
|
|
SpeakerDraw();
|
2012-11-26 19:26:15 +04:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-07 18:01:43 +03:00
|
|
|
|
void SpeakerDraw()
|
2012-11-26 19:26:15 +04:00
|
|
|
|
{
|
2015-09-07 18:01:43 +03:00
|
|
|
|
dword x, y;
|
|
|
|
|
x = Form.cwidth-38;
|
|
|
|
|
y = Form.cheight-32;
|
|
|
|
|
if (active_dict)
|
|
|
|
|
{
|
|
|
|
|
DeleteButton(15);
|
|
|
|
|
DrawBar(x,y,23,20,0xFFFFFF);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DefineButton(x-5, y-5, 23+10, 20+9, 15+BT_HIDE+BT_NOFRAME, 0);
|
|
|
|
|
if (GetProcessSlot(speaker_id)==0)) _PutImage(x, y, 23,20, #speaker); else _PutImage(x, y, 23,20, 23*20*3+#speaker);
|
|
|
|
|
}
|
2012-11-26 19:26:15 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Translate()
|
|
|
|
|
{
|
2015-09-07 18:01:43 +03:00
|
|
|
|
dword translation_start, translation_end;
|
|
|
|
|
|
2013-03-11 22:16:24 +04:00
|
|
|
|
KillProcess(speaker_id);
|
2015-09-07 18:01:43 +03:00
|
|
|
|
sprintf(#search_word, "\10%s\13", #edword);
|
2012-11-26 19:26:15 +04:00
|
|
|
|
strupr(#search_word);
|
2015-09-07 18:01:43 +03:00
|
|
|
|
|
|
|
|
|
if (!io.FILES_SIZE) || (!edword) goto _TR_END;
|
|
|
|
|
|
|
|
|
|
translation_start = strstr(io.buffer_data, #search_word);
|
|
|
|
|
if (!translation_start)
|
2012-11-26 19:26:15 +04:00
|
|
|
|
{
|
2015-09-07 18:01:43 +03:00
|
|
|
|
strcpy(#translate_result, WORD_NOT_FOUND);
|
2012-11-26 19:26:15 +04:00
|
|
|
|
}
|
2015-09-07 18:01:43 +03:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
translation_start = strchr(translation_start, '"') + 1;
|
|
|
|
|
translation_end = strchr(translation_start, '"');
|
|
|
|
|
strlcpy(#translate_result, translation_start, translation_end - translation_start);
|
2012-11-26 19:26:15 +04:00
|
|
|
|
}
|
2015-09-07 18:01:43 +03:00
|
|
|
|
_TR_END:
|
|
|
|
|
strcpy(#search_word, #search_word+1);
|
|
|
|
|
DrawTranslation();
|
2012-11-26 19:26:15 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-09-07 18:01:43 +03:00
|
|
|
|
void OpenDictionary(dword dict_id)
|
2013-03-11 22:16:24 +04:00
|
|
|
|
{
|
2015-09-07 18:01:43 +03:00
|
|
|
|
dword res;
|
|
|
|
|
if (dict_id==active_dict) return;
|
2013-03-26 02:50:35 +04:00
|
|
|
|
KillProcess(speaker_id);
|
2015-09-07 18:01:43 +03:00
|
|
|
|
active_dict = dict_id;
|
|
|
|
|
if (io.buffer_data) free(io.buffer_data);
|
|
|
|
|
if (active_dict==ENG_RUS) res=io.read("dictionaries/eng - rus.dict");
|
|
|
|
|
if (active_dict==RUS_ENG) res=io.read("dictionaries/rus - eng.dict");
|
|
|
|
|
if (!io.buffer_data)
|
2013-03-11 22:16:24 +04:00
|
|
|
|
{
|
2015-09-07 18:01:43 +03:00
|
|
|
|
sprintf(#search_word, ERROR, res);
|
|
|
|
|
strcpy(#translate_result, DICTIONARY_NOT_FOUND);
|
2015-02-18 23:49:48 +03:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-09-07 18:01:43 +03:00
|
|
|
|
if (active_dict==ENG_RUS) strcpy(#search_word, TEXT_ENG_RUS);
|
|
|
|
|
if (active_dict==RUS_ENG) strcpy(#search_word, TEXT_RUS_ENG);
|
|
|
|
|
strcpy(#translate_result, DICTIONARY_LOADED);
|
2013-03-11 22:16:24 +04:00
|
|
|
|
}
|
2015-09-07 18:01:43 +03:00
|
|
|
|
DrawTranslation();
|
2013-03-11 22:16:24 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-11-26 19:26:15 +04:00
|
|
|
|
void DrawTranslation()
|
|
|
|
|
{
|
|
|
|
|
int text_break=0;
|
|
|
|
|
char tt[4096]='';
|
|
|
|
|
|
2015-09-07 18:01:43 +03:00
|
|
|
|
int y_pos=TOPH+1;
|
2012-11-26 19:26:15 +04:00
|
|
|
|
char draw_buf[4096];
|
|
|
|
|
strcpy(#draw_buf, #translate_result);
|
|
|
|
|
|
2013-03-11 22:16:24 +04:00
|
|
|
|
DrawBar(0, y_pos, Form.width-9, Form.cheight - y_pos, 0xFFFFFF);
|
2012-11-26 19:26:15 +04:00
|
|
|
|
strttl(#draw_buf);
|
2015-09-07 18:01:43 +03:00
|
|
|
|
WriteTextB(10+1, y_pos+8, 10000001b, 0x800080, #search_word);
|
2012-11-26 19:26:15 +04:00
|
|
|
|
while (draw_buf)
|
|
|
|
|
{
|
|
|
|
|
text_break= Form.width/6-6;
|
|
|
|
|
if (text_break>strlen(#draw_buf))
|
|
|
|
|
{
|
2015-09-07 18:01:43 +03:00
|
|
|
|
WriteText(10, y_pos+31, 0x80, 0, #draw_buf);
|
2013-03-11 22:16:24 +04:00
|
|
|
|
break;
|
2012-11-26 19:26:15 +04:00
|
|
|
|
}
|
|
|
|
|
while (draw_buf[text_break]<>' ') && (text_break>0) text_break--;
|
|
|
|
|
strcpy(#tt, #draw_buf+text_break+1);
|
|
|
|
|
draw_buf[text_break]=0x0;
|
2015-09-07 18:01:43 +03:00
|
|
|
|
WriteText(10, y_pos+31, 0x80, 0, #draw_buf);
|
2012-11-26 19:26:15 +04:00
|
|
|
|
strcpy(#draw_buf, #tt);
|
|
|
|
|
y_pos+=12;
|
2015-09-07 18:01:43 +03:00
|
|
|
|
if (y_pos+24+8>Form.cheight) break;
|
2012-11-26 19:26:15 +04:00
|
|
|
|
}
|
2015-09-07 18:01:43 +03:00
|
|
|
|
SpeakerDraw();
|
2012-11-26 19:26:15 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stop:
|