Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 04-10-2009, 04:18 PM
DarkAngel DarkAngel is offline
Senior Member
 
Join Date: Sep 2002
Posts: 292
Default move and clear a piece

i'm making a chinese chess component, the pieces are put on 90 crosses, when a piece is moved, we should clear the piece on the old position, most of 90 crosses look different, what i did is to save the background or the canvas (with all broders and crosses) in a imagelist, this is done in createbglist and i put this procedure in paint procedure of the component, whenever a piece is moved, the relative bg image will be read from the imagelist and to be put on the old position of the piece moved. most of time this works fine, but....

sometimes a piece was moved away, but on the old position a piece is still there, i am wondering why and how to fix this problem.

thanks a bunch

DarkAngel
^-^
Reply With Quote
  #2  
Old 04-10-2009, 04:32 PM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default RE: move and clear a piece

Use InvalidateRect.

MrBaseball34
Hook'Em Horns!

2005 College Football National Champions
2005 College Baseball National Champions
Reply With Quote
  #3  
Old 04-10-2009, 05:28 PM
DarkAngel DarkAngel is offline
Senior Member
 
Join Date: Sep 2002
Posts: 292
Default RE: move and clear a piece

thanks for your reply.but it will refresh the canvas each time when there is a move, it looks no good.

DarkAngel
^-^
Reply With Quote
  #4  
Old 04-10-2009, 06:14 PM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default RE: move and clear a piece

No, you invalidate the rect where the piece was moved FROM.

MrBaseball34
Hook'Em Horns!

2005 College Football National Champions
2005 College Baseball National Champions
Reply With Quote
  #5  
Old 04-11-2009, 03:58 PM
DarkAngel DarkAngel is offline
Senior Member
 
Join Date: Sep 2002
Posts: 292
Default RE: move and clear a piece

i put below codes into the procesure which is to clear the old piece by drawing a bg image:
...
var
x,y: Integer;
myrect : trect;
begin
x:=(Ord(cr)-1) mod 9;
y:=(Ord(cr)-1) div 9;
bglist.Draw(Canvas, x,y, Ord(cr)-1);
myrect:=rect(x,y,x+piecesize,y+piecesize);
invalidaterect(canvas.Handle,@myrect,true);
...

but upon testing there is still the same problem. the problem does not always come up, if you have a chat window, when you transfer from this window to that one, and if you are lucky, the problem will show up, that is when you move a piece away, the old one will not disappear, but new one is appear, there will be two pieces you can download the new demo from www.qc2z.cn/down/project1.zip

thank u

any ideas?

DarkAngel
^-^
Reply With Quote
  #6  
Old 04-11-2009, 08:36 PM
chris_w chris_w is offline
Senior Member
 
Join Date: Jan 2004
Posts: 1,397
Default RE: move and clear a piece

[pre]
InvalidateRect() just adds the rect to the region, it doesn't
cause the control to actually do anything with it.

[/pre][DELPHI]
//Try this...

procedure ProcessPaintMessages;
var
msg: TMsg;
begin
while PeekMessage(msg, 0, WM_PAINT, WM_PAINT, PM_REMOVE) do
DispatchMessage(msg);
end;

...
myrect:=rect(x,y,x+piecesize,y+piecesize);
invalidaterect(canvas.Handle,@myrect,true);
ProcessPaintMessages;
...

// Some controls are very stubborn and just won't cooperate
// with paint messages, if all else fails try putting your
// control on a TPanel. TPanel seems to solve a lot of
// painting/updating issues with other controls.

[/DELPHI][pre]
"There is a theory which states that if ever anybody discovers
exactly what the Universe is for and why it is here, it will
instantly disappear and be replaced by something even more
bizarre and inexplicable. There is another theory which states
that this has already happened."
-- Douglas Adams
[/pre]

Chris
Reply With Quote
  #7  
Old 04-12-2009, 05:17 AM
DarkAngel DarkAngel is offline
Senior Member
 
Join Date: Sep 2002
Posts: 292
Default RE: move and clear a piece

still not working

i tried to put these codes in the component or in the application, neither works.

i guess the problem is that i put the create image list procedure in the paint procedure of the component, when it is called, it may create all small images with the pieces on the crosses.

i will try to put the background image into a res file, and will create image list in Ceate procedure.

thanks anyway

DarkAngel
^-^
Reply With Quote
  #8  
Old 04-12-2009, 06:16 AM
DarkAngel DarkAngel is offline
Senior Member
 
Join Date: Sep 2002
Posts: 292
Default RE: move and clear a piece

i solved this sissue simply by adding below into paint procedure:

if (firstshow=true) then
begin
Createbglist;
firstshow:=false;
end;

thus only the first time it will create bg list, later even you shift between windows, it will not perform createbglist again.

tks

DarkAngel
^-^
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 11:27 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.