📄 utils.c
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Module Name:
Utils.c
--*/
// Utility functions
#include "multibox.h"
#include "recog.h"
/*
* Special ALC Masks
*/
#define ALC_NOKANJI (ALC_ALL | ALC_HIRAGANA | ALC_KATAKANA)
#define ALC_SUJI (ALC_NUMERIC | ALC_NUMERIC_PUNC)
void ConnectTheDots(POINT *, int);
/******************************Public*Routine******************************\
* Recognize
*
* We do this on the LBUTTON_DOWN for a new stroke in a new box or when
* the timeout/recognize button is hit. This sends the ink off to the
* recognition thread for processing.
*
\**************************************************************************/
void Recognize(void)
{
PostThreadMessage(v_rThreadID, THRDMSG_RECOGNIZE, 0, 0);
}
// Start a new stroke
void NewStroke(int iBox)
{
// Check if we've entered a new box
if (iBox != glob.iCurrBox)
{
// We need to blow away the strokes we saved for redrawing the screen
EraseStroke();
Recognize();
}
}
// Finish up the current stroke
void Terminate(void)
{
STROKE *pstrkLocal;
STROKE *pstrkRecog;
STROKE *ptemp;
// Copy any remaining points in the raw buffer to the final buffer.
if (glob.cptOut + glob.cptRaw >= glob.maxOut)
{
POINT *ppt = (POINT *) LocalAlloc(LPTR, (glob.maxOut + 16) * sizeof(POINT));
if (ppt == (POINT *) NULL)
return;
memcpy(ppt, glob.pptOut, glob.cptOut * sizeof(POINT));
LocalFree(glob.pptOut);
glob.pptOut = ppt;
glob.maxOut += 16;
}
memcpy(&glob.pptOut[glob.cptOut], glob.aptRaw, glob.cptRaw * sizeof(POINT));
glob.cptOut += glob.cptRaw;
// Can we draw something?
if (glob.cptOut)
{
if (glob.cptRaw < glob.cptOut)
glob.cptRaw++;
ConnectTheDots(&glob.pptOut[glob.cptOut - glob.cptRaw], glob.cptRaw);
}
else
{
// This wasn't a real stroke. Eat it
glob.cptOut = 0;
return;
}
// Make a two copies. One of these will stay around until the user starts writing
// in another box. This allows for repaints and single stroke erasure. The other
// is sent to the recognizer, which will delete it.
if ((pstrkLocal = (STROKE *) LocalAlloc(LPTR, sizeof(STROKE) + glob.cptOut * sizeof(POINT))) == (STROKE *) NULL)
return;
if ((pstrkRecog = (STROKE *) LocalAlloc(LPTR, sizeof(STROKE) + glob.cptOut * sizeof(POINT))) == (STROKE *) NULL)
{
LocalFree(pstrkLocal);
return;
}
memcpy(pstrkLocal->apt, glob.pptOut, glob.cptOut * sizeof(POINT));
pstrkLocal->cpt = glob.cptOut;
pstrkLocal->iBox = 0;
pstrkLocal->xLeft = (glob.iCurrBox * BOX_SIZE) << 2;
pstrkLocal->pNext = (STROKE *) NULL;
memcpy(pstrkRecog->apt, glob.pptOut, glob.cptOut * sizeof(POINT));
pstrkRecog->cpt = glob.cptOut;
pstrkRecog->iBox = 0;
pstrkRecog->xLeft = (glob.iCurrBox * BOX_SIZE) << 2;
pstrkRecog->pNext = (STROKE *) NULL;
// Now, add the local stroke to the list of strokes
if (glob.bNoInk)
glob.bNoInk = FALSE;
ptemp = glob.pstrk;
if (ptemp == (STROKE *) NULL)
glob.pstrk = pstrkLocal;
else
{
while (ptemp->pNext)
ptemp = ptemp->pNext;
ptemp->pNext = pstrkLocal;
}
// Send the stroke to the recognizer
PostThreadMessage(v_rThreadID, THRDMSG_ADDINK, (WPARAM) 0, (LONG) pstrkRecog);
// Finally, reset for the next stroke
glob.cptOut = 0;
}
// Erase the previous box's ink.
//
void EraseRecogInk(HDC hdc, int iBox)
{
const int xOffset = BOX_SIZE * iBox;
PatBlt(hdc,
xOffset + BOX_OFFSET + 1,
BOX_OFFSET + 1,
BOX_WRITING_AREA - 2,
BOX_WRITING_AREA - 2,
PATCOPY
);
}
// Delete the current box's ink
//
void EraseStroke(void)
{
STROKE *pstrk = glob.pstrk;
STROKE *ptemp;
glob.pstrk = (STROKE *) NULL;
while(pstrk)
{
ptemp = pstrk->pNext;
LocalFree(pstrk);
pstrk = ptemp;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -