completed picross
@@ -1,3 +1,3 @@
|
|||||||
Picross.port = 9980
|
Picross.port = 9980
|
||||||
Picross.dataRoot = ${application.configDir}bin/data/
|
Picross.dataRoot = ${application.configDir}data/
|
||||||
Picross.extjsRoot = ${application.configDir}../../testsuite/bin/
|
Picross.extjsRoot = ${application.configDir}../../testsuite/bin/
|
BIN
WebWidgets/ExtJS/samples/Picross/data/cancel.png
Normal file
After Width: | Height: | Size: 4.2 KiB |
BIN
WebWidgets/ExtJS/samples/Picross/data/cancelgrey.png
Normal file
After Width: | Height: | Size: 3.9 KiB |
Before Width: | Height: | Size: 361 B After Width: | Height: | Size: 361 B |
Before Width: | Height: | Size: 167 B After Width: | Height: | Size: 167 B |
BIN
WebWidgets/ExtJS/samples/Picross/data/select.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
WebWidgets/ExtJS/samples/Picross/data/selectgrey.png
Normal file
After Width: | Height: | Size: 3.9 KiB |
Before Width: | Height: | Size: 126 B After Width: | Height: | Size: 126 B |
@@ -0,0 +1 @@
|
|||||||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>eeebbbbbb<EFBFBD><EFBFBD><EFBFBD>eee<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>eeeeee<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>eeeeee<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>eee
|
@@ -170,8 +170,9 @@ protected:
|
|||||||
if (!_helpRequested)
|
if (!_helpRequested)
|
||||||
{
|
{
|
||||||
unsigned short port = (unsigned short) config().getInt("Picross.port", 9980);
|
unsigned short port = (unsigned short) config().getInt("Picross.port", 9980);
|
||||||
std::string data = config().getString("Picross.dataRoot", ".");
|
std::string data = config().getString("Picross.dataRoot", config().expand("${application.configDir}img/"));
|
||||||
std::string extJSDir = config().getString("Picross.extjsRoot", ".");
|
std::string extJSDir = config().getString("Picross.extjsRoot", config().expand("${application.configDir}../../testsuite/bin/"));
|
||||||
|
std::string puzzleDir = config().getString("Picross.puzzles", config().expand("${application.configDir}puzzles/"));
|
||||||
Poco::Path aPath(data);
|
Poco::Path aPath(data);
|
||||||
aPath.makeAbsolute();
|
aPath.makeAbsolute();
|
||||||
aPath.makeDirectory();
|
aPath.makeDirectory();
|
||||||
@@ -185,13 +186,20 @@ protected:
|
|||||||
if (!extJSFile.exists() || extJSFile.isFile())
|
if (!extJSFile.exists() || extJSFile.isFile())
|
||||||
throw Poco::Util::InvalidArgumentException("extjsRoot is either a file or doesn't exist: must be directory!");
|
throw Poco::Util::InvalidArgumentException("extjsRoot is either a file or doesn't exist: must be directory!");
|
||||||
|
|
||||||
|
Poco::Path puzzle(puzzleDir);
|
||||||
|
puzzle.makeAbsolute();
|
||||||
|
puzzle.makeDirectory();
|
||||||
|
Poco::File puzzleFile(puzzle);
|
||||||
|
if (!puzzleFile.exists() || puzzleFile.isFile())
|
||||||
|
throw Poco::Util::InvalidArgumentException("puzzles directory is either a file or doesn't exist: must be directory!");
|
||||||
|
|
||||||
ResourceManager::Ptr pRM = new ResourceManager();
|
ResourceManager::Ptr pRM = new ResourceManager();
|
||||||
ExtJS::Utility::initialize(pRM, Poco::Path("/extjs"));
|
ExtJS::Utility::initialize(pRM, Poco::Path("/extjs"));
|
||||||
SharedPtr<WebApplication> pWebApp = new WebApplication(Poco::URI("/"), pRM);
|
SharedPtr<WebApplication> pWebApp = new WebApplication(Poco::URI("/"), pRM);
|
||||||
LookAndFeel::Ptr laf(new LookAndFeel());
|
LookAndFeel::Ptr laf(new LookAndFeel());
|
||||||
Poco::WebWidgets::ExtJS::Utility::initialize(laf);
|
Poco::WebWidgets::ExtJS::Utility::initialize(laf);
|
||||||
pWebApp->setLookAndFeel(laf);
|
pWebApp->setLookAndFeel(laf);
|
||||||
PicrossPage::Ptr ptr = new PicrossPage(aPath);
|
PicrossPage::Ptr ptr = new PicrossPage(puzzle);
|
||||||
ptr->createComponents();
|
ptr->createComponents();
|
||||||
ptr->initComponents();
|
ptr->initComponents();
|
||||||
|
|
||||||
|
@@ -4,8 +4,9 @@
|
|||||||
#include "Poco/WebWidgets/ImageButtonCell.h"
|
#include "Poco/WebWidgets/ImageButtonCell.h"
|
||||||
#include "Poco/WebWidgets/TextFieldCell.h"
|
#include "Poco/WebWidgets/TextFieldCell.h"
|
||||||
#include "Poco/WebWidgets/SimpleTableModel.h"
|
#include "Poco/WebWidgets/SimpleTableModel.h"
|
||||||
#include "Poco/WebWidgets/Label.h"
|
|
||||||
#include "Poco/WebWidgets/VerticalLayout.h"
|
#include "Poco/WebWidgets/VerticalLayout.h"
|
||||||
|
#include "Poco/WebWidgets/HorizontalLayout.h"
|
||||||
|
#include "Poco/NumberFormatter.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
|
||||||
@@ -25,6 +26,7 @@ PicrossFrame::PicrossFrame(const Poco::File& bmp):
|
|||||||
void PicrossFrame::createComponents()
|
void PicrossFrame::createComponents()
|
||||||
{
|
{
|
||||||
GridLayout::Ptr pRoot(new GridLayout(2, 2));
|
GridLayout::Ptr pRoot(new GridLayout(2, 2));
|
||||||
|
createUpperLeftComponents(pRoot);
|
||||||
createUpperTable();
|
createUpperTable();
|
||||||
createLeftTable();
|
createLeftTable();
|
||||||
createGameTable();
|
createGameTable();
|
||||||
@@ -38,7 +40,7 @@ void PicrossFrame::createComponents()
|
|||||||
void PicrossFrame::initComponents()
|
void PicrossFrame::initComponents()
|
||||||
{
|
{
|
||||||
initGameTable();
|
initGameTable();
|
||||||
initLeftTable();
|
//already initialized initLeftTable();
|
||||||
initUpperTable();
|
initUpperTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,25 +49,106 @@ void PicrossFrame::setupJavaScript(Page* pPage)
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
std::ostringstream str;
|
std::ostringstream str;
|
||||||
str << "function handleClick(elem, val, guessSet) {" << std::endl;
|
str << "function updateGlobalCntRecord(rec){" << std::endl;
|
||||||
str << "if (val == 'O'){" << std::endl;
|
str << "var i = 0;" << std::endl;
|
||||||
str << "elem.innerHTML = '<img src=\"ok.png\" width=\"";
|
str << "var val = 1;" << std::endl;
|
||||||
str << "16\" height=\"13" << "\" border=\"0\" alt=\"\" />';" << std::endl;
|
str << "for (i = 0; i < global.cols; ++i){" << std::endl;
|
||||||
|
str << "val = rec.get(i.toString());" << std::endl;
|
||||||
|
str << "if (val == 'O') ++global.cnt;" << std::endl;
|
||||||
str << "}" << std::endl;
|
str << "}" << std::endl;
|
||||||
str << "else {" << std::endl;
|
str << "}" << std::endl;
|
||||||
str << "elem.innerHTML = '<img src=\"x.png\" width=\"";
|
pPage->addDynamicFunction(str.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
std::ostringstream str;
|
||||||
|
str << "function updateGlobalCnt(table){" << std::endl;
|
||||||
|
str << "global.cols = table.getColumnModel().getColumnCount() - 1;" << std::endl;
|
||||||
|
str << "global.cnt = 0;" << std::endl;
|
||||||
|
str << "table.store.each(updateGlobalCntRecord);" << std::endl;
|
||||||
|
str << "}" << std::endl;
|
||||||
|
pPage->addDynamicFunction(str.str());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::ostringstream str;
|
||||||
|
str << "function getImgClass(el) {" << std::endl;
|
||||||
|
str << "var elem = Ext.Element.fly(el);" << std::endl;
|
||||||
|
str << "var img = elem.child('.img', true);" << std::endl;
|
||||||
|
str << "if (!img) return 'default.png';" << std::endl;
|
||||||
|
str << "var result = img.attributes.getNamedItem('src');" << std::endl;
|
||||||
|
str << "return result.value;" << std::endl;
|
||||||
|
str << "}" << std::endl;
|
||||||
|
pPage->addDynamicFunction(str.str());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::ostringstream str;
|
||||||
|
str << "function checkSuccess() {" << std::endl;
|
||||||
|
str << "if (global.cnt == 0){" << std::endl;
|
||||||
|
str << "stopClock();" << std::endl;
|
||||||
|
str << "var err = parseInt(Ext.getCmp('" << _pErrors->id() << "').text);" << std::endl;
|
||||||
|
str << "Ext.getCmp('" << _pGameTable->id() << "').disable();" << std::endl;
|
||||||
|
str << "if (err == 0) " << std::endl;
|
||||||
|
str << "Ext.Msg.alert('Success', 'Congratulations. Picross solved without a single error');" << std::endl;
|
||||||
|
str << "else if (err == 1) " << std::endl;
|
||||||
|
str << "Ext.Msg.alert('Success', 'Congratulations. Picross solved with one single error');" << std::endl;
|
||||||
|
str << "else if (err <= 3) " << std::endl;
|
||||||
|
str << "Ext.Msg.alert('Success', 'Congratulations. Picross solved with ' + err + ' errors');" << std::endl;
|
||||||
|
str << "else " << std::endl;
|
||||||
|
str << "Ext.Msg.alert('Success', 'Picross Solved. Too many errors though.');" << std::endl;
|
||||||
|
str << "}" << std::endl;
|
||||||
|
str << "}" << std::endl;
|
||||||
|
pPage->addDynamicFunction(str.str());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::ostringstream str;
|
||||||
|
str << "function handleClick(elem, val) {" << std::endl;
|
||||||
|
str << "var oldImgClass = getImgClass(elem);" << std::endl;
|
||||||
|
str << "var defaultHTML = '<img class=\"img\" src=\"default.png\" width=\"";
|
||||||
str << "16\" height=\"13" << "\" border=\"0\" alt=\"\" />';" << std::endl;
|
str << "16\" height=\"13" << "\" border=\"0\" alt=\"\" />';" << std::endl;
|
||||||
str << "if (guessSet){" << std::endl; // means the user guesses there is an entry
|
str << "var okHTML = '<img class=\"img\" src=\"ok.png\" width=\"";
|
||||||
str << "if (val != 'O') {" << std::endl;
|
str << "16\" height=\"13" << "\" border=\"0\" alt=\"\" />';" << std::endl;
|
||||||
str << "Ext.Msg.alert('Error', 'You guessed wrong');" << std::endl;
|
str << "var xHTML = '<img class=\"img\" src=\"x.png\" width=\"";
|
||||||
|
str << "16\" height=\"13" << "\" border=\"0\" alt=\"\" />';" << std::endl;
|
||||||
|
str << "if (oldImgClass == 'x.png'){" << std::endl;
|
||||||
|
str << "if (global.selectMode){" << std::endl;
|
||||||
|
str << "elem.innerHTML = defaultHTML;" << std::endl;
|
||||||
|
str << "}" << std::endl;
|
||||||
|
str << "}" << std::endl;
|
||||||
|
str << "else if (oldImgClass == 'ok.png'){" << std::endl;
|
||||||
|
str << "if (!global.selectMode){" << std::endl;
|
||||||
|
str << "elem.innerHTML = xHTML;" << std::endl;
|
||||||
|
str << "global.cnt++;" << std::endl;
|
||||||
|
str << "}" << std::endl;
|
||||||
|
str << "}" << std::endl;
|
||||||
|
str << "else {" << std::endl; // default.png
|
||||||
|
str << "if (val == 'O'){" << std::endl;
|
||||||
|
str << "if (global.selectMode){" << std::endl;
|
||||||
|
str << "global.cnt--;" << std::endl;
|
||||||
|
str << "elem.innerHTML = okHTML;" << std::endl;
|
||||||
|
str << "}" << std::endl;
|
||||||
|
str << "else {" << std::endl;
|
||||||
|
str << "elem.innerHTML = xHTML;" << std::endl;
|
||||||
str << "}" << std::endl;
|
str << "}" << std::endl;
|
||||||
str << "}" << std::endl;
|
str << "}" << std::endl;
|
||||||
str << "else {" << std::endl;
|
str << "else {" << std::endl;
|
||||||
str << "if (val == 'O') {" << std::endl;
|
str << "elem.innerHTML = xHTML;" << std::endl;
|
||||||
str << "Ext.Msg.alert('Error', 'You guessed wrong');" << std::endl;
|
str << "if (global.selectMode){" << std::endl;
|
||||||
|
str << "wrongClick();" << std::endl;
|
||||||
str << "}" << std::endl;
|
str << "}" << std::endl;
|
||||||
str << "}" << std::endl;
|
str << "}" << std::endl;
|
||||||
str << "}" << std::endl;
|
str << "}" << std::endl;
|
||||||
|
str << "checkSuccess();" << std::endl;
|
||||||
|
str << "}" << std::endl;
|
||||||
|
pPage->addDynamicFunction(str.str());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::ostringstream str;
|
||||||
|
str << "function setImageURI(e, uri){" << std::endl;
|
||||||
|
str << "if (!e) return;" << std::endl;
|
||||||
|
str << "var img = e.child('.img', 'true');" << std::endl;
|
||||||
|
str << "var attr = document.createAttribute('src');" << std::endl;
|
||||||
|
str << "attr.value = uri;" << std::endl;
|
||||||
|
str << "img.attributes.setNamedItem(attr);" << std::endl;
|
||||||
str << "}" << std::endl;
|
str << "}" << std::endl;
|
||||||
pPage->addDynamicFunction(str.str());
|
pPage->addDynamicFunction(str.str());
|
||||||
}
|
}
|
||||||
@@ -87,10 +170,85 @@ void PicrossFrame::setupJavaScript(Page* pPage)
|
|||||||
str << "var rec = grid.store.getAt(row);" << std::endl;
|
str << "var rec = grid.store.getAt(row);" << std::endl;
|
||||||
str << "var val = rec.get(''+col);" << std::endl;
|
str << "var val = rec.get(''+col);" << std::endl;
|
||||||
str << "var html = grid.getView().getCell(row,col);" << std::endl;
|
str << "var html = grid.getView().getCell(row,col);" << std::endl;
|
||||||
str << "handleClick(html.firstChild, val, true);" << std::endl;
|
str << "handleClick(html.firstChild, val);" << std::endl;
|
||||||
str << "}" << std::endl;
|
str << "}" << std::endl;
|
||||||
_pGameTable->cellClicked.add(jsDelegate(str.str()));
|
_pGameTable->cellClicked.add(jsDelegate(str.str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
//pPage->appendPostRenderCode("global.cnt = " + Poco::NumberFormatter::format(_cnt) + ";");
|
||||||
|
std::ostringstream str;
|
||||||
|
str << "function(){" << std::endl;
|
||||||
|
str << "var table = Ext.getCmp('" << _pGameTable->id() << "');" << std::endl;
|
||||||
|
str << "updateGlobalCnt(table);" << std::endl;
|
||||||
|
str << "}" << std::endl;
|
||||||
|
_pGameTable->afterLoad.add(jsDelegate(str.str()));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::ostringstream str;
|
||||||
|
str << "function updateClock(){" << std::endl;
|
||||||
|
str << "var tDate = new Date();" << std::endl;
|
||||||
|
str << "if (!global.puzzleStart)" << std::endl;
|
||||||
|
str << "global.puzzleStart = new Date();" << std::endl;
|
||||||
|
str << "var tDiff = Math.floor((tDate.getTime() - global.puzzleStart.getTime())/1000);" << std::endl;
|
||||||
|
str << "var h = Math.floor(tDiff/3600);" << std::endl;
|
||||||
|
str << "if (h<10) h = '0' + h.toString();" << std::endl;
|
||||||
|
str << "var m = Math.floor((tDiff%3600)/60);" << std::endl;
|
||||||
|
str << "if (m<10) m = '0' + m.toString();" << std::endl;
|
||||||
|
str << "var s = tDiff%60;" << std::endl;
|
||||||
|
str << "if (s<10) s = '0' + s.toString();" << std::endl;
|
||||||
|
str << "var value = h + ':' + m + ':' + s;" << std::endl;
|
||||||
|
str << "Ext.getCmp('" << _pTime->id() << "').setText(value);" << std::endl;
|
||||||
|
str << "}" << std::endl;
|
||||||
|
pPage->addDynamicFunction(str.str());
|
||||||
|
pPage->appendPostRenderCode("global.puzzleClock = window.setInterval(updateClock, 1000);");
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::ostringstream str;
|
||||||
|
str << "function stopClock(){" << std::endl;
|
||||||
|
str << "window.clearInterval(global.puzzleClock);" << std::endl;
|
||||||
|
str << "}" << std::endl;
|
||||||
|
pPage->addDynamicFunction(str.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
std::ostringstream str;
|
||||||
|
str << "function wrongClick(){" << std::endl;
|
||||||
|
str << "var err = Ext.getCmp('" << _pErrors->id() << "');" << std::endl;
|
||||||
|
str << "var val = parseInt(err.text);" << std::endl;
|
||||||
|
str << "err.setText(1+val);" << std::endl;
|
||||||
|
str << "}" << std::endl;
|
||||||
|
pPage->addDynamicFunction(str.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
std::ostringstream str;
|
||||||
|
str << "function onCancelClicked(){" << std::endl;
|
||||||
|
str << "if (!global.selectMode) return;" << std::endl;
|
||||||
|
str << "global.selectMode = false;" << std::endl;
|
||||||
|
str << "var cancelElem = Ext.get('" << _pCancel->id() << "');" << std::endl;
|
||||||
|
str << "var selectElem = Ext.get('" << _pSelect->id() << "');" << std::endl;
|
||||||
|
str << "setImageURI(cancelElem, 'cancel.png');" << std::endl;
|
||||||
|
str << "setImageURI(selectElem, 'selectGrey.png');" << std::endl;
|
||||||
|
str << "}" << std::endl;
|
||||||
|
pPage->addDynamicFunction(str.str());
|
||||||
|
_pCancel->buttonClicked.add(jsDelegate("onCancelClicked()"));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
std::ostringstream str;
|
||||||
|
str << "function onSelectClicked(){" << std::endl;
|
||||||
|
str << "if (global.selectMode) return;" << std::endl;
|
||||||
|
str << "global.selectMode = true;" << std::endl;
|
||||||
|
str << "var cancelElem = Ext.get('" << _pCancel->id() << "');" << std::endl;
|
||||||
|
str << "var selectElem = Ext.get('" << _pSelect->id() << "');" << std::endl;
|
||||||
|
str << "setImageURI(cancelElem, 'cancelGrey.png');" << std::endl;
|
||||||
|
str << "setImageURI(selectElem, 'select.png');" << std::endl;
|
||||||
|
str << "}" << std::endl;
|
||||||
|
pPage->addDynamicFunction(str.str());
|
||||||
|
_pSelect->buttonClicked.add(jsDelegate("onSelectClicked()"));
|
||||||
|
pPage->appendPostRenderCode("global.selectMode = true;");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -111,29 +269,16 @@ void PicrossFrame::createUpperTable()
|
|||||||
_pUpperStore = new SimpleTableModel(tc.size());
|
_pUpperStore = new SimpleTableModel(tc.size());
|
||||||
_pUpperTable = new Table(tc, _pUpperStore);
|
_pUpperTable = new Table(tc, _pUpperStore);
|
||||||
_pUpperTable->setWidth(w*(PI_CELLWIDTH+2));
|
_pUpperTable->setWidth(w*(PI_CELLWIDTH+2));
|
||||||
_pUpperTable->setHeight(h*(PI_CELLHEIGHT));
|
//_pUpperTable->setHeight(h*(PI_CELLHEIGHT));
|
||||||
_pUpperTable->hideHeaders(true);
|
_pUpperTable->hideHeaders(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PicrossFrame::createLeftTable()
|
void PicrossFrame::createLeftTable()
|
||||||
{
|
{
|
||||||
// the left grid can have at most (width+1)/2 entries
|
// we create the left grid later when we have the data!
|
||||||
int h = _bmp.height();
|
initLeftTable();
|
||||||
int w = (_bmp.width()+1)/2;
|
|
||||||
Table::TableColumns tc;
|
|
||||||
for (int i = 0; i < w; ++i)
|
|
||||||
{
|
|
||||||
TableColumn::Ptr pCol = new TableColumn(new NumberFieldCell(0), "", PI_CELLWIDTH, false);
|
|
||||||
pCol->resizable(false);
|
|
||||||
pCol->setEditable(false);
|
|
||||||
tc.push_back(pCol);
|
|
||||||
}
|
|
||||||
_pLeftStore = new SimpleTableModel(tc.size());
|
|
||||||
_pLeftTable = new Table(tc, _pLeftStore);
|
|
||||||
_pLeftTable->setWidth(w*(PI_CELLWIDTH+1));
|
|
||||||
_pLeftTable->setHeight(h*(PI_CELLHEIGHT));
|
|
||||||
_pLeftTable->hideHeaders(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -141,6 +286,7 @@ void PicrossFrame::createGameTable()
|
|||||||
{
|
{
|
||||||
Table::TableColumns tc;
|
Table::TableColumns tc;
|
||||||
Image::Ptr pImg(new Image(Poco::URI("default.png")));
|
Image::Ptr pImg(new Image(Poco::URI("default.png")));
|
||||||
|
pImg->setClass("img");
|
||||||
for (int i = 0; i < _bmp.width(); ++i)
|
for (int i = 0; i < _bmp.width(); ++i)
|
||||||
{
|
{
|
||||||
TableColumn::Ptr pCol = new TableColumn(new TextFieldCell(0), "", PI_CELLWIDTH, false);
|
TableColumn::Ptr pCol = new TableColumn(new TextFieldCell(0), "", PI_CELLWIDTH, false);
|
||||||
@@ -162,23 +308,29 @@ void PicrossFrame::createGameTable()
|
|||||||
|
|
||||||
void PicrossFrame::initGameTable()
|
void PicrossFrame::initGameTable()
|
||||||
{
|
{
|
||||||
|
int cnt(0);
|
||||||
for (int x = 0; x < _bmp.width(); ++x)
|
for (int x = 0; x < _bmp.width(); ++x)
|
||||||
{
|
{
|
||||||
for (int y = 0; y < _bmp.height(); ++y)
|
for (int y = 0; y < _bmp.height(); ++y)
|
||||||
{
|
{
|
||||||
std::string val;
|
std::string val;
|
||||||
if (_bmp.get(x, y))
|
if (_bmp.get(x, y))
|
||||||
|
{
|
||||||
|
++cnt;
|
||||||
val = "O";
|
val = "O";
|
||||||
|
}
|
||||||
_pGameStore->setValue(val, y, x);
|
_pGameStore->setValue(val, y, x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_cnt = cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PicrossFrame::initUpperTable()
|
void PicrossFrame::initUpperTable()
|
||||||
{
|
{
|
||||||
int rows = (_bmp.height()+1)/2;
|
|
||||||
// count consecutive blocks in columns
|
// count consecutive blocks in columns
|
||||||
|
std::size_t maxRows(3); // make at least three rows, otherwise GUI looks ugly
|
||||||
|
std::vector<std::vector<int> > cols;
|
||||||
for (int x = 0; x < _bmp.width(); ++x)
|
for (int x = 0; x < _bmp.width(); ++x)
|
||||||
{
|
{
|
||||||
bool lastVal(false);
|
bool lastVal(false);
|
||||||
@@ -204,17 +356,29 @@ void PicrossFrame::initUpperTable()
|
|||||||
}
|
}
|
||||||
if (lastCnt > 0)
|
if (lastCnt > 0)
|
||||||
cnt.push_back(lastCnt);
|
cnt.push_back(lastCnt);
|
||||||
|
|
||||||
int offset = rows - cnt.size();
|
cols.push_back(cnt);
|
||||||
for (int i = 0; i < cnt.size(); ++i)
|
if (maxRows < cnt.size())
|
||||||
_pUpperTable->setValue(cnt[i], i+offset, x);
|
maxRows = cnt.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int j = 0; j < cols.size(); ++j)
|
||||||
|
{
|
||||||
|
const std::vector<int>& cnt = cols[j];
|
||||||
|
std::size_t offset = maxRows - cnt.size();
|
||||||
|
for (int i = 0; i < cnt.size(); ++i)
|
||||||
|
_pUpperTable->setValue(cnt[i], offset+ i, j);
|
||||||
|
}
|
||||||
|
_pUpperTable->setHeight(_pUpperTable->getRowCount()*(PI_CELLHEIGHT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PicrossFrame::initLeftTable()
|
void PicrossFrame::initLeftTable()
|
||||||
{
|
{
|
||||||
// count consecutive blocks in rows
|
// count consecutive blocks in rows
|
||||||
|
|
||||||
|
std::vector<std::vector<int> > rows;
|
||||||
|
std::size_t maxCols(5); // make at least five cols, otherwise GUI looks ugly
|
||||||
for (int y = 0; y < _bmp.height(); ++y)
|
for (int y = 0; y < _bmp.height(); ++y)
|
||||||
{
|
{
|
||||||
bool lastVal(false);
|
bool lastVal(false);
|
||||||
@@ -241,9 +405,66 @@ void PicrossFrame::initLeftTable()
|
|||||||
if (lastCnt > 0)
|
if (lastCnt > 0)
|
||||||
cnt.push_back(lastCnt);
|
cnt.push_back(lastCnt);
|
||||||
|
|
||||||
int cols = (_bmp.width()+1)/2;
|
rows.push_back(cnt);
|
||||||
int offset = cols - cnt.size();
|
|
||||||
for (int i = 0; i < cnt.size(); ++i)
|
|
||||||
_pLeftTable->setValue(cnt[i], y, offset + i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int h = _bmp.height();
|
||||||
|
int w = static_cast<int>(maxCols);;
|
||||||
|
Table::TableColumns tc;
|
||||||
|
for (int i = 0; i < w; ++i)
|
||||||
|
{
|
||||||
|
TableColumn::Ptr pCol = new TableColumn(new NumberFieldCell(0), "", PI_CELLWIDTH, false);
|
||||||
|
pCol->resizable(false);
|
||||||
|
pCol->setEditable(false);
|
||||||
|
tc.push_back(pCol);
|
||||||
|
}
|
||||||
|
_pLeftStore = new SimpleTableModel(tc.size());
|
||||||
|
_pLeftTable = new Table(tc, _pLeftStore);
|
||||||
|
_pLeftTable->setWidth(w*(PI_CELLWIDTH+1));
|
||||||
|
_pLeftTable->setHeight(h*(PI_CELLHEIGHT));
|
||||||
|
_pLeftTable->hideHeaders(true);
|
||||||
|
for (int j = 0; j < rows.size(); ++j)
|
||||||
|
{
|
||||||
|
const std::vector<int>& cnt = rows[j];
|
||||||
|
std::size_t offset = maxCols - cnt.size();
|
||||||
|
for (int i = 0; i < cnt.size(); ++i)
|
||||||
|
_pLeftTable->setValue(cnt[i], j, offset+i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PicrossFrame::createUpperLeftComponents(GridLayout::Ptr pRoot)
|
||||||
|
{
|
||||||
|
VerticalLayout::Ptr pVert(new VerticalLayout(2));
|
||||||
|
GridLayout::Ptr pGrid(new GridLayout(2,2));
|
||||||
|
pGrid->setHorizontalPadding(2);
|
||||||
|
Label::Ptr pTmp(new Label("", "Time:"));
|
||||||
|
pTmp->setWidth(60);
|
||||||
|
pGrid->add(pTmp);
|
||||||
|
|
||||||
|
_pTime = new Label("", "00:00:00");
|
||||||
|
pGrid->add(_pTime);
|
||||||
|
|
||||||
|
pTmp = new Label("", "Errors:");
|
||||||
|
pGrid->add(pTmp);
|
||||||
|
_pErrors = new Label("", "0");
|
||||||
|
_pErrors->setWidth(60);
|
||||||
|
pGrid->add(_pErrors);
|
||||||
|
pVert->add(pGrid);
|
||||||
|
HorizontalLayout::Ptr pHor(new HorizontalLayout(10));
|
||||||
|
Image::Ptr pSelectImg(new Image(Poco::URI("select.png")));
|
||||||
|
pSelectImg->setClass("img");
|
||||||
|
Image::Ptr pCancelImg(new Image(Poco::URI("cancelgrey.png")));
|
||||||
|
pCancelImg->setClass("img");
|
||||||
|
_pSelect = new ImageButton("select", pSelectImg);
|
||||||
|
_pSelect->setText("");
|
||||||
|
_pSelect->enable(false);
|
||||||
|
_pCancel = new ImageButton("cancel", pCancelImg);
|
||||||
|
_pCancel->setText("");
|
||||||
|
|
||||||
|
pHor->add(_pSelect);
|
||||||
|
pHor->add(_pCancel);
|
||||||
|
pVert->add(pHor);
|
||||||
|
pRoot->add(pVert);
|
||||||
}
|
}
|
@@ -10,6 +10,8 @@
|
|||||||
#include "Poco/WebWidgets/Page.h"
|
#include "Poco/WebWidgets/Page.h"
|
||||||
#include "Poco/WebWidgets/Table.h"
|
#include "Poco/WebWidgets/Table.h"
|
||||||
#include "Poco/WebWidgets/GridLayout.h"
|
#include "Poco/WebWidgets/GridLayout.h"
|
||||||
|
#include "Poco/WebWidgets/ImageButton.h"
|
||||||
|
#include "Poco/WebWidgets/Label.h"
|
||||||
#include "RAWReader.h"
|
#include "RAWReader.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -33,19 +35,26 @@ private:
|
|||||||
void createUpperTable();
|
void createUpperTable();
|
||||||
void createLeftTable();
|
void createLeftTable();
|
||||||
void createGameTable();
|
void createGameTable();
|
||||||
|
void createUpperLeftComponents(Poco::WebWidgets::GridLayout::Ptr pRoot);
|
||||||
|
|
||||||
void initGameTable();
|
void initGameTable();
|
||||||
void initUpperTable();
|
void initUpperTable();
|
||||||
void initLeftTable();
|
void initLeftTable();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RAWReader _bmp;
|
RAWReader _bmp;
|
||||||
Poco::WebWidgets::Table::Ptr _pUpperTable;
|
Poco::WebWidgets::Table::Ptr _pUpperTable;
|
||||||
Poco::WebWidgets::Table::Ptr _pLeftTable;
|
Poco::WebWidgets::Table::Ptr _pLeftTable;
|
||||||
Poco::WebWidgets::Table::Ptr _pGameTable;
|
Poco::WebWidgets::Table::Ptr _pGameTable;
|
||||||
Poco::WebWidgets::TableModel::Ptr _pUpperStore;
|
Poco::WebWidgets::TableModel::Ptr _pUpperStore;
|
||||||
Poco::WebWidgets::TableModel::Ptr _pLeftStore;
|
Poco::WebWidgets::TableModel::Ptr _pLeftStore;
|
||||||
Poco::WebWidgets::TableModel::Ptr _pGameStore;
|
Poco::WebWidgets::TableModel::Ptr _pGameStore;
|
||||||
|
Poco::WebWidgets::ImageButton::Ptr _pSelect;
|
||||||
|
Poco::WebWidgets::ImageButton::Ptr _pCancel;
|
||||||
|
Poco::WebWidgets::Label::Ptr _pTime;
|
||||||
|
Poco::WebWidgets::Label::Ptr _pErrors;
|
||||||
|
int _cnt;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
@@ -4,16 +4,16 @@
|
|||||||
PicrossPage::PicrossPage(const Poco::Path& dataRoot):
|
PicrossPage::PicrossPage(const Poco::Path& dataRoot):
|
||||||
_dataRoot(dataRoot)
|
_dataRoot(dataRoot)
|
||||||
{
|
{
|
||||||
setWidth(800);
|
//setWidth(800);
|
||||||
setHeight(600);
|
//setHeight(600);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PicrossPage::createComponents()
|
void PicrossPage::createComponents()
|
||||||
{
|
{
|
||||||
Poco::Path file(_dataRoot);
|
Poco::Path file(_dataRoot.toString()+"/level0");
|
||||||
file.makeDirectory();
|
file.makeDirectory();
|
||||||
file.setFileName("x_16x16.raw");
|
file.setFileName("door_5x5.raw");
|
||||||
_pFrame = new PicrossFrame(Poco::File(file));
|
_pFrame = new PicrossFrame(Poco::File(file));
|
||||||
add (_pFrame);
|
add (_pFrame);
|
||||||
setupJavaScript();
|
setupJavaScript();
|
||||||
|
@@ -59,9 +59,9 @@ void RAWReader::readRow(Poco::BinaryReader& in)
|
|||||||
in >> r;
|
in >> r;
|
||||||
in >> g;
|
in >> g;
|
||||||
in >> b;
|
in >> b;
|
||||||
// we shoul do a conversion to YUB and then judge dependening on the luminace value
|
// we shoul do a conversion to YUV and then judge depending on the luminace value
|
||||||
// simple check r only
|
// simple check r only
|
||||||
if (r >= 0x80u)
|
if (r <= 0x80u)
|
||||||
_data.push_back(true);
|
_data.push_back(true);
|
||||||
else
|
else
|
||||||
_data.push_back(false);
|
_data.push_back(false);
|
||||||
|