移动图片movepicture

来自中国的朋友,欢迎您在本版面使用中文讨论问题。请注意,如果您想得到不懂中文的人的帮助,请同时提供英文译文。
Help and discussions in Chinese.
Post Reply
liqi98136
Posts: 53
Joined: Sun Jan 17, 2010 11:37 pm

移动图片movepicture

Post by liqi98136 »

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 {};



Post Reply