#include "VegaMain.h" #include "Tournament.h" struct FontDisplay2 : Display { virtual void Paint(Draw& w, const Rect& r, const Value& q, Color ink, Color paper, dword style) const { Font fnt = Courier(14).Bold(); //Font(q, r.Height() - 2); // String txt = Font::GetFaceName(q); String txt = AsString(q); w.DrawRect(r, paper); w.DrawText(r.left + 2, r.top + (r.Height() - GetTextSize(txt, fnt).cy) / 2, txt, fnt, ink); // <- Change is here - "w." no more needed //w.DrawText(r.left + 2+1, r.top + (r.Height() - GetTextSize(txt, fnt).cy) / 2, txt, fnt, ink); // <- Change is here - "w." no more needed } }; void EditResult(One& ctrl) { ctrl.Create().MaxChars(1); } VegaTab3::VegaTab3() { CtrlLayout(*this); SizePos(); CtrlLayout(tabpair); CtrlLayout(tabinsert); tabsPairInsert.Add(tabpair, t_("New Pairing")); tabsPairInsert.Add(tabinsert, t_("Insert/Modify Result")); //id, label, width arrp.AddColumn("Board", t_("Bo."), 3) ; //0 arrp.AddColumn("White", t_("White Player"), 19).SetDisplay(Single()); //1 arrp.AddColumn("Black", t_("Black Player"), 19).SetDisplay(Single()); //2 arrp.AddColumn("ID", t_("IDW-IDB"), 4); //3 arrp.AddColumn("Edit", "code", 4).Ctrls(EditResult); //4 // arrp.AddColumn("Edit", "code", 3).Ctrls(); //3 arrp.AddColumn("Result", t_("Result"), 4); //5 // arrp.AddColumn("code", "code pairing", 5).HeaderTab().WhenAction = THISBACK1(HideTab, &arrp); //6 arrp.AddColumn("code", "code pairing", 5); //6 arrp.EvenRowColor(); arrp.SetLineCy(EditField::GetStdHeight()); arrp.WhenCtrlsAction = THISBACK(UpdateLabelResultCB); arrp.WhenEnterKey = THISBACK(StartArrayCursor); arrp.WhenLeftDouble = THISBACK(SwapColorsCB); HideTab(&arrp); //remove the column 5 arrp.Tip(t_("Double click to exchange the colors")); arrp.HeaderObject().HideTab(4); arrp.HeaderObject().HideTab(6); // tabpair spinRound <<= 1; round = TD.currentRound; spinRound.SetFont(StdFont(18).Bold()).WhenAction = THISBACK(SpinRoundCB); tabpair.optVerbose <<= true; tabpair.optVerbose.Tip(t_("Save the explanation pairing file")); tabpair.optVerbose.WhenAction = THISBACK1(SetOptionCB, 1); tabpair.optThree.WhenAction = THISBACK1(SetOptionCB, 2); tabpair.optThree.Tip(t_("Permit the same color\nthree time in a row")); tabpair.optDanubian.WhenAction = THISBACK1(SetOptionCB, 3); tabpair.optDanubian.Tip(t_("Enable the Danubian variant\nfor the dubov system")); tabpair.btnVerbose <<= THISBACK(ShowVerboseCB); tabpair.btnManual.SetImage(Vega5Img::manual() ); tabpair.btnAuto.SetImage(Vega5Img::computer() ); tabpair.btnPrint.SetImage(CtrlImg::print()); tabpair.btnVerbose.SetImage(Vega5Img::verbose()); // tabinsert tabinsert.btn0.SetLabel("0 - 1 [0]"); tabinsert.btn5.SetLabel("½ - ½ [5]"); tabinsert.btn3.SetLabel("1F - 0 [3]"); tabinsert.btn4.SetLabel("0 - 1F [4]"); tabinsert.btn1.SetLabel("1 - 0 [1]"); tabinsert.btn2.SetLabel("0F - 0F [2]"); tabinsert.btn0 <<= THISBACK1(BtnResultCB, 0); tabinsert.btn1 <<= THISBACK1(BtnResultCB, 1); tabinsert.btn2 <<= THISBACK1(BtnResultCB, 2); tabinsert.btn3 <<= THISBACK1(BtnResultCB, 3); tabinsert.btn4 <<= THISBACK1(BtnResultCB, 4); tabinsert.btn5 <<= THISBACK1(BtnResultCB, 5); tabinsert.btn7 <<= THISBACK1(BtnResultCB, 7); tabinsert.btn8 <<= THISBACK1(BtnResultCB, 8); tabinsert.btnModify.SetImage(Vega5Img::modifypair()); tabinsert.btnUpdate.SetImage(Vega5Img::update()); tabinsert.btnLoad <<= THISBACK(LoadResultCB); tabinsert.btnLoad.SetImage(CtrlImg::open()); //tabinsert.btnImprove.Disable(); tabinsert.btnImprove.SetImage(Vega5Img::colors()); tabinsert.btnUpdate <<= THISBACK1(UpdateData, 1); } void VegaTab3::SetOptionCB(int flag) { switch (flag) { case 1: if (~tabpair.optVerbose) TD.IS_SET_VERBOSE = true; else TD.IS_SET_VERBOSE = false; break; case 2: if (~tabpair.optThree) TD.PERMIT3COLOR = true; else TD.PERMIT3COLOR = false; break; case 3: if (~tabpair.optDanubian) TD.DROP_PLAYER = true; else TD.DROP_PLAYER = false; break; } } void VegaTab3::SpinRoundCB() { round = StrIntValue(AsString(~spinRound)); if (round<1 || round>TD.currentRound) { if (TD.IS_CLOSED_REGISTRATION) Exclamation(t_("Round not valid")); spinRound <<= TD.currentRound; round = TD.currentRound; // ShowPairingCB(); // return; } else if (round!=TD.currentRound && TD.STATUS_ROUND==READY_FOR_INSERTION) { Exclamation(t_("You cannot visualize other rounds.&First insert the results of the current round")); spinRound <<= TD.currentRound; round = TD.currentRound; // ShowPairingCB(); // return; } //else ShowPairingCB(); ShowPairingCB(); } void VegaTab3::HideTab(ArrayCtrl *x) { x->HeaderObject().HideTab(6); x->HeaderObject().HideTab(4); } /* bool VegaTab3::Key(dword key, int count) { if(key == K_1) { Exclamation("1"); // if (slist.IsCursor()) MoveItemCB(); return true; // key accepted } return TopWindow::Key(key, count); } */ void VegaTab3::ShowPairingCB() { int i, npair, code; int idw, idb, res; arrp.Clear(); if (TD.IS_SWISS) npair = TD.pairing[0][round]; else npair = TD.pairingRR[0][round]; for (i=1; i<=npair; i++) { if (TD.IS_SWISS) code = TD.pairing[i][round]; else code = TD.pairingRR[i][round]; TD.DecodeResult(code, &idw, &idb, &res); if (!TD.IS_SWISS && (TD.NPlayer&1) && i==npair) { } //skip, do nothing else arrp.Add( AsString(i), NFormat("%-20.20s (%4.1f)", player[idw].name, player[idw].tiebreak[SCORE]), NFormat("%-20.20s (%4.1f)", player[idb].name, player[idb].tiebreak[SCORE]), NFormat("%3d - %3d", idw, idb), "", TD.LabelResult( res, code, round), AsString (code) ); } arrp.GoBegin(); } // calling from hided editint widget void VegaTab3::UpdateLabelResultCB() { int int_row = arrp.GetCursor(); int idw, idb, newresult, board, code, res; String str; if (int_row < 0) return; //prevent the crash of the application when int_row = -1) Value v = arrp.Get(int_row, 4); if ( IsNull(v) ) return; //to avoid non digit key newresult = StrIntValue(AsString(v)); //get the inserted result code = StrIntValue(AsString(arrp.Get(int_row, 6))); //get the code result in the hided column to discover if we are changing if (newresult==9 || newresult==6) { arrp.Set( int_row, 4, ""); // clear the edit field MoveNextPair(int_row + 1); return; } if ( newresult==8 ) { Exclamation( "If you need to insert a non standard result& please use the appropriate button"); arrp.Set( int_row, 4, ""); // clear the edit field MoveNextPair(int_row + 1); return; } else { TD.DecodeResult(code, &idw, &idb, &res); // get the old result if (res!=9 && newresult!=res) { // changing an old result if (!PromptOKCancel(t_("Are you sure do you want&to change an old result?")) ) { //ask confirmation arrp.Set( int_row, 4, ""); // clear return; // go away } } str = TD.LabelResult( newresult, 0, 0) ; arrp.Set( int_row, 5, str); // set the new label result to the right arrp.Set( int_row, 4, ""); // clear the edit field arrp.Set( int_row, 6, AsString(TD.CodifyResult(idw,idb,newresult))); //set new value board = int_row + 1; //the array is zero based in contrast with the board index if (TD.IS_SWISS) TD.pairing[board][round] = TD.CodifyResult(idw,idb,newresult); //set new result else TD.pairingRR[board][round] = TD.CodifyResult(idw,idb,newresult); //set new result MoveNextPair(int_row + 1); } } /* insertedResult++; if(insertedResult%15==0) { IS_SAVED_ROUND=0; SaveFileCB(NULL, 0L, NULL); // save a new updated *.veg file } */ void VegaTab3::LoadResultCB() { int i, idw, idb, npair, res, round; String line, fn; FileSel fs; // for Linux and windows if (!TD.IS_SWISS) { Exclamation(t_("Option not available for Round Robin")); return; // no color swap } fs.Type( t_("Load result file"), "*.res").DefaultExt("res"); if(fs.ExecuteOpen()) fn = ~fs; // file selected else return; // no file selected FileIn in(fn); line = in.GetLine(); Vector field = Split( line, ' '); npair = StrIntValue(field[0]); round = StrIntValue(field[1]); if (round != TD.currentRound) { Exclamation( t_("The selected file doens't correspond to the current round!&Please choose the correct one") ); in.Close(); return; } for (i=1; i<=npair; i++) { Vector field = Split( line, ' '); idw = StrIntValue(field[0]); idb = StrIntValue(field[1]); res = StrIntValue(field[2]); TD.pairing[i][round] = TD.CodifyResult(idw,idb,res); //set result for selected round } ShowPairingCB(); in.Close(); } void VegaTab3::StartArrayCursor() { arrp.SetCursor(0); } void VegaTab3::MoveNextPair( int position) { int board, npair; String coderesult; // if (round != currentRound) return position; // there aren't missing result npair = arrp.GetCount(); board = position; while (boardZoomable(); filename = TD.PATHDIR + "verbose" + AsString(round) + ".txt" ; lineeditverbose.SetFont(Courier(11)).Set(LoadFile(filename)); filename = TD.PATHDIR + "scgr" + AsString(round) + "-0.txt" ; lineeditgroup.SetFont(Courier(11)).Set(LoadFile(filename)); } */ ShowVerboseDlg::ShowVerboseDlg(int round) { String filename; h.Horz(a, v); v << b; // << c << d; Add(h.SizePos()); filename = TD.PATHDIR + "verbose" + AsString(round) + ".txt" ; a.SetFont(Courier(11)).Set(LoadFile(filename)); filename = TD.PATHDIR + "scgr" + AsString(round) + "-0.txt" ; b.SetFont(Courier(11)).Set(LoadFile(filename)); }