summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/rockpaint.c171
1 files changed, 111 insertions, 60 deletions
diff --git a/apps/plugins/rockpaint.c b/apps/plugins/rockpaint.c
index 3ce37a813d..da0d1c83c3 100644
--- a/apps/plugins/rockpaint.c
+++ b/apps/plugins/rockpaint.c
@@ -276,6 +276,9 @@ static union
276 char text[MAX_TEXT+1]; 276 char text[MAX_TEXT+1];
277 char font[MAX_PATH+1]; 277 char font[MAX_PATH+1];
278 char old_font[MAX_PATH+1]; 278 char old_font[MAX_PATH+1];
279 int fh_buf[30];
280 int fw_buf[30];
281 char fontname_buf[30][MAX_PATH];
279 } text; 282 } text;
280} buffer; 283} buffer;
281 284
@@ -780,93 +783,133 @@ static bool browse_fonts( char *dst, int dst_size )
780 int fvi = 0; /* first visible item */ 783 int fvi = 0; /* first visible item */
781 int lvi = 0; /* last visible item */ 784 int lvi = 0; /* last visible item */
782 int si = 0; /* selected item */ 785 int si = 0; /* selected item */
786 int osi = 0; /* old selected item */
783 int li = 0; /* last item */ 787 int li = 0; /* last item */
784 int nvih = 0; /* next visible item height */ 788 int nvih = 0; /* next visible item height */
785 int i; 789 int i;
790 int b_need_redraw = 1; /* Do we need to redraw ? */
786 791
787 int cp = 0; /* current position */ 792 int cp = 0; /* current position */
788 int fh; /* font height */ 793 int fh; /* font height */
789 794
795 #define fh_buf buffer.text.fh_buf /* 30 might not be enough ... */
796 #define fw_buf buffer.text.fw_buf
797 int fw;
798 #define fontname_buf buffer.text.fontname_buf
799
790 rb->snprintf( old_font, MAX_PATH, 800 rb->snprintf( old_font, MAX_PATH,
791 ROCKBOX_DIR FONT_DIR "/%s.fnt", 801 ROCKBOX_DIR FONT_DIR "/%s.fnt",
792 rb->global_settings->font_file ); 802 rb->global_settings->font_file );
793 803
794 while( 1 ) 804 while( 1 )
795 { 805 {
796 d = rb->PREFIX(opendir)( ROCKBOX_DIR FONT_DIR "/" ); 806 if( !b_need_redraw )
797 if( !d )
798 {
799 return false;
800 }
801 top_inside = draw_window( HEIGHT, WIDTH, &top, &left, "Fonts" );
802 i = 0;
803 li = -1;
804 while( i < fvi )
805 { 807 {
806 rb->PREFIX(readdir)( d ); 808 /* we don't need to redraw ... but we need to unselect
807 i++; 809 * the previously selected item */
810 cp = top_inside + LINE_SPACE;
811 for( i = 0; i+fvi < osi; i++ )
812 {
813 cp += fh_buf[i] + LINE_SPACE;
814 }
815 rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
816 rb->lcd_fillrect( left+10, cp, fw_buf[i], fh_buf[i] );
817 rb->lcd_set_drawmode(DRMODE_SOLID);
808 } 818 }
809 cp = top_inside+LINE_SPACE; 819
810 while( cp < top+HEIGHT ) 820 if( b_need_redraw )
811 { 821 {
812 de = rb->PREFIX(readdir)( d ); 822 b_need_redraw = 0;
813 if( !de ) 823
824 d = rb->PREFIX(opendir)( ROCKBOX_DIR FONT_DIR "/" );
825 if( !d )
814 { 826 {
815 li = i-1; 827 return false;
816 break;
817 } 828 }
818 if( rb->strlen( de->d_name ) < 4 829 top_inside = draw_window( HEIGHT, WIDTH, &top, &left, "Fonts" );
819 || rb->strcmp( de->d_name + rb->strlen( de->d_name ) - 4, 830 i = 0;
820 ".fnt" ) ) 831 li = -1;
821 continue; 832 while( i < fvi )
822 rb->snprintf( bbuf, MAX_PATH, ROCKBOX_DIR FONT_DIR "/%s",
823 de->d_name );
824 rb->font_load( bbuf );
825 rb->font_getstringsize( de->d_name, NULL, &fh, FONT_UI );
826 if( nvih > 0 )
827 { 833 {
828 nvih -= fh; 834 rb->PREFIX(readdir)( d );
829 fvi++;
830 if( nvih < 0 ) nvih = 0;
831 i++; 835 i++;
832 continue;
833 }
834 if( cp + fh >= top+HEIGHT )
835 {
836 nvih = fh;
837 break;
838 } 836 }
839 rb->lcd_set_foreground((si==i?COLOR_WHITE:COLOR_BLACK)); 837 cp = top_inside+LINE_SPACE;
840 rb->lcd_set_background((si==i?COLOR_BLUE:COLOR_LIGHTGRAY)); 838
841 rb->lcd_putsxy( left+10, cp, de->d_name ); 839 rb->lcd_set_foreground(COLOR_BLACK);
842 cp += fh + LINE_SPACE; 840 rb->lcd_set_background(COLOR_LIGHTGRAY);
843 if( si == i ) 841
844 rb->strcpy( bbuf_s, bbuf ); 842 while( cp < top+HEIGHT )
845 i++;
846 }
847 lvi = i-1;
848 if( li == -1 )
849 {
850 if( !(de = rb->PREFIX(readdir)( d ) ) )
851 {
852 li = lvi;
853 }
854 else if( !nvih && !rb->strlen( de->d_name ) < 4
855 && !rb->strcmp( de->d_name + rb->strlen( de->d_name ) - 4,
856 ".fnt" ) )
857 { 843 {
844 de = rb->PREFIX(readdir)( d );
845 if( !de )
846 {
847 li = i-1;
848 break;
849 }
850 if( rb->strlen( de->d_name ) < 4
851 || rb->strcmp( de->d_name + rb->strlen( de->d_name ) - 4,
852 ".fnt" ) )
853 continue;
858 rb->snprintf( bbuf, MAX_PATH, ROCKBOX_DIR FONT_DIR "/%s", 854 rb->snprintf( bbuf, MAX_PATH, ROCKBOX_DIR FONT_DIR "/%s",
859 de->d_name ); 855 de->d_name );
860 rb->font_load( bbuf ); 856 rb->font_load( bbuf );
861 rb->font_getstringsize( de->d_name, NULL, &fh, FONT_UI ); 857 rb->font_getstringsize( de->d_name, &fw, &fh, FONT_UI );
862 nvih = fh; 858 if( nvih > 0 )
859 {
860 nvih -= fh;
861 fvi++;
862 if( nvih < 0 ) nvih = 0;
863 i++;
864 continue;
865 }
866 if( cp + fh >= top+HEIGHT )
867 {
868 nvih = fh;
869 break;
870 }
871 rb->lcd_putsxy( left+10, cp, de->d_name );
872 fh_buf[i-fvi] = fh;
873 fw_buf[i-fvi] = fw;
874 cp += fh + LINE_SPACE;
875 rb->strcpy( fontname_buf[i-fvi], bbuf );
876 i++;
877 }
878 lvi = i-1;
879 if( li == -1 )
880 {
881 if( !(de = rb->PREFIX(readdir)( d ) ) )
882 {
883 li = lvi;
884 }
885 else if( !nvih && !rb->strlen( de->d_name ) < 4
886 && !rb->strcmp( de->d_name + rb->strlen( de->d_name ) - 4,
887 ".fnt" ) )
888 {
889 rb->snprintf( bbuf, MAX_PATH, ROCKBOX_DIR FONT_DIR "/%s",
890 de->d_name );
891 rb->font_load( bbuf );
892 rb->font_getstringsize( de->d_name, NULL, &fh, FONT_UI );
893 nvih = fh;
894 }
863 } 895 }
896 rb->font_load( old_font );
897 rb->PREFIX(closedir)( d );
864 } 898 }
865 rb->font_load( old_font ); 899
866 rb->PREFIX(closedir)( d ); 900 rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
901 cp = top_inside + LINE_SPACE;
902 for( i = 0; i+fvi < si; i++ )
903 {
904 cp += fh_buf[i] + LINE_SPACE;
905 }
906 rb->lcd_fillrect( left+10, cp, fw_buf[i], fh_buf[i] );
907 rb->lcd_set_drawmode(DRMODE_SOLID);
867 908
868 rb->lcd_update_rect( left, top, WIDTH, HEIGHT ); 909 rb->lcd_update_rect( left, top, WIDTH, HEIGHT );
869 910
911 osi = si;
912 i = fvi;
870 switch( rb->button_get(true) ) 913 switch( rb->button_get(true) )
871 { 914 {
872 case ROCKPAINT_UP: 915 case ROCKPAINT_UP:
@@ -894,14 +937,23 @@ static bool browse_fonts( char *dst, int dst_size )
894 937
895 case ROCKPAINT_RIGHT: 938 case ROCKPAINT_RIGHT:
896 case ROCKPAINT_DRAW: 939 case ROCKPAINT_DRAW:
897 rb->snprintf( dst, dst_size, "%s", bbuf_s ); 940 rb->snprintf( dst, dst_size, "%s", fontname_buf[si-fvi] );
898 return true; 941 return true;
899 } 942 }
943
944 if( i != fvi || si > lvi )
945 {
946 b_need_redraw = 1;
947 }
948
900 if( si<=lvi ) 949 if( si<=lvi )
901 { 950 {
902 nvih = 0; 951 nvih = 0;
903 } 952 }
904 } 953 }
954#undef fh_buf
955#undef fw_buf
956#undef fontname_buf
905#undef WIDTH 957#undef WIDTH
906#undef HEIGHT 958#undef HEIGHT
907#undef LINE_SPACE 959#undef LINE_SPACE
@@ -1327,7 +1379,6 @@ static void draw_text( int x, int y )
1327 rb->snprintf( buffer.text.old_font, MAX_PATH, 1379 rb->snprintf( buffer.text.old_font, MAX_PATH,
1328 ROCKBOX_DIR FONT_DIR "/%s.fnt", 1380 ROCKBOX_DIR FONT_DIR "/%s.fnt",
1329 rb->global_settings->font_file ); 1381 rb->global_settings->font_file );
1330 DEBUGF( "old font: %s\n", buffer.text.old_font );
1331 while( 1 ) 1382 while( 1 )
1332 { 1383 {
1333 int m = TEXT_MENU_TEXT; 1384 int m = TEXT_MENU_TEXT;