diff --git a/src/shared/MAPDEF.pas b/src/shared/MAPDEF.pas
index 53bedb79b1c329fa632fee6755cd1a82312133e6..ceedbe3f5aaf6d36b6e98c9b011b2af261f25bc8 100644 (file)
--- a/src/shared/MAPDEF.pas
+++ b/src/shared/MAPDEF.pas
-(* Copyright (C) DooM 2D:Forever Developers
+(* Copyright (C) Doom 2D: Forever Developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
+ * the Free Software Foundation, version 3 of the License ONLY.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
function isValid (): Boolean; inline;
end;
function isValid (): Boolean; inline;
end;
- Char16 = packed array[0..15] of Char;
- Char32 = packed array[0..31] of Char;
- Char64 = packed array[0..63] of Char;
- Char100 = packed array[0..99] of Char;
- Char256 = packed array[0..255] of Char;
- Byte128 = packed array[0..127] of Byte;
+ TDFColor = packed record
+ public
+ r, g, b, a: Byte; // a: 0 is transparent, 255 is opaque
+
+ public
+ constructor Create (ar, ag, ab: LongInt; aa: LongInt=0);
+
+ function isTransparent (): Boolean; inline;
+ function isOpaque (): Boolean; inline;
+ function isBlack (): Boolean; inline;
+ function isWhite (): Boolean; inline;
+ end;
{$INCLUDE mapdef.inc}
// various helpers to access map structures
type
{$INCLUDE mapdef.inc}
// various helpers to access map structures
type
+ TDynFieldHelper = class helper for TDynField
+ public
+ function getRGBA (): TDFColor; inline;
+ procedure setRGBA (const v: TDFColor); inline;
+
+ public
+ property rgba: TDFColor read getRGBA write setRGBA; // for `TColor`
+ end;
+
TDynRecordHelper = class helper for TDynRecord
private
function getFieldWithType (const aname: AnsiString; atype: TDynField.TType): TDynField; inline;
TDynRecordHelper = class helper for TDynRecord
private
function getFieldWithType (const aname: AnsiString; atype: TDynField.TType): TDynField; inline;
function TDFSize.isZero (): Boolean; inline; begin result := (w = 0) and (h = 0); end;
function TDFSize.isValid (): Boolean; inline; begin result := (w > 0) and (h > 0); end;
function TDFSize.isZero (): Boolean; inline; begin result := (w = 0) and (h = 0); end;
function TDFSize.isValid (): Boolean; inline; begin result := (w > 0) and (h > 0); end;
+constructor TDFColor.Create (ar, ag, ab: LongInt; aa: LongInt=0);
+begin
+ if (ar < 0) then r := 0 else if (ar > 255) then r := 255 else r := Byte(ar);
+ if (ag < 0) then g := 0 else if (ag > 255) then g := 255 else g := Byte(ag);
+ if (ab < 0) then b := 0 else if (ab > 255) then b := 255 else b := Byte(ab);
+ if (aa < 0) then a := 0 else if (aa > 255) then a := 255 else a := Byte(aa);
+end;
+function TDFColor.isTransparent (): Boolean; inline; begin result := (a = 0); end;
+function TDFColor.isOpaque (): Boolean; inline; begin result := (a = 255); end;
+function TDFColor.isBlack (): Boolean; inline; begin result := (r = 0) and (g = 0) and (b = 0); end;
+function TDFColor.isWhite (): Boolean; inline; begin result := (r = 255) and (g = 255) and (b = 255); end;
+
+
+// ////////////////////////////////////////////////////////////////////////// //
+function TDynFieldHelper.getRGBA (): TDFColor; inline; begin result := TDFColor.Create(red, green, blue, alpha); end;
+procedure TDynFieldHelper.setRGBA (const v: TDFColor); inline; begin red := v.r; green := v.g; blue := v.b; alpha := v.a; end;
+
// ////////////////////////////////////////////////////////////////////////// //
function TDynRecordHelper.getUserPanelId (): Integer; inline;
// ////////////////////////////////////////////////////////////////////////// //
function TDynRecordHelper.getUserPanelId (): Integer; inline;
begin
fld := field[aname];
if (fld = nil) then raise Exception.Create(Format('field ''%s'' not found in record ''%s'' of type ''%s''', [aname, typeName, id]));
begin
fld := field[aname];
if (fld = nil) then raise Exception.Create(Format('field ''%s'' not found in record ''%s'' of type ''%s''', [aname, typeName, id]));
- if (fld.baseType <> TPoint) then raise Exception.Create(Format('field ''%s'' in record ''%s'' of type ''%s'' has invalid data type', [aname, typeName, id]));
+ if (fld.baseType <> fld.TType.TPoint) then raise Exception.Create(Format('field ''%s'' in record ''%s'' of type ''%s'' has invalid data type', [aname, typeName, id]));
result := TDFPoint.Create(fld.ival, fld.ival2);
end;
result := TDFPoint.Create(fld.ival, fld.ival2);
end;
begin
fld := field[aname];
if (fld = nil) then raise Exception.Create(Format('field ''%s'' not found in record ''%s'' of type ''%s''', [aname, typeName, id]));
begin
fld := field[aname];
if (fld = nil) then raise Exception.Create(Format('field ''%s'' not found in record ''%s'' of type ''%s''', [aname, typeName, id]));
- if (fld.baseType <> TSize) and (fld.baseType <> TPoint) then raise Exception.Create(Format('field ''%s'' in record ''%s'' of type ''%s'' has invalid data type', [aname, typeName, id]));
+ if (fld.baseType <> fld.TType.TSize) and (fld.baseType <> fld.TType.TPoint) then raise Exception.Create(Format('field ''%s'' in record ''%s'' of type ''%s'' has invalid data type', [aname, typeName, id]));
result := TDFSize.Create(fld.ival, fld.ival2);
end;
result := TDFSize.Create(fld.ival, fld.ival2);
end;