int ImagingDrawPoint(Imaging im, int x0, int y0, const void* ink_, int op) { DRAW* draw; INT32 ink; DRAWINIT(); draw->point(im, x0, y0, ink); return 0; }
int ImagingDrawLine(Imaging im, int x0, int y0, int x1, int y1, const void* ink_, int op) { DRAW* draw; INT32 ink; DRAWINIT(); draw->line(im, x0, y0, x1, y1, ink); return 0; }
int ImagingDrawOutline(Imaging im, ImagingOutline outline, const void* ink_, int fill, int op) { DRAW* draw; INT32 ink; DRAWINIT(); draw->polygon(im, outline->count, outline->edges, ink, 0); return 0; }
int ImagingDrawWideLine(Imaging im, int x0, int y0, int x1, int y1, const void* ink_, int width, int op) { DRAW* draw; INT32 ink; int dx, dy; double big_hypotenuse, small_hypotenuse, ratio_max, ratio_min; int dxmin, dxmax, dymin, dymax; Edge e[4]; DRAWINIT(); if (width <= 1) { draw->line(im, x0, y0, x1, y1, ink); return 0; } dx = x1-x0; dy = y1-y0; if (dx == 0 && dy == 0) { draw->point(im, x0, y0, ink); return 0; } big_hypotenuse = sqrt((double) (dx*dx + dy*dy)); small_hypotenuse = (width - 1) / 2.0; ratio_max = ROUND_UP(small_hypotenuse) / big_hypotenuse; ratio_min = ROUND_DOWN(small_hypotenuse) / big_hypotenuse; dxmin = ROUND_DOWN(ratio_min * dy); dxmax = ROUND_DOWN(ratio_max * dy); dymin = ROUND_DOWN(ratio_min * dx); dymax = ROUND_DOWN(ratio_max * dx); { int vertices[4][2] = { {x0 - dxmin, y0 + dymax}, {x1 - dxmin, y1 + dymax}, {x1 + dxmax, y1 - dymin}, {x0 + dxmax, y0 - dymin} }; add_edge(e+0, vertices[0][0], vertices[0][1], vertices[1][0], vertices[1][1]); add_edge(e+1, vertices[1][0], vertices[1][1], vertices[2][0], vertices[2][1]); add_edge(e+2, vertices[2][0], vertices[2][1], vertices[3][0], vertices[3][1]); add_edge(e+3, vertices[3][0], vertices[3][1], vertices[0][0], vertices[0][1]); draw->polygon(im, 4, e, ink, 0); } return 0; }
execute () { register struct file *file = &cur->d.cat[cur->d.curfile]; register char *name = file->name; int updir, dev, ino; switch (file->mode & S_IFMT) { case S_IFDIR: if (! strcmp (name, ".")) { // setdir (cur, NULL); break; } if (updir = !strcmp (name, "..")) { dev = cur->d.dev; ino = cur->d.ino; } if (cur->chdir(name) < 0) break; setdir (cur, "."); if (updir) { for (cur->d.curfile=0; cur->d.curfile<cur->d.num; ++cur->d.curfile) { if (cur->d.cat[cur->d.curfile].dev == dev && cur->d.cat[cur->d.curfile].ino == ino) break; } if (cur->d.curfile >= cur->d.num) cur->d.curfile = 0; if (cur->d.topfile + PAGELEN (cur) <= cur->d.curfile) cur->d.topfile = cur->d.curfile - PAGELEN (cur) + 1; } if (visualwin) { draw.drawdir(left, 0, left, right); draw.drawdir(right, 0, left, right); } break; // case S_IFREG: // if (file->execable) // strcpy (command, file->name); // else // excommand (command, file->name); // cpos = strlen (command); // if (! command [0]) // break; // cmd.exec(cur, &left, &right, file->execable ? 1 : 0, 1); // draw.draw(cur, &left, &right); // break; } }
int ImagingDrawRectangle(Imaging im, int x0, int y0, int x1, int y1, const void* ink_, int fill, int width, int op) { int i; int y; int tmp; DRAW* draw; INT32 ink; DRAWINIT(); if (y0 > y1) tmp = y0, y0 = y1, y1 = tmp; if (fill) { if (y0 < 0) y0 = 0; else if (y0 >= im->ysize) return 0; if (y1 < 0) return 0; else if (y1 > im->ysize) y1 = im->ysize; for (y = y0; y <= y1; y++) draw->hline(im, x0, y, x1, ink); } else { /* outline */ if (width == 0) { width = 1; } for (i = 0; i < width; i++) { draw->hline(im, x0, y0+i, x1, ink); draw->hline(im, x0, y1-i, x1, ink); draw->line(im, x1-i, y0, x1-i, y1, ink); draw->line(im, x0+i, y1, x0+i, y0, ink); } } return 0; }
int ImagingDrawPolygon(Imaging im, int count, int* xy, const void* ink_, int fill, int op) { int i, n; DRAW* draw; INT32 ink; if (count <= 0) return 0; DRAWINIT(); if (fill) { /* Build edge list */ /* malloc check ok, using calloc */ Edge* e = calloc(count, sizeof(Edge)); if (!e) { (void) ImagingError_MemoryError(); return -1; } for (i = n = 0; i < count-1; i++) add_edge(&e[n++], xy[i+i], xy[i+i+1], xy[i+i+2], xy[i+i+3]); if (xy[i+i] != xy[0] || xy[i+i+1] != xy[1]) add_edge(&e[n++], xy[i+i], xy[i+i+1], xy[0], xy[1]); draw->polygon(im, n, e, ink, 0); free(e); } else { /* Outline */ for (i = 0; i < count-1; i++) draw->line(im, xy[i+i], xy[i+i+1], xy[i+i+2], xy[i+i+3], ink); draw->line(im, xy[i+i], xy[i+i+1], xy[0], xy[1], ink); } return 0; }
static int ellipse(Imaging im, int x0, int y0, int x1, int y1, int start, int end, const void* ink_, int fill, int mode, int op) { int i, n; int cx, cy; int w, h; int x = 0, y = 0; int lx = 0, ly = 0; int sx = 0, sy = 0; DRAW* draw; INT32 ink; w = x1 - x0; h = y1 - y0; if (w < 0 || h < 0) return 0; DRAWINIT(); cx = (x0 + x1) / 2; cy = (y0 + y1) / 2; while (end < start) end += 360; if (mode != ARC && fill) { /* Build edge list */ Edge* e = malloc((end - start + 3) * sizeof(Edge)); if (!e) { ImagingError_MemoryError(); return -1; } n = 0; for (i = start; i <= end; i++) { x = FLOOR((cos(i*M_PI/180) * w/2) + cx + 0.5); y = FLOOR((sin(i*M_PI/180) * h/2) + cy + 0.5); if (i != start) add_edge(&e[n++], lx, ly, x, y); else sx = x, sy = y; lx = x, ly = y; } if (n > 0) { /* close and draw polygon */ if (mode == PIESLICE) { if (x != cx || y != cy) { add_edge(&e[n++], x, y, cx, cy); add_edge(&e[n++], cx, cy, sx, sy); } } else { if (x != sx || y != sy) add_edge(&e[n++], x, y, sx, sy); } draw->polygon(im, n, e, ink, 0); } free(e); } else { for (i = start; i <= end; i++) { x = FLOOR((cos(i*M_PI/180) * w/2) + cx + 0.5); y = FLOOR((sin(i*M_PI/180) * h/2) + cy + 0.5); if (i != start) draw->line(im, lx, ly, x, y, ink); else sx = x, sy = y; lx = x, ly = y; } if (i != start) { if (mode == PIESLICE) { if (x != cx || y != cy) { draw->line(im, x, y, cx, cy, ink); draw->line(im, cx, cy, sx, sy, ink); } } else if (mode == CHORD) { if (x != sx || y != sy) draw->line(im, x, y, sx, sy, ink); } } } return 0; }
static int ellipse(Imaging im, int x0, int y0, int x1, int y1, float start, float end, const void* ink_, int fill, int width, int mode, int op) { float i; int j; int n; int cx, cy; int w, h; int x = 0, y = 0; int lx = 0, ly = 0; int sx = 0, sy = 0; DRAW* draw; INT32 ink; DRAWINIT(); if (width == 0) { width = 1; } for (j = 0; j < width; j++) { w = x1 - x0; h = y1 - y0; if (w < 0 || h < 0) return 0; cx = (x0 + x1) / 2; cy = (y0 + y1) / 2; while (end < start) end += 360; if (end - start > 360) { /* no need to go in loops */ end = start + 361; } if (mode != ARC && fill) { /* Build edge list */ /* malloc check UNDONE, FLOAT? */ Edge* e = calloc((end - start + 3), sizeof(Edge)); if (!e) { ImagingError_MemoryError(); return -1; } n = 0; for (i = start; i < end+1; i++) { if (i > end) { i = end; } ellipsePoint(cx, cy, w, h, i, &x, &y); if (i != start) add_edge(&e[n++], lx, ly, x, y); else sx = x, sy = y; lx = x, ly = y; } if (n > 0) { /* close and draw polygon */ if (mode == PIESLICE) { if (x != cx || y != cy) { add_edge(&e[n++], x, y, cx, cy); add_edge(&e[n++], cx, cy, sx, sy); } } else { if (x != sx || y != sy) add_edge(&e[n++], x, y, sx, sy); } draw->polygon(im, n, e, ink, 0); } free(e); } else { for (i = start; i < end+1; i++) { if (i > end) { i = end; } ellipsePoint(cx, cy, w, h, i, &x, &y); if (i != start) draw->line(im, lx, ly, x, y, ink); else sx = x, sy = y; lx = x, ly = y; } if (i != start) { if (mode == PIESLICE) { if (j == 0 && (x != cx || y != cy)) { if (width == 1) { draw->line(im, x, y, cx, cy, ink); draw->line(im, cx, cy, sx, sy, ink); } else { ImagingDrawWideLine(im, x, y, cx, cy, &ink, width, op); ImagingDrawWideLine(im, cx, cy, sx, sy, &ink, width, op); } } } else if (mode == CHORD) { if (x != sx || y != sy) draw->line(im, x, y, sx, sy, ink); } } } x0++; y0++; x1--; y1--; } return 0; }
main (int argc, char **argv, char **envp) { register c; if (argc > 2) { outerr("Usage: deco [dirname]\n",0); exit (1); } outerr("Demos Commander, Copyright (C) 1989-1994 Serge Vakulenko\n",0); palette = dflt_palette; EnvInit (envp); uid = getuid (); gid = getgid (); # ifdef GROUPS gidnum = getgroups (sizeof(gidlist)/sizeof(gidlist[0]), (unsigned int *)gidlist); # endif ppid = getppid (); user = username (uid); group = groupname (gid); tty = ttyname (0); machine = getmachine (); #if 0 sigign(); #else signal(SIGTERM, SIG_IGN); signal(SIGQUIT, SIG_IGN); signal(SIGINT, SIG_IGN); # ifdef SIGTSTP signal(SIGTSTP, SIG_IGN); # endif #endif init (); // inithome (); VClear (); /* init class dir */ if (argc > 1) // chdir (argv [1]); left = new dir(argv [1]); else left = new dir; right = new dir; left->d.basecol = 0; right->d.basecol = 40; /*-----------*/ initfile.read(); if (uid == 0) palette.dimfg = 6; v.VSetPalette (palette.fg, palette.bg, palette.revfg, palette.revbg, palette.boldfg, palette.boldbg, palette.boldrevfg, palette.boldrevbg, palette.dimfg, palette.dimbg, palette.dimrevfg, palette.dimrevbg); setdir (left, "."); setdir (right, "."); left->chdir(left->d.cwd); cur = left; draw.draw(cur, left, right); for (;;) { if (! cmdreg) draw.drawcursor(cur); // cmd.drawcmd(cur, &left, &right); VSync (); c = KeyGet (); if (! cmdreg) draw.undrawcursor(cur); switch (c) { case '+': /* select */ case '-': /* unselect */ if (! cpos && ! cmdreg && ! cur->d.status) { if (c == '+') tagall (); else untagall (); draw.draw(cur, left, right); continue; } default: // if (c>=' ' && c<='~' || c>=0300 && c<=0376) { // if (cpos || c!=' ') // cmd.inscmd(c); // continue; // } VBeep (); continue; // case cntrl ('V'): /* quote next char */ // cmd.inscmd(quote ()); // continue; // case cntrl ('J'): /* insert file name */ // if (! cmdreg && ! cur->status) // cmd.namecmd(cur); // continue; // case cntrl ('G'): // cmd.delcmd(); // continue; // case meta ('b'): /* backspace */ // if (cpos) { // cmd.leftcmd(); // cmd.delcmd(); // } // continue; case cntrl ('O'): /* set/unset command mode */ case cntrl ('P'): /* set/unset command mode */ switchcmdreg (); if (! cmdreg) visualwin = 1; draw.draw(cur, left, right); continue; case cntrl ('M'): /* return */ // if (command [0]) { // cmd.exec(cur, &left, &right, 1, 1); // draw.draw(cur, &left, &right); // continue; // } if (cmdreg) { cmdreg = 0; if (! visualwin) { visualwin = 1; setdir (cur==left ? right : left, NULL); setdir (cur, NULL); } draw.draw(cur, left, right); continue; } execute (); continue; case cntrl (']'): /* redraw screen */ VRedraw (); continue; // case cntrl ('B'): /* history */ // if (! visualwin) // VClearBox (1, 0, LINES-2, 80); // cmd.histmenu(cur, &left, &right); // draw.draw(cur, &left, &right); // continue; case meta ('A'): /* f1 */ genhelp (); draw.draw(cur, left, right); continue; case meta ('B'): /* f2 */ udm.menu(); draw.draw(cur, left, right); continue; case meta ('I'): /* f9 */ mymenu.runmenu (cur==left ? 'l' : 'r'); draw.draw(cur, left, right); continue; case meta ('J'): /* f0 */ case cntrl ('C'): /* quit */ quit (); continue; case cntrl ('U'): /* swap panels */ swappanels (); draw.draw(cur, left, right); continue; case cntrl ('F'): /* full screen */ fullscreen (); draw.draw(cur, left, right); continue; case cntrl ('^'): /* cd / */ directory (0, 'r'); if (! cur->d.status) draw.drawdir(cur, 1, left, right); continue; case cntrl ('\\'): /* cd $HOME */ directory (0, 'o'); if (! cur->d.status) draw.drawdir(cur, 1, left, right); continue; // case cntrl ('Y'): /* clear line */ // command [cpos = 0] = 0; // continue; // case cntrl ('X'): /* next history */ // cmd.nextcmd(); // continue; // case cntrl ('E'): /* prev history */ // cmd.prevcmd(); // continue; // case cntrl ('S'): /* char left */ // case cntrl ('A'): /* char left */ // cmd.leftcmd(); // continue; // case cntrl ('D'): /* char right */ // cmd.rightcmd(); // continue; case cntrl ('I'): /* tab */ if (cmdreg) {} // if (command [cpos]) // cmd.endcmd(); // else // cmd.homecmd(); else { switchpanels (); if (fullwin) { draw.drawbanners(); draw.drawdir(cur, 0, left, right); break; } } continue; case cntrl ('W'): /* double width */ if (! cmdreg) { setdwid (); draw.draw(cur, left, right); } continue; // case meta ('G'): /* f7 */ // makedir (); // draw.draw(cur, &left, &right); // continue; case meta ('h'): /* home */ case meta ('e'): /* end */ case meta ('u'): /* up */ case meta ('d'): /* down */ case meta ('l'): /* left */ case meta ('r'): /* right */ case meta ('n'): /* next page */ case meta ('p'): /* prev page */ case cntrl ('K'): /* find file */ case cntrl ('R'): /* reread catalog */ case cntrl ('T'): /* tag file */ case meta ('C'): /* f3 */ case meta ('D'): /* f4 */ case meta ('E'): /* f5 */ case meta ('F'): /* f6 */ case meta ('H'): /* f8 */ case cntrl ('L'): /* status */ if (cmdreg || cur->d.status) {} // docmdreg (c); else doscrreg (c); continue; } } }
void doscrreg (int c) { switch (c) { case meta ('h'): /* home */ cur->d.curfile = cur->d.topfile = 0; break; case meta ('e'): /* end */ cur->d.curfile = cur->d.num - 1; cur->d.topfile = cur->d.num - PAGELEN (cur); if (cur->d.topfile < 0) cur->d.topfile = 0; break; case meta ('u'): /* up */ if (cur->d.curfile <= 0) return; if (cur->d.curfile > cur->d.topfile) { --cur->d.curfile; return; } cur->d.topfile = --cur->d.curfile; break; case meta ('d'): /* down */ if (cur->d.curfile >= cur->d.num-1) return; if (cur->d.topfile + PAGELEN (cur) - 1 > cur->d.curfile) { ++cur->d.curfile; return; } cur->d.topfile = ++cur->d.curfile - PAGELEN (cur) + 1; break; case meta ('l'): /* left */ if (cur->d.curfile < H) { if (cur->d.topfile <= 0) return; cur->d.curfile -= cur->d.topfile; cur->d.topfile = 0; break; } cur->d.curfile -= H; if (cur->d.topfile <= cur->d.curfile) return; cur->d.topfile -= H; if (cur->d.topfile <= 0) { cur->d.curfile -= cur->d.topfile; cur->d.topfile = 0; } break; case meta ('r'): /* right */ if (cur->d.curfile + H < cur->d.num) { cur->d.curfile += H; if (cur->d.topfile + PAGELEN (cur) > cur->d.curfile) return; cur->d.topfile += H; break; } if (cur->d.topfile + PAGELEN (cur) < cur->d.num) { cur->d.curfile = cur->d.num-1; cur->d.topfile += H; break; } if ((cur->d.curfile - cur->d.topfile) / H < (cur->d.num - cur->d.topfile - 1) / H) cur->d.curfile = cur->d.num-1; return; case meta ('n'): /* next page */ if (cur->d.topfile + PAGELEN (cur) >= cur->d.num) { cur->d.curfile = cur->d.num-1; } else if (cur->d.topfile + 2 * PAGELEN (cur) >= cur->d.num) { cur->d.curfile = cur->d.num-1; cur->d.topfile = cur->d.num - PAGELEN (cur); } else { cur->d.curfile += PAGELEN (cur); cur->d.topfile += PAGELEN (cur); } break; case meta ('p'): /* prev page */ if (cur->d.topfile == 0) { cur->d.curfile = 0; } else { cur->d.curfile -= PAGELEN (cur); if (cur->d.topfile > cur->d.curfile) cur->d.topfile -= PAGELEN (cur); if (cur->d.topfile < 0) { cur->d.curfile -= cur->d.topfile; cur->d.topfile = 0; } } break; case cntrl ('K'): /* find file */ findname (); break; case cntrl ('R'): /* reread catalog */ reread (cur); break; case cntrl ('T'): /* tag file */ if ((cur->d.cat[cur->d.curfile].mode & S_IFMT) == (unsigned) S_IFREG) { cur->d.cat[cur->d.curfile].tag ^= 1; counttag (cur); } if (cur->d.curfile < cur->d.num-1) { /* move down */ ++cur->d.curfile; if (cur->d.topfile + PAGELEN (cur) - 1 < cur->d.curfile) cur->d.topfile = cur->d.curfile - PAGELEN (cur) + 1; } break; // case meta ('C'): /* f3 */ // if ((cur->d.cat[cur->d.curfile].mode & S_IFMT) != (unsigned) S_IFREG) // return; // view (); // draw.draw(cur, &left, &right); // return; // case meta ('D'): /* f4 */ // edit (); // setdir (cur==&left ? &right : &left, NULL); // setdir (cur, NULL); // draw.draw(cur, &left, &right); // return; case meta ('E'): /* f5 */ copy (); draw.draw(cur, left, right); return; // case meta ('F'): /* f6 */ // renmove (); // draw.draw(cur, &left, &right); // return; // case meta ('H'): /* f8 */ // mydelete (); // draw.draw(cur, &left, &right); // return; case cntrl ('L'): /* status */ setstatus (); draw.draw(cur, left, right); return; } draw.drawdir(cur, 1, left, right); }