• Advertisement
Sign in to follow this  

SDL Drag&Drop Windows problem

This topic is 2399 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I used C and SDL in Ubuntu Linux for graphics side for my game program and there was no problem with SDL functions in Ubuntu.However when I switched to mingw32 and Windows XP, I started having problems with Drag&Drop.The code is the same but I can't drag the image.Just when I click on somewhere, the image is Blitted to the screen.But there is no continuous motion.Here is the code:



BOOL mouse_down=false;
BOOL mouse_motion=false;
BOOL mouse_pressed=false;
BOOL mouse_up=false;
BOOL startdrag=false;


void SDL_MouseDown_Event(SDL_Event *event)
{
int x,y;

x=event->button.x;
y=event->button.y;

if(event->button.button==SDL_BUTTON_LEFT)
{
mouse_down=true;
startdrag=true;

}

}

void SDL_MouseMove_Event(SDL_Event* event)
{
int x,y;

x=(int)event->motion.x;
y=(int)event->motion.y;

if(event->motion.state==SDL_BUTTON_LEFT && startdrag)
{

SDL_Rect src;

src.h=50;
src.w=50;
src.x=x;
src.y=y;


SDL_Drag_Event(&src,x,y);

}

}

void SDL_MouseUp_Event(SDL_Event* event)
{
int x,y;
x=(int)event->button.x;
y=(int)event->button.y;

if(startdrag)
{
startdrag=false;

}

}


void SDL_Drag_Event(SDL_Rect* src,int x,int y)
{
SDL_Rect dest;

dest.x=x;
dest.y=y;
dest.w=50;
dest.h=50;

SDL_Apply_Surface(100,20,image);

SDL_BlitSurface(picture,NULL,screen,&hedef_kare);

SDL_FillRect(screen,NULL,C_WHITE);


}


void SDL_Refresh(void)
{
SDL_UpdateRect(image,0,0,0,0);


}



My Event Handling functions are in "main.c" which I am sure are working properly.Here are the Event Handling function:


do{

SDL_WaitEvent(&event);

while ( SDL_PollEvent(&event) ) {

switch(event.type)

{
case SDL_MOUSEBUTTONDOWN:
SDL_MouseDown_Event(&event);

break;

case SDL_MOUSEMOTION:
SDL_MouseMove_Event(&event);

break;

case SDL_MOUSEBUTTONUP:
SDL_MouseUp_Event(&event);

break;

case SDL_QUIT:

exit(0);
break;

case SDL_KEYDOWN:

exit(0);
break;

}
}

}while(event.type!=SDL_QUIT && event.type!=SDL_KEYDOWN);



Any suggestions?Thank you very much

Share this post


Link to post
Share on other sites
Advertisement
You don't handle the events you get from SDL_WaitEvent.

Share this post


Link to post
Share on other sites

You don't handle the events you get from SDL_WaitEvent.


Can you be more specific?You mean I should change the event handling procedure?Or should I add another "case" for SDL_WaitEvent?Thanks

Share this post


Link to post
Share on other sites
In the loop you have SDL_WaitEvent(&event). If there is no events in the event queue it will wait for an event to arrive. You never do anything with the events you get from SDL_WaitEvent so you likely miss most of the events. I think if you remove the line with SDL_WaitEvent(&event) it will work better.

Share this post


Link to post
Share on other sites

In the loop you have SDL_WaitEvent(&event). If there is no events in the event queue it will wait for an event to arrive. You never do anything with the events you get from SDL_WaitEvent so you likely miss most of the events. I think if you remove the line with SDL_WaitEvent(&event) it will work better.


It worked.Thank you very much: )

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement