Rev 5674 | Rev 6638 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5818 | leency | 1 | #ifndef AUTOBUILD |
2 | #include "lang.h--" |
||
3 | #endif |
||
4 | |||
3363 | leency | 5 | #define MEMSIZE 0x8000 |
6 | #include "..\lib\strings.h" |
||
5818 | leency | 7 | #include "..\lib\io.h" |
5499 | leency | 8 | #include "..\lib\gui.h" |
9 | #include "..\lib\obj\box_lib.h" |
||
3363 | leency | 10 | |
11 | unsigned char speaker[23*40*3]= FROM "speaker.raw"; |
||
12 | |||
5818 | leency | 13 | #ifdef LANG_RUS |
14 | #define WINDOW_TITLE "Словарик 2.0" |
||
15 | #define DICTIONARY_NOT_FOUND "Словарь не найден" |
||
16 | #define DICTIONARY_LOADED "Словарь загружен" |
||
17 | #define WORD_NOT_FOUND "Слово не найдено в словаре" |
||
18 | #define ERROR "Ошибка #" |
||
19 | #else |
||
20 | #define WINDOW_TITLE "Dictionary v2.0" |
||
21 | #define DICTIONARY_NOT_FOUND "Dictionary not found" |
||
22 | #define DICTIONARY_LOADED "Dictionary loaded" |
||
23 | #define WORD_NOT_FOUND "Word isn't found in the dictionary" |
||
24 | #define ERROR "Error #" |
||
25 | #endif |
||
26 | |||
3363 | leency | 27 | proc_info Form; |
5818 | leency | 28 | char edword[256], search_word[256], translate_result[4096]; |
3991 | leency | 29 | #define PRONOUNCED_FILE "/sys/pronounced.txt" |
30 | #define SPEECH_PATH "/kolibrios/media/speech/speech" |
||
5818 | leency | 31 | #define TOPH 44 |
3363 | leency | 32 | |
5818 | leency | 33 | #define TEXT_ENG_RUS "ENG\26RUS" |
34 | #define TEXT_RUS_ENG "RUS\26ENG" |
||
35 | #define ENG_RUS 0 |
||
36 | #define RUS_ENG 1 |
||
37 | int active_dict=2; |
||
38 | |||
3363 | leency | 39 | int mouse_dd, speaker_id; |
5818 | leency | 40 | edit_box edit1= {200,16,16,0xffffff,0x94AECE,0xffffff,0x94AECE,0,248,#edword,#mouse_dd,100000000000010b}; |
3363 | leency | 41 | |
42 | |||
43 | void main() |
||
44 | { |
||
5818 | leency | 45 | int id; |
5626 | leency | 46 | load_dll(boxlib, #box_lib_init,0); |
5818 | leency | 47 | OpenDictionary(ENG_RUS); |
3363 | leency | 48 | if (param) |
49 | { |
||
50 | strcpy(#edword, #param); |
||
51 | edit1.size=edit1.pos=strlen(#edword); |
||
52 | Translate(); |
||
53 | } |
||
54 | SetEventMask(0x27); |
||
55 | loop() |
||
56 | { |
||
57 | switch(WaitEvent()) |
||
58 | { |
||
59 | case evMouse: |
||
60 | edit_box_mouse stdcall (#edit1); |
||
61 | break; |
||
62 | |||
63 | case evButton: |
||
64 | id=GetButtonID(); |
||
5818 | leency | 65 | if (id==01) { KillProcess(speaker_id); ExitProcess(); } |
66 | if (id==10) { OpenDictionary(ENG_RUS); DrawLangButtons(); } |
||
67 | if (id==11) { OpenDictionary(RUS_ENG); DrawLangButtons(); } |
||
3363 | leency | 68 | if (id==15) |
69 | { |
||
70 | if (GetProcessSlot(speaker_id)!=0)) |
||
71 | { |
||
72 | KillProcess(speaker_id); |
||
73 | pause(50); |
||
74 | } |
||
75 | else |
||
76 | { |
||
77 | if (WriteFile(strlen(#translate_result)+1, #translate_result, PRONOUNCED_FILE)!=0) break; |
||
78 | pause(50); |
||
79 | speaker_id = RunProgram(SPEECH_PATH, PRONOUNCED_FILE); |
||
80 | } |
||
5818 | leency | 81 | SpeakerDraw(); |
3363 | leency | 82 | } |
83 | break; |
||
84 | |||
85 | case evKey: |
||
5818 | leency | 86 | GetKeys(); |
87 | EAX=key_ascii<<8; |
||
88 | edit_box_key stdcall(#edit1); |
||
89 | Translate(); |
||
3363 | leency | 90 | break; |
91 | |||
92 | case evReDraw: |
||
5818 | leency | 93 | system.color.get(); |
94 | DefineAndDrawWindow(215,120,400,250,0x73,system.color.work,WINDOW_TITLE); |
||
95 | GetProcessInfo(#Form, SelfInfo); |
||
96 | if (Form.status_window>2) break; |
||
97 | if (Form.height<140) { MoveSize(OLD,OLD,OLD,140); break; } |
||
98 | if (Form.width<400) { MoveSize(OLD,OLD,400,OLD); break; } |
||
99 | DrawBar(0, 0, Form.width-9, TOPH, system.color.work); //top bg |
||
100 | DrawBar(0, TOPH, Form.width-9, 1, system.color.work_graph); |
||
101 | edit1.width=Form.width-edit1.left-edit1.left-9 - 116; |
||
102 | edit_box_draw stdcall(#edit1); |
||
103 | DrawWideRectangle(edit1.left-2, edit1.top-2, edit1.width+3, 19, 2, 0xffffff); |
||
104 | DrawRectangle(edit1.left-3, edit1.top-3, edit1.width+4, 20, system.color.work_graph); |
||
105 | DrawTranslation(); |
||
106 | DrawLangButtons(); |
||
3363 | leency | 107 | } |
108 | } |
||
109 | } |
||
110 | |||
111 | |||
5818 | leency | 112 | void DrawLangButtons() |
3363 | leency | 113 | { |
5818 | leency | 114 | DrawCaptButton(Form.width-130, edit1.top-3, 50,19, 10, system.color.work_button, system.color.work_button_text, TEXT_ENG_RUS); |
115 | DrawCaptButton(Form.width-70, edit1.top-3, 50,19, 11, system.color.work_button, system.color.work_button_text, TEXT_RUS_ENG); |
||
116 | PutShadow(-active_dict*60 + Form.width-70, edit1.top-3, 50,19, 1, 2); |
||
117 | SpeakerDraw(); |
||
3363 | leency | 118 | } |
119 | |||
5818 | leency | 120 | void SpeakerDraw() |
3363 | leency | 121 | { |
5818 | leency | 122 | dword x, y; |
123 | x = Form.cwidth-38; |
||
124 | y = Form.cheight-32; |
||
125 | if (active_dict) |
||
126 | { |
||
127 | DeleteButton(15); |
||
128 | DrawBar(x,y,23,20,0xFFFFFF); |
||
129 | } |
||
130 | else |
||
131 | { |
||
132 | DefineButton(x-5, y-5, 23+10, 20+9, 15+BT_HIDE+BT_NOFRAME, 0); |
||
133 | if (GetProcessSlot(speaker_id)==0)) _PutImage(x, y, 23,20, #speaker); else _PutImage(x, y, 23,20, 23*20*3+#speaker); |
||
134 | } |
||
3363 | leency | 135 | } |
136 | |||
137 | void Translate() |
||
138 | { |
||
5818 | leency | 139 | dword translation_start, translation_end; |
140 | |||
3363 | leency | 141 | KillProcess(speaker_id); |
5818 | leency | 142 | sprintf(#search_word, "\10%s\13", #edword); |
3363 | leency | 143 | strupr(#search_word); |
5818 | leency | 144 | |
145 | if (!io.FILES_SIZE) || (!edword) goto _TR_END; |
||
146 | |||
147 | translation_start = strstr(io.buffer_data, #search_word); |
||
148 | if (!translation_start) |
||
3363 | leency | 149 | { |
5818 | leency | 150 | strcpy(#translate_result, WORD_NOT_FOUND); |
3363 | leency | 151 | } |
5818 | leency | 152 | else |
153 | { |
||
154 | translation_start = strchr(translation_start, '"') + 1; |
||
155 | translation_end = strchr(translation_start, '"'); |
||
156 | strlcpy(#translate_result, translation_start, translation_end - translation_start); |
||
3363 | leency | 157 | } |
5818 | leency | 158 | _TR_END: |
159 | strcpy(#search_word, #search_word+1); |
||
160 | DrawTranslation(); |
||
3363 | leency | 161 | } |
162 | |||
163 | |||
5818 | leency | 164 | void OpenDictionary(dword dict_id) |
3363 | leency | 165 | { |
5818 | leency | 166 | dword res; |
167 | if (dict_id==active_dict) return; |
||
3412 | leency | 168 | KillProcess(speaker_id); |
5818 | leency | 169 | active_dict = dict_id; |
170 | if (io.buffer_data) free(io.buffer_data); |
||
171 | if (active_dict==ENG_RUS) res=io.read("dictionaries/eng - rus.dict"); |
||
172 | if (active_dict==RUS_ENG) res=io.read("dictionaries/rus - eng.dict"); |
||
173 | if (!io.buffer_data) |
||
3363 | leency | 174 | { |
5818 | leency | 175 | sprintf(#search_word, ERROR, res); |
176 | strcpy(#translate_result, DICTIONARY_NOT_FOUND); |
||
5423 | leency | 177 | } |
178 | else |
||
179 | { |
||
5818 | leency | 180 | if (active_dict==ENG_RUS) strcpy(#search_word, TEXT_ENG_RUS); |
181 | if (active_dict==RUS_ENG) strcpy(#search_word, TEXT_RUS_ENG); |
||
182 | strcpy(#translate_result, DICTIONARY_LOADED); |
||
5423 | leency | 183 | } |
5818 | leency | 184 | DrawTranslation(); |
3363 | leency | 185 | } |
186 | |||
187 | |||
188 | void DrawTranslation() |
||
189 | { |
||
190 | int text_break=0; |
||
191 | char tt[4096]=''; |
||
192 | |||
5818 | leency | 193 | int y_pos=TOPH+1; |
3363 | leency | 194 | char draw_buf[4096]; |
195 | strcpy(#draw_buf, #translate_result); |
||
196 | |||
197 | DrawBar(0, y_pos, Form.width-9, Form.cheight - y_pos, 0xFFFFFF); |
||
198 | strttl(#draw_buf); |
||
5818 | leency | 199 | WriteTextB(10+1, y_pos+8, 10000001b, 0x800080, #search_word); |
3363 | leency | 200 | while (draw_buf) |
201 | { |
||
202 | text_break= Form.width/6-6; |
||
203 | if (text_break>strlen(#draw_buf)) |
||
204 | { |
||
5818 | leency | 205 | WriteText(10, y_pos+31, 0x80, 0, #draw_buf); |
3363 | leency | 206 | break; |
207 | } |
||
208 | while (draw_buf[text_break]<>' ') && (text_break>0) text_break--; |
||
209 | strcpy(#tt, #draw_buf+text_break+1); |
||
210 | draw_buf[text_break]=0x0; |
||
5818 | leency | 211 | WriteText(10, y_pos+31, 0x80, 0, #draw_buf); |
3363 | leency | 212 | strcpy(#draw_buf, #tt); |
213 | y_pos+=12; |
||
5818 | leency | 214 | if (y_pos+24+8>Form.cheight) break; |
3363 | leency | 215 | } |
5818 | leency | 216 | SpeakerDraw(); |
3363 | leency | 217 | } |
218 | |||
219 | |||
220 | stop:>400)>140)>8; |