Code: Select all
import "ecere"
class Form1 : Window
{
text = "移动图片";
background = black;
borderStyle = sizable;
hasMaximize = true;
hasMinimize = true;
hasClose = true;
size = { 800, 600 };
Bitmap bmp;
Point drag , moving;
bool dragging;
bool OnLoadGraphics(void)
{
bmp = Bitmap{};
bmp.LoadT(":back.jpg", null, displaySystem);
return true;
}
void OnUnloadGraphics(void)
{
bmp.Free();
bmp = null;
}
void OnRedraw(Surface surface)
{
surface.SetForeground(white);
surface.Blit(bmp, moving.x-drag.x,moving.y-drag.y, 0,0, bmp.width, bmp.height);
}
bool OnLeftButtonDown(int x, int y, Modifiers mods)
{
dragging = true;
drag.x = moving.x = x;
drag.y = moving.y = y;
Capture();
SetMouseRange( Box { 0, 0, this.size.w-1,this.size.h-1} );
return true;
}
bool OnLeftButtonUp(int x, int y, Modifiers mods)
{
ReleaseCapture();
FreeMouseRange();
dragging = false;
moving.x=x;
moving.y=y;
Update(null);
return true;
}
/*bool OnMoving(int * x, int * y, int w, int h)
{
drag.x=x;
drag.y=y;
Update(null);
return true;
}
bool OnCreate(void)
{
drag=moving={0,0};
Update(null);
return true;
}
*/
}
Form1 form1 {};