Changeset 113


Ignore:
Timestamp:
04/14/07 20:03:52 (6 years ago)
Author:
GrAnd
Message:
Location:
branches/grand
Files:
38 added
8 edited

Legend:

Unmodified
Added
Removed
  • branches/grand/core/conf.c

    r110 r113  
    102102    CONF_INFO( 43, conf.reader_autoscroll,      CONF_DEF_VALUE, i:0, NULL), 
    103103    CONF_INFO( 44, conf.reader_autoscroll_delay, CONF_DEF_VALUE, i:5, NULL), 
     104    CONF_INFO( 45, conf.reader_rbf_file,        CONF_DEF_PTR,   ptr:"", NULL), 
    104105}; 
    105106#define CONF_NUM (sizeof(conf_info)/sizeof(conf_info[0])) 
  • branches/grand/core/gui.c

    r110 r113  
    4646static void gui_draw_read(int arg); 
    4747static void gui_draw_read_last(int arg); 
     48static void gui_draw_load_rbf(int arg); 
    4849static void gui_draw_calendar(int arg); 
    4950static void gui_menuproc_mkbootdisk(int arg); 
     
    99100    {"Enable autoscroll",           MENUITEM_BOOL,    &conf.reader_autoscroll }, 
    100101    {"Autoscroll delay (sec)",      MENUITEM_INT|MENUITEM_F_UNSIGNED|MENUITEM_F_MINMAX, &conf.reader_autoscroll_delay, MENU_MINMAX(0, 60) }, 
     102    {"Select RBF font",             MENUITEM_PROC,    (int*)gui_draw_load_rbf }, 
    101103    {"<- Back",                     MENUITEM_UP }, 
    102104    {0} 
     
    835837 
    836838    // if exists "A/SCRIPTS" go into 
    837     d=opendir("A/SCRIPTS"); 
     839    d=opendir(path); 
    838840    if (d) { 
    839841        closedir(d); 
     
    854856static void gui_draw_read_selected(const char *fn) { 
    855857    if (fn) { 
     858        if (!rbf_load(conf.reader_rbf_file)) 
     859            rbf_load_from_8x16(current_font); 
    856860        gui_mode = GUI_MODE_READ; 
    857861        gui_read_init(fn); 
     
    887891 
    888892//------------------------------------------------------------------- 
     893static void gui_draw_rbf_selected(const char *fn) { 
     894    if (fn) { 
     895        strcpy(conf.reader_rbf_file, fn); 
     896    } 
     897} 
     898void gui_draw_load_rbf(int arg) { 
     899    DIR   *d; 
     900    char  *path="A/FONTS"; 
     901 
     902    // if exists "A/FONTS" go into 
     903    d=opendir(path); 
     904    if (d) { 
     905        closedir(d); 
     906    } else { 
     907        path="A"; 
     908    } 
     909 
     910    gui_fselect_init(path, gui_draw_rbf_selected); 
     911} 
     912 
     913//------------------------------------------------------------------- 
  • branches/grand/core/gui_draw.h

    r66 r113  
    2929void draw_init(); 
    3030 
    31 extern void draw_pixel(coord x, coord y, color cl); 
    3231extern color draw_get_pixel(coord x, coord y); 
    3332 
  • branches/grand/core/gui_read.c

    r110 r113  
    55#include "conf.h" 
    66#include "gui.h" 
     7#include "font.h" 
    78#include "gui_draw.h" 
    89#include "gui_read.h" 
     
    1415static int read_on_screen; 
    1516static int read_to_draw; 
    16 static coord x, y, h, w, s; 
    17 #define READ_BUFFER_SIZE        (45*15) 
    18 static char buffer[READ_BUFFER_SIZE+45]; 
     17static coord x, y, h, w; 
     18#define READ_BUFFER_SIZE  100 
     19static char buffer[READ_BUFFER_SIZE+1]; 
    1920static long last_time; 
     21static int xx, yy; 
    2022 
    2123//------------------------------------------------------------------- 
     
    3335    } 
    3436    read_to_draw = 1; 
    35     x=0;  
    36     y=1; 
    37     w=(screen_width-(x+1)*FONT_WIDTH)/FONT_WIDTH; 
    38     h=(screen_height-y*FONT_HEIGHT)/FONT_HEIGHT; 
    39     s=w*h; 
     37    x=6;  
     38    y=FONT_HEIGHT; 
     39    w=screen_width-6-6-8; 
     40    h=screen_height-y; 
    4041    last_time = get_tick_count(); 
    4142     
     43    draw_filled_rect(0, y, screen_width-1, screen_height-1, MAKE_COLOR((conf.reader_color>>8)&0xFF, (conf.reader_color>>8)&0xFF)); 
     44 
    4245    return (read_file >= 0); 
    4346} 
    4447 
     48//------------------------------------------------------------------- 
     49static void read_goto_next_line() { 
     50    draw_filled_rect(xx, yy, x+w-1, yy+rbf_font_height()-1, MAKE_COLOR(conf.reader_color>>8, conf.reader_color>>8)); 
     51    xx  = x; 
     52    yy += rbf_font_height(); 
     53} 
     54 
     55//------------------------------------------------------------------- 
     56static int read_fit_next_char(int ch) { 
     57    return (xx+rbf_char_width(ch) < x+w); 
     58} 
    4559//------------------------------------------------------------------- 
    4660void gui_read_draw() { 
     
    5064    } 
    5165    if (read_to_draw) { 
    52         int i, j; 
     66        int n, i; 
    5367         
    54         if (read_to_draw) { 
    55             lseek(read_file, conf.reader_pos, SEEK_SET); 
    56             i=read(read_file, buffer, s); 
    57             buffer[i]=0; 
     68        xx=x; yy=y; 
    5869 
    59             j=0; i=1; 
    60             for (read_on_screen=0; read_on_screen<s && j<h; ++read_on_screen) { 
    61                 if (buffer[read_on_screen]) { 
    62                     switch (buffer[read_on_screen]) { 
    63                         case '\r': 
    64                             break; 
    65                         case '\n': 
    66                             for (; i<w-1; ++i) { 
    67                                 draw_txt_char(x+i, y+j, ' ', conf.reader_color); //fill the rest 
    68                             } 
    69                             break; 
    70                         case '\t': 
    71                             draw_txt_string(x+i, y+j, "    ", conf.reader_color); //text 
    72                             i+=4; 
    73                             break; 
    74                         default: 
    75                             draw_txt_char(x+i, y+j, buffer[read_on_screen], conf.reader_color); //text 
    76                             ++i; 
    77                             break; 
     70        lseek(read_file, conf.reader_pos, SEEK_SET); 
     71        read_on_screen=0; 
    7872 
    79                     } 
    80                     if (i>=w-1) { 
    81                         ++j; 
    82                         i=1; 
    83                     } 
    84                 } else { 
    85                     for (; j<h; ++j) { 
    86                         for (; i<w-1; ++i) { 
    87                             draw_txt_char(x+i, y+j, ' ', conf.reader_color); //fill the rest 
     73        while (yy<=y+h-rbf_font_height()) { 
     74            n=read(read_file, buffer, READ_BUFFER_SIZE); 
     75            if (n==0) { 
     76                 read_goto_next_line(); 
     77                 if (yy < y+h) 
     78                     draw_filled_rect(x, yy, x+w-1, y+h-1, MAKE_COLOR(conf.reader_color>>8, conf.reader_color>>8)); 
     79                 break; 
     80            } 
     81            i=0; 
     82            while (i<n && yy<=y+h-rbf_font_height()) { 
     83                switch (buffer[i]) { 
     84                    case '\r': 
     85                        break; 
     86                    case '\n': 
     87                        read_goto_next_line(); 
     88                        break; 
     89                    case '\t': 
     90                        buffer[i] = ' '; 
     91                        continue; 
     92                    default: 
     93                        if (!read_fit_next_char(buffer[i])) { 
     94                            read_goto_next_line(); 
     95                            continue; 
    8896                        } 
    89                         i=1; 
    90                     } 
     97                        xx+=rbf_draw_char(xx, yy, buffer[i], conf.reader_color); 
     98                        break; 
     99                } 
     100                ++i; 
     101                if (xx >= x+w) { 
     102                    xx  = x; 
     103                    yy += rbf_font_height(); 
    91104                } 
    92105            } 
    93          
    94             sprintf(buffer, "(%3d%%) %d/%d%45s", (read_file_size)?(conf.reader_pos*100/read_file_size):0, conf.reader_pos, read_file_size, ""); 
    95             buffer[screen_width/FONT_WIDTH]=0; 
    96             draw_txt_string(0, 0, buffer, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE)); //title infoline 
     106            read_on_screen+=i; 
     107        } 
     108     
     109        sprintf(buffer, "(%3d%%) %d/%d%45s", (read_file_size)?(conf.reader_pos*100/read_file_size):0, conf.reader_pos, read_file_size, ""); 
     110        buffer[screen_width/FONT_WIDTH]=0; 
     111        draw_txt_string(0, 0, buffer, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE)); //title infoline 
    97112 
    98             draw_filled_rect(0, y*FONT_HEIGHT,  
    99                              FONT_WIDTH-1, (y+h)*FONT_HEIGHT, MAKE_COLOR((conf.reader_color>>8)&0xFF, (conf.reader_color>>8)&0xFF)); 
    100             // scrollbar 
    101             draw_filled_rect((x+w-1)*FONT_WIDTH, y*FONT_HEIGHT,  
    102                              (x+w)*FONT_WIDTH+8, (y+h)*FONT_HEIGHT, MAKE_COLOR((conf.reader_color>>8)&0xFF, (conf.reader_color>>8)&0xFF)); 
    103             if (read_file_size) { 
    104                 i=h*FONT_HEIGHT-1 -1;           // full height 
    105                 j=i*s/read_file_size;           // bar height 
    106                 if (j<20) j=20; 
    107                 i=(i-j)*conf.reader_pos/read_file_size;   // top pos 
    108                 draw_filled_rect((x+w)*FONT_WIDTH+2, y*FONT_HEIGHT+1,  
    109                                  (x+w)*FONT_WIDTH+6, y*FONT_HEIGHT+1+i, MAKE_COLOR(COLOR_BLACK, COLOR_BLACK)); 
    110                 draw_filled_rect((x+w)*FONT_WIDTH+2, y*FONT_HEIGHT+i+j,  
    111                                  (x+w)*FONT_WIDTH+6, (y+h)*FONT_HEIGHT-1-1, MAKE_COLOR(COLOR_BLACK, COLOR_BLACK)); 
    112                 draw_filled_rect((x+w)*FONT_WIDTH+2, y*FONT_HEIGHT+1+i,  
    113                                  (x+w)*FONT_WIDTH+6, y*FONT_HEIGHT+i+j, MAKE_COLOR(COLOR_WHITE, COLOR_WHITE)); 
    114             } else { 
    115                 draw_filled_rect((x+w)*FONT_WIDTH+2, y*FONT_HEIGHT+1,  
    116                                  (x+w)*FONT_WIDTH+6, (y+h)*FONT_HEIGHT-1-1, MAKE_COLOR(COLOR_BLACK, COLOR_BLACK)); 
    117             } 
     113        // scrollbar 
     114        if (read_file_size) { 
     115            i=h-1 -1;           // full height 
     116            n=i*read_on_screen/read_file_size;           // bar height 
     117            if (n<20) n=20; 
     118            i=(i-n)*conf.reader_pos/read_file_size;   // top pos 
     119            draw_filled_rect(x+w+6+2, y+1,   x+w+6+6, y+1+i,   MAKE_COLOR(COLOR_BLACK, COLOR_BLACK)); 
     120            draw_filled_rect(x+w+6+2, y+i+n, x+w+6+6, y+h-1-1, MAKE_COLOR(COLOR_BLACK, COLOR_BLACK)); 
     121            draw_filled_rect(x+w+6+2, y+1+i, x+w+6+6, y+i+n,   MAKE_COLOR(COLOR_WHITE, COLOR_WHITE)); 
     122        } else { 
     123            draw_filled_rect((x+w)*FONT_WIDTH+2, y*FONT_HEIGHT+1,  
     124                             (x+w)*FONT_WIDTH+6, (y+h)*FONT_HEIGHT-1-1, MAKE_COLOR(COLOR_BLACK, COLOR_BLACK)); 
     125        } 
    118126 
    119             read_to_draw = 0; 
    120             last_time = get_tick_count(); 
    121         } 
     127        read_to_draw = 0; 
     128        last_time = get_tick_count(); 
    122129    } 
    123130} 
     
    129136        case KEY_UP: 
    130137            if (conf.reader_pos>0) { 
    131                 conf.reader_pos -= s-w; 
     138                conf.reader_pos -= 45*15; 
    132139                if (conf.reader_pos<0) conf.reader_pos=0; 
    133140                read_to_draw = 1; 
  • branches/grand/include/conf.h

    r110 r113  
    5959    int reader_autoscroll; 
    6060    int reader_autoscroll_delay; 
     61    char reader_rbf_file[100]; 
    6162 
    6263    int sokoban_level; 
  • branches/grand/include/font.h

    r91 r113  
    11#ifndef FONT_H 
    22#define FONT_H 
     3 
     4#include "gui.h" 
     5 
    36//------------------------------------------------------------------- 
    4  
    57#define FONT_DEFAULT    0 
    68#define FONT_UNIRUS     1 
     
    1416extern void font_set(int font); 
    1517 
     18extern int rbf_load(char *file); 
     19extern void rbf_load_from_8x16(const char *font); 
     20extern int rbf_font_height(); 
     21extern int rbf_char_width(int ch); 
     22extern int rbf_draw_char(int x, int y, int ch, color cl); 
     23 
    1624//------------------------------------------------------------------- 
    1725#endif 
  • branches/grand/include/gui.h

    r108 r113  
    2323extern void gui_force_restore(); 
    2424 
     25extern void draw_pixel(coord x, coord y, color cl); 
     26 
    2527extern enum Gui_Mode gui_get_mode(); 
    2628extern void gui_set_mode(enum Gui_Mode mode); 
  • branches/grand/lib/font/Makefile

    r91 r113  
    33include $(topdir)makefile.inc 
    44 
    5 OBJS = font_8x16.o 
     5OBJS = font_8x16.o rbf_font.o 
    66 
    77all: libfont.a 
Note: See TracChangeset for help on using the changeset viewer.