Bugs d'affichage grille

This commit is contained in:
Jérôme Henry-Barnaudière - GeeHB 2023-12-19 21:39:04 +01:00
parent 3a9de9587c
commit 70436cac25
7 changed files with 186 additions and 51 deletions

View File

@ -10,6 +10,7 @@ set(SOURCES
src/shared/bFile.cpp
src/shared/keyboard.cpp
src/shared/menuBar.cpp
src/shared/scrCapture.cpp
src/position.cpp
src/element.cpp
src/tinySquare.cpp

View File

@ -28,7 +28,7 @@ extern "C" {
// App. infos
//
#define APP_NAME "sudoSolv"
#define APP_VERSION "0.1-2"
#define APP_VERSION "0.1-3"
#define APP_AUTHOR "GeeHB"
// Informations about the grid

50
src/shared/scrCapture.cpp Normal file
View File

@ -0,0 +1,50 @@
//---------------------------------------------------------------------------
//--
//-- File : scrCapture.cpp
//--
//-- Author : Jérôme Henry-Barnaudière - GeeHB
//--
//-- Project :
//--
//---------------------------------------------------------------------------
//--
//-- Description:
//--
//-- Implementation of scrCapture - Screen capture using fxlink
//--
//---------------------------------------------------------------------------
#include "scrCapture.h"
#include <gint/display.h>
#include <gint/usb.h>
#include <gint/usb-ff-bulk.h>
// Install
//
bool scrCapture::install(){
if (set_){
return false; // Already installed
}
// List of interfaces
usb_interface_t const *intf[] = { &usb_ff_bulk, NULL };
// Waiting for connexion
usb_open((usb_interface_t const **)&intf, GINT_CALL_NULL);
usb_open_wait();
// Set the hook
dupdate_set_hook(GINT_CALL(usb_fxlink_videocapture, 0));
return true;
}
// Remove
void scrCapture::remove(){
if (set_){
dupdate_set_hook(GINT_CALL_NULL);
set_ = false;
}
}
// EOF

64
src/shared/scrCapture.h Normal file
View File

@ -0,0 +1,64 @@
//---------------------------------------------------------------------------
//--
//-- File : scrCapture.h
//--
//-- Author : Jérôme Henry-Barnaudière - GeeHB
//--
//-- Project :
//--
//---------------------------------------------------------------------------
//--
//-- Description:
//--
//-- Definition of scrCapture - Screen capture using fxlink
//--
//---------------------------------------------------------------------------
#ifndef __CASIO_CALC_SCREEN_CAPTURE_h__
#define __CASIO_CALC_SCREEN_CAPTURE_h__ 1
#ifdef __cplusplus
extern "C" {
#endif // #ifdef __cplusplus
//---------------------------------------------------------------------------
//--
//-- scrCapture object - Screen capture using fxlink command -[ fxlink -iw ]
//--
//---------------------------------------------------------------------------
class scrCapture{
public:
// Construction
scrCapture(){
set_ = false;
}
// Destruction
~scrCapture(){
remove();
}
// Already installed ?
bool isSet(){
return set_;
}
// Install
bool install();
// Remove
void remove();
private:
// Members
bool set_; // Is the capture on ?
};
#ifdef __cplusplus
}
#endif // #ifdef __cplusplus
#endif // __CASIO_CALC_SCREEN_CAPTURE_h__
// EOF

View File

@ -1,4 +1,4 @@
//---------------------------------------------------------------------------
//----------------------------------------------------------------------
//--
//-- sudoSolv.cpp
//--
@ -6,7 +6,7 @@
//--
//-- App. entry point
//--
//---------------------------------------------------------------------------
//----------------------------------------------------------------------
#include "sudoku.h"
#include "menu.h"
@ -28,7 +28,6 @@ void _homeScreen();
int main(void)
{
// Launch the application
dclear(C_WHITE);
_homeScreen();
// App menus
@ -38,7 +37,7 @@ int main(void)
RECT mainRect;
menu.getRect(mainRect); // menu bar position
mainRect = {0, 0, mainRect.w, CASIO_HEIGHT - mainRect.h}; // Screen dimensions
mainRect = {0, 0, mainRect.w, CASIO_HEIGHT - mainRect.h};
//
// App. main loop
@ -66,6 +65,7 @@ int main(void)
// Modify current grid
case IDM_EDIT:{
game.display();
bool modified = game.edit();
break;
}
@ -78,6 +78,7 @@ int main(void)
// Try to find a solution
case IDM_SOLVE_FIND:
game.display();
if (!game.resolve()){
// No soluce found ...
// ... return to original grid
@ -121,7 +122,6 @@ int main(void)
//
void _createMenu(menuBar& menu){
// "File" sub menu
//menuBar* subMenu = menu.createSubMenu(); // equivalent to new menuBar()
menuBar fileMenu;
fileMenu.appendItem(IDM_FILE_NEW, IDS_FILE_NEW);
fileMenu.appendItem(IDM_FILE_PREV, IDS_FILE_PREV, ITEM_INACTIVE);
@ -133,10 +133,10 @@ void _createMenu(menuBar& menu){
menu.appendItem(IDM_EDIT, IDS_EDIT);
// "Solve" submenu
menuBar solveMenu;
solveMenu.appendItem(IDM_SOLVE_OBVIOUS, IDS_SOLVE_OBVIOUS);
solveMenu.appendItem(IDM_SOLVE_FIND, IDS_SOLVE_FIND);
menu.appendSubMenu(&solveMenu, IDM_SOLVE_SUBMENU, IDS_SOLVE_SUBMENU);
menuBar sMenu;
sMenu.appendItem(IDM_SOLVE_OBVIOUS, IDS_SOLVE_OBVIOUS);
sMenu.appendItem(IDM_SOLVE_FIND, IDS_SOLVE_FIND);
menu.appendSubMenu(&sMenu, IDM_SOLVE_SUBMENU, IDS_SOLVE_SUBMENU);
menu.addItem(ITEM_POS_RIGHT, IDM_QUIT, IDS_QUIT);
}
@ -145,8 +145,8 @@ void _createMenu(menuBar& menu){
//
void _homeScreen(){
#ifdef DEST_CASIO_CALC
dclear(C_WHITE);
dimage(0, 0, &g_homeScreen);
drect(0,0,CASIO_WIDTH, CASIO_HEIGHT - MENUBAR_DEF_HEIGHT, C_WHITE);
dimage(0,0,&g_homeScreen);
char copyright[255];
strcpy(copyright, APP_NAME);
@ -157,7 +157,10 @@ void _homeScreen(){
int w, h;
dsize(copyright, NULL, &w, &h);
dtext(CASIO_WIDTH - w - 5, CASIO_HEIGHT - MENUBAR_DEF_HEIGHT - h - 10, COLOUR_BLACK, copyright);
dtext(CASIO_WIDTH - w - 5,
CASIO_HEIGHT - MENUBAR_DEF_HEIGHT - h - 10,
COLOUR_BLACK,
copyright);
dupdate();
#endif // #ifdef DEST_CASIO_CALC

View File

@ -1,11 +1,11 @@
//---------------------------------------------------------------------------
//----------------------------------------------------------------------
//--
//-- sudoku.cpp
//--
//-- Implementation of sudoku object - Edition and resolution of a
//-- sudoku grid
//-- Implementation of sudoku object - Edition and
//-- resolution of a sudoku grid
//--
//---------------------------------------------------------------------------
//----------------------------------------------------------------------
#include "sudoku.h"
#include "shared/bFile.h"
@ -135,7 +135,8 @@ uint8_t sudoku::load(FONTCHARACTER fName){
if (car >= '0' and car <= '9'){
value = (uint8_t)(car - '0');
if (value && _checkValue(pos, value)){
elements_[pos].setValue(value, STATUS_ORIGINAL); // This value is valid at this position and is ORIGINAL
// This value is valid at this position and is ORIGINAL
elements_[pos].setValue(value, STATUS_ORIGINAL);
}
}
else{
@ -173,7 +174,9 @@ uint8_t sudoku::save(FONTCHARACTER fName){
for (lId = 0; lId < LINE_COUNT; lId++){
for (cId = 0; cId < ROW_COUNT; cId++){
pElement = &elements_[pos];
buffer[index++] = pElement->isEmpty()?'0':('0' + pElement->value()); // '0' means empty !
// '0' means empty !
buffer[index++] = pElement->isEmpty()?'0':('0' + pElement->value());
buffer[index++] = VALUE_SEPARATOR;
pos+=1; // next element
@ -219,11 +222,15 @@ bool sudoku::edit(){
while (cont){
// if sel. changed, erase previously selected element
if (prevPos != currentPos){
_drawSingleElement(prevPos.row(), prevPos.line(), elements_[prevPos].value(), BK_COLOUR, ORIGINAL_COLOUR);
_drawSingleElement(prevPos.row(), prevPos.line(),
elements_[prevPos].value(),
BK_COLOUR, ORIGINAL_COLOUR);
}
// Hilight the new value
_drawSingleElement(currentPos.row(), currentPos.line(), elements_[currentPos].value(), SEL_BK_COLOUR, SEL_TXT_COLOUR);
_drawSingleElement(currentPos.row(), currentPos.line(),
elements_[currentPos].value(),
SEL_BK_COLOUR, SEL_TXT_COLOUR);
dupdate();
prevPos = currentPos;
@ -305,7 +312,9 @@ bool sudoku::edit(){
} // while (cont)
// unselect
_drawSingleElement(currentPos.row(), currentPos.line(), elements_[currentPos].value(), BK_COLOUR, ORIGINAL_COLOUR);
_drawSingleElement(currentPos.row(), currentPos.line(),
elements_[currentPos].value(),
BK_COLOUR, ORIGINAL_COLOUR);
return modified;
}
@ -322,7 +331,7 @@ uint8_t sudoku::findObviousValues(){
do{
values = _findObviousValues();
found += values;
} while(values); // since we put some values, maybe we can guess new ones
} while(values); // since we put values, we'll search new ones
return found;
}
@ -336,19 +345,22 @@ bool sudoku::resolve(){
position pos(0, true);
uint8_t status = _findFirstEmptyPos(pos); // Start from the first empty place
// All the elements "before" the current position - pos - are set with possible/allowed values
// we'll try to put the "candidate" value (ie. the smallest possible value) at the current position
// All the elements "before" the current position - pos -
// are set with possible/allowed values
// we'll try to put the "candidate" value
// (ie. the smallest possible value) at the current position
while (POS_VALID == status){
candidate++; // Next possible value
if (candidate > VALUE_MAX){
// No possible value found at this position
// we'll have to go backward, to the last value setted
// when no position can be found (ie. all possibles values have been previously
// tested), the next pos has an invalid index, -1, and status = POS_INDEX_ERROR
// when no position can be found (ie. all possibles values
// have been previously tested), the next pos has an
// invalid index, -1, and status = POS_INDEX_ERROR
// no soluton can be found
if (POS_VALID == (status = _previousPos(pos))){
// The next candidate value is the currently used value + 1
// next candidate value is the currently used value + 1
candidate = elements_[pos].empty();
}
}
@ -360,7 +372,8 @@ bool sudoku::resolve(){
elements_[pos].setValue(candidate);
// Go to the next "empty" position
// if the grid is completed, the next pos is out of range ! (status = POS_END_OF_LIST)
// if the grid is completed, the next pos is
// out of range ! (status = POS_END_OF_LIST)
status = _findFirstEmptyPos(pos);
// At the next pos., we'll use (again) the lowest possible value
@ -446,21 +459,23 @@ void sudoku::_drawBackground(){
drect(0, 0, grid_.w, grid_.h, BK_COLOUR);
// draw thin borders
uint8_t pos;
uint8_t id;
int posX, posY;
int id;
for (id = 1; id < LINE_COUNT; id++){
pos = grid_.x + id * SQUARE_SIZE;
dline(pos, grid_.y, pos, grid_.y + GRID_SIZE, BORDER_COLOUR); // vert
dline (grid_.x, pos, grid_.x + GRID_SIZE, pos, BORDER_COLOUR); // horz
posX = grid_.x + id * SQUARE_SIZE;
posY = grid_.y + id * SQUARE_SIZE;
dline(posX, grid_.y, posX, grid_.y + GRID_SIZE, BORDER_COLOUR); // vert
dline (grid_.x, posY, grid_.x + GRID_SIZE, posY, BORDER_COLOUR); // horz
}
// and large ext. borders
uint8_t lSquare(SQUARE_SIZE * 3);
uint8_t thick(BORDER_THICK - 1);
int lSquare(SQUARE_SIZE * 3);
int thick(BORDER_THICK - 1);
for (id = 0; id <= 3; id++){
pos = grid_.x + id * lSquare;
drect(pos, grid_.y, pos + thick, grid_.y + GRID_SIZE, BORDER_COLOUR); // vert
drect(grid_.x, pos, grid_.x + GRID_SIZE, pos + thick, BORDER_COLOUR); // horz
posX = grid_.x + id * lSquare;
posY = grid_.y + id * lSquare;
drect(posX, grid_.y, posX + thick, grid_.y + GRID_SIZE, BORDER_COLOUR); // vert
drect(grid_.x, posY, grid_.x + GRID_SIZE, posY + thick, BORDER_COLOUR); // horz
}
}
@ -474,7 +489,9 @@ void sudoku::_drawContent(){
for (row = 0; row < ROW_COUNT; row++){
pElement = &elements_[pos];
if (!pElement->isEmpty()){
_drawSingleElement(row, line, pElement->value(), BK_COLOUR, (pElement->isOriginal()?ORIGINAL_COLOUR:(pElement->isObvious()?OBVIOUS_COLOUR:TXT_COLOUR)));
_drawSingleElement(row, line,
pElement->value(), BK_COLOUR,
(pElement->isOriginal()?ORIGINAL_COLOUR:(pElement->isObvious()?OBVIOUS_COLOUR:TXT_COLOUR)));
}
pos+=1; // next element
}
@ -489,8 +506,8 @@ void sudoku::_drawContent(){
// @txtColour : text colour
//
void sudoku::_drawSingleElement(uint8_t row, uint8_t line, uint8_t value, int bkColour, int txtColour){
uint8_t x(grid_.x + row * SQUARE_SIZE + BORDER_THICK);
uint8_t y(grid_.y + line * SQUARE_SIZE + BORDER_THICK);
uint16_t x(grid_.x + row * SQUARE_SIZE + BORDER_THICK);
uint16_t y(grid_.y + line * SQUARE_SIZE + BORDER_THICK);
// Erase background
drect(x, y, x + INT_SQUARE_SIZE, y + INT_SQUARE_SIZE, bkColour);
@ -506,8 +523,8 @@ void sudoku::_drawSingleElement(uint8_t row, uint8_t line, uint8_t value, int bk
dsize(sVal, NULL, &w, &h);
// Center the text
uint8_t dx(1 + (INT_SQUARE_SIZE - w) / 2);
uint8_t dy(1 + (INT_SQUARE_SIZE - h) / 2);
uint16_t dx(1 + (INT_SQUARE_SIZE - w) / 2);
uint16_t dy(1 + (INT_SQUARE_SIZE - h) / 2);
dtext_opt(x + dx, y + dy, txtColour, bkColour, DTEXT_LEFT, DTEXT_TOP, sVal, 1);
}
}
@ -615,7 +632,7 @@ uint8_t sudoku::_setObviousValueInLines(position& pos, uint8_t value){
CPOINT firstPos(tSquares_[firstID].findValue(elements_, value));
CPOINT secondPos(tSquares_[secondID].findValue(elements_, value));
// No for both them or yes for both
// No for both of them or yes for both
if ((-1 == firstPos.line && -1 == secondPos.line) || (-1 != firstPos.line && -1 != secondPos.line)){
return 0;
}
@ -702,7 +719,7 @@ uint8_t sudoku::_setObviousValueInRows(position& pos, uint8_t value){
CPOINT firstPos(tSquares_[firstID].findValue(elements_, value));
CPOINT secondPos(tSquares_[secondID].findValue(elements_, value));
// No for both them or yes for both
// No for both of them or yes for both
if ((-1 == firstPos.row && -1 == secondPos.row) || (-1 != firstPos.row && -1 != secondPos.row)){
return 0;
}

View File

@ -1,11 +1,11 @@
//---------------------------------------------------------------------------
//----------------------------------------------------------------------
//--
//-- sudoku.h
//--
//-- Definition of sudoku object - Edition and resolution of a
//-- sudoku grid
//--
//---------------------------------------------------------------------------
//----------------------------------------------------------------------
#ifndef __S_SOLVER_SUDOKU_h__
#define __S_SOLVER_SUDOKU_h__ 1
@ -64,7 +64,7 @@ public:
#ifdef DEST_CASIO_CALC
// edit() : Edit / modify the current grid
//
// @return : true if grid has been modified or false if left unchanged
// @return : true if grid has been modified or false if unchanged
//
bool edit();
#endif // #ifdef DEST_CASIO_CALC
@ -114,12 +114,12 @@ private:
//
bool _checkRow(position& pos, uint8_t value);
// _checTinySquare() : Can we put the value in the current tinySquare ?
// _checTinySquare() : Can we put the value in this tinySquare ?
//
// @pos : position
// @value : Check this value
//
// @return : true if the given value is valid in the given tinySquare
// @return : true if the given value is valid in the tinySquare
//
bool _checkTinySquare(position& pos, uint8_t value){
return (false == tSquares_[pos.squareID()].inMe(elements_, value)); // Is the value in the tinySquare ?