From 49e095a83fbe3d82aeba3cfa88a53d1abe671678 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 19 Aug 2008 15:35:14 +0200 Subject: [PATCH] - Added missing URegions.pas - Disabled .hgignore for now --- .hgignore | 2 +- Server/URegions.pas | 229 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 230 insertions(+), 1 deletion(-) create mode 100644 Server/URegions.pas diff --git a/.hgignore b/.hgignore index 8f0665c..ef1816f 100644 --- a/.hgignore +++ b/.hgignore @@ -1,2 +1,2 @@ syntax: regexp -(? nil then + begin + nodeList := xmlElement.GetChildNodes; + for i := 0 to nodeList.Count - 1 do + begin + if nodeList.Item[i].NodeName = 'Rect' then + begin + xmlArea := TDOMElement(nodeList.Item[i]); + if TryStrToInt(xmlArea.AttribStrings['x1'], x1) and + TryStrToInt(xmlArea.AttribStrings['y1'], y1) and + TryStrToInt(xmlArea.AttribStrings['x2'], x2) and + TryStrToInt(xmlArea.AttribStrings['y2'], y2) then + begin + FAreas.Add(x1, y1, x2, y2); + end else + raise TInvalidConfigException.Create('Invalid area.'); + end; + end; + nodeList.Free; + end; +end; + +destructor TRegion.Destroy; +begin + if FAreas <> nil then FreeAndNil(FAreas); + inherited Destroy; +end; + +procedure TRegion.SetName(const AValue: string); +begin + FName := AValue; + Invalidate; +end; + +procedure TRegion.Invalidate; +begin + FOwner.Invalidate; +end; + +procedure TRegion.Serialize(AElement: TDOMElement); +var + i : Integer; + child, area: TDOMElement; +begin + TXmlHelper.WriteString(AElement, 'Name', FName); + child := TXmlHelper.AssureElement(AElement, 'Area'); + for i := 0 to FAreas.Count -1 do + begin + area := child.OwnerDocument.CreateElement('Rect'); + child.AppendChild(area); + area.AttribStrings['x1'] := IntToStr(FAreas.Rects[i].Left); + area.AttribStrings['y1'] := IntToStr(FAreas.Rects[i].Top); + area.AttribStrings['x2'] := IntToStr(FAreas.Rects[i].Right); + area.AttribStrings['y2'] := IntToStr(FAreas.Rects[i].Bottom); + end; +end; + +{ TRegionList } + +constructor TRegionList.Create(AOwner: IInvalidate); +begin + inherited Create(True); + FOwner := AOwner; +end; + +constructor TRegionList.Deserialize(AOwner: IInvalidate; AElement: TDOMElement); +var + nodelist: TDOMNodeList; + i: Integer; +begin + Create(AOwner); + nodeList := AElement.GetChildNodes; + for i := 0 to nodeList.Count - 1 do + begin + if nodeList.Item[i].NodeName = 'Region' then + Add(TRegion.Deserialize(Self, TDOMElement(nodeList.Item[i]))); + end; + nodeList.Free; +end; + +function TRegionList.IndexOf(AName: string): Integer; +var + i: Integer; +begin + Result := -1; + i := 0; + while (i < Count) and (Result = -1) do + begin + if TRegion(Items[i]).Name = AName then + Result := i; + Inc(i); + end; +end; + +function TRegionList.Find(AName: string): TRegion; +var + i: Integer; +begin + i := IndexOf(AName); + if i > -1 then + Result := TRegion(Items[i]) + else + Result := nil; +end; + +procedure TRegionList.Delete(AName: string); +var + i: Integer; +begin + i := IndexOf(AName); + if i > -1 then + inherited Delete(i); +end; + +procedure TRegionList.Invalidate; +begin + FOwner.Invalidate; +end; + +procedure TRegionList.Serialize(AElement: TDOMElement); +var + i: Integer; + xmlRegion: TDOMElement; +begin + for i := 0 to Count - 1 do + begin + xmlRegion := AElement.OwnerDocument.CreateElement('Region'); + AElement.AppendChild(xmlRegion); + TRegion(Items[i]).Serialize(xmlRegion); + end; +end; + +end. +