From a8bba08a18aa2b142eefaed05580f598ad5f1c95 Mon Sep 17 00:00:00 2001 From: Peter Schojer Date: Tue, 7 Oct 2008 06:53:01 +0000 Subject: [PATCH] fixed picross sample --- .../ExtJS/samples/Picross/Picross.properties | 3 + .../samples/Picross/bin/data/default.png | Bin 0 -> 361 bytes .../ExtJS/samples/Picross/src/Picross.cpp | 36 ++++++----- .../samples/Picross/src/PicrossFrame.cpp | 58 +++++++++++++----- .../ExtJS/samples/Picross/src/PicrossPage.cpp | 8 ++- .../ExtJS/samples/Picross/src/PicrossPage.h | 4 +- .../include/Poco/WebWidgets/PeriodicUpdater.h | 1 + 7 files changed, 78 insertions(+), 32 deletions(-) create mode 100644 WebWidgets/ExtJS/samples/Picross/Picross.properties create mode 100644 WebWidgets/ExtJS/samples/Picross/bin/data/default.png diff --git a/WebWidgets/ExtJS/samples/Picross/Picross.properties b/WebWidgets/ExtJS/samples/Picross/Picross.properties new file mode 100644 index 000000000..969cdecef --- /dev/null +++ b/WebWidgets/ExtJS/samples/Picross/Picross.properties @@ -0,0 +1,3 @@ +Picross.port = 9980 +Picross.dataRoot = ${application.configDir}bin/data/ +Picross.extjsRoot = ${application.configDir}../../testsuite/bin/ \ No newline at end of file diff --git a/WebWidgets/ExtJS/samples/Picross/bin/data/default.png b/WebWidgets/ExtJS/samples/Picross/bin/data/default.png new file mode 100644 index 0000000000000000000000000000000000000000..4e39c3c3066ed07fad4263e1762b36790ff86ab4 GIT binary patch literal 361 zcmeAS@N?(olHy`uVBq!ia0vp^0wBx*Bp9q_EZ7UAI14-?iy0WWg+Q3`(%rg03=E9Y vo-U3d5|WGpjPL(3&I74N0!&D3Fmq%H>HOT9pu6{1-oD!M<9IX{t literal 0 HcmV?d00001 diff --git a/WebWidgets/ExtJS/samples/Picross/src/Picross.cpp b/WebWidgets/ExtJS/samples/Picross/src/Picross.cpp index 48b518a92..e5ff4f17f 100644 --- a/WebWidgets/ExtJS/samples/Picross/src/Picross.cpp +++ b/WebWidgets/ExtJS/samples/Picross/src/Picross.cpp @@ -83,13 +83,14 @@ using namespace Poco::WebWidgets; class WebAppHandlerFactory: public HTTPRequestHandlerFactory { public: - WebAppHandlerFactory(SharedPtr pApp, const Poco::Path& dataPath, Poco::Logger* pLogger): + WebAppHandlerFactory(SharedPtr pApp, const Poco::Path& dataPath, const Poco::Path& extJSPath, Poco::Logger* pLogger): _pApp(pApp), _dataRoot(dataPath), _aliases(), _pLogger(pLogger) { _aliases.insert(std::make_pair("", _dataRoot)); + _aliases.insert(std::make_pair("extjs", extJSPath)); } HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request) @@ -168,29 +169,36 @@ protected: { if (!_helpRequested) { - ResourceManager::Ptr pRM = new ResourceManager(); - ExtJS::Utility::initialize(pRM, Poco::Path()); - SharedPtr 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); std::string data = config().getString("Picross.dataRoot", "."); + std::string extJSDir = config().getString("Picross.extjsRoot", "."); Poco::Path aPath(data); aPath.makeAbsolute(); aPath.makeDirectory(); Poco::File aFile(aPath); if (!aFile.exists() || aFile.isFile()) 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 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); - HTTPServer srv(new WebAppHandlerFactory(pWebApp, aPath, &logger()), svs, new HTTPServerParams); + HTTPServer srv(new WebAppHandlerFactory(pWebApp, aPath, extJS, &logger()), svs, new HTTPServerParams); srv.start(); waitForTerminationRequest(); srv.stop(); diff --git a/WebWidgets/ExtJS/samples/Picross/src/PicrossFrame.cpp b/WebWidgets/ExtJS/samples/Picross/src/PicrossFrame.cpp index bc7c7fa60..76f013b29 100644 --- a/WebWidgets/ExtJS/samples/Picross/src/PicrossFrame.cpp +++ b/WebWidgets/ExtJS/samples/Picross/src/PicrossFrame.cpp @@ -45,6 +45,47 @@ void PicrossFrame::initComponents() 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 = '\"\"';" << std::endl; + str << "}" << std::endl; + str << "else {" << std::endl; + str << "elem.innerHTML = '\"\"';" << 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 = '\"\"addDynamicFunction(str.str()); + } { // setup cellclick event //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 val = rec.get(''+col);" << std::endl; str << "var html = grid.getView().getCell(row,col);" << std::endl; - str << "if (val == 'O'){" << std::endl; - str << "html.firstChild.innerHTML = '\"\"';" << std::endl; - str << "}" << std::endl; - str << "else {" << std::endl; - str << "html.firstChild.innerHTML = '\"\"';" << std::endl; - str << "}" << std::endl; + str << "handleClick(html.firstChild, val, (e.button == 0));" << std::endl; str << "}" << std::endl; _pGameTable->cellClicked.add(jsDelegate(str.str())); } @@ -119,13 +153,7 @@ void PicrossFrame::createGameTable() TableColumn::Ptr pCol = new TableColumn(new TextFieldCell(0), "", PI_CELLWIDTH, false); pCol->resizable(false); pCol->setEditable(false); - // return an image - std::ostringstream str; - str << "function(){"; - str << "return '\"\"';"; - str << "}"; - pCol->setCustomRenderer(str.str()); + pCol->setCustomRenderer("renderColumn"); tc.push_back(pCol); } diff --git a/WebWidgets/ExtJS/samples/Picross/src/PicrossPage.cpp b/WebWidgets/ExtJS/samples/Picross/src/PicrossPage.cpp index 81cc26e20..7325bd418 100644 --- a/WebWidgets/ExtJS/samples/Picross/src/PicrossPage.cpp +++ b/WebWidgets/ExtJS/samples/Picross/src/PicrossPage.cpp @@ -1,7 +1,8 @@ #include "PicrossPage.h" -PicrossPage::PicrossPage() +PicrossPage::PicrossPage(const Poco::Path& dataRoot): + _dataRoot(dataRoot) { setWidth(800); setHeight(600); @@ -10,7 +11,10 @@ PicrossPage::PicrossPage() 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); setupJavaScript(); } diff --git a/WebWidgets/ExtJS/samples/Picross/src/PicrossPage.h b/WebWidgets/ExtJS/samples/Picross/src/PicrossPage.h index 3e8418b20..73c4cbd73 100644 --- a/WebWidgets/ExtJS/samples/Picross/src/PicrossPage.h +++ b/WebWidgets/ExtJS/samples/Picross/src/PicrossPage.h @@ -7,13 +7,14 @@ #include "Poco/WebWidgets/Page.h" +#include "Poco/Path.h" #include "PicrossFrame.h" class PicrossPage: public Poco::WebWidgets::Page { public: typedef Poco::AutoPtr Ptr; - PicrossPage(); + PicrossPage(const Poco::Path& dataRoot); void createComponents(); void initComponents(); @@ -23,6 +24,7 @@ private: private: PicrossFrame::Ptr _pFrame; + Poco::Path _dataRoot; }; #endif \ No newline at end of file diff --git a/WebWidgets/include/Poco/WebWidgets/PeriodicUpdater.h b/WebWidgets/include/Poco/WebWidgets/PeriodicUpdater.h index 2cf57c081..2c4fe95c3 100644 --- a/WebWidgets/include/Poco/WebWidgets/PeriodicUpdater.h +++ b/WebWidgets/include/Poco/WebWidgets/PeriodicUpdater.h @@ -60,6 +60,7 @@ public: PeriodicUpdater(TableUpdater::Ptr pUpdater, Poco::UInt32 interValInSeconds); /// Creates the PeriodicUpdater for the given table + /// You must call start manually to start it! void update(); /// Updates the table from a given source