Revision 298
implemented chat. changed place of some macros
proj.c | ||
---|---|---|
155 | 155 |
counter_mouse_ih = 0; |
156 | 156 |
} |
157 | 157 |
break; |
158 |
case COM1_IRQ: nctp_ih(); break; |
|
158 | 159 |
} |
159 | 160 |
} |
160 | 161 |
} |
... | ... | |
294 | 295 |
|
295 | 296 |
} |
296 | 297 |
break; |
298 |
case COM1_IRQ: nctp_ih(); break; |
|
297 | 299 |
} |
298 | 300 |
} |
299 | 301 |
} |
... | ... | |
323 | 325 |
return SUCCESS; |
324 | 326 |
} |
325 | 327 |
|
326 |
#define CHAT_MAX_SIZE 64
|
|
327 |
#define CHAT_MAX_NUM 10
|
|
328 |
#define CHAT_MAX_SIZE 75
|
|
329 |
#define CHAT_MAX_NUM 19
|
|
328 | 330 |
|
329 | 331 |
text_t *t_text[CHAT_MAX_NUM] = {NULL}; |
330 | 332 |
rectangle_t *r_text = NULL; |
... | ... | |
357 | 359 |
int (chat)(void){ |
358 | 360 |
int r; |
359 | 361 |
|
362 |
nctp_dump(); |
|
360 | 363 |
nctp_set_processor(chat_process); |
361 | 364 |
|
362 | 365 |
struct packet pp; |
363 | 366 |
|
367 |
char buffer[CHAT_MAX_SIZE] = ""; |
|
364 | 368 |
rectangle_t *r_buffer = NULL; { |
365 |
r_buffer = rectangle_ctor(0,0,750,70);
|
|
369 |
r_buffer = rectangle_ctor(0,0,900,70);
|
|
366 | 370 |
rectangle_set_pos(r_buffer, graph_get_XRes()/2 -rectangle_get_w(r_buffer)/2, |
367 |
graph_get_YRes()*0.8-rectangle_get_h(r_buffer)/2); |
|
371 |
graph_get_YRes()*0.87-rectangle_get_h(r_buffer)/2);
|
|
368 | 372 |
rectangle_set_fill_color (r_buffer, GRAPH_BLACK); |
369 | 373 |
rectangle_set_outline_width(r_buffer, 2); |
370 | 374 |
rectangle_set_outline_color(r_buffer, GRAPH_WHITE); |
... | ... | |
378 | 382 |
text_set_valign(t_buffer, text_valign_center); |
379 | 383 |
text_set_color (t_buffer, TEXT_COLOR); |
380 | 384 |
} |
385 |
text_t *t_size = NULL; { |
|
386 |
t_size = text_ctor(consolas, ""); |
|
387 |
text_set_pos(t_size, rectangle_get_x(r_buffer)+rectangle_get_w(r_buffer)-5, |
|
388 |
rectangle_get_y(r_buffer)+rectangle_get_h(r_buffer)-5); |
|
389 |
text_set_halign(t_size, text_halign_right); |
|
390 |
text_set_valign(t_size, text_valign_bottom); |
|
391 |
text_set_color (t_size, TEXT_COLOR); |
|
392 |
text_set_size (t_size, 18); |
|
393 |
char buffer2[20]; |
|
394 |
sprintf(buffer2, "%d/%d", strlen(buffer), CHAT_MAX_SIZE); |
|
395 |
text_set_text(t_size, buffer2); |
|
396 |
} |
|
381 | 397 |
|
382 | 398 |
/** r_text */ { |
383 |
r_text = rectangle_ctor(0,0,750,500);
|
|
399 |
r_text = rectangle_ctor(0,0,900,550);
|
|
384 | 400 |
rectangle_set_pos(r_text, graph_get_XRes()/2 -rectangle_get_w(r_buffer)/2, |
385 |
graph_get_YRes()*0.1-rectangle_get_h(r_buffer)/2);
|
|
401 |
graph_get_YRes()*0.09);
|
|
386 | 402 |
rectangle_set_fill_color (r_text, GRAPH_BLACK); |
387 | 403 |
rectangle_set_outline_width(r_text, 2); |
388 | 404 |
rectangle_set_outline_color(r_text, GRAPH_WHITE); |
... | ... | |
392 | 408 |
for(size_t i = 0; i < CHAT_MAX_NUM; ++i){ |
393 | 409 |
t_text[i] = text_ctor(consolas, " "); |
394 | 410 |
text_set_pos(t_text[i], rectangle_get_x(r_text)+50, |
395 |
rectangle_get_y(r_text)+rectangle_get_h(r_text)-30-30*i);
|
|
411 |
rectangle_get_y(r_text)+rectangle_get_h(r_text)-30-25*i);
|
|
396 | 412 |
text_set_halign(t_text[i], text_halign_left); |
397 | 413 |
text_set_valign(t_text[i], text_valign_bottom); |
398 | 414 |
text_set_color (t_text[i], TEXT_COLOR); |
... | ... | |
402 | 418 |
/// loop stuff |
403 | 419 |
int ipc_status; |
404 | 420 |
message msg; |
405 |
|
|
406 |
char buffer[CHAT_MAX_SIZE] = ""; |
|
407 |
|
|
408 | 421 |
int good = true; |
409 |
|
|
410 | 422 |
while (good) { |
411 | 423 |
/* Get a request message. */ |
412 | 424 |
if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { |
... | ... | |
426 | 438 |
|
427 | 439 |
rectangle_draw(r_buffer); |
428 | 440 |
text_draw(t_buffer); |
441 |
text_draw(t_size); |
|
429 | 442 |
|
430 | 443 |
rectangle_draw(r_text); |
431 | 444 |
for(size_t i = 0; i < CHAT_MAX_NUM; ++i) text_draw(t_text[i]); |
... | ... | |
434 | 447 |
graph_draw(); |
435 | 448 |
break; |
436 | 449 |
case KBC_IRQ: |
437 |
if ((scancode[0]) == ESC_BREAK_CODE) good = false;
|
|
438 |
else if ((scancode[0]) == ENTER_MAKE_CODE) {
|
|
450 |
if (scancode[0] == ESC_BREAK_CODE) good = false;
|
|
451 |
else if (scancode[0] == ENTER_MAKE_CODE) {
|
|
439 | 452 |
hltp_send_string(buffer); |
440 | 453 |
char buffer2[CHAT_MAX_SIZE+3] = "> "; |
441 | 454 |
strncat(buffer2, buffer, strlen(buffer)); |
... | ... | |
451 | 464 |
text_set_halign(t_text[i], text_halign_right); |
452 | 465 |
} |
453 | 466 |
} |
454 |
|
|
455 | 467 |
buffer[0] = '\0'; |
456 |
text_set_text(t_buffer, buffer);
|
|
457 |
}
|
|
458 |
else { |
|
468 |
} else if(scancode[0] == BACKSPACE_MAKE_CODE){
|
|
469 |
buffer[strlen(buffer)-1] = '\0';
|
|
470 |
} else {
|
|
459 | 471 |
char c = map_makecode(scancode[0]); |
460 | 472 |
if (c == ERROR_CODE) break; |
461 | 473 |
if(strlen(buffer) < CHAT_MAX_SIZE) strncat(buffer, &c, 1); |
462 |
else printf("Char limit exceeded\n"); |
|
463 |
text_set_text(t_buffer, buffer); |
|
474 |
else printf("Char limit exceeded\n"); |
|
464 | 475 |
} |
476 |
text_set_text(t_buffer, buffer); |
|
477 |
char buffer2[20]; |
|
478 |
sprintf(buffer2, "%d/%d", strlen(buffer), CHAT_MAX_SIZE); |
|
479 |
text_set_text(t_size, buffer2); |
|
465 | 480 |
case MOUSE_IRQ: |
466 | 481 |
if (counter_mouse_ih >= 3) { |
467 | 482 |
mouse_parse_packet(packet_mouse_ih, &pp); |
... | ... | |
469 | 484 |
counter_mouse_ih = 0; |
470 | 485 |
} |
471 | 486 |
break; |
472 |
case COM1_IRQ: |
|
473 |
nctp_ih(); |
|
474 |
break; |
|
487 |
case COM1_IRQ: nctp_ih(); break; |
|
475 | 488 |
} |
476 | 489 |
} |
477 | 490 |
} |
478 |
|
|
479 | 491 |
break; |
480 | 492 |
default: |
481 | 493 |
break; /* no other notifications expected: do nothing */ |
... | ... | |
491 | 503 |
rectangle_dtor(r_text); |
492 | 504 |
for(size_t i = 0; i < CHAT_MAX_NUM; ++i) text_dtor(t_text[i]); |
493 | 505 |
|
506 |
nctp_set_processor(NULL); |
|
507 |
|
|
494 | 508 |
return SUCCESS; |
495 | 509 |
} |
Also available in: Unified diff