Game Development Community

Movable guiBitmapCtrl (canMove)

by James Laker (BurNinG) · in Torque Game Engine · 11/20/2007 (3:20 am) · 3 replies

Hi

I'm trying to make a guiBitmapCtrl drag-able/movable with the mouse. I've moved the all the functions needed from guiWindowCtrl to it:

In the private section of guiBitmapCtrl.h I added this:
//JL - Movable BItmaps
	bool mCanMove;
	bool mMouseMovingWin;
	Point2I mMouseDownPosition;

	RectI mOrigBounds;
	//JL - Movable BItmaps

In the public section I Added this:
// JL - Movable bitmap
   GuiControl* findHitControl(const Point2I &pt, S32 initialLayer = -1);

   void onMouseDown(const GuiEvent &event);
   void onMouseDragged(const GuiEvent &event);
	void onMouseUp(const GuiEvent &event);

   void selectWindow(void);
	// JL - Movable bitmap

On to the Cpp file in the contructor method I added:
//JL - Moveable Bitmaps
	mCanMove = true;
   mMouseMovingWin = false;
	mActive = true;
	//JL - Moveable Bitmaps

Then I added this to initPersistFields():
addField("canMove",           TypeBool,         Offset(mCanMove, GuiBitmapCtrl)); //JL - Movable Bitmaps

Then at the bottom of the CPP file I added the following methods:
GuiControl* GuiBitmapCtrl::findHitControl(const Point2I &pt, S32 initialLayer)
{
	return Parent::findHitControl(pt, initialLayer);
}

void GuiBitmapCtrl::selectWindow(void)
{
   //first make sure this window is the front most of its siblings
   GuiControl *parent = getParent();
   if (parent)
   {
      parent->pushObjectToBack(this);
   }

   //also set the first responder to be the one within this window
   setFirstResponder(mFirstResponder);
}

void GuiBitmapCtrl::onMouseDown(const GuiEvent &event)
{
   setUpdate();

   mOrigBounds = mBounds;

   mMouseDownPosition = event.mousePoint;
   Point2I localPoint = globalToLocalCoord(event.mousePoint);

   //select this window - move it to the front, and set the first responder
   selectWindow();

   GuiControl *ctrl = findHitControl(localPoint);
	if (ctrl && ctrl != this){
		mMouseMovingWin = false;
      ctrl->onMouseDown(event);
	}
	else {
		mMouseMovingWin = mCanMove;
		mouseLock();
	}

}

void GuiBitmapCtrl::onMouseDragged(const GuiEvent &event)
{
   GuiControl *parent = getParent();
   GuiCanvas *root = getRoot();
   if (!root) return;

   Point2I deltaMousePosition = event.mousePoint - mMouseDownPosition;

   Point2I newPosition = mBounds.point;
   Point2I newExtent = mBounds.extent;
	bool update = false;

   if (mMouseMovingWin && parent)
   {
      newPosition.x = getMax(0, getMin(parent->mBounds.extent.x - mBounds.extent.x, mOrigBounds.point.x + deltaMousePosition.x));
      newPosition.y = getMax(0, getMin(parent->mBounds.extent.y - mBounds.extent.y, mOrigBounds.point.y + deltaMousePosition.y));
      
		update = true;
   }

	if (update)
	{
		Point2I pos = parent->localToGlobalCoord(mBounds.point);
		[b]root->addUpdateRegion(pos, mBounds.extent);[/b] //<--- COMPILE ERRRROR
      //resize(newPosition, newExtent);
	}

}

void GuiBitmapCtrl::onMouseUp(const GuiEvent &event)
{

   event;
   mouseUnlock();

   mMouseMovingWin = false;

   GuiControl *parent = getParent();
   if (! parent)
      return;

}

But I'm getting the following errors at the Bold/Underlined line in the above method:

Error	1	error C2027: use of undefined type 'GuiCanvas'	c:\Torque\TGEA_1_0_2\engine\gui\controls\guiBitmapCtrl.cpp	259
Error	2	error C2227: left of '->addUpdateRegion' must point to class/struct/union/generic type	c:\Torque\TGEA_1_0_2\engine\gui\controls\guiBitmapCtrl.cpp	259

This was taken straight from guiWindowCtrl and I dont understand why it wont compile.
Any help will be appreciated.

James

#1
11/20/2007 (7:09 pm)
I believe you need to add at the header:
#include "gui/core/guiCanvas.h"
So it will "know" about the GuiCanvas class. Better to take all includes from guiWindowCtrl.cpp and copy it over into guiBitmapCtrl.cpp, and remove one by one to see what minimum is required.
#2
11/20/2007 (11:13 pm)
Hehe... Sometimes I can be a total idiot.
#3
11/21/2007 (12:39 am)
Anyone interested can see the resource here