📄 recogwindow.cpp
字号:
SFXGraphicsPtr graphics(SFXGraphics::GetInstance());
if (status == BarCodeReader::STATUS_FRAME || status == BarCodeReader::STATUS_GOTBARCODE) {
_isCameraHaveData = true;
// 榞慄偺昤夋
bitmap = _barcodeReader.GetBitmap();
graphics->SetDestination(bitmap);
graphics->SetFillMode(false);
DrawFrame(graphics);
graphics->ResetDestination();
}
// 僶乕僐乕僪偐傜僨乕僞傪庢摼偟偨応崌
if (status == BarCodeReader::STATUS_GOTBARCODE) {
// 偡偱偵忣曬傪庢摼偟偰偄傞偐挷傋傞
filename = pself::GetInstance()->GetFilename(_barcodeReader.GetCode());
if (!filename.IsEmpty()) { // 偡偱偵忣曬傪庢摼偟偨傾僀僥儉側傜
StopCamera();
// XML 傪夝愅偡傞
_parser.SetParseImageUrl(true);
_parser.SetParseCustomerReviews(true);
_parser.SetParseSimilarProducts(true);
if (_parser.Parse(filename) == SFERR_NO_ERROR) {
// 寢壥昞帵僂僀儞僪僂傪奐偔
::new InformationWindow(&_parser, this);
}
// 嫮惂嵞昤夋
SFRApplication::GetInstance()->Invoke(SFXEvent(SREVT_RESPONDER_RENDER, SRP16_RENDER_INVOKE, true));
} else { // 忣曬傪庢摼偟偨偙偲偺側偄傾僀僥儉側傜
if (!_isStream) { // 楢懕儌乕僪偱側偄側傜
StopCamera();
// 僱僢僩儚乕僋愙懕
_networkDialog.Open(SGXAWSParser::GetUrl(_barcodeReader.GetCode()), true, OnNetworkEntry, this);
}
}
}
else if (status == BarCodeReader::STATUS_STOP) {
if (_isClosing) {
_barcodeReader.Terminate();
Invoke(SFXEvent(SREVT_RESPONDER_TERMINATE, SRP16_TERMINATE_INVOKE, true));
}
}
}
Void RecogWindow::DrawFrame(SFXGraphicsPtr graphics)
{
SInt16 radius = 10; // 妏偺墌敿宎
SFXRGBColor red = SFXRGBColor(0xFF, 0x99, 0x99, 0x00); // 昤夋怓
SFXRectangle rect = SFXRectangle((_previewRect.GetWidth() - BARCODE_SQUARE_SIZE) / 2, (_previewRect.GetHeight() - BARCODE_SQUARE_SIZE) / 2, BARCODE_SQUARE_SIZE, BARCODE_SQUARE_SIZE);
graphics->DrawArc(SFXArc(rect.GetX() + radius, rect.GetY() + radius, radius, 90, 90), red);
graphics->DrawArc(SFXArc(rect.GetRight() - radius, rect.GetY() + radius, radius, 0, 90), red);
graphics->DrawArc(SFXArc(rect.GetX() + radius, rect.GetBottom() - radius, radius, 180, 90), red);
graphics->DrawArc(SFXArc(rect.GetRight() - radius, rect.GetBottom() - radius, radius, 270, 90), red);
graphics->DrawLine(SFXLine(rect.GetX() + radius, rect.GetY() , rect.GetRight() - radius, rect.GetY() ), red);
graphics->DrawLine(SFXLine(rect.GetX() , rect.GetY() + radius, rect.GetX() , rect.GetBottom() - radius), red);
graphics->DrawLine(SFXLine(rect.GetX() + radius, rect.GetBottom() , rect.GetRight() - radius, rect.GetBottom() ), red);
graphics->DrawLine(SFXLine(rect.GetRight() , rect.GetY() + radius, rect.GetRight() , rect.GetBottom() - radius), red);
graphics->DrawLine(SFXLine(rect.GetX() , rect.GetY() + rect.GetHeight() / 2, rect.GetX() + 5 , rect.GetY() + rect.GetHeight() / 2), red);
graphics->DrawLine(SFXLine(rect.GetRight(), rect.GetY() + rect.GetHeight() / 2, rect.GetRight() - 5, rect.GetY() + rect.GetHeight() / 2), red);
graphics->DrawLine(SFXLine(rect.GetX() + rect.GetWidth() / 2, rect.GetY() , rect.GetX() + rect.GetWidth() / 2, rect.GetY() + 5 ), red);
graphics->DrawLine(SFXLine(rect.GetX() + rect.GetWidth() / 2, rect.GetBottom(), rect.GetX() + rect.GetWidth() / 2, rect.GetBottom() - 5), red);
}
// 僇儊儔傪掆巭偡傞
Void RecogWindow::StopCamera(Void)
{
_barcodeReader.Stop();
_isPreviewed = false;
}
// 僱僢僩儚乕僋僟僀傾儘僌偐傜偺捠抦乮static 斉乯
Void RecogWindow::OnNetworkEntry(SGRNetworkDialogSet::NotifyEnum notify, SFCError error, VoidPtr reference)
{
RecogWindowPtr(reference)->OnNetwork(notify, error);
}
// 僱僢僩儚乕僋僟僀傾儘僌偐傜偺捠抦
Void RecogWindow::OnNetwork(SGRNetworkDialogSet::NotifyEnum notify, SFCError error)
{
unused(error);
switch(notify) {
case SGRNetworkDialogSet::NOTIFY_CONNECT_START:
_isConnecting = true;
break;
case SGRNetworkDialogSet::NOTIFY_CONNECT_CANCEL:
StartCamera();
break;
case SGRNetworkDialogSet::NOTIFY_CONNECT_END:
_isConnecting = false;
_streamParsingError = ParseXML();
break;
}
}
SFCError RecogWindow::ParseXML(Void)
{
SFCError error;
SFXAnsiString str;
// 僼傽僀儖柤偺惗惉
SFXMTRandom rand;
SFUFileStream fstream;
SFBFileMgrSmp fileManager(SFBFileMgr::NewInstance());
SFXAnsiString filename;
SInt16 i;
for (i = 0; i < FILE_RETRY_TIMES; ++i) {
filename = DIR_NAME;
filename << SFXAnsiString::Format("data%d", rand.GetUInt16())
<< "_sjis" << EXTENSION_NAME;
if (fileManager->Test(filename) != SFERR_NO_ERROR) {
break;
}
}
if (i < FILE_RETRY_TIMES) {
// sjis 偵曄姺
error = Utf8toAnsiString(_networkDialog.GetText(), &str);
if (error == SFERR_NO_ERROR) {
_networkDialog.ClearText();
fileManager->Remove(filename);
error = fstream.Open(filename, _OFM_CREATE);
if (error == SFERR_NO_ERROR) {
fstream << str;
fstream.Close();
// XML 傪夝愅偡傞
_parser.SetParseImageUrl(true);
_parser.SetParseCustomerReviews(true);
_parser.SetParseSimilarProducts(true);
error = _parser.Parse(filename);
if (error == SFERR_NO_ERROR) {
error = pself::GetInstance()->AddItem(_barcodeReader.GetCode(), _parser.GetTitle(), filename);
if (error == SFERR_NO_ERROR) {
if (!_isStream) {
// 寢壥昞帵僂僀儞僪僂傪奐偔
if ((::new InformationWindow(&_parser, this)) == null) {
error = SFERR_NO_MEMORY;
}
} else {
_timecount = SFXDate::CurrentDate();
}
}
} else {
fileManager->Remove(filename);
}
} else {
SFXHelper::dbgprintf("[RecogWindow] fopen err [%d]", error);
}
}
if (error != SFERR_NO_ERROR) {
_timecount = SFXDate::CurrentDate();
}
}
else {
error = SFERR_FAILED;
}
return error;
}
// 夋柺壓偺暥帤傪峏怴偡傞偨傔偺僞僀儅乕
Void RecogWindow::OnDrawingTimer(Void) {
// RecogWindow 偑慜柺偵偁傞偐丄傑偨偼愙懕偟偰偄傞搑拞偐
if (SFRApplication::GetInstance()->GetFront() == this || _isConnecting) {
/*if (_flags & STATUS_PARSEERROR) {
if ((SFXDate::CurrentDate() - _timecount).ToSInt32() > 3) {
_flags &= ~STATUS_PARSEERROR;
} else {
_messageLeft = "[夝愅偵幐攕偟傑偟偨]";
_messageRight = "ISBN: " + _barcodeReader.GetCode();
}
} else if (_flags & STATUS_PARSEOK) {
if ((SFXDate::CurrentDate() - _timecount).ToSInt32() > 2) {
_flags &= ~STATUS_PARSEOK;
} else {
//_messageLeft = "撉傒庢傝姰椆";
_messageLeft = pself::GetInstance()->GetTitle(_barcodeReader.GetCode());
_messageRight = "ISBN: " + _barcodeReader.GetCode();
}
} else */if (_isAlreadyHaving) {
if ((SFXDate::CurrentDate() - _timecount).ToSInt32() > 2) {
_isAlreadyHaving = false;
} else {
//_messageLeft = "[偡偱偵撉傒庢傝嵪傒偱偡]";
_messageLeft = pself::GetInstance()->GetTitle(_barcodeReader.GetCode());
_messageRight = "ISBN: " + _barcodeReader.GetCode();
}
} else {
if (_isConnecting) {
_messageLeft = "愙懕拞";
_messageRight = "ISBN: " + _barcodeReader.GetCode();
} else {
_messageLeft = "撉傒庢傝拞";
_messageRight = "pself Version1.0";
}
if (_animationcount == 1) {
_messageLeft += ".";
} else if (_animationcount == 2) {
_messageLeft += "..";
} else if (_animationcount == 3) {
_messageLeft += "...";
}
++_animationcount;
_animationcount %= 4;
}
_isTimerDrawing = true; // 僞僀儅乕偵傛傞昤夋偱偁傞偙偲傪抦傜偣傞
InvalidateContent(); // 嵞昤夋
SFRApplication::GetInstance()->Invoke(SFXEvent(SREVT_RESPONDER_RENDER, SRP16_RENDER_INVOKE, false));
}
// 嵞傃僞僀儅乕偺愝掕
SFBShell::GetInstance()->SetTimer(500, OnDrawingTimerEntry, this);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -