home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / grafik / dc / svgamap.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1992-10-21  |  5.0 KB  |  167 lines

  1. {
  2.   Copyright 1992 by Digital Crime.
  3.  
  4.   All rights reserved.
  5.  
  6.   Permission to use, copy, modify, and distribute this software and its
  7.   documentation for any purpose and without fee is hereby granted,
  8.   provided that the above copyright notice appear in all copies and that
  9.   both that copyright notice and this permission notice appear in
  10.   supporting documentation, and that the name of the Digital Crime
  11.   not be used in advertising or publicity pertaining to distribution
  12.   of the software without specific, written  prior permission.
  13.  
  14.   DIGITAL CRIME DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  15.   SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  16.   AND FITNESS, IN NO EVENT SHALL DIGITAL CRIME BE LIABLE FOR ANY SPECIAL,
  17.   INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
  18.   FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  19.   NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  20.   WITH THE USE OR PERFORMANCE OF THIS  SOFTWARE.
  21.  
  22.   s924683@minyos.xx.rmit.OZ.AU   Chandi.
  23.   s924698@minyos.xx.rmit.OZ.AU   Ed.
  24.  
  25. }
  26.  
  27. {$R-}
  28.  
  29. program SVGA_Image_Maker;
  30.  
  31. { This lets you create and edit your own bitmaps. This program        }
  32. { must be run from TP if you need to start modifying bitmap sizes     }
  33. { If editing small images the pixel size can be increased by simply   }
  34. { changing PixelWidth.  Image is saved to disk by dumping whole array }
  35. { to disk.  This makes quicker loads and saves                        }
  36.  
  37. uses SVGA, Crt;
  38.  
  39. const MaxWidth = 120;           { Width of image }
  40.       MaxHeight = 120;          { Height of image }
  41.       PaletteName = 'dc.pal'; { Name of pallette to use }
  42.       ImageName = 'd.img';      { name of image }
  43.       PixelWidth = 4;           { size of pixels }
  44.  
  45. type ImageType = array[ 0..MaxWidth, 0..MaxHeight ] of byte;
  46.  
  47. var GM : GraphicMouse;
  48.     Image : ImageType;
  49.     XPos, YPos, Btn, TX, TY : integer;
  50.     ActiveColor : byte;
  51.     XCoord, YCoord : string;
  52.     Quit : boolean;
  53.     Ch : char;
  54.  
  55.  
  56. procedure Grid;
  57.  
  58.   var i, j : integer;
  59.  
  60.   begin
  61.     GM.Show( False );
  62.     for i := 0 to MaxHeight do
  63.       for j := 0 to MaxWidth do
  64.         begin
  65.           RectFill( j*PixelWidth, i*PixelWidth, j*PixelWidth+PixelWidth-1,
  66.                     i*PixelWidth+PixelWidth-1, Image[i,j] );
  67.           Plot( 500+j, 300+i, Image[i,j] )
  68.         end;
  69.     GM.Show( True );
  70.   end;
  71.  
  72. procedure SaveImage;
  73.  
  74.   var  fil : File of ImageType;
  75.  
  76.   begin
  77.     assign( fil, ImageName );
  78.     rewrite( fil );
  79.     write( fil, Image );
  80.     close( fil );
  81.   end;
  82.  
  83. procedure LoadImage;
  84.  
  85.   var  fil : File of ImageType;
  86.  
  87.   begin
  88.     assign( fil, ImageName );
  89.     reset( fil );
  90.     read( fil, Image );
  91.     close( fil );
  92.     Grid;
  93.   end;
  94.  
  95. procedure SetUp;
  96.  
  97.   var i, j : integer;
  98.  
  99.   begin
  100.     SetMode( SVGAMED );              { Set Mode 640*480*256   }
  101.     LoadPalette( PaletteName );      { Load desired Palette   }
  102.     LoadFont( StandardFont );        { Load desired Font      }
  103.     SetFontColor( 253, 0, false );   { Set Font Color and     }
  104.     for i := 0 to 7 do               { turn on overwrite mode }
  105.       for j := 0 to 31 do
  106.         RectFill( 500+i*15, j*7, 500+i*15+14, j*7+7, i*32+j );
  107.     for i := 0 to MaxWidth do
  108.       for j := 0 to MaxHeight do
  109.         Image[ i, j ] := 226;
  110.     Quit := False;
  111.     ActiveColor := 45;
  112.     GM.Initialize;
  113.   end;
  114.  
  115. begin
  116.   SetUp;
  117.   Grid;
  118.   repeat
  119.     GM.CheckMouse;
  120.     GM.GetPosition( Btn, XPos, YPos );
  121.     TX := ( XPos div PixelWidth );
  122.     TY := ( YPos div PixelWidth );
  123.     if (XPos < (MaxWidth+1)*PixelWidth ) AND (YPos < (MaxHeight+1)*PixelWidth) then
  124.       begin
  125.         str( XPos div PixelWidth, XCoord );
  126.         str( YPos div PixelWidth, YCoord );
  127.         OutTextXY( 525, 260, XCoord+'  ' );
  128.         OutTextXY( 575, 260, YCoord+'  ' );
  129.       end;
  130.     if ( XPos > 500 ) AND ( Btn AND $01 = $01 )
  131.         AND ( YPos < 225 ) then
  132.       begin
  133.         GM.Show( False );
  134.         for TX := 0 to 7 do
  135.           for TY := 0 to 31 do
  136.             RectFill( 500+TX*15, TY*7, 500+TX*15+14, TY*7+7, TX*32+TY );
  137.         TX := ((XPos-500) div 15);
  138.         TY := (YPos div 7 );
  139.         Rectangle( 500+TX*15, TY*7, 500+TX*15+14, TY*7+7, 255 );
  140.         Rectangle( 500+TX*15+1, TY*7+1, 500+TX*15+13, TY*7+6, 252 );
  141.         GM.Show( True );
  142.         ActiveColor := TX*32 + TY;
  143.       end;
  144.     if ( XPos < (MaxWidth+1)*PixelWidth) AND (Btn AND $03 <> 0)
  145.         AND (YPos < (MaxHeight+1)*PixelWidth) then
  146.       begin
  147.         GM.Show( False );
  148.         Image[ TY, TX ] := ActiveColor;
  149.         RectFill( TX * PixelWidth, TY * PixelWidth,
  150.                   TX * PixelWidth+ PixelWidth-1,
  151.                   TY * PixelWidth+ PixelWidth-1, ActiveColor );
  152.         Plot( 500+TX, 300+TY, ActiveColor );
  153.         GM.Show( True );
  154.       end;
  155.     if keypressed then
  156.       begin
  157.         Ch := ReadKey;
  158.         case Ch of
  159.             'q','Q' : Quit := True;
  160.             's','S' : SaveImage;
  161.             'l','L' : LoadImage;
  162.         end;
  163.       end;
  164.     until Quit;
  165.   ExitGraphics;
  166.   GM.ExitSVGA;
  167. end.