📄 recogwindow.cpp
字号:
//
// RecogWindow.cpp
//
#include "pself.hpp"
#include "pself_res.h"
#include "RecogWindow.hpp"
#include "TitleWindow.hpp"
#include "InformationWindow.hpp"
#include "SGRSoftkeyWindow.hpp"
#include "SGRSoftkeyToolbox.hpp"
#define FILE_RETRY_TIMES 64
// 榞慄偺戝偒偝
#define BARCODE_SQUARE_SIZE 146
RecogWindow::RecogWindow(Void) : SFRPlainWindow(SFRApplication::GetInstance(),
SGRSoftkeyToolbox::GetWindowPosition()), _isPreviewed(false), _isCameraHaveData(false),
_isStream(false), _isConnecting(false), _isTimerDrawing(false), _isAlreadyHaving(false),
_isClosing(false) static_throws
{
// 昤夋僴儞僪儔傪搊榐
if (static_try()) {
static_throw(
RegisterHandler(SREVT_RESPONDER_RENDER, SRP16_RENDER_CONTENT,
HANDLER_BEFORE, HANDLER_FUNCTION(OnRenderContent)));
}
// 僜僼僩僉乕偺搊榐
SGRSoftkeyWindowPtr softkey;
SGRSoftkeyWindow::Initialize(this);
static_throw(RegisterHandler(static_cast<SFCEventEnum>(SGRSoftkeyWindow::USEREVT_SOFTKEY), HANDLER_AFTER, HANDLER_FUNCTION(OnSoftkey)));
if (static_try()) {
if ((softkey = SGRSoftkeyWindow::GetInstance()) != null) {
static_throw(softkey->Register(this, SGRSoftkeyWindow::SOFTKEY_1, "楢懕"));
if (static_try()) {
static_throw(softkey->Register(this, SGRSoftkeyWindow::SOFTKEY_2, "栠傞"));
//if (static_try()) {
// static_throw(softkey->Register(this, SGRSoftkeyWindow::SOFTKEY_3, ""));
if (static_try()) {
SetReference(softkey->Bind(this));
// 僇儊儔僾儗價儏乕昤夋偺弨旛
SFXRectangleConst display(GetContentWorld());
_resultRect = _previewRect = display;
_resultRect.SetHeight(SFXGraphics::GetFontHeight(AEE_FONT_NORMAL));
_previewRect.SetHeight(display.GetHeight() - (_resultRect.GetHeight() + 1) * 3 - 2);
_previewRect.AddY(_resultRect.GetHeight() + 2);
_resultRect.Offset(0, _previewRect.GetHeight());
// 僶乕僐乕僪儕乕僟偺弶婜壔
if (_barcodeReader.Initialize(_previewRect, OnBarCodeSHP, this) == SFERR_NO_ERROR) {
StartCamera();
// 僞僀儅乕偺婲摦
SFBShell::GetInstance()->SetTimer(0, OnDrawingTimerEntry, this);
}
else {
SFXHelper::dbgprintf("Camera Initialization Failed.");
SFRApplication::Terminate();
}
}
//}
}
}
}
return;
}
Void RecogWindow::StartCamera(Void)
{
SFBShell::GetInstance()->SetTimer(100, OnStartTimerEntry, this);
}
// 僇儊儔偺婲摦傪抶傜偣傞
Void RecogWindow::OnStartTimer(Void)
{
// 僇儊儔傪僗僞乕僩偡傞
if (_barcodeReader.Start() == SFERR_NO_ERROR) {
_isPreviewed = true;
_isCameraHaveData = false;
} else {
SFXHelper::dbgprintf("Preview Failed.");
SFRApplication::Terminate();
}
}
// 僨僗僩儔僋僞乮僂傿儞僪僂攋婞帪偵幚峴乯
RecogWindow::~RecogWindow(Void)
{
// 僞僀儅乕偺廔椆
SFBShell::GetInstance()->CancelTimer(OnStartTimerEntry, this);
SFBShell::GetInstance()->CancelTimer(OnDrawingTimerEntry, this);
_barcodeReader.Terminate();
SGRSoftkeyWindow::Terminate(this);
return;
}
Void RecogWindow::Close(Void)
{
_isClosing = true;
// 僂傿儞僪僂傪暵偠傞偨傔偵僇儊儔傪掆巭偡傞乮幚嵺偵暵偠傞偺偼僇儊儔偺僐乕儖僶僢僋偺拞乯
_barcodeReader.Stop();
}
// 昤夋僴儞僪儔
HANDLER_IMPLEMENT_VOIDRENDER(RecogWindow, OnRenderContent, graphics)
{
// 僼僅儞僩偺崅偝傪庢摼
SInt16 fontHeight = SFXGraphics::GetFontHeight(AEE_FONT_NORMAL);
SFXGrid grid(0, 0); // 昤夋弶婜埵抲
if (_isTimerDrawing) { // 僞僀儅乕偑峴偆昤夋偺応崌
grid.AddY(1 + fontHeight + _previewRect.GetHeight() + 1 + 1);
graphics->FillRectangle(SFXRectangle(grid, GetContentWorld().GetWidth(), fontHeight * 2 + 1), SFXRGBColor(0xFF, 0xFF, 0xFF, 0x00));
_isTimerDrawing = false;
} else { // 捠忢偺昤夋偺応崌
// 奜榞偺昤夋
graphics->FillRectangle(GetContentWorld(), SFXRGBColor(0xFF, 0xFF, 0xFF, 0x00));
grid.AddY(1);
// 僞僀僩儖昤夋
if (_isStream) {
graphics->DrawText("僶乕僐乕僪撉傒庢傝[楢懕]", grid, SFXRGBColor(0x00, 0x00, 0x00, 0x00));
} else {
graphics->DrawText("僶乕僐乕僪撉傒庢傝", grid, SFXRGBColor(0x00, 0x00, 0x00, 0x00));
}
grid.AddY(fontHeight);
// 嬫愗傝慄偺昤夋
graphics->DrawLine(SFXLine(0, grid.GetY(), GetContentWorld().GetWidth(), grid.GetY()), SFXRGBColor(0x00, 0x00, 0x00, 0x00));
grid.AddY(_previewRect.GetHeight() + 1);
graphics->DrawLine(SFXLine(0, grid.GetY(), GetContentWorld().GetWidth(), grid.GetY()), SFXRGBColor(0x00, 0x00, 0x00, 0x00));
grid.AddY(1);
graphics->DrawText("僇儊儔弶婜壔拞", GetContentWorld(), SFXRGBColor(0x00, 0x00, 0x00, 0x00), IDF_ALIGN_CENTER);
if (_isCameraHaveData) {
graphics->BitBlt(_previewRect, _barcodeReader.GetBitmap(), SFXGrid(0, 0)); // 僇儊儔夋憸傪夋柺偵昞帵偡傞
}
}
// 忣曬, 嬫愗傝慄偺昤夋
graphics->DrawText(_messageLeft, grid, SFXRGBColor(0x00, 0x00, 0x00, 0x00));
grid.AddY(fontHeight);
graphics->DrawLine(SFXLine(0, grid.GetY(), GetContentWorld().GetWidth(), grid.GetY()), SFXRGBColor(0x00, 0x00, 0x00, 0x00));
grid.AddY(1);
graphics->DrawText(_messageRight, SFXRectangle(grid, GetContentWorld().GetWidth(), fontHeight), SFXRGBColor(0x00, 0x00, 0x00, 0x00), IDF_ALIGN_RIGHT);
return;
}
// 僜僼僩僉乕偑墴偝傟偨偲偒偺僴儞僪儔
HANDLER_IMPLEMENT_VOIDEVENT(RecogWindow, OnSoftkey, event)
{
SFRMultiDialogPtr dialog;
SFRMultiDialog::ParamRec param;
SGRSoftkeyWindowPtr softkey;
switch (event.GetP16()) {
case SGRSoftkeyWindow::SOFTKEY_1:
if (_isStream) {
if ((softkey = SGRSoftkeyWindow::GetInstance()) != null) {
static_throw(softkey->Register(this, SGRSoftkeyWindow::SOFTKEY_1, "楢懕"));
if (static_try()) {
_isStream = false;
}
}
InvalidateContent();
} else {
param.text = "楢懕儌乕僪偼尰嵼巊梡偱偒傑偣傫丅";
param.ok = "偼偄";
param.cancel = "偄偄偊";
param.focus = SFRMultiDialog::FOCUS_CANCEL;
param.image = SFBShell::GetInstance()->LoadResImage(PSELF_RES_FILE, ACCEPT);
if ((dialog = ::new SFRMultiDialog(SGRSoftkeyToolbox::GetDialogPosition(SFRMultiDialog::GetMargin(), 220), "妋擣", param)) != null) {
StopCamera();
SGRSoftkeyToolbox::OpenStandardDialog(dialog, HANDLER_FUNCTION(FromSoftkey1));
}
}
break;
case SGRSoftkeyWindow::SOFTKEY_2: // "栠傞" 僉乕
// 帺暘帺恎傪暵偠傞
Close();
break;
}
return;
}
// 楢懕儌乕僪妋擣僟僀傾儘僌偺儃僞儞偑墴偝傟偨偲偒偺僴儞僪儔
HANDLER_IMPLEMENT_VOIDDIALOG(RecogWindow, FromSoftkey1, result, dialog)
{
switch (result) {
case SRP16_OK: // "偼偄"
// 僟僀傾儘僌傪暵偠傞
SGRSoftkeyToolbox::CloseStandardDialog(dialog);
// 崱偺抜奒偱偼楢懕儌乕僪偼僒億乕僩偟側偄
break;
case SRP16_ESCAPE: // 僋儕傾乕僉乕偑墴偝傟偨
case SRP16_CANCEL: // "偄偄偊"
// 僟僀傾儘僌傪暵偠傞
SGRSoftkeyToolbox::CloseStandardDialog(dialog);
StartCamera();
break;
}
return;
}
// 僶乕僐乕僪儕乕僟偐傜偺捠抦乮static斉乯
Void RecogWindow::OnBarCodeSHP(BarCodeReader::StatusEnum status, VoidPtr reference)
{
RecogWindowPtr p(reinterpret_cast<RecogWindowPtr>(reference));
p->OnBarCode(status);
}
// 僶乕僐乕僪儕乕僟偐傜偺捠抦
Void RecogWindow::OnBarCode(BarCodeReader::StatusEnum status)
{
SFXAnsiString filename;
SFBBitmapSmp bitmap;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -