mirror of
https://github.com/pocoproject/poco.git
synced 2025-07-05 10:00:01 +02:00
fixed picross sample
This commit is contained in:
parent
c8f5d2ca64
commit
a8bba08a18
3
WebWidgets/ExtJS/samples/Picross/Picross.properties
Normal file
3
WebWidgets/ExtJS/samples/Picross/Picross.properties
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Picross.port = 9980
|
||||||
|
Picross.dataRoot = ${application.configDir}bin/data/
|
||||||
|
Picross.extjsRoot = ${application.configDir}../../testsuite/bin/
|
BIN
WebWidgets/ExtJS/samples/Picross/bin/data/default.png
Normal file
BIN
WebWidgets/ExtJS/samples/Picross/bin/data/default.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 361 B |
@ -83,13 +83,14 @@ using namespace Poco::WebWidgets;
|
|||||||
class WebAppHandlerFactory: public HTTPRequestHandlerFactory
|
class WebAppHandlerFactory: public HTTPRequestHandlerFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WebAppHandlerFactory(SharedPtr<WebApplication> pApp, const Poco::Path& dataPath, Poco::Logger* pLogger):
|
WebAppHandlerFactory(SharedPtr<WebApplication> pApp, const Poco::Path& dataPath, const Poco::Path& extJSPath, Poco::Logger* pLogger):
|
||||||
_pApp(pApp),
|
_pApp(pApp),
|
||||||
_dataRoot(dataPath),
|
_dataRoot(dataPath),
|
||||||
_aliases(),
|
_aliases(),
|
||||||
_pLogger(pLogger)
|
_pLogger(pLogger)
|
||||||
{
|
{
|
||||||
_aliases.insert(std::make_pair("", _dataRoot));
|
_aliases.insert(std::make_pair("", _dataRoot));
|
||||||
|
_aliases.insert(std::make_pair("extjs", extJSPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request)
|
HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request)
|
||||||
@ -168,29 +169,36 @@ protected:
|
|||||||
{
|
{
|
||||||
if (!_helpRequested)
|
if (!_helpRequested)
|
||||||
{
|
{
|
||||||
ResourceManager::Ptr pRM = new ResourceManager();
|
|
||||||
ExtJS::Utility::initialize(pRM, Poco::Path());
|
|
||||||
SharedPtr<WebApplication> pWebApp = new WebApplication(Poco::URI("/"), pRM);
|
|
||||||
LookAndFeel::Ptr laf(new LookAndFeel());
|
|
||||||
Poco::WebWidgets::ExtJS::Utility::initialize(laf);
|
|
||||||
pWebApp->setLookAndFeel(laf);
|
|
||||||
PicrossPage::Ptr ptr = new PicrossPage();
|
|
||||||
ptr->createComponents();
|
|
||||||
ptr->initComponents();
|
|
||||||
|
|
||||||
pWebApp->setCurrentPage(ptr);
|
|
||||||
|
|
||||||
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", ".");
|
||||||
|
std::string extJSDir = config().getString("Picross.extjsRoot", ".");
|
||||||
Poco::Path aPath(data);
|
Poco::Path aPath(data);
|
||||||
aPath.makeAbsolute();
|
aPath.makeAbsolute();
|
||||||
aPath.makeDirectory();
|
aPath.makeDirectory();
|
||||||
Poco::File aFile(aPath);
|
Poco::File aFile(aPath);
|
||||||
if (!aFile.exists() || aFile.isFile())
|
if (!aFile.exists() || aFile.isFile())
|
||||||
throw Poco::Util::InvalidArgumentException("dataRoot is either a file or doesn't exist: must be directory!");
|
throw Poco::Util::InvalidArgumentException("dataRoot is either a file or doesn't exist: must be directory!");
|
||||||
|
Poco::Path extJS(extJSDir);
|
||||||
|
extJS.makeAbsolute();
|
||||||
|
extJS.makeDirectory();
|
||||||
|
Poco::File extJSFile(extJS);
|
||||||
|
if (!extJSFile.exists() || extJSFile.isFile())
|
||||||
|
throw Poco::Util::InvalidArgumentException("extjsRoot is either a file or doesn't exist: must be directory!");
|
||||||
|
|
||||||
|
ResourceManager::Ptr pRM = new ResourceManager();
|
||||||
|
ExtJS::Utility::initialize(pRM, Poco::Path("/extjs"));
|
||||||
|
SharedPtr<WebApplication> pWebApp = new WebApplication(Poco::URI("/"), pRM);
|
||||||
|
LookAndFeel::Ptr laf(new LookAndFeel());
|
||||||
|
Poco::WebWidgets::ExtJS::Utility::initialize(laf);
|
||||||
|
pWebApp->setLookAndFeel(laf);
|
||||||
|
PicrossPage::Ptr ptr = new PicrossPage(aPath);
|
||||||
|
ptr->createComponents();
|
||||||
|
ptr->initComponents();
|
||||||
|
|
||||||
|
pWebApp->setCurrentPage(ptr);
|
||||||
|
|
||||||
ServerSocket svs(port);
|
ServerSocket svs(port);
|
||||||
HTTPServer srv(new WebAppHandlerFactory(pWebApp, aPath, &logger()), svs, new HTTPServerParams);
|
HTTPServer srv(new WebAppHandlerFactory(pWebApp, aPath, extJS, &logger()), svs, new HTTPServerParams);
|
||||||
srv.start();
|
srv.start();
|
||||||
waitForTerminationRequest();
|
waitForTerminationRequest();
|
||||||
srv.stop();
|
srv.stop();
|
||||||
|
@ -45,6 +45,47 @@ void PicrossFrame::initComponents()
|
|||||||
|
|
||||||
void PicrossFrame::setupJavaScript(Page* pPage)
|
void PicrossFrame::setupJavaScript(Page* pPage)
|
||||||
{
|
{
|
||||||
|
{
|
||||||
|
std::ostringstream str;
|
||||||
|
str << "function handleRightClick(elem, val) {" << std::endl;
|
||||||
|
str << "handleClick(elem, val, false);" << std::endl;
|
||||||
|
str << "}";
|
||||||
|
pPage->addDynamicFunction(str.str());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::ostringstream str;
|
||||||
|
str << "function handleClick(elem, val, leftClick) {" << std::endl;
|
||||||
|
str << "if (val == 'O'){" << std::endl;
|
||||||
|
str << "elem.innerHTML = '<img src=\"ok.png\" width=\"";
|
||||||
|
str << "16\" height=\"13" << "\" border=\"0\" alt=\"\" />';" << std::endl;
|
||||||
|
str << "}" << std::endl;
|
||||||
|
str << "else {" << std::endl;
|
||||||
|
str << "elem.innerHTML = '<img src=\"x.png\" width=\"";
|
||||||
|
str << "16\" height=\"13" << "\" border=\"0\" alt=\"\" />';" << std::endl;
|
||||||
|
str << "if (leftClick){" << std::endl; // left mouse click means the user guesses there is an entry
|
||||||
|
str << "if (val != 'O') {" << std::endl;
|
||||||
|
str << "Ext.Msg.alert('Error', 'You guessed wrong');" << std::endl;
|
||||||
|
str << "}" << std::endl;
|
||||||
|
str << "}" << std::endl;
|
||||||
|
str << "else if (e.button == 2){" << std::endl;
|
||||||
|
str << "if (val == 'O') {" << std::endl;
|
||||||
|
str << "Ext.Msg.alert('Error', 'You guessed wrong');" << std::endl;
|
||||||
|
str << "}" << std::endl;
|
||||||
|
str << "}" << std::endl;
|
||||||
|
str << "}" << std::endl;
|
||||||
|
str << "}" << std::endl;
|
||||||
|
pPage->addDynamicFunction(str.str());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::ostringstream str;
|
||||||
|
str << "function renderColumn(val){" << std::endl;
|
||||||
|
str << "var retVal = '<img src=\"default.png\" width=\"";
|
||||||
|
str << "16\" height=\"13" << "\" border=\"0\" alt=\"\" ';"<< std::endl;
|
||||||
|
str << "retVal += '/>';" << std::endl;
|
||||||
|
str << "return retVal;" << std::endl;
|
||||||
|
str << "}"<< std::endl;
|
||||||
|
pPage->addDynamicFunction(str.str());
|
||||||
|
}
|
||||||
{
|
{
|
||||||
// setup cellclick event
|
// setup cellclick event
|
||||||
//cellclick : ( Grid this, Number rowIndex, Number columnIndex, Ext.EventObject e )
|
//cellclick : ( Grid this, Number rowIndex, Number columnIndex, Ext.EventObject e )
|
||||||
@ -53,14 +94,7 @@ 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 << "if (val == 'O'){" << std::endl;
|
str << "handleClick(html.firstChild, val, (e.button == 0));" << std::endl;
|
||||||
str << "html.firstChild.innerHTML = '<img src=\"ok.png\" width=\"";
|
|
||||||
str << "16\" height=\"13" << "\" border=\"0\" alt=\"\" />';" << std::endl;
|
|
||||||
str << "}" << std::endl;
|
|
||||||
str << "else {" << std::endl;
|
|
||||||
str << "html.firstChild.innerHTML = '<img src=\"x.png\" width=\"";
|
|
||||||
str << "16\" height=\"13" << "\" border=\"0\" alt=\"\" />';" << std::endl;
|
|
||||||
str << "}" << std::endl;
|
|
||||||
str << "}" << std::endl;
|
str << "}" << std::endl;
|
||||||
_pGameTable->cellClicked.add(jsDelegate(str.str()));
|
_pGameTable->cellClicked.add(jsDelegate(str.str()));
|
||||||
}
|
}
|
||||||
@ -119,13 +153,7 @@ void PicrossFrame::createGameTable()
|
|||||||
TableColumn::Ptr pCol = new TableColumn(new TextFieldCell(0), "", PI_CELLWIDTH, false);
|
TableColumn::Ptr pCol = new TableColumn(new TextFieldCell(0), "", PI_CELLWIDTH, false);
|
||||||
pCol->resizable(false);
|
pCol->resizable(false);
|
||||||
pCol->setEditable(false);
|
pCol->setEditable(false);
|
||||||
// return an image
|
pCol->setCustomRenderer("renderColumn");
|
||||||
std::ostringstream str;
|
|
||||||
str << "function(){";
|
|
||||||
str << "return '<img src=\"default.png\" width=\"";
|
|
||||||
str << "16\" height=\"13" << "\" border=\"0\" alt=\"\" />';";
|
|
||||||
str << "}";
|
|
||||||
pCol->setCustomRenderer(str.str());
|
|
||||||
tc.push_back(pCol);
|
tc.push_back(pCol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
#include "PicrossPage.h"
|
#include "PicrossPage.h"
|
||||||
|
|
||||||
|
|
||||||
PicrossPage::PicrossPage()
|
PicrossPage::PicrossPage(const Poco::Path& dataRoot):
|
||||||
|
_dataRoot(dataRoot)
|
||||||
{
|
{
|
||||||
setWidth(800);
|
setWidth(800);
|
||||||
setHeight(600);
|
setHeight(600);
|
||||||
@ -10,7 +11,10 @@ PicrossPage::PicrossPage()
|
|||||||
|
|
||||||
void PicrossPage::createComponents()
|
void PicrossPage::createComponents()
|
||||||
{
|
{
|
||||||
_pFrame = new PicrossFrame(Poco::File("x_16x16.raw"));
|
Poco::Path file(_dataRoot);
|
||||||
|
file.makeDirectory();
|
||||||
|
file.setFileName("x_16x16.raw");
|
||||||
|
_pFrame = new PicrossFrame(Poco::File(file));
|
||||||
add (_pFrame);
|
add (_pFrame);
|
||||||
setupJavaScript();
|
setupJavaScript();
|
||||||
}
|
}
|
||||||
|
@ -7,13 +7,14 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "Poco/WebWidgets/Page.h"
|
#include "Poco/WebWidgets/Page.h"
|
||||||
|
#include "Poco/Path.h"
|
||||||
#include "PicrossFrame.h"
|
#include "PicrossFrame.h"
|
||||||
|
|
||||||
class PicrossPage: public Poco::WebWidgets::Page
|
class PicrossPage: public Poco::WebWidgets::Page
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef Poco::AutoPtr<PicrossPage> Ptr;
|
typedef Poco::AutoPtr<PicrossPage> Ptr;
|
||||||
PicrossPage();
|
PicrossPage(const Poco::Path& dataRoot);
|
||||||
|
|
||||||
void createComponents();
|
void createComponents();
|
||||||
void initComponents();
|
void initComponents();
|
||||||
@ -23,6 +24,7 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
PicrossFrame::Ptr _pFrame;
|
PicrossFrame::Ptr _pFrame;
|
||||||
|
Poco::Path _dataRoot;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -60,6 +60,7 @@ public:
|
|||||||
|
|
||||||
PeriodicUpdater(TableUpdater::Ptr pUpdater, Poco::UInt32 interValInSeconds);
|
PeriodicUpdater(TableUpdater::Ptr pUpdater, Poco::UInt32 interValInSeconds);
|
||||||
/// Creates the PeriodicUpdater for the given table
|
/// Creates the PeriodicUpdater for the given table
|
||||||
|
/// You must call start manually to start it!
|
||||||
|
|
||||||
void update();
|
void update();
|
||||||
/// Updates the table from a given source
|
/// Updates the table from a given source
|
||||||
|
Loading…
x
Reference in New Issue
Block a user