diff options
Diffstat (limited to 'apps/plugins/rockpaint.c')
-rw-r--r-- | apps/plugins/rockpaint.c | 541 |
1 files changed, 232 insertions, 309 deletions
diff --git a/apps/plugins/rockpaint.c b/apps/plugins/rockpaint.c index f92c616e07..5112931d9b 100644 --- a/apps/plugins/rockpaint.c +++ b/apps/plugins/rockpaint.c | |||
@@ -516,89 +516,46 @@ static void buffer_putsxyofs( fb_data *buf, int buf_width, int buf_height, | |||
516 | /*********************************************************************** | 516 | /*********************************************************************** |
517 | * Menu handling | 517 | * Menu handling |
518 | ***********************************************************************/ | 518 | ***********************************************************************/ |
519 | struct menu_items | ||
520 | { | ||
521 | int value; | ||
522 | char label[16]; /* GRUIK ? */ | ||
523 | }; | ||
524 | |||
525 | #define MENU_ESC -1242 | ||
526 | enum { | 519 | enum { |
527 | /* Generic menu items */ | ||
528 | MENU_END = -42, MENU_TITLE = -12, | ||
529 | /* Main menu */ | 520 | /* Main menu */ |
530 | MAIN_MENU_RESUME, | 521 | MAIN_MENU_RESUME, |
531 | MAIN_MENU_NEW, MAIN_MENU_LOAD, MAIN_MENU_SAVE, | 522 | MAIN_MENU_NEW, MAIN_MENU_LOAD, MAIN_MENU_SAVE, |
532 | MAIN_MENU_BRUSH_SIZE, MAIN_MENU_BRUSH_SPEED, MAIN_MENU_COLOR, | 523 | MAIN_MENU_BRUSH_SIZE, MAIN_MENU_BRUSH_SPEED, MAIN_MENU_COLOR, |
533 | MAIN_MENU_GRID_SIZE, | 524 | MAIN_MENU_GRID_SIZE, |
534 | MAIN_MENU_EXIT, | 525 | MAIN_MENU_EXIT, |
526 | }; | ||
527 | enum { | ||
535 | /* Select action menu */ | 528 | /* Select action menu */ |
536 | SELECT_MENU_CUT, SELECT_MENU_COPY, SELECT_MENU_INVERT, | 529 | SELECT_MENU_CUT, SELECT_MENU_COPY, SELECT_MENU_INVERT, |
537 | SELECT_MENU_HFLIP, SELECT_MENU_VFLIP, SELECT_MENU_ROTATE90, | 530 | SELECT_MENU_HFLIP, SELECT_MENU_VFLIP, SELECT_MENU_ROTATE90, |
538 | SELECT_MENU_ROTATE180, SELECT_MENU_ROTATE270, | 531 | SELECT_MENU_ROTATE180, SELECT_MENU_ROTATE270, |
539 | SELECT_MENU_CANCEL, | 532 | SELECT_MENU_CANCEL, |
533 | }; | ||
534 | enum { | ||
540 | /* Text menu */ | 535 | /* Text menu */ |
541 | TEXT_MENU_TEXT, TEXT_MENU_FONT, | 536 | TEXT_MENU_TEXT, TEXT_MENU_FONT, |
542 | TEXT_MENU_PREVIEW, TEXT_MENU_APPLY, TEXT_MENU_CANCEL, | 537 | TEXT_MENU_PREVIEW, TEXT_MENU_APPLY, TEXT_MENU_CANCEL, |
543 | }; | 538 | }; |
544 | 539 | ||
545 | static struct menu_items main_menu[]= | 540 | MENUITEM_STRINGLIST(main_menu, "RockPaint", NULL, |
546 | { { MENU_TITLE, "RockPaint" }, | 541 | "Resume", "New", "Load", "Save", |
547 | { MAIN_MENU_RESUME, "Resume" }, | 542 | "Brush Size", "Brush Speed", |
548 | { MAIN_MENU_NEW, "New" }, | 543 | "Choose Color", "Grid Size", "Exit"); |
549 | { MAIN_MENU_LOAD, "Load" }, | 544 | MENUITEM_STRINGLIST(size_menu, "Choose Size", NULL, |
550 | { MAIN_MENU_SAVE, "Save" }, | 545 | "1x", "2x","4x", "8x"); |
551 | { MAIN_MENU_BRUSH_SIZE, "Brush Size" }, | 546 | MENUITEM_STRINGLIST(speed_menu, "Choose Speed", NULL, |
552 | { MAIN_MENU_BRUSH_SPEED, "Brush Speed" }, | 547 | "1x", "2x","4x"); |
553 | { MAIN_MENU_COLOR, "Choose Color" }, | 548 | MENUITEM_STRINGLIST(gridsize_menu, "Grid Size", NULL, |
554 | { MAIN_MENU_GRID_SIZE, "Grid Size" }, | 549 | "No grid", "5px", "10px", "20px"); |
555 | { MAIN_MENU_EXIT, "Exit" }, | 550 | MENUITEM_STRINGLIST(select_menu, "Select...", NULL, |
556 | { MENU_END, "" } }; | 551 | "Cut", "Copy", "Invert", "Horizontal Flip" , |
557 | 552 | "Vertical Flip", "Rotate 90°", | |
558 | static struct menu_items size_menu[] = | 553 | "Rotate 180°", "Rotate 270°", "Cancel"); |
559 | { { MENU_TITLE, "Choose Size" }, | 554 | MENUITEM_STRINGLIST(text_menu, "Text", NULL, |
560 | { 1, "1x" }, | 555 | "Set Text", "Change Font", |
561 | { 2, "2x" }, | 556 | "Preview", "Apply", "Cancel"); |
562 | { 4, "4x" }, | 557 | static const int times_list[] = { 1, 2, 4, 8 }; |
563 | { 8, "8x" }, | 558 | static const int gridsize_list[] = { 0, 5, 10, 20 }; |
564 | { MENU_END, "" } }; | ||
565 | |||
566 | static struct menu_items speed_menu[] = | ||
567 | { { MENU_TITLE, "Choose Speed" }, | ||
568 | { 1, "1x" }, | ||
569 | { 2, "2x" }, | ||
570 | { 4, "4x" }, | ||
571 | { MENU_END, "" } }; | ||
572 | |||
573 | static struct menu_items gridsize_menu[] = | ||
574 | { { MENU_TITLE, "Grid Size" }, | ||
575 | { 0, "No grid" }, | ||
576 | { 5, "5px" }, | ||
577 | { 10, "10px" }, | ||
578 | { 20, "20px" }, | ||
579 | { MENU_END, "" } }; | ||
580 | |||
581 | static struct menu_items select_menu[] = | ||
582 | { { MENU_TITLE, "Select..." }, | ||
583 | { SELECT_MENU_CUT, "Cut" }, | ||
584 | { SELECT_MENU_COPY, "Copy" }, | ||
585 | { SELECT_MENU_INVERT, "Invert" }, | ||
586 | { SELECT_MENU_HFLIP, "Horizontal flip" }, | ||
587 | { SELECT_MENU_VFLIP, "Vertical flip" }, | ||
588 | // { SELECT_MENU_ROTATE90, "Rotate 90°" }, | ||
589 | { SELECT_MENU_ROTATE180, "Rotate 180°" }, | ||
590 | // { SELECT_MENU_ROTATE270, "Rotate 270°" }, | ||
591 | { SELECT_MENU_CANCEL, "Cancel" }, | ||
592 | { MENU_END, "" } }; | ||
593 | |||
594 | static struct menu_items text_menu[] = | ||
595 | { { MENU_TITLE, "Text" }, | ||
596 | { TEXT_MENU_TEXT, "Set text" }, | ||
597 | { TEXT_MENU_FONT, "Change font" }, | ||
598 | { TEXT_MENU_PREVIEW, "Preview" }, | ||
599 | { TEXT_MENU_APPLY, "Apply" }, | ||
600 | { TEXT_MENU_CANCEL, "Cancel" }, | ||
601 | { MENU_END, "" } }; | ||
602 | 559 | ||
603 | static int draw_window( int height, int width, | 560 | static int draw_window( int height, int width, |
604 | int *top, int *left, | 561 | int *top, int *left, |
@@ -624,143 +581,37 @@ static int draw_window( int height, int width, | |||
624 | return _top+fh+4; | 581 | return _top+fh+4; |
625 | } | 582 | } |
626 | 583 | ||
627 | static int menu_display( struct menu_items menu[], int prev_value ) | ||
628 | { | ||
629 | int i, | ||
630 | fh, /* font height */ | ||
631 | width, height, | ||
632 | a, b, | ||
633 | selection=1, | ||
634 | menu_length, | ||
635 | top, left; | ||
636 | int scroll = 0, onscreen = 0; | ||
637 | |||
638 | rb->lcd_getstringsize( menu[0].label, &width, &fh ); | ||
639 | for( i=1; menu[i].value != MENU_END; i++ ) | ||
640 | { | ||
641 | if( prev_value == menu[i].value ) | ||
642 | { | ||
643 | selection = i; | ||
644 | } | ||
645 | rb->lcd_getstringsize( menu[i].label, &a, &b ); | ||
646 | if( a > width ) width = a; | ||
647 | if( b > fh ) fh = b; | ||
648 | } | ||
649 | menu_length = i; | ||
650 | fh++; | ||
651 | width += 10; | ||
652 | |||
653 | height = menu_length * fh + 4 + 2 + 2; | ||
654 | if( height >= LCD_HEIGHT ) | ||
655 | { | ||
656 | scroll = 1; | ||
657 | onscreen = ( LCD_HEIGHT - 4 - 2 - 2 )/fh; | ||
658 | height = onscreen * fh + 4 + 2 + 2; | ||
659 | width += 5; | ||
660 | } | ||
661 | else | ||
662 | { | ||
663 | onscreen = menu_length; | ||
664 | } | ||
665 | |||
666 | draw_window( height, width, &top, &left, menu[0].label ); | ||
667 | |||
668 | while( 1 ) | ||
669 | { | ||
670 | for( i = (scroll == 0 ? 1 : scroll); | ||
671 | i < (scroll ? scroll + onscreen - 1:onscreen); | ||
672 | i++ ) | ||
673 | { | ||
674 | if( i == selection ) | ||
675 | { | ||
676 | rb->lcd_set_foreground( COLOR_WHITE ); | ||
677 | rb->lcd_set_background( COLOR_BLUE ); | ||
678 | } | ||
679 | else | ||
680 | { | ||
681 | rb->lcd_set_foreground( COLOR_BLACK ); | ||
682 | rb->lcd_set_background( COLOR_LIGHTGRAY ); | ||
683 | } | ||
684 | rb->lcd_putsxy( left+2, | ||
685 | top+6+fh*(i-(scroll == 0 ? 0 : scroll-1 )), | ||
686 | menu[i].label ); | ||
687 | } | ||
688 | if( scroll ) | ||
689 | { | ||
690 | int scroll_height = ((height-fh-4-2)*onscreen)/menu_length; | ||
691 | rb->lcd_set_foreground( COLOR_BLACK ); | ||
692 | rb->lcd_vline( left+width-5, top+fh+4, top+height-2 ); | ||
693 | rb->lcd_fillrect( left+width-4, | ||
694 | top+fh+4+((height-4-2-fh-scroll_height)*(scroll-1))/(menu_length-onscreen), | ||
695 | 3, scroll_height ); | ||
696 | } | ||
697 | rb->lcd_update(); | ||
698 | |||
699 | switch( rb->button_get(true) ) | ||
700 | { | ||
701 | case ROCKPAINT_UP: | ||
702 | case ROCKPAINT_UP|BUTTON_REPEAT: | ||
703 | selection = (selection + menu_length-1)%menu_length; | ||
704 | if( !selection ) selection = menu_length-1; | ||
705 | break; | ||
706 | |||
707 | case ROCKPAINT_DOWN: | ||
708 | case ROCKPAINT_DOWN|BUTTON_REPEAT: | ||
709 | selection = (selection + 1)%menu_length; | ||
710 | if( !selection ) selection++; | ||
711 | break; | ||
712 | |||
713 | case ROCKPAINT_LEFT: | ||
714 | restore_screen(); | ||
715 | return MENU_ESC; | ||
716 | |||
717 | case ROCKPAINT_RIGHT: | ||
718 | case ROCKPAINT_DRAW: | ||
719 | restore_screen(); | ||
720 | return menu[selection].value; | ||
721 | } | ||
722 | if( scroll ) | ||
723 | { | ||
724 | if( selection < scroll ) | ||
725 | { | ||
726 | scroll = selection; | ||
727 | draw_window( height, width, NULL, NULL, menu[0].label ); | ||
728 | } | ||
729 | if( selection >= scroll + onscreen - 1 ) | ||
730 | { | ||
731 | scroll++; | ||
732 | draw_window( height, width, NULL, NULL, menu[0].label ); | ||
733 | } | ||
734 | } | ||
735 | } | ||
736 | } | ||
737 | |||
738 | /*********************************************************************** | 584 | /*********************************************************************** |
739 | * File browser | 585 | * File browser |
740 | ***********************************************************************/ | 586 | ***********************************************************************/ |
741 | 587 | ||
742 | char bbuf[MAX_PATH+1]; /* used by file and font browsers */ | 588 | char bbuf[MAX_PATH+1]; /* used by file and font browsers */ |
743 | char bbuf_s[MAX_PATH+1]; /* used by file and font browsers */ | 589 | char bbuf_s[MAX_PATH+1]; /* used by file and font browsers */ |
590 | struct tree_context *tree = NULL; | ||
744 | 591 | ||
745 | static bool browse( char *dst, int dst_size, const char *start ) | 592 | static char * browse_get_name_cb( int selected_item, void *data, |
593 | char *buffer, size_t buffer_len ) | ||
746 | { | 594 | { |
747 | #define WIDTH ( LCD_WIDTH - 20 ) | 595 | int *indexes = (int *) data; |
748 | #define HEIGHT ( LCD_HEIGHT - 20 ) | 596 | struct entry* dc = tree->dircache; |
749 | #define LINE_SPACE 2 | 597 | struct entry* e = &dc[indexes[selected_item]]; |
750 | int top, top_inside, left; | 598 | (void) buffer; |
599 | (void) buffer_len; | ||
751 | 600 | ||
752 | DIR *d; | 601 | return (e->name); |
753 | struct dirent *de; | 602 | } |
754 | int fvi = 0; /* first visible item */ | ||
755 | int lvi = 0; /* last visible item */ | ||
756 | int si = 0; /* selected item */ | ||
757 | int li = 0; /* last item */ | ||
758 | int i; | ||
759 | 603 | ||
760 | int fh; | 604 | static bool browse( char *dst, int dst_size, const char *start ) |
761 | char *a; | 605 | { |
606 | struct gui_synclist browse_list; | ||
607 | int item_count, selected, button; | ||
608 | struct tree_context backup; | ||
609 | struct entry *dc; | ||
610 | bool reload = true; | ||
611 | int dirfilter = SHOW_ALL; | ||
612 | int *indexes = (int *) buffer.clipboard; | ||
762 | 613 | ||
763 | rb->lcd_getstringsize( "Ap", NULL, &fh ); | 614 | char *a; |
764 | 615 | ||
765 | rb->strcpy( bbuf, start ); | 616 | rb->strcpy( bbuf, start ); |
766 | a = bbuf+rb->strlen(bbuf)-1; | 617 | a = bbuf+rb->strlen(bbuf)-1; |
@@ -769,124 +620,106 @@ static bool browse( char *dst, int dst_size, const char *start ) | |||
769 | a[1] = '/'; | 620 | a[1] = '/'; |
770 | a[2] = '\0'; | 621 | a[2] = '\0'; |
771 | } | 622 | } |
623 | bbuf_s[0] = '\0'; | ||
624 | |||
625 | rb->gui_synclist_init( &browse_list, browse_get_name_cb, | ||
626 | (void*) indexes, false, 1, NULL ); | ||
772 | 627 | ||
628 | tree = rb->tree_get_context(); | ||
629 | backup = *tree; | ||
630 | dc = tree->dircache; | ||
631 | a = backup.currdir+rb->strlen(backup.currdir)-1; | ||
632 | if( *a != '/' ) | ||
633 | { | ||
634 | *++a = '/'; | ||
635 | *++a = '\0'; | ||
636 | } | ||
637 | rb->strcpy( a, dc[tree->selected_item].name ); | ||
638 | tree->dirfilter = &dirfilter; | ||
773 | while( 1 ) | 639 | while( 1 ) |
774 | { | 640 | { |
775 | d = rb->opendir( bbuf ); | 641 | if( reload ) |
776 | if( !d ) | ||
777 | { | 642 | { |
778 | /* | 643 | int i; |
779 | if( errno == ENOTDIR ) | 644 | rb->set_current_file(bbuf); |
780 | {*/ | 645 | item_count = 0; |
781 | /* this is a file */ | 646 | selected = 0; |
782 | bbuf[rb->strlen(bbuf)-1] = '\0'; | 647 | for( i = 0; i < tree->filesindir ; i++) |
783 | rb->strncpy( dst, bbuf, dst_size ); | ||
784 | return true; | ||
785 | /*} | ||
786 | else if( errno == EACCES || errno == ENOENT ) | ||
787 | { | 648 | { |
788 | bbuf[0] = '/'; bbuf[1] = '\0'; | 649 | /* only displayes directories and .bmp files */ |
789 | d = rb->opendir( "/" ); | 650 | if( ((dc[i].attr & ATTR_DIRECTORY ) && |
790 | } | 651 | rb->strcmp( dc[i].name, "." ) && |
791 | else | 652 | rb->strcmp( dc[i].name, ".." )) || |
792 | { | 653 | ( !(dc[i].attr & ATTR_DIRECTORY) && |
793 | return false; | 654 | (a = rb->strrchr( dc[i].name,'.' )) && |
794 | }*/ | 655 | !rb->strcmp( a, ".bmp" ) )) |
795 | } | 656 | { |
796 | top_inside = draw_window( HEIGHT, WIDTH, &top, &left, bbuf ); | 657 | if( !rb->strcmp( dc[i].name, bbuf_s ) ) |
797 | i = 0; | 658 | selected = item_count; |
798 | li = -1; | 659 | indexes[item_count++] = i; |
799 | while( i < fvi ) | 660 | } |
800 | { | ||
801 | rb->readdir( d ); | ||
802 | i++; | ||
803 | } | ||
804 | while( top_inside+(i-fvi)*(fh+LINE_SPACE) < HEIGHT ) | ||
805 | { | ||
806 | de = rb->readdir( d ); | ||
807 | if( !de ) | ||
808 | { | ||
809 | li = i-1; | ||
810 | break; | ||
811 | } | ||
812 | rb->lcd_set_foreground((si==i?COLOR_WHITE:COLOR_BLACK)); | ||
813 | rb->lcd_set_background((si==i?COLOR_BLUE:COLOR_LIGHTGRAY)); | ||
814 | rb->lcd_putsxy( left+10, | ||
815 | top_inside+(i-fvi)*(fh+LINE_SPACE), | ||
816 | de->d_name ); | ||
817 | if( si == i ) | ||
818 | rb->strcpy( bbuf_s, de->d_name ); | ||
819 | i++; | ||
820 | } | ||
821 | lvi = i-1; | ||
822 | if( li == -1 ) | ||
823 | { | ||
824 | if( !rb->readdir( d ) ) | ||
825 | { | ||
826 | li = lvi; | ||
827 | } | 661 | } |
828 | } | ||
829 | rb->closedir( d ); | ||
830 | |||
831 | rb->lcd_update(); | ||
832 | 662 | ||
833 | switch( rb->button_get(true) ) | 663 | rb->gui_synclist_set_nb_items(&browse_list,item_count); |
664 | rb->gui_synclist_select_item(&browse_list, selected); | ||
665 | rb->gui_synclist_set_title(&browse_list, bbuf, NOICON); | ||
666 | rb->gui_synclist_draw(&browse_list); | ||
667 | reload = false; | ||
668 | } | ||
669 | button = rb->get_action(CONTEXT_LIST,TIMEOUT_BLOCK); | ||
670 | if (rb->gui_synclist_do_button(&browse_list,&button,LIST_WRAP_UNLESS_HELD)) | ||
671 | continue; | ||
672 | switch( button ) | ||
834 | { | 673 | { |
835 | case ROCKPAINT_UP: | 674 | case ACTION_STD_CANCEL: |
836 | case ROCKPAINT_UP|BUTTON_REPEAT: | 675 | if( !rb->strcmp( bbuf, "/" ) ) |
837 | if( si > 0 ) | ||
838 | { | 676 | { |
839 | si--; | 677 | *tree = backup; |
840 | if( si<fvi ) | 678 | rb->set_current_file( backup.currdir ); |
841 | { | 679 | return false; |
842 | fvi--; | ||
843 | } | ||
844 | } | 680 | } |
845 | break; | 681 | rb->strcpy( bbuf_s, ".." ); |
846 | 682 | case ACTION_STD_OK: | |
847 | case ROCKPAINT_DOWN: | 683 | if( button == ACTION_STD_OK ) |
848 | case ROCKPAINT_DOWN|BUTTON_REPEAT: | ||
849 | if( li == -1 || si < li ) | ||
850 | { | 684 | { |
851 | si++; | 685 | selected = rb->gui_synclist_get_sel_pos( &browse_list ); |
852 | if( si>lvi ) | 686 | if( selected < 0 || selected >= item_count ) |
687 | break; | ||
688 | struct entry* e = &dc[indexes[selected]]; | ||
689 | rb->strncpy( bbuf_s, e->name, sizeof( bbuf_s ) ); | ||
690 | if( !( e->attr & ATTR_DIRECTORY ) ) | ||
853 | { | 691 | { |
854 | fvi++; | 692 | *tree = backup; |
693 | rb->set_current_file( backup.currdir ); | ||
694 | rb->snprintf( dst, dst_size, "%s%s", bbuf, bbuf_s ); | ||
695 | return true; | ||
855 | } | 696 | } |
856 | } | 697 | } |
857 | break; | 698 | if( !rb->strcmp( bbuf_s, "." ) ) break; |
858 | 699 | a = bbuf+rb->strlen(bbuf); | |
859 | case ROCKPAINT_LEFT: | 700 | if( !rb->strcmp( bbuf_s, ".." ) ) |
860 | if( bbuf[0] == '/' && !bbuf[1] ) return false; | ||
861 | bbuf_s[0] = '.'; | ||
862 | bbuf_s[1] = '.'; | ||
863 | bbuf_s[2] = '\0'; | ||
864 | case ROCKPAINT_RIGHT: | ||
865 | case ROCKPAINT_DRAW: | ||
866 | if( *bbuf_s == '.' && !bbuf_s[1] ) break; | ||
867 | a = bbuf; | ||
868 | while( *a ) a++; | ||
869 | if( *bbuf_s == '.' && bbuf_s[1] == '.' && !bbuf_s[2] ) | ||
870 | { | 701 | { |
871 | a--; | 702 | a--; |
872 | if( a == bbuf ) break; | 703 | if( a == bbuf ) break; |
873 | if( *a == '/' ) a--; | 704 | if( *a == '/' ) a--; |
874 | while( *a != '/' ) a--; | 705 | while( *a != '/' ) a--; |
875 | *++a = '\0'; | 706 | rb->strcpy( bbuf_s, ++a ); |
707 | /* select parent directory */ | ||
708 | bbuf_s[rb->strlen(bbuf_s)-1] = '\0'; | ||
709 | *a = '\0'; | ||
710 | reload = true; | ||
876 | break; | 711 | break; |
877 | } | 712 | } |
878 | rb->strcpy( a, bbuf_s ); | 713 | rb->snprintf( a, bbuf+sizeof(bbuf)-a, "%s/", bbuf_s ); |
879 | while( *a ) a++; | 714 | reload = true; |
880 | *a++ = '/'; | ||
881 | *a = '\0'; | ||
882 | fvi = si = 0; | ||
883 | break; | 715 | break; |
716 | |||
717 | case ACTION_STD_MENU: | ||
718 | *tree = backup; | ||
719 | rb->set_current_file( backup.currdir ); | ||
720 | return false; | ||
884 | } | 721 | } |
885 | } | 722 | } |
886 | |||
887 | #undef WIDTH | ||
888 | #undef HEIGHT | ||
889 | #undef LINE_SPACE | ||
890 | } | 723 | } |
891 | 724 | ||
892 | /*********************************************************************** | 725 | /*********************************************************************** |
@@ -898,7 +731,6 @@ static bool browse( char *dst, int dst_size, const char *start ) | |||
898 | ***********************************************************************/ | 731 | ***********************************************************************/ |
899 | static bool browse_fonts( char *dst, int dst_size ) | 732 | static bool browse_fonts( char *dst, int dst_size ) |
900 | { | 733 | { |
901 | char old_font[MAX_PATH]; | ||
902 | #define WIDTH ( LCD_WIDTH - 20 ) | 734 | #define WIDTH ( LCD_WIDTH - 20 ) |
903 | #define HEIGHT ( LCD_HEIGHT - 20 ) | 735 | #define HEIGHT ( LCD_HEIGHT - 20 ) |
904 | #define LINE_SPACE 2 | 736 | #define LINE_SPACE 2 |
@@ -923,7 +755,7 @@ static bool browse_fonts( char *dst, int dst_size ) | |||
923 | int fw; | 755 | int fw; |
924 | #define fontname_buf buffer.text.fontname_buf | 756 | #define fontname_buf buffer.text.fontname_buf |
925 | 757 | ||
926 | rb->snprintf( old_font, MAX_PATH, | 758 | rb->snprintf( buffer.text.old_font, MAX_PATH, |
927 | FONT_DIR "/%s.fnt", | 759 | FONT_DIR "/%s.fnt", |
928 | rb->global_settings->font_file ); | 760 | rb->global_settings->font_file ); |
929 | 761 | ||
@@ -1019,7 +851,7 @@ static bool browse_fonts( char *dst, int dst_size ) | |||
1019 | nvih = fh; | 851 | nvih = fh; |
1020 | } | 852 | } |
1021 | } | 853 | } |
1022 | rb->font_load( old_font ); | 854 | rb->font_load( buffer.text.old_font ); |
1023 | rb->closedir( d ); | 855 | rb->closedir( d ); |
1024 | } | 856 | } |
1025 | 857 | ||
@@ -1501,6 +1333,74 @@ static void draw_vflip( int x1, int y1, int x2, int y2 ) | |||
1501 | rb->lcd_update(); | 1333 | rb->lcd_update(); |
1502 | } | 1334 | } |
1503 | 1335 | ||
1336 | /* direction: -1 = left, 1 = right */ | ||
1337 | static void draw_rot_90_deg( int x1, int y1, int x2, int y2, int direction ) | ||
1338 | { | ||
1339 | int i, j; | ||
1340 | if( x1 > x2 ) | ||
1341 | { | ||
1342 | i = x1; | ||
1343 | x1 = x2; | ||
1344 | x2 = i; | ||
1345 | } | ||
1346 | if( y1 > y2 ) | ||
1347 | { | ||
1348 | i = y1; | ||
1349 | y1 = y2; | ||
1350 | y2 = i; | ||
1351 | } | ||
1352 | |||
1353 | copy_to_clipboard(); | ||
1354 | |||
1355 | fb_data color = rp_colors[ bgdrawcolor ]; | ||
1356 | const int width = x2 - x1, height = y2 - y1; | ||
1357 | const int sub_half = width/2-height/2, add_half = (width+height)/2; | ||
1358 | if( width > height ) | ||
1359 | { | ||
1360 | for( i = 0; i <= height; i++ ) | ||
1361 | { | ||
1362 | for( j = 0; j < sub_half; j++ ) | ||
1363 | save_buffer[(y1+i)*COLS+x1+j] = color; | ||
1364 | for( j = add_half+1; j <= width; j++ ) | ||
1365 | save_buffer[(y1+i)*COLS+x1+j] = color; | ||
1366 | } | ||
1367 | } | ||
1368 | else if( width < height ) | ||
1369 | { | ||
1370 | for( j = 0; j <= width; j++ ) | ||
1371 | { | ||
1372 | for( i = 0; i < -sub_half; i++ ) | ||
1373 | save_buffer[(y1+i)*COLS+x1+j] = color; | ||
1374 | for( i = add_half+1; i <= height; i++ ) | ||
1375 | save_buffer[(y1+i)*COLS+x1+j] = color; | ||
1376 | } | ||
1377 | } | ||
1378 | int x3 = x1 + sub_half, y3 = y1 - sub_half; | ||
1379 | int is = x3<0?-x3:0, ie = COLS-x3-1, js = y3<0?-y3:0, je = ROWS-y3-1; | ||
1380 | if( ie > height ) ie = height; | ||
1381 | if( je > width ) je = width; | ||
1382 | for( i = is; i <= ie; i++ ) | ||
1383 | { | ||
1384 | for( j = js; j <= je; j++ ) | ||
1385 | { | ||
1386 | int x, y; | ||
1387 | if(direction > 0) | ||
1388 | { | ||
1389 | x = x1+j; | ||
1390 | y = y1+height-i; | ||
1391 | } | ||
1392 | else | ||
1393 | { | ||
1394 | x = x1+width-j; | ||
1395 | y = y1+i; | ||
1396 | } | ||
1397 | save_buffer[(y3+j)*COLS+x3+i] = buffer.clipboard[y*COLS+x]; | ||
1398 | } | ||
1399 | } | ||
1400 | restore_screen(); | ||
1401 | rb->lcd_update(); | ||
1402 | } | ||
1403 | |||
1504 | static void draw_paste_rectangle( int src_x1, int src_y1, int src_x2, | 1404 | static void draw_paste_rectangle( int src_x1, int src_y1, int src_x2, |
1505 | int src_y2, int x1, int y1, int mode ) | 1405 | int src_y2, int x1, int y1, int mode ) |
1506 | { | 1406 | { |
@@ -1558,18 +1458,18 @@ static void show_grid( bool update ) | |||
1558 | 1458 | ||
1559 | static void draw_text( int x, int y ) | 1459 | static void draw_text( int x, int y ) |
1560 | { | 1460 | { |
1461 | int selected = 0; | ||
1561 | buffer.text.text[0] = '\0'; | 1462 | buffer.text.text[0] = '\0'; |
1562 | rb->snprintf( buffer.text.old_font, MAX_PATH, | 1463 | rb->snprintf( buffer.text.old_font, MAX_PATH, |
1563 | FONT_DIR "/%s.fnt", | 1464 | FONT_DIR "/%s.fnt", |
1564 | rb->global_settings->font_file ); | 1465 | rb->global_settings->font_file ); |
1565 | while( 1 ) | 1466 | while( 1 ) |
1566 | { | 1467 | { |
1567 | int m = TEXT_MENU_TEXT; | 1468 | switch( rb->do_menu( &text_menu, &selected, NULL, NULL ) ) |
1568 | switch( m = menu_display( text_menu, m ) ) | ||
1569 | { | 1469 | { |
1570 | case TEXT_MENU_TEXT: | 1470 | case TEXT_MENU_TEXT: |
1471 | rb->lcd_set_foreground(COLOR_BLACK); | ||
1571 | rb->kbd_input( buffer.text.text, MAX_TEXT ); | 1472 | rb->kbd_input( buffer.text.text, MAX_TEXT ); |
1572 | restore_screen(); | ||
1573 | break; | 1473 | break; |
1574 | 1474 | ||
1575 | case TEXT_MENU_FONT: | 1475 | case TEXT_MENU_FONT: |
@@ -1583,7 +1483,7 @@ static void draw_text( int x, int y ) | |||
1583 | rb->lcd_set_foreground( rp_colors[ drawcolor ] ); | 1483 | rb->lcd_set_foreground( rp_colors[ drawcolor ] ); |
1584 | while( 1 ) | 1484 | while( 1 ) |
1585 | { | 1485 | { |
1586 | unsigned int button; | 1486 | int button; |
1587 | restore_screen(); | 1487 | restore_screen(); |
1588 | rb->lcd_putsxy( x, y, buffer.text.text ); | 1488 | rb->lcd_putsxy( x, y, buffer.text.text ); |
1589 | rb->lcd_update(); | 1489 | rb->lcd_update(); |
@@ -1614,10 +1514,14 @@ static void draw_text( int x, int y ) | |||
1614 | break; | 1514 | break; |
1615 | 1515 | ||
1616 | case ROCKPAINT_DRAW: | 1516 | case ROCKPAINT_DRAW: |
1617 | button = 1242; | 1517 | break; |
1518 | default: | ||
1519 | if(rb->default_event_handler(button) | ||
1520 | == SYS_USB_CONNECTED) | ||
1521 | button = ROCKPAINT_DRAW; | ||
1618 | break; | 1522 | break; |
1619 | } | 1523 | } |
1620 | if( button == 1242 ) break; | 1524 | if( button == ROCKPAINT_DRAW ) break; |
1621 | } | 1525 | } |
1622 | break; | 1526 | break; |
1623 | 1527 | ||
@@ -1626,6 +1530,7 @@ static void draw_text( int x, int y ) | |||
1626 | buffer_putsxyofs( save_buffer, COLS, ROWS, x, y, 0, | 1530 | buffer_putsxyofs( save_buffer, COLS, ROWS, x, y, 0, |
1627 | buffer.text.text ); | 1531 | buffer.text.text ); |
1628 | case TEXT_MENU_CANCEL: | 1532 | case TEXT_MENU_CANCEL: |
1533 | default: | ||
1629 | restore_screen(); | 1534 | restore_screen(); |
1630 | rb->font_load( buffer.text.old_font ); | 1535 | rb->font_load( buffer.text.old_font ); |
1631 | return; | 1536 | return; |
@@ -2541,10 +2446,11 @@ static void clear_drawing(void) | |||
2541 | static void goto_menu(void) | 2446 | static void goto_menu(void) |
2542 | { | 2447 | { |
2543 | int multi; | 2448 | int multi; |
2449 | int selected = 0; | ||
2544 | 2450 | ||
2545 | while( 1 ) | 2451 | while( 1 ) |
2546 | { | 2452 | { |
2547 | switch( menu_display( main_menu, 1 ) ) | 2453 | switch( rb->do_menu( &main_menu, &selected, NULL, false ) ) |
2548 | { | 2454 | { |
2549 | case MAIN_MENU_NEW: | 2455 | case MAIN_MENU_NEW: |
2550 | clear_drawing(); | 2456 | clear_drawing(); |
@@ -2569,6 +2475,7 @@ static void goto_menu(void) | |||
2569 | break; | 2475 | break; |
2570 | 2476 | ||
2571 | case MAIN_MENU_SAVE: | 2477 | case MAIN_MENU_SAVE: |
2478 | rb->lcd_set_foreground(COLOR_BLACK); | ||
2572 | if (!filename[0]) | 2479 | if (!filename[0]) |
2573 | rb->strcpy(filename,"/"); | 2480 | rb->strcpy(filename,"/"); |
2574 | if( !rb->kbd_input( filename, MAX_PATH ) ) | 2481 | if( !rb->kbd_input( filename, MAX_PATH ) ) |
@@ -2582,15 +2489,19 @@ static void goto_menu(void) | |||
2582 | break; | 2489 | break; |
2583 | 2490 | ||
2584 | case MAIN_MENU_BRUSH_SIZE: | 2491 | case MAIN_MENU_BRUSH_SIZE: |
2585 | multi = menu_display( size_menu, bsize ); | 2492 | for(multi = 0; multi<4; multi++) |
2586 | if( multi != - 1 ) | 2493 | if(bsize == times_list[multi]) break; |
2587 | bsize = multi; | 2494 | rb->do_menu( &size_menu, &multi, NULL, false ); |
2495 | if( multi >= 0 ) | ||
2496 | bsize = times_list[multi]; | ||
2588 | break; | 2497 | break; |
2589 | 2498 | ||
2590 | case MAIN_MENU_BRUSH_SPEED: | 2499 | case MAIN_MENU_BRUSH_SPEED: |
2591 | multi = menu_display( speed_menu, bspeed ); | 2500 | for(multi = 0; multi<3; multi++) |
2592 | if( multi != -1 ) | 2501 | if(bspeed == times_list[multi]) break; |
2593 | bspeed = multi; | 2502 | rb->do_menu( &speed_menu, &multi, NULL, false ); |
2503 | if( multi >= 0 ) | ||
2504 | bspeed = times_list[multi]; | ||
2594 | break; | 2505 | break; |
2595 | 2506 | ||
2596 | case MAIN_MENU_COLOR: | 2507 | case MAIN_MENU_COLOR: |
@@ -2598,17 +2509,21 @@ static void goto_menu(void) | |||
2598 | break; | 2509 | break; |
2599 | 2510 | ||
2600 | case MAIN_MENU_GRID_SIZE: | 2511 | case MAIN_MENU_GRID_SIZE: |
2601 | multi = menu_display( gridsize_menu, gridsize ); | 2512 | for(multi = 0; multi<4; multi++) |
2602 | if( multi != - 1 ) | 2513 | if(gridsize == gridsize_list[multi]) break; |
2603 | gridsize = multi; | 2514 | rb->do_menu( &gridsize_menu, &multi, NULL, false ); |
2515 | if( multi >= 0 ) | ||
2516 | gridsize = gridsize_list[multi]; | ||
2604 | break; | 2517 | break; |
2605 | 2518 | ||
2606 | case MAIN_MENU_EXIT: | 2519 | case MAIN_MENU_EXIT: |
2520 | restore_screen(); | ||
2607 | quit=true; | 2521 | quit=true; |
2608 | return; | 2522 | return; |
2609 | 2523 | ||
2610 | case MAIN_MENU_RESUME: | 2524 | case MAIN_MENU_RESUME: |
2611 | case MENU_ESC: | 2525 | default: |
2526 | restore_screen(); | ||
2612 | return; | 2527 | return; |
2613 | }/* end switch */ | 2528 | }/* end switch */ |
2614 | }/* end while */ | 2529 | }/* end while */ |
@@ -2660,6 +2575,7 @@ static bool rockpaint_loop( void ) | |||
2660 | case ROCKPAINT_MENU: | 2575 | case ROCKPAINT_MENU: |
2661 | inv_cursor(false); | 2576 | inv_cursor(false); |
2662 | goto_menu(); | 2577 | goto_menu(); |
2578 | restore_screen(); | ||
2663 | inv_cursor(true); | 2579 | inv_cursor(true); |
2664 | break; | 2580 | break; |
2665 | 2581 | ||
@@ -2697,8 +2613,8 @@ static bool rockpaint_loop( void ) | |||
2697 | else if( tool == SelectRectangle | 2613 | else if( tool == SelectRectangle |
2698 | && ( prev_x2 == -1 || prev_y2 == -1 ) ) | 2614 | && ( prev_x2 == -1 || prev_y2 == -1 ) ) |
2699 | { | 2615 | { |
2700 | tool_mode = menu_display( select_menu, | 2616 | tool_mode = rb->do_menu( &select_menu, |
2701 | SELECT_MENU_CUT ); | 2617 | NULL, NULL, false ); |
2702 | switch( tool_mode ) | 2618 | switch( tool_mode ) |
2703 | { | 2619 | { |
2704 | case SELECT_MENU_CUT: | 2620 | case SELECT_MENU_CUT: |
@@ -2726,22 +2642,29 @@ static bool rockpaint_loop( void ) | |||
2726 | break; | 2642 | break; |
2727 | 2643 | ||
2728 | case SELECT_MENU_ROTATE90: | 2644 | case SELECT_MENU_ROTATE90: |
2645 | draw_rot_90_deg( prev_x, prev_y, x, y, 1 ); | ||
2646 | reset_tool(); | ||
2729 | break; | 2647 | break; |
2648 | |||
2730 | case SELECT_MENU_ROTATE180: | 2649 | case SELECT_MENU_ROTATE180: |
2731 | draw_hflip( prev_x, prev_y, x, y ); | 2650 | draw_hflip( prev_x, prev_y, x, y ); |
2732 | draw_vflip( prev_x, prev_y, x, y ); | 2651 | draw_vflip( prev_x, prev_y, x, y ); |
2733 | reset_tool(); | 2652 | reset_tool(); |
2734 | break; | 2653 | break; |
2654 | |||
2735 | case SELECT_MENU_ROTATE270: | 2655 | case SELECT_MENU_ROTATE270: |
2656 | draw_rot_90_deg( prev_x, prev_y, x, y, -1 ); | ||
2657 | reset_tool(); | ||
2736 | break; | 2658 | break; |
2737 | 2659 | ||
2738 | case SELECT_MENU_CANCEL: | 2660 | case SELECT_MENU_CANCEL: |
2739 | reset_tool(); | 2661 | reset_tool(); |
2740 | break; | 2662 | break; |
2741 | 2663 | ||
2742 | case MENU_ESC: | 2664 | default: |
2743 | break; | 2665 | break; |
2744 | } | 2666 | } |
2667 | restore_screen(); | ||
2745 | } | 2668 | } |
2746 | else if( tool == Curve | 2669 | else if( tool == Curve |
2747 | && ( prev_x3 == -1 || prev_y3 == -1 ) ) | 2670 | && ( prev_x3 == -1 || prev_y3 == -1 ) ) |