2014-05-19 1 views
1

이 구성 요소를 양식에 놓을 때, TImage가 맵 이미지 (육각형)를 표시하지 않습니다. 구성 요소를 양식 위로 끌기 전까지는 양식 위로 끌어 놓기 전까지 표시됩니다. . (이것은 모두 desgin 모드입니다). 어떻게 항상 보여 주나요? 드래그 할 때가 아닙니다.TImage가 보이지 않음

type 
     THexMap = Class(TScrollingWinControl) 

생성자

Constructor THexMap.Create(AOwner: Tcomponent); 
begin 
    inherited Create(AOwner); 

    Width := DEFAULT_MAP_WIDTH; 
    Height := DEFAULT_MAP_HEIGHT; 

    FCanvas := timage.Create(self); 
    tempMap := timage.Create(self); 

    fcanvas.Parent := self; 
    tempmap.Parent := self; 

    fCanvas.Width := DEFAULT_MAP_WIDTH; 
    fCAnvas.Height := DEFAULT_MAP_WIDTH; 


    { Set intial property values for component } 

    //create map 
    MakeSolidMap; 

end; 

MakeSolidMap

Procedure THexMap.MakeSolidMap; 
var 
p0 : TPoint; 
looprow,Loopcol : integer; 
begin 
     TempMap.width := ((HexColumns-1) * round((1.5 * HexRadius))) + (2 * hexRadius); 
     TempMap.height := ((HexRows) * (2 * rise)) + rise; 

     With TempMap.Canvas do 
     begin 
     {set Background color} 
     brush.Color := BackColor; 
     fillrect(rect(0,0,TempMap.Width,TempMap.Height)); 

     {draw Hex's left to right/top to bottom} 
     for looprow := 1 to HexRows do 
      begin 
      for loopcol := 1 to HexColumns do 
       begin 
       {compute center coords} 
       p0 := ConvertCoords(Point(LoopCol,LoopRow),ptROWCOL); 

       {draw the hex} 
       DrawSolidHex(Tempmap,bsSolid,hexColor,psSolid,LineColor,P0.X,p0.Y,hexRadius,hex3d); 

      end; 
      end; 
     end; 
end; 

DrawSoildHex

procedure THexMap.DrawSolidHex(Target: timage; 
           FillStyle: TBrushStyle; 
           FillColor: TColor; 
           LineStyle: TPenStyle; 
           LineColor: TColor; 
           x: Integer; 
           y: Integer; 
           Radius: Integer; 
           button: Boolean); 
var 
    p0,p1,p2,p3,p4,p5,p6:TPoint; 
begin 
    p0 := Point(x,y); 

    {compute each point based on hex center} 
    p1.X := p0.X - round(Radius /2); 
    p1.Y := p0.Y - rise; 
    p2.X := p0.X + round(Radius/2); 
    p2.Y := p1.Y; 
    p3.X := p0.X + Radius; 
    p3.Y := p0.Y; 
    p4.X := p2.X; 
    p4.Y := p0.Y + rise; 
    p5.X := p1.X; 
    p5.Y := p4.Y; 
    p6.X := p0.X - Radius; 
    p6.Y := p0.Y; 

    {set color/style of lines} 
    target.canvas.Pen.Color := LineColor; 
    target.canvas.Pen.Style := LineStyle; 

    {set color/style of hex} 
    target.canvas.Brush.Color := FillColor; 
    Target.canvas.Brush.Style := FillStyle; 

    {draw the hex} 
    target.canvas.Polygon([p1,p2,p3,p4,p5,p6]); 

    {if desired, draw the boarder for the hex} 
    if button = true then 
    begin 
    with target.canvas do 
    begin 
     pen.Mode :=pmCopy; 
     pen.Color :=clWhite; 
     moveto(p5.X+1,p5.Y-1); 
     lineto(p6.X+1,p6.Y); 
     lineto(p1.X+1,p1.Y+1); 
     lineto(p2.X-1,p2.Y+1); 
     pen.Color :=clBlack; 
     lineto(p3.X-1,p3.Y); 
     lineto(p4.X-1,p4.Y-1); 
     lineto(p5.X+1,p5.Y-1); 
    end; 
    end; 
    invalidate; 
end; 

의 WndProc

procedure THexMap.WndProc(var Message: TMessage); 
const 
    DISCARD_CURRENT_ORIGIN = nil; 
var 
    R : TRect; 
    PS : PAINTSTRUCT; 
begin 
    if Message.Msg = WM_PAINT then 
    begin 
    if GetUpdateRect(Handle, nil, false) then 
    begin 
     BeginPaint(Handle, PS); 
     try 
     R := PS.rcPaint; 
     bitblt(fCanvas.Canvas.Handle, R.Left, R.Top, R.Width, R.Height, TempMap.Canvas.Handle, R.Left+FOffset.X, R.Top+FOffset.Y, SRCCOPY); 
     finally 
     EndPaint(Handle, PS); 
     end; 
    end 
    else 
     inherited; 
    end 
    else 
    inherited; 
end; 
+0

GetUpdateRect는 항상 true를 반환합니다. 업데이트 할 것이 없다면 왜 페인트 메시지가 합성 될까요? –

+0

정확합니다. 나는 그것을 추가했다. 왜냐하면 내가 육각형 중 하나를 변경하는 다른 절차를 수행 할 때 false로 설정했기 때문이다. 따라서 이미지 전체 대신 하나의 육각형 만 변경할 수있다. 하지만이게 나 한테 역효과를 낸 것 같아 ... 고마워! –

답변

3

WM_PAINT을 넘겨서 컨트롤 그리기를 수행했기 때문에 아무 것도 표시되지 않습니다. WM_PAINT을 처리 할 때 BeginPaint에 의해 반환 된 장치 컨텍스트에 아무 것도 페인트하지 않습니다. 상속 된 핸들러를 호출하지 않고 Paint을 호출 한 다음 하위를 그립니다. 따라서 아무 것도 귀하의 통제에 나타나지 않습니다.

시각적 컨트롤을 사용하여 VCL에 페인트를 적용하거나 컨트롤을 직접 페인트 할 수도 있습니다. 현재 두 가지를 모두 시도하고 있지만 어느 것도 달성하려고 시도하지 않았습니다!

내가 무엇을하고 있는지 전혀 알지 못하기 때문에 픽스를 제안 할 수 없습니다. 왜 시각적 컨트롤이 있고 페인트 메시지 처리기를 재정의하는지 이해가 안됩니다. 앞으로 나아 가기 위해서는 하나의 방법이나 다른 방법을 선택해야합니다.

+0

바로! 페인트를 제거하고 구성 요소를 제어하게하는 것은 물론 결국 변경해야합니다.하지만 이것이 왜 일어나는지에 대한 큰 문제는 해결되었습니다! 감사. –