⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zgv.c

📁 zgv-5.6,一个Linux系统下的图片浏览器(VGA/SVGA)
💻 C
📖 第 1 页 / 共 5 页
字号:
           *   seeing if button is currently not pressed, not quite the           *   same thing)           */          /* now then, check buttons depending on horizontal position. */          if(mx<SCRLBAR_MAIN_XPOS || mx>=SCRLBAR_RIGHTARROW_XPOS)            {            /* an arrow */            if(mleft)              {              if(mx<SCRLBAR_MAIN_XPOS)                curent=startfrom,curent-=YSIZ;              else                curent=startfrom+XSIZ*YSIZ-1,curent+=YSIZ;              }            if(curent<1) curent=1;            if(curent>gifdirsiz) curent=gifdirsiz;            }          else            if(slid_xpos!=-1)	/* sanity check */              {              if(mx<SCRLBAR_MAIN_XPOS+slid_xpos ||                 mx>=SCRLBAR_MAIN_XPOS+slid_xpos+slid_width)                {                /* non-slider */                if(mleft)                  {                  if(mx<SCRLBAR_MAIN_XPOS+slid_xpos)                    curent=startfrom,curent-=XSIZ*YSIZ;                  else                    curent=startfrom+XSIZ*YSIZ-1,curent+=XSIZ*YSIZ;                  }                if(curent<1) curent=1;                if(curent>gifdirsiz) curent=gifdirsiz;                }              else                {                /* slider */                /* anyone who tries to visit parallel universes using this                 * does so at their own risk :-) */                if(mleft_start)                  slider_drag=1;                }              }          }        }	/* end of if(cfg.scrollbar) */            /* check for on-file-area-and-started-button-press */      if(mleft_start)        if(mx>=XSTARTPOS && mx<XSTARTPOS+XSIZ*BARWIDTH &&           my>=fwinypos(1) && my<fwinypos(1)+YSIZ*barheight)          {          /* ok, on the file area and pressed button.           * find the entry matching the mouse position.           */          int tmpcurent=startfrom+YSIZ*((mx-XSTARTPOS)/BARWIDTH)+          		(my-fwinypos(1))/barheight;                    /* however, only *do* anything if there's a file/dir there :-) */          if(tmpcurent<=gifdirsiz)            {            /* update cursor position */            curent=tmpcurent;            if(curent!=oldent)              {              showbar(oldent,0,startfrom);              showbar(curent,1,startfrom);              }            oldent=curent;	/* stop it being redrawn again */            pending_mouse_viewsel=1;	/* view it when we let go */            }          }            /* check for on-current-dir-bit-and-released-left */      if(mleft)        {        if(mx>=DIR_OF_XPOS && mx<DIR_OF_XPOS+DIR_OF_XSIZ &&           my>=DIR_OF_YPOS && my<DIR_OF_YPOS+20)          /* pretty easy, fake a `G'. */          key='G';        }      }        /* if left button isn't pressed currently, can't be dragging slider.     * tested here (at end of mouse bits) to make sure we don't miss any     * of the dragging.     */    if(!(mbuttons&MOUSE_LEFTBUTTON))      slider_drag=0;    }		/* end of if(has_mouse) */    /* now the good old keyboard stuff */  parsekey:  if(key) slider_drag=pending_mouse_viewsel=0;    /* disable any picture orientation override.   * *slight* overkill to do it each time round the loop :-),   * but it can't hurt.   */  orient_override=0;    if(fs_vgamode!=G640x480x16 &&     ((key>=RK_F1 && key<=RK_F10) || (key>=RK_SHIFT_F1 && key<=RK_SHIFT_F10)))    {    struct modedesc_tag *md_ptr;    int oldmode=fs_vgamode;        fs_vgamode=0;    for(md_ptr=modedesc;md_ptr->mode;md_ptr++)      {      if(key==md_ptr->fs_key && md_ptr->bytespp==1)        {        fs_vgamode=md_ptr->mode;        break;        }      }        if(!fs_vgamode ||       !vga_hasmode(fs_vgamode) || !cfg.mode_allowed[fs_vgamode])      fs_vgamode=oldmode;    else      if(fs_vgamode!=oldmode)        {        /* we have to redraw a little unusually to          * make sure startfrom is sane before drawing.         * save/restore_mouse_pos effectively rescale the mouse pos.         */        save_mouse_pos();        screenon();        restore_mouse_pos();        fix_startfrom(curent,&startfrom);        oldstart=startfrom;	/* since we're redrawing here */        showgifdir(startfrom,0,1,0);        showbar(curent,1,startfrom);        }    }  else /* if not selecting a mode... */    switch(key)      {      case 128+'n':	/* sort by name */      case 128+'e':	/* sort by `extension' */      case 128+'s':	/* sort by size */      case 128+'t':      case 128+'d':	/* sort by mtime (time/date) */        switch(key)          {          case 128+'n':	filesel_sorttype=sort_name; break;          case 128+'e':	filesel_sorttype=sort_ext; break;          case 128+'s':	filesel_sorttype=sort_size; break;          case 128+'t':          case 128+'d':	filesel_sorttype=sort_mtime; break;          }        sort_files();        redrawall(curent,startfrom);        break;      case 'u': case 128+'u':        /* ignore it in an xvpics dir */        {        char cdir[MAXPATHLEN+1];        *cdir=0;        getcwd(cdir,MAXPATHLEN);        if(strstr(cdir,"/.xvpics")==NULL && cfg.xvpic_index)          {          updating_index=1;          if(key=='u')            update_xvpics(0);          else            {            /* recursive update can take ages; make sure they know.             * (This is possibly annoying, but I still think it's a good idea.)             */            if(!msgbox(zgv_ttyfd,                       "Recursive updates can take quite some time; are you sure?",                       MSGBOXTYPE_YESNO, idx_light,idx_dark,idx_black))              {              updating_index=0;              break;	/* skip redraw too */              }            recursive_update();            /* restore old state */            readgifdir(1);            if(curent>gifdirsiz || startfrom>gifdirsiz) curent=startfrom=1;            oldent=curent;            fix_startfrom(curent,&startfrom);            oldstart=startfrom;	/* since we're redrawing below */            }          updating_index=0;          redrawall(curent,startfrom);          }        }        break;      case 'd':        if(cfg.xvpic_index)          {          updating_index=1;          update_xvpics(1);          updating_index=0;          redrawall(curent,startfrom);          }        break;      case 'v':        cfg.xvpic_index=!cfg.xvpic_index;        redrawall(curent,startfrom);        break;      case 'c':        if(fs_vgamode!=G640x480x16) break;        cfg.fs16col=!cfg.fs16col;        redrawall(curent,startfrom);        break;      case 's':        cfg.scrollbar=!cfg.scrollbar;        redrawall(curent,startfrom);        break;      case '?':        save_mouse_pos();		/* showhelp restores this save */        showhelp(zgv_ttyfd,"- KEYS FOR FILE SELECTOR -",zgvhelp);        redrawall(curent,startfrom);        break;      case '\'': case 'g':        do          tmpkey=mousecur_wait_for_keys_or_mouse(zgv_ttyfd);        while(tmpkey==RK_NO_KEY);        if(tmpkey>=33 && tmpkey<=126)          {          int nofiles=1,found=0;                    /* go to first file (not dir) which starts with that char.           * if there isn't one, go to first which starts with a later           * char.           * also, if there aren't any files (just dirs) don't move;           * otherwise, if there are no files with 1st char >=tmpkey,           * go to last file.           *           * nicest way to do this would be a binary search, but that           * would complicate matters; a linear search may be crude           * but it's still blindingly fast. And at least a linear one           * gives *predictably* useless results when not using           * sort-by-name. :-)           */          for(f=1;f<=gifdirsiz;f++)            if(!gifdir[f].isdir)              {              nofiles=0;              if(gifdir[f].name[0]>=tmpkey)                {                curent=f;                found=1;                break;                }              }          /* if didn't find one >=tmpkey but there *are* files in the           * dir, go to the last one.           */          if(!found && !nofiles)            curent=gifdirsiz;          }        break;      case RK_HOME: case 'A'-0x40: /* home or ^a */        curent=1;        break;      case RK_END:  case 'E'-0x40: /* end  or ^e */        curent=gifdirsiz;        break;      case RK_PAGE_UP: case 'U'-0x40: /* pgup or ^u */        curent-=YSIZ*(XSIZ-1);        if(curent<1) curent=1;        break;      case RK_PAGE_DOWN: case 'V'-0x40: /* pgdn or ^v */        curent+=YSIZ*(XSIZ-1);        if(curent>gifdirsiz) curent=gifdirsiz;        break;      case 'K':	/* kill mouse */        if(!has_mouse)          msgbox(zgv_ttyfd,"No mouse enabled!",          	MSGBOXTYPE_OK,idx_light,idx_dark,idx_black);        else          if(msgbox(zgv_ttyfd,"Really disable mouse for rest of session?",          	MSGBOXTYPE_YESNO,idx_light,idx_dark,idx_black))            {            mouse_close();            has_mouse=0;            }        break;      case 128+'f':	/* Alt-f, file (and tagged file) count */        file_count();        break;      case 'D':		/* shift-D deletes tagged files (current if none) */      case RK_DELETE:	/* `Del' deletes a single file */        if(key=='D')          {          /* delete tagged files. We always prompt for this (unless           * overridden by hand), even if no files are tagged, to           * make it clear just what shift-D is doing.           */          if(cfg.nodelprompt_tagged ||             msgbox(zgv_ttyfd,"Really delete ALL tagged files?",                    MSGBOXTYPE_YESNO, idx_light,idx_dark,idx_black))            {            copymovedel_file_or_tagged_files(curent,1,1,delete_file_simple,                                             "delete","deleting","deleted",                                             HOWFAR_DELETING_MSG);            goto do_redraw;            }          }        else          {          if(gifdir[curent].isdir) break;                    /* delete file at cursor */          if(delete_file(gifdir[curent].name,!cfg.nodelprompt,1))            {            delete_gifdir_element(curent);            goto do_redraw;            }          }        break;      case 128+'r':	/* Alt-r, rename file */      case 'R':		/* now also on R :-) */        if(rename_file(curent,startfrom))          {          sort_files();	/* order may have changed */          goto do_redraw;          }        break;      case 'C':	/* copy tagged files, or current file if none */        copymovedel_file_or_tagged_files(curent,0,0,copyfile,                                         "copy","copying","copied",                                         HOWFAR_COPYING_MSG);        /* the redraw is needed as we may have used a `percentage' bar. */        /* (XXX may no longer be needed?) */        redrawall(curent,startfrom);        break;      case 'M':	/* move tagged files, or current file if none */        copymovedel_file_or_tagged_files(curent,1,0,movefile,                                         "move","moving","moved",                                         HOWFAR_MOVING_MSG);        /* need redraw, and will probably have fewer files so fix things */        goto do_redraw;        break;      case 18: case 12:   /* ^R and ^L */        readgifdir(1);        do_redraw:        if(curent>gifdirsiz) curent=gifdirsiz;        oldent=curent;        fix_startfrom(curent,&startfrom);        oldstart=startfrom;	/* since we're redrawing here */        redrawall(curent,startfrom);        break;      case 'G':	/* goto new directory (by entering name) */        /* we don't do any pastpos stuff here, as it's a direct         * jump and it doesn't seem to make sense to me to         * remember old positions etc. in such a case.         */        if(goto_named_dir())          {          oldent=curent=startfrom=1;          readgifdir(1);          redrawall(curent,startfrom);          }        break;      case 't':	/* tag current file and move on */        if(gifdir[curent].isdir==0)          {          gifdir[curent].marked=1;          markchange=1;          }        if(curent<gifdirsiz) curent++;        break;      case 'n':	/* untag current file and move on */        if(gifdir[curent].isdir==0)          {          gifdir[curent].marked=0;          markchange=1;          }        if(curent<gifdirsiz) curent++;        break;      case ' ':   /* toggle tag/untag flag of current file and move on */        if(gifdir[curent].isdir==0)          {          gifdir[curent].marked=1-gifdir[curent].marked;          markchange=1;          }        if(curent<gifdirsiz) curent++;        break;      case 128+'m':	/* toggle find-by-magic-number */        cfg.fsmagic=!cfg.fsmagic;        if(cfg.fsmagic)           msgbox(zgv_ttyfd,"Find files by magic number enabled",          	MSGBOXTYPE_OK,idx_light,idx_dark,idx_black);        else          msgbox(zgv_ttyfd,"Find files by magic number disabled",          	MSGBOXTYPE_OK,idx_light,idx_dark,idx_black);        /* and obviously we want a reread/redraw after... */        readgifdir(1);        goto do_redraw;        break;      case 'L':	/* toggle slideshow looping */        cfg.loop=!cfg.loop;        if(cfg.loop)           msgbox(zgv_ttyfd,"Loop in slideshow now enabled",          	MSGBOXTYPE_OK,idx_light,idx_dark,idx_black);        else          msgbox(zgv_ttyfd,"Looping in slideshow now disabled",          	MSGBOXTYPE_OK,idx_light,idx_dark,idx_black);        break;      case 'S':	/* toggle slideshow shuffle */        cfg.shuffleslideshow=!cfg.shuffleslideshow;        if(cfg.shuffleslideshow)           msgbox(zgv_ttyfd,"Slideshow shuffling now enabled",          	MSGBOXTYPE_OK,idx_light,idx_dark,idx_black);        else          msgbox(zgv_ttyfd,"Slideshow shuffling now disabled",          	MSGBOXTYPE_OK,idx_light,idx_dark,idx_black);        break;      case 'T':	/* tag all files */        for(f=1;f<=gifdirsiz;f++) if(gifdir[f].isdir==0) gifdir[f].marked=1;        showgifdir(startfrom,0,0,0);        break;      case 'N':	/* untag all files */        for(f=1;f<=gifdirsiz;f++) if(gifdir[f].isdir==0) gifdir[f].marked=0;        showgifdir(startfrom,0,0,0);        break;      case 'q': case 'k': case 'P'-0x40: case RK_CURSOR_UP:        if(curent>1) curent--; break;      case 'a': case 'j': case 'N'-0x40: case RK_CURSOR_DOWN:        if(curent<gifdirsiz) curent++; break;      case 'o': case 'h': case 'B'-0x40: case RK_CURSOR_LEFT:        curent-=YSIZ;        if(curent<1) curent=1;        break;      case 'p': case 'l': case 'F'-0x40: case RK_CURSOR_RIGHT:        curent+=YSIZ;        if(curent>gifdirsiz) curent=gifdirsiz;        break;      case RK_ENTER:        /* uhhhhh my head hurts */                /* we do our own mouse pos save, in case showgif() isn't run */        save_mouse_pos();                sgres=0;                do          {          if(permissiondenied(gifdir[curent].name))            {            msgbox(zgv_ttyfd,"Permission denied or file not found",            	MSGBOXTYPE_OK,idx_light,idx_dark,idx_black);            pic_incr=0;	/* stop here *even if ^p or ^n used* */            if(!msgbox_draw_ok)              redrawall(curent,startfrom);            break;            }                    /* this is only in the loop so that it's after the permissiondenied           * stuff. It's unsightly having it here, but is otherwise ok.           */          if(gifdir[curent].isdir)            {            new_pastpos(curent,startfrom);            showbar(curent,0,startfrom);            showgifdir(startfrom,1,1,0);            chdir(gifdir[curent].name);            readgifdir(1);            get_pastpos(&curent,&startfrom);            /* if these are off the end, it's clearly out of date (dir             * must have changed) so might as well just start at top.             */            if(curent>gifdirsiz || startfrom>gifdirsiz) curent=startfrom=1;            oldent=curent;            showgifdir(startfrom,0,1,0);            showbar(curent,1,startfrom);            break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -