void Game::DrawCell(int nX, int nY, int nLeft, int nTop, int nPieceSize) { //if( nX == m_nCurrentX && nY == m_nCurrentY ) //return; SDL_Rect rect; rect.x = nLeft + nX*nPieceSize; rect.y = nTop + nY*nPieceSize; rect.w = nPieceSize; rect.h = nPieceSize; if( IsHitoriSpotMarked(m_Hitori, nX, nY) ) { if( IsAdjacentMarked(nX, nY) && m_pConfig->GetSolutionHelper() ) { DrawAdjacentMarkedSpot(rect); } else { DrawMarkedSpot(rect); } } else{ if( m_pConfig->GetSolutionHelper() ) { if( IsIsolatedSpot(nX, nY) ) { DrawIsolatedSpot(rect); } else if( IsMaybeMarked(nX, nY) ) { DrawMaybeMarkedCell(rect); } } } int nValue = GetHitoriSpotValue(m_Hitori, nX, nY); char buffer[16]; Hit_itoa(nValue, buffer, 16); int nIndent = (nPieceSize - nSDL_GetStringWidth(m_pFont, buffer))/2; nSDL_DrawString(m_pScreen, m_pFont, nLeft + nX*nPieceSize + nIndent, nTop + nY*nPieceSize + nPieceSize/2, buffer ); }
// Activation int ActivateList(Widget *w) { SDL_Surface *scr = w->construct->scr; wTHEME *t = w->construct->theme; ListArgs *args = w->args; args->isActive = 1; wMENU *m = args->menu; int ok = ACTION_CONTINUE; int db = w->displayBounds; do { DrawList(w); SDL_Flip(scr); wait_key_pressed(); if (K_CLICK() && args->menu->nItems) { int ws = nSDL_GetStringWidth(t->font, m->title); int xw = (w->bounds.w*3)/5; if (!m->title) xw = w->bounds.w - 6; else if (xw + ws + 9 > w->bounds.w) xw = w->bounds.w - ws - 9; int x = w->bounds.x + w->bounds.w - xw - 3; w->displayBounds = -1; ok=OpenMenu(w, m, x+1, 0, xw, w->bounds.y+4); w->displayBounds = db; wDrawBounds(w); if (ok == MENU_QUIT) ok = ACTION_CONTINUE; if (ok != ACTION_CONTINUE) break; while (K_ESC() || K_LEFT() || K_ENTER()); } else if (K_UP() || K_DOWN() || K_LEFT() || K_RIGHT() || K_MENU() || K_TAB() || K_SCRATCHPAD() || K_ENTER()) break; else if (any_key_pressed()) { if ((ok=wExecCallback(w, SIGNAL_KEY)) != ACTION_CONTINUE) break; SDL_Flip(scr); } } while (!K_ESC()); args->isActive = 0; return ok; }
// Dessin void DrawList(Widget *w) { SDL_Surface *scr = w->construct->scr; wTHEME *t = w->construct->theme; ListArgs *args = w->args; wMENU *m = args->menu; Uint32 c = Darker(t->color1, 60); Uint32 c2 = args->isActive? t->request_c1:t->request_c2; if (!c2) c2 = t->color1; char *s; int ws = nSDL_GetStringWidth(t->font, m->title); int xw = (w->bounds.w*3)/5; if (!m->title) xw = w->bounds.w - 6; else if (xw + ws + 9 > w->bounds.w) xw = w->bounds.w - ws - 9; int x = w->bounds.x + w->bounds.w - xw - 3; if (m->title) DrawClippedStr(scr, t->font, w->bounds.x+3, w->bounds.y+6, m->title); DrawFillRectXY(scr, x, w->bounds.y + 3, xw, 14, c2); DrawRectXY(scr, x, w->bounds.y + 3, xw, 14, c); if (!args->isActive) SDL_SetAlpha(t->menus_right, SDL_SRCALPHA, 128); DrawSurface(t->menus_right, NULL, scr, &(SDL_Rect) {x+xw-8, w->bounds.y+6, 5, 7}); if (!args->isActive) SDL_SetAlpha(t->menus_right, SDL_SRCALPHA, SDL_ALPHA_OPAQUE); if (args->nSelected) { s = wMenu_GetSelectedStr(m); SDL_Rect clip; SDL_GetClipRect(scr, &clip); SDL_SetClipRect(scr, &(SDL_Rect) {x+2, w->bounds.y, xw-11, w->bounds.h}); if (args->nSelected>1) { char str[strlen(s)+5]; sprintf(str, "%s,...", s); DrawClippedStr(scr, t->menus_font1, x+2, w->bounds.y+6, str); } else if (args->nSelected==1) DrawClippedStr(scr, t->menus_font1, x+2, w->bounds.y+6, s); SDL_SetClipRect(scr, &clip); } else { DrawClippedStr(scr, t->menus_font1, x+2 + (xw-4)/2, w->bounds.y+6, "-"); } }
void GameDrawer::DrawCell(int nX, int nY) { int nValue = GetBinarySpotValue(m_Binary, nX, nY); if( nValue < 0 ) return; if( IsBinarySpot3InRow(m_Binary, nX, nY) != BINARYLIB_NOT_MULTIPILE_INROW ) { SDL_Rect rect; rect.w = rect.h = m_pBoardMetrics->GetPieceSize(); rect.x = m_pBoardMetrics->GetXPos(nX); rect.y = m_pBoardMetrics->GetYPos(nY); SDL_FillRect(m_pSurface, &rect, SDL_MapRGB(m_pSurface->format, 255, 255, 0)); } char buffer[16]; Puz_itoa(nValue, buffer, 16); int nIndent = (m_pBoardMetrics->GetPieceSize() - nSDL_GetStringWidth(m_pFont, buffer))/2; bool bPermanent = IsBinarySpotPermanent(m_Binary, nX, nY) == BINARYLIB_SPOT_PERMANENT; nSDL_DrawString(m_pSurface, bPermanent ? m_pFontPermanent : m_pFont, m_pBoardMetrics->GetXPos(nX) + nIndent, m_pBoardMetrics->GetYPos(nY) + m_pBoardMetrics->GetPieceSize()/2, buffer); }
int OpenMenu(Widget *w, wMENU *m, int xr, int xl, int minWidth, int y) { if (!w || !m) return MENU_QUIT; if (!m->nItems || !m->items) return MENU_QUIT; SDL_Surface *scr = w->construct->scr; wTHEME *t = w->construct->theme; ListArgs *args = w->args; wITEM *itm; wMENU *menu; int x, l; SDL_Rect area; SDL_Surface *saveImage; Uint32 c = Darker(t->color1, 60); Uint32 cs1 = Darker(t->menus_c1, 15); // color selection args->cMenu = m; args->yItem = 0; args->cItem = 0; int dItems = min(args->dItems, m->nItems); if (!dItems) dItems = m->nItems; SDL_Rect clip; SDL_GetClipRect(scr, &clip); int b; int ok = ACTION_CONTINUE; // calcul de la hauteur int h = 10*dItems+2; while (h > 234) h-=10, dItems-=1; if (y+h > scr->h) y = scr->h - h; // calcul de la largeur int wd = 0; for (x=0; x < m->nItems; x++) { itm = m->items[x]; l = nSDL_GetStringWidth(t->menus_font1, itm->str); if (l > wd) wd = l; l = nSDL_GetStringWidth(t->menus_font2, itm->str); if (l > wd) wd = l; } wd += 10; if (m->nItems > dItems) wd += 7; // pour les scrollbars if (wd < minWidth) wd = minWidth; if (wd > scr->w) wd = scr->w; if (xr+wd > scr->w) { if (xl-wd > 0) xr = xl - wd; else xr = scr->w - wd; } // sauvegarde de l'image area = (SDL_Rect) {xr, y, wd, h}; saveImage = SDL_CreateRGBSurface(SDL_SWSURFACE, wd, h, 16, 0, 0, 0, 0); DrawSurface(scr, &area, saveImage, NULL); if ((ok=wExecCallback(w, SIGNAL_ACTION)) != ACTION_CONTINUE) { SDL_FreeSurface(saveImage); return ok; } do { // dessin !!! SDL_SetClipRect(scr, &area); DrawFillRect(scr, &area, t->menus_c1); DrawRect(scr, &area, c); for (x=0; x < dItems; x++) { itm = m->items[x + args->yItem]; if (x == args->cItem) DrawFillRectXY(scr, xr+1, y+1+10*x, wd-2, 10, cs1); if (itm->magicNumber == 1) { menu = (wMENU *) itm; if (wMenu_HasSelectedItemOrMenu(menu)) DrawClippedStr(scr, t->menus_font2, xr+2, y+2+10*x, menu->title); else DrawClippedStr(scr, t->menus_font1, xr+2, y+2+10*x, menu->title); DrawSurface(t->menus_right,NULL,scr, &(SDL_Rect){xr+wd - (m->nItems > dItems? 17:8), y+2+10*x, 5, 7}); } else { if (itm->isSelected) DrawClippedStr(scr, t->menus_font2, xr+2, y+2+10*x, itm->str); else DrawClippedStr(scr, t->menus_font1, xr+2, y+2+10*x, itm->str); } } if (m->nItems > dItems) DrawVScrollBar(scr, t, &area, 10*m->nItems+2, 10*args->yItem); SDL_SetClipRect(scr, &clip); // activation !!! itm = m->items[args->cItem + args->yItem]; ACTIVATION: SDL_Flip(scr); while ((any_key_pressed() && !K_CTRL()) || K_CLICK()); while (!any_key_pressed()); if (K_CLICK() || K_ENTER()) { if (K_ENTER() && args->maxSelected != 1) { ok = wExecCallback(w, SIGNAL_CLICK); break; } if (itm->magicNumber == 1) goto NEWMENU; if (args->maxSelected == 1) { if (args->nSelected) wMenu_DeselectAll(args->menu); wMenu_SelectItem(m, args->yItem + args->cItem); args->nSelected = 1; DrawSurface(saveImage, NULL, scr, &area); SDL_FreeSurface(saveImage); saveImage = NULL; ok = wExecCallback(w, K_CLICK() || K_ENTER()? SIGNAL_CLICK : SIGNAL_ACTION); break; } else if (args->maxSelected >= 0) { b = wMenu_IsSelected(m, args->yItem + args->cItem); if (!b && args->nSelected) if (args->nSelected == args->maxSelected) goto ACTIVATION; wMenu_SelectItem(m, args->yItem + args->cItem); if (b) args->nSelected--; else args->nSelected++; } if ((ok=wExecCallback(w, SIGNAL_CLICK)) != ACTION_CONTINUE) break; } else if (K_UP()) { if (!args->yItem && !args->cItem) { if (K_CTRL()) goto ACTIVATION; args->cItem = dItems-1; args->yItem = m->nItems-dItems; } else { if (args->cItem) args->cItem--; else args->yItem--; } if ((ok=wExecCallback(w, SIGNAL_ACTION)) != ACTION_CONTINUE) break; } else if (K_DOWN()) { if (args->yItem + args->cItem >= m->nItems-1) { if (K_CTRL()) goto ACTIVATION; args->cItem = 0; args->yItem = 0; } else { if (args->cItem < dItems-1) args->cItem++; else args->yItem++; } if ((ok=wExecCallback(w, SIGNAL_ACTION)) != ACTION_CONTINUE) break; } else if (K_RIGHT() && itm->magicNumber == 1) { NEWMENU:; int yI = args->yItem, cI = args->cItem; ok = OpenMenu(w, (wMENU *) itm, xr+wd-3, xr, minWidth, y+10*args->cItem); args->cMenu = m; args->yItem = yI; args->cItem = cI; if (K_ESC() || K_ENTER() || (K_CLICK() && args->maxSelected == 1) || ok != ACTION_CONTINUE) break; if ((ok=wExecCallback(w, SIGNAL_ACTION)) != ACTION_CONTINUE) break; } else if (K_LEFT()) break; } while (!K_ESC()); if (saveImage) { DrawSurface(saveImage, NULL, scr, &area); SDL_FreeSurface(saveImage); } return ok; }