diff options
-rw-r--r-- | apps/recorder/keyboard.c | 112 |
1 files changed, 57 insertions, 55 deletions
diff --git a/apps/recorder/keyboard.c b/apps/recorder/keyboard.c index ddfbcf4585..d87272cfee 100644 --- a/apps/recorder/keyboard.c +++ b/apps/recorder/keyboard.c | |||
@@ -310,7 +310,6 @@ int kbd_input(char* text, int buflen) | |||
310 | bool morse_reading = false; | 310 | bool morse_reading = false; |
311 | unsigned char morse_code = 0; | 311 | unsigned char morse_code = 0; |
312 | int morse_tick = 0; | 312 | int morse_tick = 0; |
313 | char buf[2]; | ||
314 | #endif | 313 | #endif |
315 | int oldbars = viewportmanager_set_statusbar(VP_SB_HIDE_ALL); | 314 | int oldbars = viewportmanager_set_statusbar(VP_SB_HIDE_ALL); |
316 | FOR_NB_SCREENS(l) | 315 | FOR_NB_SCREENS(l) |
@@ -410,23 +409,19 @@ int kbd_input(char* text, int buflen) | |||
410 | } | 409 | } |
411 | 410 | ||
412 | sc->setfont(pm->curfont); | 411 | sc->setfont(pm->curfont); |
413 | pm->font_w = 0; /* reset font width */ | 412 | /* find max width of keyboard glyphs. |
414 | /* find max width of keyboard glyphs */ | 413 | * since we're going to be adding spaces, |
414 | * max width is at least their width */ | ||
415 | pm->font_w = font_get_width(pm->font, ' '); | ||
415 | for (i = 0; i < pm->nchars; i++) | 416 | for (i = 0; i < pm->nchars; i++) |
416 | { | 417 | { |
417 | if (pm->kbd_buf[i] != '\n') | 418 | if (pm->kbd_buf[i] != '\n') |
418 | { | 419 | { |
419 | w = font_get_width(pm->font, pm->kbd_buf[i]); | 420 | w = font_get_width(pm->font, pm->kbd_buf[i]); |
420 | if ( w > pm->font_w ) | 421 | if (w > pm->font_w) |
421 | pm->font_w = w; | 422 | pm->font_w = w; |
422 | } | 423 | } |
423 | } | 424 | } |
424 | |||
425 | /* Since we're going to be adding spaces, make sure that we check | ||
426 | * their width too */ | ||
427 | w = font_get_width( pm->font, ' ' ); | ||
428 | if ( w > pm->font_w ) | ||
429 | pm->font_w = w; | ||
430 | } | 425 | } |
431 | 426 | ||
432 | FOR_NB_SCREENS(l) | 427 | FOR_NB_SCREENS(l) |
@@ -487,6 +482,7 @@ int kbd_input(char* text, int buflen) | |||
487 | { | 482 | { |
488 | struct keyboard_parameters *pm = ¶m[l]; | 483 | struct keyboard_parameters *pm = ¶m[l]; |
489 | struct screen *sc = &screens[l]; | 484 | struct screen *sc = &screens[l]; |
485 | int icon_w; | ||
490 | 486 | ||
491 | pm->text_w = pm->font_w; | 487 | pm->text_w = pm->font_w; |
492 | 488 | ||
@@ -500,7 +496,11 @@ int kbd_input(char* text, int buflen) | |||
500 | pm->text_w = w; | 496 | pm->text_w = w; |
501 | } | 497 | } |
502 | 498 | ||
503 | pm->max_chars_text = sc->getwidth() / pm->text_w - 2; | 499 | icon_w = get_icon_width(l); |
500 | pm->max_chars_text = (sc->getwidth() - icon_w * 2) | ||
501 | / pm->text_w; | ||
502 | if(pm->max_chars_text < 3 && icon_w > pm->text_w) | ||
503 | pm->max_chars_text = sc->getwidth() / pm->text_w - 2; | ||
504 | 504 | ||
505 | if (!kbd_loaded) | 505 | if (!kbd_loaded) |
506 | { | 506 | { |
@@ -512,7 +512,7 @@ int kbd_input(char* text, int buflen) | |||
512 | pm->lines = (sc->getheight() - BUTTONBAR_HEIGHT - statusbar_size) | 512 | pm->lines = (sc->getheight() - BUTTONBAR_HEIGHT - statusbar_size) |
513 | / pm->font_h - 1; | 513 | / pm->font_h - 1; |
514 | pm->keyboard_margin = sc->getheight() - BUTTONBAR_HEIGHT - | 514 | pm->keyboard_margin = sc->getheight() - BUTTONBAR_HEIGHT - |
515 | statusbar_size - (pm->lines+1)*pm->font_h; | 515 | statusbar_size - (pm->lines+1)*pm->font_h; |
516 | 516 | ||
517 | if (pm->keyboard_margin < 3) | 517 | if (pm->keyboard_margin < 3) |
518 | { | 518 | { |
@@ -525,7 +525,7 @@ int kbd_input(char* text, int buflen) | |||
525 | } | 525 | } |
526 | 526 | ||
527 | pm->pages = (pm->nchars + (pm->lines*pm->max_chars-1)) | 527 | pm->pages = (pm->nchars + (pm->lines*pm->max_chars-1)) |
528 | / (pm->lines*pm->max_chars); | 528 | / (pm->lines*pm->max_chars); |
529 | 529 | ||
530 | if (pm->pages == 1 && kbd_loaded) | 530 | if (pm->pages == 1 && kbd_loaded) |
531 | pm->lines = (pm->nchars + pm->max_chars - 1) / pm->max_chars; | 531 | pm->lines = (pm->nchars + pm->max_chars - 1) / pm->max_chars; |
@@ -575,14 +575,14 @@ int kbd_input(char* text, int buflen) | |||
575 | /* declare scoped pointers inside screen loops - hide the | 575 | /* declare scoped pointers inside screen loops - hide the |
576 | declarations from previous block level */ | 576 | declarations from previous block level */ |
577 | const int w = 6; /* sysfixed font width */ | 577 | const int w = 6; /* sysfixed font width */ |
578 | struct keyboard_parameters *pm = ¶m[l]; | ||
579 | struct screen *sc = &screens[l]; | 578 | struct screen *sc = &screens[l]; |
580 | int i; | 579 | int i, x, y; |
581 | 580 | ||
582 | sc->setfont(FONT_SYSFIXED); /* Draw morse code screen with sysfont */ | 581 | /* Draw morse code screen with sysfont */ |
583 | pm->x = 0; | 582 | sc->setfont(FONT_SYSFIXED); |
584 | pm->y = statusbar_size; | 583 | x = 0; |
585 | buf[1] = '\0'; | 584 | y = statusbar_size; |
585 | outline[1] = '\0'; | ||
586 | 586 | ||
587 | /* Draw morse code table with code descriptions. */ | 587 | /* Draw morse code table with code descriptions. */ |
588 | for (i = 0; morse_alphabets[i] != '\0'; i++) | 588 | for (i = 0; morse_alphabets[i] != '\0'; i++) |
@@ -590,26 +590,26 @@ int kbd_input(char* text, int buflen) | |||
590 | int morse_len; | 590 | int morse_len; |
591 | int j; | 591 | int j; |
592 | 592 | ||
593 | buf[0] = morse_alphabets[i]; | 593 | outline[0] = morse_alphabets[i]; |
594 | sc->putsxy(pm->x, pm->y, buf); | 594 | sc->putsxy(x, y, outline); |
595 | 595 | ||
596 | for (j = 0; (morse_codes[i] >> j) > 0x01; j++) ; | 596 | for (j = 0; (morse_codes[i] >> j) > 0x01; j++) ; |
597 | morse_len = j; | 597 | morse_len = j; |
598 | 598 | ||
599 | pm->x += w + 3; | 599 | x += w + 3; |
600 | for (j = 0; j < morse_len; j++) | 600 | for (j = 0; j < morse_len; j++) |
601 | { | 601 | { |
602 | if ((morse_codes[i] >> (morse_len-j-1)) & 0x01) | 602 | if ((morse_codes[i] >> (morse_len-j-1)) & 0x01) |
603 | sc->fillrect(pm->x + j*4, pm->y + 2, 3, 4); | 603 | sc->fillrect(x + j*4, y + 2, 3, 4); |
604 | else | 604 | else |
605 | sc->fillrect(pm->x + j*4, pm->y + 3, 1, 2); | 605 | sc->fillrect(x + j*4, y + 3, 1, 2); |
606 | } | 606 | } |
607 | 607 | ||
608 | pm->x += w*5 - 3; | 608 | x += w*5 - 3; |
609 | if (pm->x >= sc->getwidth() - w*6) | 609 | if (x + w*6 >= sc->getwidth()) |
610 | { | 610 | { |
611 | pm->x = 0; | 611 | x = 0; |
612 | pm->y += 8; /* sysfixed font height */ | 612 | y += 8; /* sysfixed font height */ |
613 | } | 613 | } |
614 | } | 614 | } |
615 | } | 615 | } |
@@ -647,22 +647,23 @@ int kbd_input(char* text, int buflen) | |||
647 | } | 647 | } |
648 | } | 648 | } |
649 | 649 | ||
650 | /* separator */ | ||
651 | FOR_NB_SCREENS(l) | 650 | FOR_NB_SCREENS(l) |
652 | { | 651 | { |
653 | struct keyboard_parameters *pm = ¶m[l]; | 652 | struct keyboard_parameters *pm = ¶m[l]; |
654 | struct screen *sc = &screens[l]; | 653 | struct screen *sc = &screens[l]; |
655 | int i = 0, j = 0; | 654 | int i = 0, j = 0, icon_w; |
656 | int text_w = pm->text_w; | 655 | int text_w = pm->text_w; |
656 | int sc_w = sc->getwidth(); | ||
657 | int text_margin = (sc_w - text_w * pm->max_chars_text) / 2; | ||
657 | 658 | ||
658 | /* Clear text area one pixel above separator line so any overdraw | 659 | /* Clear text area one pixel above separator line so any overdraw |
659 | doesn't collide */ | 660 | doesn't collide */ |
660 | sc->set_drawmode(DRMODE_SOLID | DRMODE_INVERSEVID); | 661 | sc->set_drawmode(DRMODE_SOLID | DRMODE_INVERSEVID); |
661 | sc->fillrect(0, pm->main_y - pm->keyboard_margin - 1, | 662 | sc->fillrect(0, pm->main_y - pm->keyboard_margin - 1, |
662 | sc->getwidth(), pm->font_h + 4); | 663 | sc_w, pm->font_h + 4); |
663 | sc->set_drawmode(DRMODE_SOLID); | 664 | sc->set_drawmode(DRMODE_SOLID); |
664 | 665 | ||
665 | sc->hline(0, sc->getwidth() - 1, pm->main_y - pm->keyboard_margin); | 666 | sc->hline(0, sc_w - 1, pm->main_y - pm->keyboard_margin); |
666 | 667 | ||
667 | /* write out the text */ | 668 | /* write out the text */ |
668 | sc->setfont(pm->curfont); | 669 | sc->setfont(pm->curfont); |
@@ -681,47 +682,48 @@ int kbd_input(char* text, int buflen) | |||
681 | int w; | 682 | int w; |
682 | outline[j] = 0; | 683 | outline[j] = 0; |
683 | j=0; | 684 | j=0; |
684 | i++; | ||
685 | sc->getstringsize(outline, &w, NULL); | 685 | sc->getstringsize(outline, &w, NULL); |
686 | sc->putsxy(i*text_w + (text_w-w)/2, pm->main_y, outline); | 686 | sc->putsxy(text_margin + i*text_w + (text_w-w)/2, |
687 | pm->main_y, outline); | ||
688 | i++; | ||
687 | } | 689 | } |
688 | } | 690 | } |
689 | 691 | ||
692 | icon_w = get_icon_width(l); | ||
690 | if (pm->leftpos > 0) | 693 | if (pm->leftpos > 0) |
691 | { | 694 | { |
692 | /* Draw nicer bitmap arrow if room, else settle for "<". */ | 695 | /* Draw nicer bitmap arrow if room, else settle for "<". */ |
693 | if (text_w >= 6 && pm->font_h >= 8) | 696 | if (text_margin >= icon_w) |
694 | { | 697 | { |
695 | screen_put_iconxy(sc, (text_w - 6) / 2, | 698 | screen_put_icon_with_offset(sc, 0, 0, |
696 | pm->main_y + (pm->font_h - 8) / 2 , | 699 | (text_margin - icon_w) / 2, |
697 | Icon_Reverse_Cursor); | 700 | pm->main_y, Icon_Reverse_Cursor); |
698 | } | 701 | } |
699 | else | 702 | else |
700 | { | 703 | { |
701 | int w; | 704 | int w; |
702 | sc->getstringsize("<", &w, NULL); | 705 | sc->getstringsize("<", &w, NULL); |
703 | sc->putsxy(text_w - w, pm->main_y, "<"); | 706 | sc->putsxy(text_margin - w, pm->main_y, "<"); |
704 | } | 707 | } |
705 | } | 708 | } |
706 | 709 | ||
707 | if (len_utf8 - pm->leftpos > pm->max_chars_text) | 710 | if (len_utf8 - pm->leftpos > pm->max_chars_text) |
708 | { | 711 | { |
709 | /* Draw nicer bitmap arrow if room, else settle for ">". */ | 712 | /* Draw nicer bitmap arrow if room, else settle for ">". */ |
710 | if (text_w >= 6 && pm->font_h >= 8) | 713 | if (text_margin >= icon_w) |
711 | { | 714 | { |
712 | screen_put_iconxy(sc, sc->getwidth() - text_w + | 715 | screen_put_icon_with_offset(sc, 0, 0, |
713 | (text_w - 6) / 2, | 716 | sc_w - (text_margin + icon_w) / 2, |
714 | pm->main_y + (pm->font_h - 8) / 2, | 717 | pm->main_y, Icon_Cursor); |
715 | Icon_Cursor); | ||
716 | } | 718 | } |
717 | else | 719 | else |
718 | { | 720 | { |
719 | sc->putsxy(sc->getwidth() - text_w, pm->main_y, ">"); | 721 | sc->putsxy(sc_w - text_margin, pm->main_y, ">"); |
720 | } | 722 | } |
721 | } | 723 | } |
722 | 724 | ||
723 | /* cursor */ | 725 | /* cursor */ |
724 | i = (pm->curpos + 1) * text_w; | 726 | i = text_margin + pm->curpos * text_w; |
725 | 727 | ||
726 | if (cur_blink) | 728 | if (cur_blink) |
727 | sc->vline(i, pm->main_y, pm->main_y + pm->font_h - 1); | 729 | sc->vline(i, pm->main_y, pm->main_y + pm->font_h - 1); |
@@ -751,6 +753,9 @@ int kbd_input(char* text, int buflen) | |||
751 | sc->getwidth(), pm->font_h + 2); | 753 | sc->getwidth(), pm->font_h + 2); |
752 | else /* highlight the key that has focus */ | 754 | else /* highlight the key that has focus */ |
753 | #endif | 755 | #endif |
756 | #ifdef KBD_MORSE_INPUT | ||
757 | if(!morse_mode) | ||
758 | #endif | ||
754 | sc->fillrect(pm->font_w*pm->x, | 759 | sc->fillrect(pm->font_w*pm->x, |
755 | statusbar_size + pm->font_h*pm->y, | 760 | statusbar_size + pm->font_h*pm->y, |
756 | pm->font_w, pm->font_h); | 761 | pm->font_w, pm->font_h); |
@@ -781,9 +786,8 @@ int kbd_input(char* text, int buflen) | |||
781 | switch ( button ) | 786 | switch ( button ) |
782 | { | 787 | { |
783 | case ACTION_KBD_ABORT: | 788 | case ACTION_KBD_ABORT: |
784 | FOR_NB_SCREENS(l) | 789 | ret = -1; |
785 | screens[l].setfont(FONT_UI); | 790 | done = true; |
786 | ret = -1; done = true; | ||
787 | break; | 791 | break; |
788 | 792 | ||
789 | case ACTION_KBD_PAGE_FLIP: | 793 | case ACTION_KBD_PAGE_FLIP: |
@@ -793,7 +797,7 @@ int kbd_input(char* text, int buflen) | |||
793 | break; | 797 | break; |
794 | #endif | 798 | #endif |
795 | if (++pm->page >= pm->pages) | 799 | if (++pm->page >= pm->pages) |
796 | pm->page = 0; | 800 | pm->page = 0; |
797 | 801 | ||
798 | ch = get_kbd_ch(pm); | 802 | ch = get_kbd_ch(pm); |
799 | kbd_spellchar(ch); | 803 | kbd_spellchar(ch); |
@@ -809,8 +813,6 @@ int kbd_input(char* text, int buflen) | |||
809 | struct keyboard_parameters *pm = ¶m[l]; | 813 | struct keyboard_parameters *pm = ¶m[l]; |
810 | struct screen *sc = &screens[l]; | 814 | struct screen *sc = &screens[l]; |
811 | 815 | ||
812 | pm->x = pm->y = pm->page = 0; | ||
813 | |||
814 | if (morse_mode) | 816 | if (morse_mode) |
815 | { | 817 | { |
816 | pm->old_main_y = pm->main_y; | 818 | pm->old_main_y = pm->main_y; |
@@ -841,7 +843,7 @@ int kbd_input(char* text, int buflen) | |||
841 | { | 843 | { |
842 | int c = utf8seek(text, ++editpos); | 844 | int c = utf8seek(text, ++editpos); |
843 | kbd_spellchar(text[c]); | 845 | kbd_spellchar(text[c]); |
844 | } | 846 | } |
845 | #if CONFIG_CODEC == SWCODEC | 847 | #if CONFIG_CODEC == SWCODEC |
846 | else if (global_settings.talk_menu) | 848 | else if (global_settings.talk_menu) |
847 | pcmbuf_beep(1000, 150, 1500); | 849 | pcmbuf_beep(1000, 150, 1500); |
@@ -885,7 +887,7 @@ int kbd_input(char* text, int buflen) | |||
885 | { | 887 | { |
886 | int c = utf8seek(text, --editpos); | 888 | int c = utf8seek(text, --editpos); |
887 | kbd_spellchar(text[c]); | 889 | kbd_spellchar(text[c]); |
888 | } | 890 | } |
889 | #if CONFIG_CODEC == SWCODEC | 891 | #if CONFIG_CODEC == SWCODEC |
890 | else if (global_settings.talk_menu) | 892 | else if (global_settings.talk_menu) |
891 | pcmbuf_beep(1000, 150, 1500); | 893 | pcmbuf_beep(1000, 150, 1500); |
@@ -940,7 +942,7 @@ int kbd_input(char* text, int buflen) | |||
940 | if (++pm->y >= pm->lines) | 942 | if (++pm->y >= pm->lines) |
941 | #ifdef KBD_MODES | 943 | #ifdef KBD_MODES |
942 | { | 944 | { |
943 | pm->line_edit = true; | 945 | pm->line_edit = true; |
944 | say_edit(); | 946 | say_edit(); |
945 | } | 947 | } |
946 | #else | 948 | #else |