Skip to content

Commit

Permalink
Lots of Refactoring
Browse files Browse the repository at this point in the history
Added ResizeTo and Undo menu options under Edit.

This refactoring is to shape things up for supporting multiple icons/sprites in future versions
  • Loading branch information
RetroNick2020 committed May 26, 2021
1 parent f75fa79 commit cdf4177
Show file tree
Hide file tree
Showing 9 changed files with 336 additions and 586 deletions.
4 changes: 2 additions & 2 deletions flood.pas
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ implementation

Procedure CheckRight;
begin
if xx<255 then
if xx< (RMCoreBase.GetWidth-1) then
begin
if RMCoreBase.getpixel(xx+1,yy) = ColTofill then
//IconImage[xx+1,yy] = ColTofill then
Expand Down Expand Up @@ -105,7 +105,7 @@ implementation

Procedure CheckDown;
begin
if yy<255 then
if yy<(RMCoreBase.GetHeight-1) then
begin
//If IconImage[xx,yy+1]=ColTofill then
If RMCoreBase.GetPixel(xx,yy+1)=ColTofill then
Expand Down
4 changes: 2 additions & 2 deletions rmabout.lfm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
object AboutDialog: TAboutDialog
Left = 233
Left = 1054
Height = 313
Top = 229
Top = 278
Width = 600
BorderStyle = bsDialog
Caption = 'About'
Expand Down
2 changes: 1 addition & 1 deletion rmabout.pas
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,lclintf;

Const
ProgramName ='Raster Master v1.0 Beta R11';
ProgramName ='Raster Master v1.0 Beta R12';
ProgramLicense = 'Released under MIT License';

type
Expand Down
4 changes: 2 additions & 2 deletions rmcolor.lfm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
object RMEGAColorDialog: TRMEGAColorDialog
Left = 250
Left = 806
Height = 256
Top = 218
Top = 640
Width = 415
BorderStyle = bsDialog
Caption = 'EGA Palette'
Expand Down
4 changes: 2 additions & 2 deletions rmcolorvga.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ object RMVgaColorDialog: TRMVgaColorDialog
Width = 512
BorderStyle = bsDialog
Caption = 'VGA Color'
ClientHeight = 348
ClientWidth = 512
ClientHeight = 0
ClientWidth = 0
DesignTimePPI = 120
LCLVersion = '2.0.10.0'
object ColorPalette: TColorPalette
Expand Down
78 changes: 66 additions & 12 deletions rmcore.pas
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ interface
Classes, Graphics, SysUtils,GraphUtil,Math;


//const
// MaxImagePixelWidth = 256;
// MaxImagePixelHeight = 256;

Type
TRMColorRec = Record
r : integer;
Expand All @@ -31,7 +35,8 @@ TRMPalette = class(TObject)
function GetRed(index : integer) : integer;
function GetGreen(index : integer) : integer;
function GetBlue(index : integer) : integer;
function FindColorMatch(r,g,b : integer) : integer;
function FindNearColorMatch(r,g,b : integer) : integer;
function FindExactColorMatch(r,g,b : integer) : integer;

procedure DownToVGA;
procedure DownToEGA;
Expand Down Expand Up @@ -63,6 +68,8 @@ TRMCoreBase = class(TObject)
TempImageBuf : TRMImageBuf;
UndoImageBuf : TRMImageBuf;
CurColor : integer; // current color
ImgBufWidth : integer;
ImgBufHeight : integer;

public

Expand All @@ -75,6 +82,11 @@ TRMCoreBase = class(TObject)
procedure ClearBuf(Color : integer);
procedure CopyToUndoBuf;
procedure UnDo;
procedure SetWidth(width : integer);
procedure SetHeight(height : integer);

function GetWidth : integer;
function GetHeight : integer;

end;

Expand Down Expand Up @@ -488,8 +500,8 @@ TRMCoreBase = class(TObject)



var
RMCoreBase : TRMCoreBase;
var
RMCoreBase : TRMCoreBase;

procedure GetRGBEGA64(index : integer;var cr : TRMColorREc);
procedure GetRGBVGA(index : integer;var cr : TRMColorREc);
Expand Down Expand Up @@ -638,13 +650,34 @@ procedure TRMPalette.GetColor(index : integer;var cr : TRMColorRec);
end;
end;

function TRMPalette.FindExactColorMatch(r,g,b : integer) : integer;
var
i: integer;
begin
FindExactColorMatch:=-1;
for i:=0 to GetColorCount-1 do
begin
if (r=GetRed(i)) AND (g=GetGreen(i)) AND (b=GetBlue(i)) then
begin
FindExactColorMatch:=i;
exit;
end;
end;
end;

function TRMPalette.FindColorMatch(r,g,b : integer) : integer;
function TRMPalette.FindNearColorMatch(r,g,b : integer) : integer;
var
c1,c2 : TColor;
gap,tgap : double;
i,fcm : integer;
i,fcm,ec : integer;
begin
ec:=FindExactColorMatch(r,g,b);
if ec > -1 then
begin
FindNearColorMatch:=ec;
exit;
end;

c1:=RGBToColor(r,g,b);
gap:=10000;
fcm:=0;
Expand All @@ -658,7 +691,7 @@ function TRMPalette.FindColorMatch(r,g,b : integer) : integer;
fcm:=i;
end;
end;
FindColorMatch:=fcm;
FindNearColorMatch:=fcm;
end;

procedure TRMPalette.SetColor(index : integer;cr : TRMColorRec);
Expand Down Expand Up @@ -744,11 +777,33 @@ procedure TRMPalette.UpToCGA;
Constructor TRMCoreBase.create;
begin
Palette:=TRMPalette.Create;
SetWidth(256);
SetHeight(256);
SetCurColor(1);
ClearBuf(0);
CopyToUndoBuf;
end;

procedure TRMCoreBase.SetWidth(width : integer);
begin
ImgBufWidth:=width;
end;

procedure TRMCoreBase.SetHeight(height : integer);
begin
ImgBufHeight:=height;
end;

function TRMCoreBase.GetWidth : integer;
begin
GetWidth:=ImgBufWidth;
end;

function TRMCoreBase.GetHeight : integer;
begin
GetHeight:=ImgBufHeight;
end;

procedure TRMCoreBase.SetCurColor(Color : integer);
begin
CurColor:=Color;
Expand All @@ -774,23 +829,22 @@ procedure TRMCoreBase.ClearBuf(Color : Integer);

procedure TRMCoreBase.PutPixel(x,y,Color : Integer);
begin
if (x > 255) or (y > 255) then exit;
ImageBuf.Pixel[x,y]:=Color;
if (x<0) or (x > (ImgBufWidth-1)) or (y<0) or (y > (ImgBufHeight-1)) then exit;
ImageBuf.Pixel[x,y]:=Color;
end;

procedure TRMCoreBase.PutPixel(x,y : Integer);
begin
if (x<0) or (x > 255) or (y<0) or (y > 255) then exit;
ImageBuf.Pixel[x,y]:=CurColor;
if (x<0) or (x > (ImgBufWidth-1)) or (y<0) or (y > (ImgBufHeight-1)) then exit;
ImageBuf.Pixel[x,y]:=CurColor;
end;


function TRMCoreBase.GetPixel(x,y : Integer) : Integer;
begin
GetPixel:=ImageBuf.Pixel[x,y];
GetPixel:=ImageBuf.Pixel[x,y];
end;


procedure TRMCoreBase.CopyToUndoBuf;
begin
UndoImageBuf:=ImageBuf;
Expand Down
52 changes: 46 additions & 6 deletions rmmain.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ object RMMainForm: TRMMainForm
Position = poDefault
LCLVersion = '2.0.10.0'
Scaled = False
object ActualBox: TImage
Left = 16
Height = 256
Top = 16
Width = 256
end
object HorizScroll: TScrollBar
Left = 368
Height = 32
Expand Down Expand Up @@ -316,6 +310,21 @@ object RMMainForm: TRMMainForm
Transparent = True
end
end
object Panel2: TPanel
Left = 32
Height = 281
Top = 40
Width = 288
ClientHeight = 281
ClientWidth = 288
TabOrder = 5
object ActualBox: TImage
Left = 16
Height = 256
Top = 8
Width = 256
end
end
object MainMenu1: TMainMenu
Left = 1584
Top = 216
Expand Down Expand Up @@ -389,6 +398,37 @@ object RMMainForm: TRMMainForm
end
object MenuItem1: TMenuItem
Caption = 'Edit'
object EditResizeTo: TMenuItem
Caption = 'Resize To'
object EditResizeTo8: TMenuItem
Caption = '8 X 8'
OnClick = EditResizeToNewSize
end
object EditResizeTo16: TMenuItem
Caption = '16 X 16'
OnClick = EditResizeToNewSize
end
object EditResizeTo32: TMenuItem
Caption = '32 X 32'
OnClick = EditResizeToNewSize
end
object EditResizeTo64: TMenuItem
Caption = '64 X 64'
OnClick = EditResizeToNewSize
end
object EditResizeTo128: TMenuItem
Caption = '128 X 128'
OnClick = EditResizeToNewSize
end
object EditResizeTo256: TMenuItem
Caption = '256 X 256'
OnClick = EditResizeToNewSize
end
end
object EditUndo: TMenuItem
Caption = 'Undo'
OnClick = ToolUndoIconClick
end
object EditCopy: TMenuItem
Caption = 'Copy'
OnClick = EditCopyClick
Expand Down
Loading

0 comments on commit cdf4177

Please sign in to comment.