Files
Work/drums/DrumControl.cpp
2024-08-07 09:16:27 -04:00

127 lines
4.1 KiB
C++

#include <drums/DrumControl.hpp>
#include <common/control.hpp>
char DrumControl::smszClassName[]={"DRUMCONTROL"};
DrumControl::DrumControl(GUIWindow &parent)
{
mPaintHandler.setCallback(this,&DrumControl::paintHandler);
mCreateHandler.setCallback(this,&DrumControl::createHandler);
mDestroyHandler.setCallback(this,&DrumControl::destroyHandler);
mSizeHandler.setCallback(this,&DrumControl::sizeHandler);
insertHandler(VectorHandler::CreateHandler,&mCreateHandler);
insertHandler(VectorHandler::PaintHandler,&mPaintHandler);
insertHandler(VectorHandler::DestroyHandler,&mDestroyHandler);
insertHandler(VectorHandler::DestroyHandler,&mSizeHandler);
registerClass();
createWindow(parent);
}
DrumControl::~DrumControl()
{
removeHandler(VectorHandler::PaintHandler,&mPaintHandler);
removeHandler(VectorHandler::CreateHandler,&mCreateHandler);
removeHandler(VectorHandler::DestroyHandler,&mDestroyHandler);
insertHandler(VectorHandler::DestroyHandler,&mSizeHandler);
}
void DrumControl::registerClass()
{
HINSTANCE hInstance(processInstance());
WNDCLASS wndClass;
if(::GetClassInfo(hInstance,smszClassName,(WNDCLASS FAR*)&wndClass))return;
wndClass.style =CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS|CS_OWNDC;
wndClass.lpfnWndProc =(WNDPROC)GUIWindow::WndProc;
wndClass.cbClsExtra =0;
wndClass.cbWndExtra =sizeof(DrumControl*);
wndClass.hInstance =hInstance;
wndClass.hIcon =::LoadIcon(NULL,IDI_APPLICATION);
wndClass.hCursor =::LoadCursor(NULL,IDC_ARROW);
// wndClass.hbrBackground =(HBRUSH)::GetStockObject(BLACK_BRUSH);
wndClass.hbrBackground =(HBRUSH)::GetStockObject(NULL_BRUSH);
wndClass.lpszMenuName =0;
wndClass.lpszClassName =smszClassName;
::RegisterClass(&wndClass);
}
void DrumControl::createWindow(GUIWindow &parent)
{
Rect winRect;
mResBitmap=new ResBitmap("Magenta");
mResBitmap.disposition(PointerDisposition::Delete);
mPureDevice=new PureDevice(*this);
mPureDevice.disposition(PointerDisposition::Delete);
mDIBitmap=new DIBitmap(*mPureDevice,mResBitmap->width(),mResBitmap->height(),*mResBitmap);
mDIBitmap.disposition(PointerDisposition::Delete);
parent.clientRect(winRect);
winRect.bottom(winRect.bottom()*.75);
Window::createWindow(WS_EX_CLIENTEDGE,smszClassName,smszClassName,
WS_CHILD|WS_OVERLAPPED|WS_CLIPCHILDREN|WS_BORDER,winRect,
parent,(HMENU)0,processInstance(),(LPSTR)this);
show(SW_SHOW);
update();
}
CallbackData::ReturnType DrumControl::createHandler(CallbackData &/*someCallbackData*/)
{
mPureDevice=new PureDevice(*this);
mPureDevice.disposition(PointerDisposition::Delete);
mDIBitmap=new DIBitmap(*mPureDevice,mResBitmap->width(),mResBitmap->height(),*mResBitmap);
mDIBitmap.disposition(PointerDisposition::Delete);
createButtons();
return (CallbackData::ReturnType)FALSE;
}
CallbackData::ReturnType DrumControl::destroyHandler(CallbackData &/*someCallbackData*/)
{
return (CallbackData::ReturnType)FALSE;
}
CallbackData::ReturnType DrumControl::sizeHandler(CallbackData &/*someCallbackData*/)
{
return (CallbackData::ReturnType)FALSE;
}
CallbackData::ReturnType DrumControl::paintHandler(CallbackData &someCallbackData)
{
if(!mResBitmap.isOkay())return (CallbackData::ReturnType)FALSE;
PaintInformation *pPaintInfo=(PaintInformation*)someCallbackData.lParam();
PureDevice &pureDevice=(PureDevice&)*pPaintInfo;
mDIBitmap->copyBits(mResBitmap->ptrData(),mResBitmap->imageExtent());
mDIBitmap->stretchBlt(pureDevice,Rect(0,0,width(),height()));
return (CallbackData::ReturnType)FALSE;
}
void DrumControl::createButtons()
{
int rows=8;
int cols=16;
int spacing=2;
int width=10;
int height=10;
int startx=10;
int starty=10;
int xpos;
int ypos;
ypos=starty;
for(int row=0;row<rows;row++)
{
xpos=startx;
for(int col=0;col<cols;col++)
{
int index=(row*cols)+col;
mButtons.insert(&SmartPointer<Control>());
SmartPointer<Control> &control=mButtons[index];
control=new Control();
control.disposition(PointerDisposition::Delete);
control->createControl("BUTTON","",WS_CHILD|WS_CLIPSIBLINGS|WS_VISIBLE,Rect(xpos,ypos,xpos+width,ypos+height),*this,index);
xpos+=(width+spacing);
}
ypos+=(height+spacing);
}
}