#include "StdAfx.h"
#include "ResizingButton.h"

ResizingButton::ResizingButton(void)
{
}

ResizingButton::~ResizingButton(void)
{
}

int ResizingButton::OnSetCursor()
{
	SetCursor(env.resizecursor);
	return 1;
}

void ResizingButton::OnMouseMove()
{
	SkinnableButton::OnMouseMove();

	if(env.mouse.LeftButton && GetFocus()==hWnd){
		int dx = env.mouse.Screen.x-env.mouse.DragOrigin.x;
		int dy = env.mouse.Screen.y-env.mouse.DragOrigin.y;

		SkinnableWindow * wnd = (SkinnableWindow*)GetWindowLongPtr(hWndParent,GWL_USERDATA);
		wnd->SetSize(env.mouse.InitialPos.x+dx,env.mouse.InitialPos.y+dy);


	}
}

void ResizingButton::OnLButtonDown()
{
	SkinnableButton::OnLButtonDown();
	
	// save the parent's current size
	RECT rect;
	GetWindowRect(hWndParent,&rect);
	env.mouse.InitialPos.x = rect.right-rect.left;
	env.mouse.InitialPos.y = rect.bottom-rect.top;

	// save my own position
	InitialPos.x = location.X;
	InitialPos.y = location.Y;
}
