📄 sugarmemolearn.c
字号:
testingStatus.passed = 0;
testingStatus.failed = 1;
break;
}
}
else if (queue == TestingQueue){
switch(PushSelection){
case bingoControl:
if (testingStatus.failed == 0){
queue = TestingQueue;
testingStatus.bingoed = 0;
testingStatus.passed = 0;
testingStatus.failed = 0;
memoStatus.eFactor -= 0.32;
if (memoStatus.eFactor < 1.3) memoStatus.eFactor = 1.3;
memoStatus.difficulty = Difficulty(memoStatus.eFactor);
memoStatus.totalLapse += 1;
memoStatus.step = 1;
memoStatus.lastTest = today;
memoStatus.currentTest = zeroDate;
memoStatus.nextTest = today;
interval = 8 - (Int32)((memoStatus.eFactor - 1.3) * 3 / 1.2);
DateAdjust(&memoStatus.nextTest, interval);
break;
}
if ((testingStatus.bingoed + testingStatus.passed) > testingStatus.failed){
queue = TestingQueue;
testingStatus.bingoed = 0;
testingStatus.passed = 0;
testingStatus.failed = 0;
memoStatus.eFactor -= 0.54;
if (memoStatus.eFactor < 1.3) memoStatus.eFactor = 1.3;
memoStatus.difficulty = Difficulty(memoStatus.eFactor);
memoStatus.totalLapse += 1;
memoStatus.step = 1;
memoStatus.lastTest = today;
memoStatus.currentTest = zeroDate;
memoStatus.nextTest = today;
interval = 8 - (Int32)((memoStatus.eFactor - 1.3) * 3 / 1.2);
DateAdjust(&memoStatus.nextTest, interval);
break;
}
testingStatus.bingoed += 1;
break;
case passControl:
testingStatus.passed += 1;
break;
case failControl:
if (testingStatus.failed > 3){
queue = LearningQueue;
testingStatus.bingoed = 0;
testingStatus.passed = 0;
testingStatus.failed = 0;
memoStatus.eFactor -= 0.8;
if (memoStatus.eFactor < 1.3) memoStatus.eFactor = 1.3;
memoStatus.difficulty = Difficulty(memoStatus.eFactor);
memoStatus.totalLapse += 1;
memoStatus.step = 0;
memoStatus.lastTest = today;
memoStatus.currentTest = zeroDate;
memoStatus.nextTest = zeroDate;
}
else {
testingStatus.failed += 1;
}
break;
} //end switch control
}//end if failed queue
SetTestingStatus(CurrentDB, CurrentRecord, testingStatus);
SetMemorizingStatus(CurrentDB, CurrentRecord, memoStatus);
SetQueue(CurrentDB, CurrentRecord, queue);
//if (queue == TestingQueue || queue == LearningQueue)
// RemoveHeaderItem(CurrentDB, HeaderRecordIndex, 0);
//if (queue == LearningQueue){
// DmRecordInfo(CurrentDB, CurrentRecord, NULL, &item, NULL);
// AddHeaderItem(CurrentDB, LearningRecordIndex, &item);
//}
if (queue == TestingQueue){
interval = TimGetSeconds()%40;
MoveHeaderItem(CurrentDB, HeaderRecordIndex, 40 + (UInt16)interval);
}
//clear push selection
PushSelection = noSelectedControl;
}//end if testing
if (LoadWord()){
LoadControls();
DrawBanner();
FrmDrawForm(FrmGetActiveForm());
DrawCanvas();
}*/
}
Boolean LearnDoHardKey(EventType* event){
Boolean rightKeyPushed = false;
Boolean leftKeyPushed = false;
Boolean prevField = false;
Boolean nextField = false;
FormType* frmP = FrmGetActiveForm();
UInt16 controlID[WordFieldsCount];
UInt16 i, j, k, result, objectID;
SugarAppInfoType* app;
WordRecordType record;
MemHandle recordH;
switch(event ->data.keyDown.chr){
case hard1Chr:
if (Lefty) leftKeyPushed = true;
else prevField = true;
break;
case hard3Chr:
if (Lefty) prevField = true;
else leftKeyPushed = true;
break;
case hard2Chr:
if (Lefty) rightKeyPushed = true;
else nextField = true;
break;
case hard4Chr:
if (Lefty) nextField = true;
else rightKeyPushed = true;
break;
default:
break;
}
if (rightKeyPushed){
SndPlaySystemSound(sndClick);
if (GetBitMacro(controlFlag.allBits, nextControl)) {
DoControlNext();
return true;;
}
if (GetBitMacro(controlFlag.allBits, showControl)) {
DoControlShowButton();
return true;
}
if (GetBitMacro(controlFlag.allBits, bingoControl) || GetBitMacro(controlFlag.allBits, rightControl)){
if (PushSelection != noSelectedControl){
DoControlNext();
}
}
return true;
}
if (leftKeyPushed){
SndPlaySystemSound(sndClick);
if (GetBitMacro(controlFlag.allBits, rightControl)) {
if (PushSelection == rightControl) PushSelection = wrongControl;
else PushSelection = rightControl;
controlFlag.allBits = ShowRightWrong;
LoadControls();
return true;
}
if (GetBitMacro(controlFlag.allBits, bingoControl)){
if (PushSelection == bingoControl) PushSelection = passControl;
else if (PushSelection == passControl) PushSelection = failControl;
else PushSelection = bingoControl;
controlFlag.allBits = ShowBingoPassFail;
LoadControls();
return true;
}
return true;
}
if (prevField || nextField){
SndPlaySystemSound(sndClick);
if (GetBitMacro(controlFlag.allBits, showControl)) return true;
objectID = (UInt16)FrmGetControlGroupSelection(FrmGetActiveForm(), DynamicPushButtonGroup);
if (objectID == frmNoSelectedControl) return true;
app = GetAppInfoPtr(CurrentDB);
GetWordRecord(CurrentDB, CurrentRecord, &record, &recordH);
j = 0;
for (i = WordFieldQuestion; i < WordFieldsCount; i++){
if (i == DefaultAnswerField || (GetBitMacro(app -> answerPageFields.allBits, i) != 0)
&& (record.field[i] != NULL)){
controlID[j] = DynamicPushButtonStart + i;
j++;
}
}
MemPtrUnlock(app);
MemHandleUnlock(recordH);
for (k = 0; k < j; k++){
if (FrmGetObjectIndex(FrmGetActiveForm(), controlID[k]) == objectID) {
break;
}
}
if (k == j) return true;
if (prevField){
if (k == 0) result = controlID[j-1];
else result = controlID[k - 1];
}
else {
if (k == j - 1) result = controlID[0];
else result = controlID[k + 1];
}
FrmSetControlGroupSelection(FrmGetActiveForm(), DynamicPushButtonGroup, result);
CurrentAnswerField = result - DynamicPushButtonStart;
CurrentAnswerTop = 0;
DrawAnswerPane();
return true;
}
return true;
}
UInt8 Difficulty(float efactor){
UInt8 x = (UInt8)((efactor - 1.3)*50);
if (x > 100) return (UInt8) 100;
return (UInt8)(100 - x);
}
RectangleType GetCanvasBounds(){
RectangleType bounds;
FormType* frmP = FrmGetActiveForm();
UInt16 index = FrmGetObjectIndex(frmP, LearnCanvasGadget);
FrmGetObjectBounds(frmP, index, &bounds);
return bounds;
}
void Finish(){
// FrmCustomAlert(FinishedAlert, "learn", NULL, NULL);
// if (CurrentDB != NULL) DmCloseDatabase(CurrentDB);
// FrmGotoForm(MainForm);
}
void SwitchButtonOff(UInt16 controlID){
ControlType* ctl = GetObjectPtr(controlID);
CtlSetValue(ctl, 0);
CtlDrawControl(ctl);
}
void SwitchButtonOn(UInt16 controlID){
ControlType* ctl = GetObjectPtr(controlID);
CtlSetValue(ctl, 1);
CtlDrawControl(ctl);
}
void DrawBanner(){
FormType * frmP = FrmGetActiveForm();
RectangleType bounds;
Char p[20];
FontID currFont;
LearningStatus s;
MemorizingStatus ms;
UInt16 i;
Char lamp[5];
if (ShowAnswerPane == true) return;
if (HeaderRecordIndex == LearningRecordIndex){
s = GetLearningStatus(CurrentDB, CurrentRecord);
switch(s){
case FirstLook:
StrPrintF(p, "%s", "1st look");
break;
case TranslationRecollection:
StrPrintF(p, "%s", "recall");
break;
case WordRecollection:
StrPrintF(p, "%s", "2nd recall");
break;
case TranslationTest:
StrPrintF(p, "%s", "final");
break;
default:
break;
}
}
if (HeaderRecordIndex == TestingRecordIndex){
ms = GetMemorizingStatus(CurrentDB, CurrentRecord);
for (i = 0; i < 5; i++){
if (ms.difficulty <= i * 20) lamp[i] = 'H';
else if (ms.difficulty - i * 20 <= 10) lamp[i] = 'G';
else lamp[i] = 'F';
}
StrPrintF(p, "%c%c%c%c%c", lamp[0], lamp[1], lamp[2], lamp[3], lamp[4]);
}
FrmGetObjectBounds(frmP, GetObjectIndex(LearnTitleBannerGadget),&bounds);
WinEraseRectangle(&bounds, 0);
if (HeaderRecordIndex == LearningRecordIndex) currFont = FntSetFont(boldFont);
else currFont = FntSetFont(PhoneticSmallFont);
WinPushDrawState();
WinSetTextColor(UIColorGetTableEntryIndex(UIObjectSelectedFill));
WinDrawChars(p, StrLen(p), bounds.topLeft.x, bounds.topLeft.y);
WinPopDrawState();
FntSetFont(currFont);
}
void LoadAnswerTab(){
FormType* frmP;
FormType** formPP;
SugarAppInfoType* app;
WordRecordType record;
MemHandle recordH;
UInt16 xpos = 1, ypos = 147, width = 12, height = 12;
WordFields i;
app = GetAppInfoPtr(CurrentDB);
GetWordRecord(CurrentDB, CurrentRecord, &record, &recordH);
for (i = WordFieldQuestion; i < WordFieldsCount; i++){
if (i == DefaultAnswerField || (GetBitMacro(app -> answerPageFields.allBits, i) != 0)
&& (record.field[i] != NULL)){
frmP = FrmGetActiveForm();
formPP = &frmP;
fieldTab[i] = CtlNewControl((void**)formPP, DynamicPushButtonStart + i, pushButtonCtl,
fieldLabel[i], xpos, ypos, width, height, stdFont, DynamicPushButtonGroup, false);
CtlDrawControl(fieldTab[i]);
xpos += width + 1;
}
}
MemPtrUnlock(app);
MemHandleUnlock(recordH);
FrmSetControlGroupSelection(FrmGetActiveForm(), DynamicPushButtonGroup, DynamicPushButtonStart + DefaultAnswerField);
}
void ClearAnswerTab(){
FormType* frmP;
FormType** formPP;
UInt16 index;
WordFields i;
SugarAppInfoType* app;
WordRecordType record;
MemHandle recordH;
app = GetAppInfoPtr(CurrentDB);
GetWordRecord(CurrentDB, CurrentRecord, &record, &recordH);
for (i = WordFieldQuestion; i < WordFieldsCount; i++){
if (i == DefaultAnswerField || (GetBitMacro(app -> answerPageFields.allBits, i) != 0)
&& (record.field[i] != NULL)){
frmP = FrmGetActiveForm();
index = FrmGetObjectIndex(frmP, DynamicPushButtonStart + i);
if (index == frmInvalidObjectId) continue;
formPP = &frmP;
FrmRemoveObject(formPP, index);
}
}
MemPtrUnlock(app);
MemHandleUnlock(recordH);
WinEraseRectangle(&ToolBar, 0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -