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