home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / BBS_GAME / LOD400G.ZIP / EDITIMG.PAS < prev    next >
Pascal/Delphi Source File  |  1993-09-16  |  5KB  |  250 lines

  1. uses graph, crt, mouse;
  2.  
  3. const
  4.  imatx=639-180;
  5. type
  6.  imagetype= array[1..12000] of word;
  7.  im2type = array[1..250,1..200] of byte;
  8.  im2ptr=^im2type;
  9. var
  10.  xsize,ysize: word;
  11.  image: imagetype;
  12.  im: im2ptr;
  13.  curcolor: byte;
  14.  imgx,imgy: word;
  15.  numx,numy: word;
  16.  fn: string;
  17.  lx1,lx2,ly1,ly2: word;
  18.  
  19. procedure init;
  20. var
  21.  grmode, grdriver: integer;
  22.  f: file of imagetype;
  23. begin;
  24.  imgx:=60;
  25.  imgy:=40;
  26.  grmode:=egahi;
  27.  grdriver:=ega;
  28.  initgraph(grdriver,grmode,'');
  29.  writeln(graphresult);
  30.  assign(f,fn);
  31.  {$I-}
  32.  reset(f);
  33.  {$i+}
  34.  if ioresult=0 then begin;
  35.   {$I-}
  36.   read(f,image);
  37.   {$I+}
  38.   if ioresult<>0 then ;
  39.   close(f);
  40.   putimage(imatx,0,image,normalput);
  41.   imgx:=image[1];
  42.   imgy:=image[2];
  43.  end;
  44.  numx:=imgx+1;
  45.  numy:=imgy+1;
  46. end;
  47.  
  48. procedure DrawImg;
  49. var
  50.  x,y: integer;
  51.  xs,ys: word;
  52. begin;
  53.  xs:=xsize-1;
  54.  ys:=ysize-1;
  55.  for x:=1 to numx do for y:=1 to numy do begin;
  56.   setfillstyle(1,im^[x,y]);
  57.   bar((x-1)*xsize+1,(y-1)*ysize+1,(x-1)*xsize+xs,(y-1)*ysize+ys);
  58.  end;
  59. end;
  60.  
  61. procedure GetFlip;
  62. var
  63.  x,y: integer;
  64. begin;
  65.  for x:=1 to numx do for y:=1 to numy do begin;
  66.   im^[numx-x+1,y]:=getpixel(imatx+x-1,y-1);
  67.  end;
  68.  for x:=1 to numx do for y:=1 to numy do begin;
  69.   putpixel(imatx+x-1,y-1,im^[x,y]);
  70.  end;
  71.  drawimg;
  72. end;
  73.  
  74. procedure MoveDown;
  75. var
  76.  x,y: integer;
  77. begin;
  78.  for x:=1 to numx do for y:=1 to numy-1 do begin;
  79.   im^[x,y+1]:=getpixel(imatx+x-1,y-1);
  80.  end;
  81.  for x:=1 to numx do for y:=1 to numy do begin;
  82.   putpixel(imatx+x-1,y-1,im^[x,y]);
  83.  end;
  84.  drawimg;
  85. end;
  86.  
  87. procedure GetOrig;
  88. var
  89.  x,y: integer;
  90. begin;
  91.  for x:=1 to numx do for y:=1 to numy do begin;
  92.   im^[x,y]:=getpixel(imatx+x-1,y-1);
  93.  end;
  94. end;
  95.  
  96. procedure DrawGrid;
  97. var
  98.  x,y: word;
  99. begin;
  100.  xsize:=((imatx-1) div (imgx+1));
  101.  ysize:=325 div imgy;
  102.  for x:=1 to numx+1 do line((x-1)*xsize,0,(x-1)*xsize,(numy)*ysize);
  103.  for y:=1 to numy+1 do line(0,(y-1)*ysize,(numx)*xsize,(y-1)*ysize);
  104. end;
  105.  
  106. procedure updatecolor;
  107. begin;
  108.  setfillstyle(1,curcolor);
  109.  bar(550,300,550+50,300+40);
  110. end;
  111.  
  112. procedure SaveImage;
  113. var
  114.  f: file;
  115. begin;
  116.  getimage(imatx,0,imatx+numx-1,numy-1,image);
  117.  assign(f,fn);
  118.  rewrite(f,1);
  119.  blockwrite(f,image,imagesize(imatx,0,imatx+numx-1,numy-1));
  120.  close(f);
  121. end;
  122.  
  123. procedure checkmouse;
  124. var
  125.  mousex,mousey,buttons: word;
  126.  imx,imy: word;
  127. begin;
  128.  buttons:=mousegetbuttonstatus(mousex,mousey);
  129.  if ((buttons and 1)<>0) and (mousex<numx*xsize) and (mousey<numy*ysize) then begin;
  130.   mousehidecursor;
  131.   imx:=(mousex div xsize)+1;
  132.   imy:=(mousey div ysize)+1;
  133.   im^[imx,imy]:=curcolor;
  134.   setfillstyle(1,curcolor);
  135.   bar((imx-1)*xsize+1,(imy-1)*ysize+1,(imx-1)*xsize+(xsize-1),(imy-1)*ysize+(ysize-1));
  136.   putpixel((imatx-1)+imx,(imy-1),curcolor);
  137.   mouseshowcursor;
  138.  end;
  139.  if (buttons and 2)<>0 then begin;
  140.   inc(curcolor);
  141.   if curcolor=16 then curcolor:=0;
  142.   mousehidecursor;
  143.   updatecolor;
  144.   mouseshowcursor;
  145.   while (buttons and 2)<>0 do buttons:=mousegetbuttonstatus(mousex,mousey);
  146.  end;
  147. end;
  148.  
  149. procedure LoadZTImg;
  150. type
  151.  nmtype= array[1..20,1..18] of byte;
  152. var
  153.  nm: nmtype;
  154.  f: file of nmtype;
  155.  s: string;
  156.  a,b: integer;
  157. begin;
  158.  readln(s);
  159.  val(s,a,b);
  160.  if a=0 then exit;
  161.  assign(f,'LOD.DAT');
  162.  reset(f);
  163.  seek(f,a-1);
  164.  read(f,nm);
  165.  close(f);
  166.  for a:=1 to 20 do for b:=1 to 18 do begin;
  167.   putpixel(550+(a-1)*3,50+(b-1)*2,nm[a,b]);
  168.   putpixel(551+(a-1)*3,50+(b-1)*2,nm[a,b]);
  169.   putpixel(552+(a-1)*3,50+(b-1)*2,nm[a,b]);
  170.   putpixel(550+(a-1)*3,50+(b-1)*2+1,nm[a,b]);
  171.   putpixel(551+(a-1)*3,50+(b-1)*2+1,nm[a,b]);
  172.   putpixel(552+(a-1)*3,50+(b-1)*2+1,nm[a,b]);
  173.  end;
  174.  getorig;
  175.  drawimg;
  176. end;
  177.  
  178. var
  179.  done: boolean;
  180.  ch: char;
  181.  buttons,mousex,mousey: word;
  182. begin;
  183.  if paramcount=1 then fn:=paramstr(1) else begin;
  184.   writeln('Format: EDITIMG FILENAME.DAT');
  185.   writeln;
  186.   writeln('Q    ... quit and save');
  187.   writeln('A    ... abort w/o save');
  188.   writeln('+/-  ... cycle colors');
  189.  end;
  190.  new(im);
  191.  init;
  192.  if not mousereset then begin;
  193.   restorecrtmode;
  194.   writeln('Mouse driver not loaded!');
  195.   halt;
  196.  end;
  197.  mousehidecursor;
  198.  drawgrid;
  199.  getorig;
  200.  drawimg;
  201.  mouseshowcursor;
  202.  mouseshowcursor;
  203.  done:=false;
  204.  curcolor:=7;
  205.  updatecolor;
  206.  repeat;
  207.   checkmouse;
  208.   if keypressed then begin;
  209.    ch:=upcase(readkey);
  210.    if ch='1' then begin;
  211.     buttons:=mousegetbuttonstatus(mousex,mousey);
  212.     lx1:=imatx+(mousex div xsize);
  213.     ly1:=mousey div ysize;
  214.    end;
  215.    if ch='2' then begin;
  216.     buttons:=mousegetbuttonstatus(mousex,mousey);
  217.     lx2:=imatx+(mousex div xsize);
  218.     ly2:=mousey div ysize;
  219.    end;
  220.    if ch='3' then begin;
  221.     setcolor(curcolor);
  222.     setfillstyle(1,curcolor);
  223.     line(lx1,ly1,lx2,ly2);
  224.     getorig;
  225.     drawimg;
  226.    end;
  227.    if ch='!' then movedown;
  228.    if ch='R' then getflip;
  229.    if ch='L' then LoadZTImg;
  230.    if ch='A' then done:=true;
  231.    if ch='Q' then done:=true;
  232.    if ch='+' then begin;
  233.     inc(curcolor);
  234.     if curcolor>15 then curcolor:=0;
  235.     mousehidecursor;
  236.     updatecolor;
  237.     mouseshowcursor;
  238.    end;
  239.    if ch='-' then begin;
  240.     dec(curcolor);
  241.     if curcolor=255 then curcolor:=15;
  242.     mousehidecursor;
  243.     updatecolor;
  244.     mouseshowcursor;
  245.    end;
  246.   end;
  247.  until done;
  248.  if ch='Q' then saveimage;
  249.  restorecrtmode;
  250. end.