Ecere SDK/eC Forums
http://www.ecere.com/forums/
Print view

移动图片movepicture
http://www.ecere.com/forums/viewtopic.php?f=30&t=41
Page 1 of 1
Author:  liqi98136 [ Wed Mar 10, 2010 8:57 am ]
Post subject:  移动图片movepicture

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



All times are UTC-05:00 Page 1 of 1