📄 lhtouch.cpp
字号:
TouchCal.ScreenWidth /
TouchCal.xRawSpan;
Pos.y = (RawY - TouchCal.yRawMin) *
TouchCal.ScreenHeight /
TouchCal.yRawSpan;
return Pos;
}
/*--------------------------------------------------------------------------*/
// WaitForTouchState-
//
// This function is used only during calibration.
/*--------------------------------------------------------------------------*/
void TouchDevice::WaitForTouchState(PEGBOOL WantTouch)
{
PEGBOOL Touched;
PEGINT xVal;
PEGINT yVal;
while(1)
{
Touched = Scan(&xVal, &yVal);
if (WantTouch)
{
if (Touched)
{
return;
}
}
else
{
if (!Touched)
{
return;
}
}
}
}
/*--------------------------------------------------------------------------*/
/*
Calibrate
This is called by PegAppInitialize.
This routine presents the user with little boxes to touch in each
corner of the screen. From this we obtain the raw ADC readings for
each screen corner. From this it is pretty simple to scale the touch
reading into pixel coordinates required by PEG.
*/
/*--------------------------------------------------------------------------*/
extern PegBitmap gbTouchMeBitmap;
void TouchDevice::Calibrate(void)
{
PEGINT RawX;
PEGINT RawY;
PegRect TargetPos;
PEGUSHORT RawSamples[8];
PegPresentationManager *pPresent = PegThing::Presentation();
TouchCal.ScreenWidth = pPresent->mReal.Width();
TouchCal.ScreenHeight = pPresent->mReal.Height();
// Wait for the screen NOT to be touched, in case something is on the
// screen or there is some sort of problem:
WaitForTouchState(FALSE);
// Put up a message box that tells the user what to do:
TouchMesgWin *pMesgBox = new TouchMesgWin(0, 0);
pPresent->Center(pMesgBox);
pPresent->Add(pMesgBox);
// Now put a target on the screen for the user to touch:
PegIcon *pTarget = new PegIcon(&gbTouchMeBitmap);
pPresent->Add(pTarget);
// Wait for the screen to be touched, this should be touch in upper-left
// corner:
while(1)
{
if (Scan(&RawX, &RawY))
{
RawSamples[0] = RawX;
RawSamples[1] = RawY;
break;
}
}
// Change the message. This give the user an indication that we got his
// touch:
pMesgBox->SetText("Now touch the box in the upper right corner of the screen");
// Wait for not touched:
WaitForTouchState(FALSE);
// Move the target to upper right corner:
pPresent->Remove(pTarget);
TargetPos = pTarget->mReal;
TargetPos.Shift(TouchCal.ScreenWidth - gbTouchMeBitmap.wWidth - 1, 0);
pTarget->Resize(TargetPos);
pPresent->Add(pTarget);
while(1)
{
// Get a raw reading:
if (Scan(&RawX, &RawY))
{
RawSamples[2] = RawX;
RawSamples[3] = RawY;
break;
}
}
// Change the message.
pMesgBox->SetText("Now touch the box in the lower right corner of the screen");
// Wait for not touched:
WaitForTouchState(FALSE);
// Move the target to lower right corner:
pPresent->Remove(pTarget);
TargetPos.Shift(0, TouchCal.ScreenHeight - gbTouchMeBitmap.wHeight - 1);
pTarget->Resize(TargetPos);
pPresent->Add(pTarget);
while(1)
{
if (Scan(&RawX, &RawY))
{
RawSamples[4] = RawX;
RawSamples[5] = RawY;
break;
}
}
// Change the message.
pMesgBox->SetText("Finally, touch the box in the lower left corner of the screen");
// Wait for not touched:
WaitForTouchState(FALSE);
// Move the target to lower left corner:
pPresent->Remove(pTarget);
TargetPos.Shift(-(TouchCal.ScreenWidth - gbTouchMeBitmap.wWidth - 1), 0);
pTarget->Resize(TargetPos);
pPresent->Add(pTarget);
while(1)
{
if (Scan(&RawX, &RawY))
{
RawSamples[6] = RawX;
RawSamples[7] = RawY;
break;
}
}
// Get rid of the message window and target:
pPresent->Destroy(pMesgBox);
pPresent->Destroy(pTarget);
// figure out if the axis are swapped:
if (RawSamples[0] >> (ADC_BITS - 2) ==
RawSamples[2] >> (ADC_BITS - 2))
{
// These values should vary by nearly the full
// span. If the two MSBs don't change, then the x and
// y axis are swapped:
TouchCal.SwapAxis = TRUE;
// swap all of the x and y readings:
PEGSWAP(RawSamples[0], RawSamples[1]);
PEGSWAP(RawSamples[2], RawSamples[3]);
PEGSWAP(RawSamples[4], RawSamples[5]);
PEGSWAP(RawSamples[6], RawSamples[7]);
}
// OK, we have all the raw sample data. We have to adjust the raw data
// to account for the width and height of the target box,
// because the user
// isn't really touching the very edges of the screen:
PEGINT ScreenSize = TouchCal.ScreenWidth;
PEGINT PixSpan = ScreenSize - gbTouchMeBitmap.wWidth;
PEGINT CountSpan = RawSamples[2] - RawSamples[0];
PEGINT FullCountSpan = CountSpan * ScreenSize / PixSpan;
PEGINT CountAdjust = (FullCountSpan - CountSpan) / 2;
TouchCal.xRawMin = ((RawSamples[0] + RawSamples[6]) / 2) - CountAdjust;
TouchCal.xRawSpan = RawSamples[4] - RawSamples[0] + (CountAdjust * 2);
ScreenSize = TouchCal.ScreenHeight;
PixSpan = ScreenSize - gbTouchMeBitmap.wHeight;
CountSpan = RawSamples[7] - RawSamples[1];
FullCountSpan = CountSpan * ScreenSize / PixSpan;
CountAdjust = (FullCountSpan - CountSpan) / 2;
TouchCal.yRawMin = ((RawSamples[1] + RawSamples[3]) / 2) - CountAdjust;
TouchCal.yRawSpan = RawSamples[5] - RawSamples[1] + (CountAdjust * 2);
TouchCal.IsCalibrated = TRUE;
}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
// TouchMeBitmap: A bitmap file generated using PegImageConvert utilty.
//
// This presents a small target on the screen for the user to touch.
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
ROMDATA PEGUBYTE ucTouchMeBitmap[424] = {
0x1f,0x09,0x1f,0x09,0x82,0x09,0x09,0x0f,0x19,0x00,0x82,0x0f,0x09,0x09,0x83,0x09,
0x09,0x00,0x0f,0x17,0x00,0x83,0x0f,0x00,0x09,0x09,0x84,0x09,0x09,0x00,0x00,0x0f,
0x15,0x00,0x84,0x0f,0x00,0x00,0x09,0x09,0x81,0x09,0x09,0x02,0x00,0x80,0x0f,0x13,
0x00,0x80,0x0f,0x02,0x00,0x81,0x09,0x09,0x81,0x09,0x09,0x03,0x00,0x80,0x0f,0x11,
0x00,0x80,0x0f,0x03,0x00,0x81,0x09,0x09,0x81,0x09,0x09,0x04,0x00,0x80,0x0f,0x0f,
0x00,0x80,0x0f,0x04,0x00,0x81,0x09,0x09,0x81,0x09,0x09,0x05,0x00,0x80,0x0f,0x0d,
0x00,0x80,0x0f,0x05,0x00,0x81,0x09,0x09,0x81,0x09,0x09,0x06,0x00,0x80,0x0f,0x0b,
0x00,0x80,0x0f,0x06,0x00,0x81,0x09,0x09,0x81,0x09,0x09,0x07,0x00,0x80,0x0f,0x09,
0x00,0x80,0x0f,0x07,0x00,0x81,0x09,0x09,0x81,0x09,0x09,0x08,0x00,0x80,0x0f,0x07,
0x00,0x80,0x0f,0x08,0x00,0x81,0x09,0x09,0x81,0x09,0x09,0x09,0x00,0x80,0x0f,0x05,
0x00,0x80,0x0f,0x09,0x00,0x81,0x09,0x09,0x81,0x09,0x09,0x0a,0x00,0x80,0x0f,0x03,
0x00,0x80,0x0f,0x0a,0x00,0x81,0x09,0x09,0x81,0x09,0x09,0x0b,0x00,0x83,0x0f,0x00,
0x00,0x0f,0x0b,0x00,0x81,0x09,0x09,0x81,0x09,0x09,0x0c,0x00,0x81,0x0f,0x0f,0x0c,
0x00,0x81,0x09,0x09,0x81,0x09,0x09,0x0c,0x00,0x81,0x0f,0x0f,0x0c,0x00,0x81,0x09,
0x09,0x81,0x09,0x09,0x0b,0x00,0x83,0x0f,0x00,0x00,0x0f,0x0b,0x00,0x81,0x09,0x09,
0x81,0x09,0x09,0x0a,0x00,0x80,0x0f,0x03,0x00,0x80,0x0f,0x0a,0x00,0x81,0x09,0x09,
0x81,0x09,0x09,0x09,0x00,0x80,0x0f,0x05,0x00,0x80,0x0f,0x09,0x00,0x81,0x09,0x09,
0x81,0x09,0x09,0x08,0x00,0x80,0x0f,0x07,0x00,0x80,0x0f,0x08,0x00,0x81,0x09,0x09,
0x81,0x09,0x09,0x07,0x00,0x80,0x0f,0x09,0x00,0x80,0x0f,0x07,0x00,0x81,0x09,0x09,
0x81,0x09,0x09,0x06,0x00,0x80,0x0f,0x0b,0x00,0x80,0x0f,0x06,0x00,0x81,0x09,0x09,
0x81,0x09,0x09,0x05,0x00,0x80,0x0f,0x0d,0x00,0x80,0x0f,0x05,0x00,0x81,0x09,0x09,
0x81,0x09,0x09,0x04,0x00,0x80,0x0f,0x0f,0x00,0x80,0x0f,0x04,0x00,0x81,0x09,0x09,
0x81,0x09,0x09,0x03,0x00,0x80,0x0f,0x11,0x00,0x80,0x0f,0x03,0x00,0x81,0x09,0x09,
0x81,0x09,0x09,0x02,0x00,0x80,0x0f,0x13,0x00,0x80,0x0f,0x02,0x00,0x81,0x09,0x09,
0x84,0x09,0x09,0x00,0x00,0x0f,0x15,0x00,0x84,0x0f,0x00,0x00,0x09,0x09,0x83,0x09,
0x09,0x00,0x0f,0x17,0x00,0x83,0x0f,0x00,0x09,0x09,0x82,0x09,0x09,0x0f,0x19,0x00,
0x82,0x0f,0x09,0x09,0x1f,0x09,0x1f,0x09,};
PegBitmap gbTouchMeBitmap = { 0x01, 8, 32, 32, 0x000000ff, (PEGUBYTE *) ucTouchMeBitmap};
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
// Constructor
// Create top level object and add all children
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
TouchMesgWin::TouchMesgWin(PEGINT iLeft, PEGINT iTop) :
PegDialog(NULL)
{
PegRect ChildRect;
mReal.Set(iLeft, iTop, iLeft + 201, iTop + 120);
InitClient();
Add (new PegTitle("Calibrating Touch Screen", 0));
//AddStatus(PSF_MOVEABLE);
TitleObject()->SetColor(PCI_NTEXT, WHITE);
SetColor(PCI_NORMAL, 159);
ChildRect.Set(iLeft + 6, iTop + 36, iLeft + 193, iTop + 111);
mpTextBox = new PegTextBox(ChildRect, 0, FF_RECESSED|TT_COPY|TJ_CENTER|EF_WRAP, NULL);
mpTextBox->DataSet("Please touch the center of the box in the upper left corner of the screen.");
mpTextBox->SetColor(PCI_NORMAL, 195);
Add(mpTextBox);
}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
void TouchMesgWin::SetText(char *pMesg)
{
// We momentarily change the color of the text box so the user
// knows we received the touch:
mpTextBox->DataSet(pMesg);
mpTextBox->Draw();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -