Files
winapp/ChipsFormUnit.cpp
2026-06-12 22:37:02 +08:00

102 lines
2.4 KiB
C++

//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "ChipsFormUnit.h"
#include "GlobalUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "PNGButton"
#pragma link "PNGButton"
#pragma resource "*.dfm"
TChipsForm *ChipsForm = NULL;
//---------------------------------------------------------------------------
__fastcall TChipsForm::TChipsForm(TComponent* Owner)
: TForm(Owner)
{
m_aChips[0] = m_btnChip1;
m_aChips[1] = m_btnChip5;
m_aChips[2] = m_btnChip10;
m_aChips[3] = m_btnChip20;
m_aChips[4] = m_btnChip50;
m_aChips[5] = m_btnChip100;
m_aChips[6] = m_btnChip500;
m_aChips[7] = m_btnChip1k;
m_aChips[8] = m_btnChip5k;
m_aChips[9] = m_btnChip10k;
m_aValues[0] = 1;
m_aValues[1] = 5;
m_aValues[2] = 10;
m_aValues[3] = 20;
m_aValues[4] = 50;
m_aValues[5] = 100;
m_aValues[6] = 500;
m_aValues[7] = 1000;
m_aValues[8] = 5000;
m_aValues[9] = 10000;
m_iSelChip = 3;
m_nSelChip = 20;
}
//---------------------------------------------------------------------------
void __fastcall TChipsForm::ChipClick(TObject *Sender)
{
TPNGButton* pBtn = (TPNGButton*)Sender;
if(!pBtn->Down){
m_aChips[m_iSelChip]->Down = false;
pBtn->Down = true;
m_iSelChip = pBtn->Tag;
m_nSelChip = m_aValues[m_iSelChip];
}
}
//---------------------------------------------------------------------------
void __fastcall TChipsForm::FormResize(TObject *Sender)
{
int dx = m_btnChip1->Width,
dy = m_btnChip1->Height;
int col = ClientWidth / dx,
row = ClientHeight / dy;
int y = 0, ind = 0;
for(int i=0; i<row && ind<10; i++,y+=dy){
int x = 0;
for(int j=0; j<col && ind<10; j++, x+=dx, ind++){
TPNGButton* pB = m_aChips[ind];
pB->Top = y;
pB->Left = x;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TChipsForm::FormCanResize(TObject *Sender, int &NewWidth, int &NewHeight, bool &Resize)
{
int dx = m_btnChip1->Width,
dy = m_btnChip1->Height,
cx = Width - ClientWidth,
cy = Height - ClientHeight;
int col, row;
if(Width!=NewWidth){
col = (NewWidth - cx) / dx;
row = 10 / col;
if(10%col) row++;
}
else if(Height!=NewHeight){
row = (NewHeight-cy) / dy;
col = 10 / row;
if(10%row) col++;
}
else
return;
NewWidth = col * dx + cx;
NewHeight = row * dy + cy;
}
//---------------------------------------------------------------------------