Rev 5626 | Rev 5674 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5626 | Rev 5651 | ||
---|---|---|---|
1 | #define MEMSIZE 0x8000 |
1 | #define MEMSIZE 0x8000 |
2 | #include "..\lib\kolibri.h" |
2 | #include "..\lib\kolibri.h" |
3 | #include "..\lib\strings.h" |
3 | #include "..\lib\strings.h" |
4 | #include "..\lib\mem.h" |
4 | #include "..\lib\mem.h" |
5 | #include "..\lib\file_system.h" |
5 | #include "..\lib\file_system.h" |
6 | #include "..\lib\gui.h" |
6 | #include "..\lib\gui.h" |
7 | #include "..\lib\dll.h" |
7 | #include "..\lib\dll.h" |
8 | #include "..\lib\obj\box_lib.h" |
8 | #include "..\lib\obj\box_lib.h" |
9 | 9 | ||
10 | 10 | ||
11 | unsigned char speaker[23*40*3]= FROM "speaker.raw"; |
11 | unsigned char speaker[23*40*3]= FROM "speaker.raw"; |
12 | char title[]= "Dictionary v1.32"; |
12 | char title[]= "Dictionary v1.32"; |
13 | char direction[] = "Translate direction:"; |
13 | char direction[] = "Translate direction:"; |
14 | char translate_caption[] = "Translate"; |
14 | char translate_caption[] = "Translate"; |
15 | char dict_not_found[] = "Dictionary not found"; |
15 | char dict_not_found[] = "Dictionary not found"; |
16 | char dict_opened[] = "Dictionary loaded"; |
16 | char dict_opened[] = "Dictionary loaded"; |
17 | char empty_word[] = "Type a word to translate"; |
17 | char empty_word[] = "Type a word to translate"; |
18 | 18 | ||
19 | 19 | ||
20 | system_colors sc; |
20 | system_colors sc; |
21 | proc_info Form; |
21 | proc_info Form; |
22 | 22 | ||
23 | char edword[256], search_word[256], translate_result[4096], cur_dict[256]; |
23 | char edword[256], search_word[256], translate_result[4096], cur_dict[256]; |
24 | dword dict_folder; |
24 | dword dict_folder; |
25 | #define DICT_DIRECROTY "dictionaries" |
25 | #define DICT_DIRECROTY "dictionaries" |
26 | #define PRONOUNCED_FILE "/sys/pronounced.txt" |
26 | #define PRONOUNCED_FILE "/sys/pronounced.txt" |
27 | #define SPEECH_PATH "/kolibrios/media/speech/speech" |
27 | #define SPEECH_PATH "/kolibrios/media/speech/speech" |
28 | dword dir_buf, file_buf, fsize; |
28 | dword dir_buf, file_buf, fsize; |
29 | 29 | ||
30 | int mouse_dd, speaker_id; |
30 | int mouse_dd, speaker_id; |
31 | edit_box edit1= {200,20,16,0xffffff,0x94AECE,0x94AECE,0x94AECE,0,248,#edword,#mouse_dd,100000000000010b}; |
31 | edit_box edit1= {200,20,16,0xffffff,0x94AECE,0x94AECE,0x94AECE,0,248,#edword,#mouse_dd,100000000000010b}; |
32 | 32 | ||
33 | 33 | ||
34 | void main() |
34 | void main() |
35 | { |
35 | { |
36 | int id, key; |
36 | int id, key; |
37 | mem_Init(); |
37 | |
38 | load_dll(boxlib, #box_lib_init,0); |
38 | load_dll(boxlib, #box_lib_init,0); |
39 | 39 | ||
40 | dict_folder = abspath(DICT_DIRECROTY); |
40 | dict_folder = abspath(DICT_DIRECROTY); |
41 | OpenDictionary(0); |
41 | OpenDictionary(0); |
42 | 42 | ||
43 | if (param) |
43 | if (param) |
44 | { |
44 | { |
45 | strcpy(#edword, #param); |
45 | strcpy(#edword, #param); |
46 | edit1.size=edit1.pos=strlen(#edword); |
46 | edit1.size=edit1.pos=strlen(#edword); |
47 | Translate(); |
47 | Translate(); |
48 | DrawTranslation(); |
48 | DrawTranslation(); |
49 | edit_box_draw stdcall(#edit1); |
49 | edit_box_draw stdcall(#edit1); |
50 | } |
50 | } |
51 | 51 | ||
52 | SetEventMask(0x27); |
52 | SetEventMask(0x27); |
53 | loop() |
53 | loop() |
54 | { |
54 | { |
55 | switch(WaitEvent()) |
55 | switch(WaitEvent()) |
56 | { |
56 | { |
57 | case evMouse: |
57 | case evMouse: |
58 | edit_box_mouse stdcall (#edit1); |
58 | edit_box_mouse stdcall (#edit1); |
59 | break; |
59 | break; |
60 | 60 | ||
61 | case evButton: |
61 | case evButton: |
62 | id=GetButtonID(); |
62 | id=GetButtonID(); |
63 | if (id==1) {KillProcess(speaker_id); ExitProcess();} |
63 | if (id==1) {KillProcess(speaker_id); ExitProcess();} |
64 | if (id==10) { Translate(); DrawTranslation(); } |
64 | if (id==10) { Translate(); DrawTranslation(); } |
65 | if (id==11) ShowDictList(); |
65 | if (id==11) ShowDictList(); |
66 | if (id==12) DrawWindowContent(); |
66 | if (id==12) DrawWindowContent(); |
67 | if (id==15) |
67 | if (id==15) |
68 | { |
68 | { |
69 | if (GetProcessSlot(speaker_id)!=0)) |
69 | if (GetProcessSlot(speaker_id)!=0)) |
70 | { |
70 | { |
71 | KillProcess(speaker_id); |
71 | KillProcess(speaker_id); |
72 | pause(50); |
72 | pause(50); |
73 | } |
73 | } |
74 | else |
74 | else |
75 | { |
75 | { |
76 | if (WriteFile(strlen(#translate_result)+1, #translate_result, PRONOUNCED_FILE)!=0) break; |
76 | if (WriteFile(strlen(#translate_result)+1, #translate_result, PRONOUNCED_FILE)!=0) break; |
77 | pause(50); |
77 | pause(50); |
78 | speaker_id = RunProgram(SPEECH_PATH, PRONOUNCED_FILE); |
78 | speaker_id = RunProgram(SPEECH_PATH, PRONOUNCED_FILE); |
79 | } |
79 | } |
80 | SpeakerDraw(Form.cwidth-38, Form.cheight-32); |
80 | SpeakerDraw(Form.cwidth-38, Form.cheight-32); |
81 | } |
81 | } |
82 | if (id>=20) OpenDictionary(id - 20); |
82 | if (id>=20) OpenDictionary(id - 20); |
83 | break; |
83 | break; |
84 | 84 | ||
85 | case evKey: |
85 | case evKey: |
86 | key = GetKey(); |
86 | key = GetKey(); |
87 | IF (key==013) //Enter |
87 | IF (key==013) //Enter |
88 | { |
88 | { |
89 | Translate(); |
89 | Translate(); |
90 | DrawTranslation(); |
90 | DrawTranslation(); |
91 | } |
91 | } |
92 | 92 | ||
93 | EAX=key<<8; |
93 | EAX=key<<8; |
94 | edit_box_key stdcall(#edit1); |
94 | edit_box_key stdcall(#edit1); |
95 | 95 | ||
96 | // Translate(); |
96 | // Translate(); |
97 | // DrawTranslation(); |
97 | // DrawTranslation(); |
98 | break; |
98 | break; |
99 | 99 | ||
100 | case evReDraw: |
100 | case evReDraw: |
101 | DrawWindowContent(); |
101 | DrawWindowContent(); |
102 | break; |
102 | break; |
103 | } |
103 | } |
104 | } |
104 | } |
105 | } |
105 | } |
106 | 106 | ||
107 | 107 | ||
108 | void DrawWindowContent() |
108 | void DrawWindowContent() |
109 | { |
109 | { |
110 | sc.get(); |
110 | sc.get(); |
111 | DefineAndDrawWindow(215,120,400,250,0x73,sc.work,#title); |
111 | DefineAndDrawWindow(215,120,400,250,0x73,sc.work,#title); |
112 | GetProcessInfo(#Form, SelfInfo); |
112 | GetProcessInfo(#Form, SelfInfo); |
113 | if (Form.status_window>2) return; |
113 | if (Form.status_window>2) return; |
114 | if (Form.height<140) MoveSize(OLD,OLD,OLD,140); |
114 | if (Form.height<140) MoveSize(OLD,OLD,OLD,140); |
115 | if (Form.width<400) MoveSize(OLD,OLD,400,OLD); |
115 | if (Form.width<400) MoveSize(OLD,OLD,400,OLD); |
116 | edit1.focus_border_color=sc.work_graph; |
116 | edit1.focus_border_color=sc.work_graph; |
117 | edit1.width=Form.width-edit1.left-edit1.left-9; |
117 | edit1.width=Form.width-edit1.left-edit1.left-9; |
118 | 118 | ||
119 | DrawBar(0, 0, Form.width-9, 69, sc.work); |
119 | DrawBar(0, 0, Form.width-9, 69, sc.work); |
120 | edit_box_draw stdcall(#edit1); |
120 | edit_box_draw stdcall(#edit1); |
121 | DrawCaptButton(edit1.left+edit1.width-80,35, 80,20, 10, sc.work_button, sc.work_button_text,#translate_caption); |
121 | DrawCaptButton(edit1.left+edit1.width-80,35, 80,20, 10, sc.work_button, sc.work_button_text,#translate_caption); |
122 | DrawBar(0, 69, Form.width-9, 1, sc.work_graph); |
122 | DrawBar(0, 69, Form.width-9, 1, sc.work_graph); |
123 | 123 | ||
124 | WriteText(edit1.left,35+7,0x80,sc.work_text,#direction); |
124 | WriteText(edit1.left,35+7,0x80,sc.work_text,#direction); |
125 | DefineButton(edit1.left+130,35, 120,20, 11, sc.work_button); |
125 | DefineButton(edit1.left+130,35, 120,20, 11, sc.work_button); |
126 | DrawBar(edit1.left+130+1,36, 107,19, 0xFFFFFF); |
126 | DrawBar(edit1.left+130+1,36, 107,19, 0xFFFFFF); |
127 | WriteText(edit1.left+130+112,35+7,0x80,sc.work_button_text,"\x19"); |
127 | WriteText(edit1.left+130+112,35+7,0x80,sc.work_button_text,"\x19"); |
128 | WriteText(edit1.left+130+8,35+7,0x80,0x000000,#cur_dict); |
128 | WriteText(edit1.left+130+8,35+7,0x80,0x000000,#cur_dict); |
129 | 129 | ||
130 | DrawTranslation(); |
130 | DrawTranslation(); |
131 | } |
131 | } |
132 | 132 | ||
133 | void SpeakerDraw(dword x, y) |
133 | void SpeakerDraw(dword x, y) |
134 | { |
134 | { |
135 | if (!strstr(#cur_dict, "- rus")) return; |
135 | if (!strstr(#cur_dict, "- rus")) return; |
136 | DefineButton(x-5, y-5, 23+10, 20+9, 15+BT_HIDE+BT_NOFRAME, 0); |
136 | DefineButton(x-5, y-5, 23+10, 20+9, 15+BT_HIDE+BT_NOFRAME, 0); |
137 | if (GetProcessSlot(speaker_id)==0)) _PutImage(x, y, 23,20, #speaker); else _PutImage(x, y, 23,20, 23*20*3+#speaker); |
137 | if (GetProcessSlot(speaker_id)==0)) _PutImage(x, y, 23,20, #speaker); else _PutImage(x, y, 23,20, 23*20*3+#speaker); |
138 | } |
138 | } |
139 | 139 | ||
140 | void Translate() |
140 | void Translate() |
141 | { |
141 | { |
142 | dword tj; |
142 | dword tj; |
143 | char w_native[100], w_translation[100], bukva[1]; |
143 | char w_native[100], w_translation[100], bukva[1]; |
144 | 144 | ||
145 | byte InfType; |
145 | byte InfType; |
146 | #define NATIVE_WORD 0 |
146 | #define NATIVE_WORD 0 |
147 | #define TRANSLATION 1 |
147 | #define TRANSLATION 1 |
148 | #define IGNORE 2 |
148 | #define IGNORE 2 |
149 | 149 | ||
150 | if (!fsize) return; |
150 | if (!fsize) return; |
151 | KillProcess(speaker_id); |
151 | KillProcess(speaker_id); |
152 | 152 | ||
153 | translate_result = 0; |
153 | translate_result = 0; |
154 | strcpy(#search_word, #edword); |
154 | strcpy(#search_word, #edword); |
155 | strupr(#search_word); |
155 | strupr(#search_word); |
156 | 156 | ||
157 | if (!edword) |
157 | if (!edword) |
158 | { |
158 | { |
159 | strcpy(#translate_result, #empty_word); |
159 | strcpy(#translate_result, #empty_word); |
160 | return; |
160 | return; |
161 | } |
161 | } |
162 | 162 | ||
163 | for (tj=0; tj |
163 | for (tj=0; tj |
164 | { |
164 | { |
165 | bukva = ESBYTE[file_buf+tj]; |
165 | bukva = ESBYTE[file_buf+tj]; |
166 | switch (bukva) |
166 | switch (bukva) |
167 | { |
167 | { |
168 | case '"': |
168 | case '"': |
169 | if (w_translation) |
169 | if (w_translation) |
170 | { |
170 | { |
171 | if (!strcmp(#w_native, #search_word)) |
171 | if (!strcmp(#w_native, #search_word)) |
172 | { |
172 | { |
173 | 173 | ||
174 | if (translate_result) strcat(#translate_result, ", "); |
174 | if (translate_result) strcat(#translate_result, ", "); |
175 | strcat(#translate_result, #w_translation); |
175 | strcat(#translate_result, #w_translation); |
176 | } |
176 | } |
177 | else |
177 | else |
178 | if (translate_result) return; |
178 | if (translate_result) return; |
179 | 179 | ||
180 | w_translation = w_native = 0; |
180 | w_translation = w_native = 0; |
181 | } |
181 | } |
182 | InfType = TRANSLATION; |
182 | InfType = TRANSLATION; |
183 | break; |
183 | break; |
184 | case 0x0a: |
184 | case 0x0a: |
185 | InfType = NATIVE_WORD; |
185 | InfType = NATIVE_WORD; |
186 | break; |
186 | break; |
187 | default: |
187 | default: |
188 | if (InfType==NATIVE_WORD) |
188 | if (InfType==NATIVE_WORD) |
189 | { |
189 | { |
190 | chrcat(#w_native, bukva); |
190 | chrcat(#w_native, bukva); |
191 | //if (w_native<>search_word) InfType = IGNORE; //åñëè ïåðâàÿ áóêâà íå ñîâïàäàåò èãíîðèì âñ¸ ñëîâî |
191 | //if (w_native<>search_word) InfType = IGNORE; //åñëè ïåðâàÿ áóêâà íå ñîâïàäàåò èãíîðèì âñ¸ ñëîâî |
192 | } |
192 | } |
193 | if (InfType==TRANSLATION) chrcat(#w_translation, bukva); |
193 | if (InfType==TRANSLATION) chrcat(#w_translation, bukva); |
194 | } |
194 | } |
195 | } |
195 | } |
196 | if (!translate_result) strcpy(#translate_result, "Word is'nt found in the dictionary"); |
196 | if (!translate_result) strcpy(#translate_result, "Word is'nt found in the dictionary"); |
197 | } |
197 | } |
198 | 198 | ||
199 | 199 | ||
200 | void OpenDictionary(dword fileid) |
200 | void OpenDictionary(dword fileid) |
201 | { |
201 | { |
202 | char open_file_path[4096]; |
202 | char open_file_path[4096]; |
203 | KillProcess(speaker_id); |
203 | KillProcess(speaker_id); |
204 | if (!dir_buf) ShowDictList(); |
204 | if (!dir_buf) ShowDictList(); |
205 | if (!dir_buf) strcpy(#cur_dict, "none"); |
205 | if (!dir_buf) strcpy(#cur_dict, "none"); |
206 | else strcpy(#cur_dict, fileid*304+dir_buf+72); |
206 | else strcpy(#cur_dict, fileid*304+dir_buf+72); |
207 | fsize = ESDWORD[fileid*304 + dir_buf+64]; |
207 | fsize = ESDWORD[fileid*304 + dir_buf+64]; |
208 | 208 | ||
209 | free(file_buf); |
209 | free(file_buf); |
210 | file_buf = malloc(fsize); |
210 | file_buf = malloc(fsize); |
211 | strcpy(#open_file_path, dict_folder); |
211 | strcpy(#open_file_path, dict_folder); |
212 | strcat(#open_file_path, "/"); |
212 | strcat(#open_file_path, "/"); |
213 | strcat(#open_file_path, #cur_dict); |
213 | strcat(#open_file_path, #cur_dict); |
214 | ReadFile(0, fsize, file_buf, #open_file_path); |
214 | ReadFile(0, fsize, file_buf, #open_file_path); |
215 | IF (EAX<>0) |
215 | IF (EAX<>0) |
216 | { |
216 | { |
217 | fsize = 0; |
217 | fsize = 0; |
218 | strcpy(#search_word, "Error #"); |
218 | strcpy(#search_word, "Error #"); |
219 | strcat(#search_word, itoa(EAX)); |
219 | strcat(#search_word, itoa(EAX)); |
220 | strcpy(#translate_result, #dict_not_found); |
220 | strcpy(#translate_result, #dict_not_found); |
221 | } |
221 | } |
222 | else |
222 | else |
223 | { |
223 | { |
224 | strcpy(#search_word, #cur_dict); |
224 | strcpy(#search_word, #cur_dict); |
225 | strcpy(#translate_result, #dict_opened); |
225 | strcpy(#translate_result, #dict_opened); |
226 | } |
226 | } |
227 | DrawWindowContent(); |
227 | DrawWindowContent(); |
228 | } |
228 | } |
229 | 229 | ||
230 | 230 | ||
231 | void ShowDictList() |
231 | void ShowDictList() |
232 | { |
232 | { |
233 | int j, fcount, error; |
233 | int j, fcount, error; |
234 | 234 | ||
235 | free(dir_buf); |
235 | free(dir_buf); |
236 | error = GetDir(#dir_buf, #fcount, dict_folder, DIRS_ONLYREAL); |
236 | error = GetDir(#dir_buf, #fcount, dict_folder, DIRS_ONLYREAL); |
237 | if (!error) |
237 | if (!error) |
238 | { |
238 | { |
239 | DefineButton(0,0, Form.width,Form.height, 12+BT_HIDE+BT_NOFRAME, sc.work_button); |
239 | DefineButton(0,0, Form.width,Form.height, 12+BT_HIDE+BT_NOFRAME, sc.work_button); |
240 | for (j=0; j |
240 | for (j=0; j |
241 | { |
241 | { |
242 | DefineButton(edit1.left+130,j+1*20+35, 107,20, 20+j, sc.work_button); |
242 | DefineButton(edit1.left+130,j+1*20+35, 107,20, 20+j, sc.work_button); |
243 | WriteText(edit1.left+130+8,j+1*20+35+7,0x80,sc.work_button_text, j*304+dir_buf+72); |
243 | WriteText(edit1.left+130+8,j+1*20+35+7,0x80,sc.work_button_text, j*304+dir_buf+72); |
244 | } |
244 | } |
245 | } |
245 | } |
246 | } |
246 | } |
247 | 247 | ||
248 | 248 | ||
249 | void DrawTranslation() |
249 | void DrawTranslation() |
250 | { |
250 | { |
251 | int text_break=0; |
251 | int text_break=0; |
252 | char tt[4096]=''; |
252 | char tt[4096]=''; |
253 | 253 | ||
254 | int y_pos=70; |
254 | int y_pos=70; |
255 | char draw_buf[4096]; |
255 | char draw_buf[4096]; |
256 | strcpy(#draw_buf, #translate_result); |
256 | strcpy(#draw_buf, #translate_result); |
257 | 257 | ||
258 | DrawBar(0, y_pos, Form.width-9, Form.cheight - y_pos, 0xFFFFFF); |
258 | DrawBar(0, y_pos, Form.width-9, Form.cheight - y_pos, 0xFFFFFF); |
259 | strttl(#draw_buf); |
259 | strttl(#draw_buf); |
260 | WriteTextB(10+1, y_pos+8, 0x90, 0x800080, #search_word); |
260 | WriteTextB(10+1, y_pos+8, 0x90, 0x800080, #search_word); |
261 | while (draw_buf) |
261 | while (draw_buf) |
262 | { |
262 | { |
263 | text_break= Form.width/6-6; |
263 | text_break= Form.width/6-6; |
264 | if (text_break>strlen(#draw_buf)) |
264 | if (text_break>strlen(#draw_buf)) |
265 | { |
265 | { |
266 | WriteText(10, y_pos+21, 0x80, 0, #draw_buf); |
266 | WriteText(10, y_pos+21, 0x80, 0, #draw_buf); |
267 | break; |
267 | break; |
268 | } |
268 | } |
269 | while (draw_buf[text_break]<>' ') && (text_break>0) text_break--; |
269 | while (draw_buf[text_break]<>' ') && (text_break>0) text_break--; |
270 | strcpy(#tt, #draw_buf+text_break+1); |
270 | strcpy(#tt, #draw_buf+text_break+1); |
271 | draw_buf[text_break]=0x0; |
271 | draw_buf[text_break]=0x0; |
272 | WriteText(10, y_pos+21, 0x80, 0, #draw_buf); |
272 | WriteText(10, y_pos+21, 0x80, 0, #draw_buf); |
273 | strcpy(#draw_buf, #tt); |
273 | strcpy(#draw_buf, #tt); |
274 | y_pos+=12; |
274 | y_pos+=12; |
275 | if (y_pos+24+8>Form.cheight) break; //÷òîá íå çàëåçàëî íà íèæíèé îáîäîê |
275 | if (y_pos+24+8>Form.cheight) break; //÷òîá íå çàëåçàëî íà íèæíèé îáîäîê |
276 | } |
276 | } |
277 | SpeakerDraw(Form.cwidth-38, Form.cheight-32); |
277 | SpeakerDraw(Form.cwidth-38, Form.cheight-32); |
278 | } |
278 | } |
279 | 279 | ||
280 | 280 | ||
281 | stop:>>>400)>140)>8; |
281 | stop:>>>400)>140)>8; |
282 | ><8; |
282 | ><8; |
283 | > |
283 | > |