mirror of
				https://github.com/pocoproject/poco.git
				synced 2025-10-27 11:06:50 +01:00 
			
		
		
		
	added picross
This commit is contained in:
		
							
								
								
									
										17
									
								
								WebWidgets/ExtJS/samples/Picross/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								WebWidgets/ExtJS/samples/Picross/Makefile
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| # | ||||
| # Makefile | ||||
| # | ||||
| # $Id: //poco/Main/WebWidgets/ExtJS/samples/Server/Makefile#1 $ | ||||
| # | ||||
| # Makefile for Poco Server | ||||
| # | ||||
|  | ||||
| include $(POCO_BASE)/build/rules/global | ||||
|  | ||||
| objects = Server | ||||
|  | ||||
| target         = Server | ||||
| target_version = 1 | ||||
| target_libs    = PocoFoundation PocoXML PocoNet PocoUtil | ||||
|  | ||||
| include $(POCO_BASE)/build/rules/exec | ||||
							
								
								
									
										233
									
								
								WebWidgets/ExtJS/samples/Picross/Picross_VS90.vcproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										233
									
								
								WebWidgets/ExtJS/samples/Picross/Picross_VS90.vcproj
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,233 @@ | ||||
| <?xml version="1.0" encoding="Windows-1252"?> | ||||
| <VisualStudioProject | ||||
| 	ProjectType="Visual C++" | ||||
| 	Version="9,00" | ||||
| 	Name="Picross_VS90" | ||||
| 	ProjectGUID="{0D0ED3CF-2841-412A-A9AC-F07F9E61341C}" | ||||
| 	RootNamespace="Picross_VS90" | ||||
| 	Keyword="Win32Proj" | ||||
| 	TargetFrameworkVersion="131072" | ||||
| 	> | ||||
| 	<Platforms> | ||||
| 		<Platform | ||||
| 			Name="Win32" | ||||
| 		/> | ||||
| 	</Platforms> | ||||
| 	<ToolFiles> | ||||
| 	</ToolFiles> | ||||
| 	<Configurations> | ||||
| 		<Configuration | ||||
| 			Name="debug_shared|Win32" | ||||
| 			OutputDirectory="obj\debug_shared" | ||||
| 			IntermediateDirectory="obj\debug_shared" | ||||
| 			ConfigurationType="1" | ||||
| 			UseOfMFC="2" | ||||
| 			CharacterSet="2" | ||||
| 			> | ||||
| 			<Tool | ||||
| 				Name="VCPreBuildEventTool" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCCustomBuildTool" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCXMLDataGeneratorTool" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCWebServiceProxyGeneratorTool" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCMIDLTool" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCCLCompilerTool" | ||||
| 				Optimization="0" | ||||
| 				AdditionalIncludeDirectories=".\src;..\..\..\..\Foundation\include;..\..\..\..\XML\include;..\..\..\..\Net\include;..\..\..\..\Util\include;..\..\..\..\WebWidgets\include;..\..\..\..\WebWidgets\ExtJS\include" | ||||
| 				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500" | ||||
| 				MinimalRebuild="true" | ||||
| 				BasicRuntimeChecks="3" | ||||
| 				RuntimeLibrary="3" | ||||
| 				BufferSecurityCheck="true" | ||||
| 				TreatWChar_tAsBuiltInType="true" | ||||
| 				ForceConformanceInForLoopScope="true" | ||||
| 				RuntimeTypeInfo="true" | ||||
| 				UsePrecompiledHeader="0" | ||||
| 				WarningLevel="3" | ||||
| 				DebugInformationFormat="4" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCManagedResourceCompilerTool" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCResourceCompilerTool" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCPreLinkEventTool" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCLinkerTool" | ||||
| 				AdditionalDependencies="PocoFoundationd.lib PocoXMLd.lib PocoNetd.lib PocoUtild.lib" | ||||
| 				OutputFile="bin/Picrossd.exe" | ||||
| 				LinkIncremental="2" | ||||
| 				AdditionalLibraryDirectories="..\..\..\..\lib" | ||||
| 				GenerateDebugInformation="true" | ||||
| 				ProgramDatabaseFile="bin/Picrossd.pdb" | ||||
| 				SubSystem="1" | ||||
| 				RandomizedBaseAddress="1" | ||||
| 				DataExecutionPrevention="0" | ||||
| 				TargetMachine="1" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCALinkTool" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCManifestTool" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCXDCMakeTool" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCBscMakeTool" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCFxCopTool" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCAppVerifierTool" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCPostBuildEventTool" | ||||
| 			/> | ||||
| 		</Configuration> | ||||
| 		<Configuration | ||||
| 			Name="release_shared|Win32" | ||||
| 			OutputDirectory="obj\release_shared" | ||||
| 			IntermediateDirectory="obj\release_shared" | ||||
| 			ConfigurationType="1" | ||||
| 			UseOfMFC="2" | ||||
| 			CharacterSet="2" | ||||
| 			> | ||||
| 			<Tool | ||||
| 				Name="VCPreBuildEventTool" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCCustomBuildTool" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCXMLDataGeneratorTool" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCWebServiceProxyGeneratorTool" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCMIDLTool" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCCLCompilerTool" | ||||
| 				Optimization="4" | ||||
| 				InlineFunctionExpansion="1" | ||||
| 				EnableIntrinsicFunctions="true" | ||||
| 				FavorSizeOrSpeed="1" | ||||
| 				OmitFramePointers="true" | ||||
| 				AdditionalIncludeDirectories=".\src;..\..\..\..\Foundation\include;..\..\..\..\XML\include;..\..\..\..\Net\include;..\..\..\..\Util\include;..\..\..\..\WebWidgets\include;..\..\..\..\WebWidgets\ExtJS\include" | ||||
| 				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500" | ||||
| 				StringPooling="true" | ||||
| 				RuntimeLibrary="2" | ||||
| 				BufferSecurityCheck="false" | ||||
| 				TreatWChar_tAsBuiltInType="true" | ||||
| 				ForceConformanceInForLoopScope="true" | ||||
| 				RuntimeTypeInfo="true" | ||||
| 				UsePrecompiledHeader="0" | ||||
| 				WarningLevel="3" | ||||
| 				DebugInformationFormat="3" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCManagedResourceCompilerTool" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCResourceCompilerTool" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCPreLinkEventTool" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCLinkerTool" | ||||
| 				AdditionalDependencies="PocoFoundation.lib PocoXML.lib PocoNet.lib PocoUtil.lib" | ||||
| 				OutputFile="bin/Picross.exe" | ||||
| 				LinkIncremental="1" | ||||
| 				AdditionalLibraryDirectories="..\..\..\..\lib" | ||||
| 				GenerateDebugInformation="false" | ||||
| 				ProgramDatabaseFile="" | ||||
| 				SubSystem="1" | ||||
| 				OptimizeReferences="2" | ||||
| 				EnableCOMDATFolding="2" | ||||
| 				RandomizedBaseAddress="1" | ||||
| 				DataExecutionPrevention="0" | ||||
| 				TargetMachine="1" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCALinkTool" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCManifestTool" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCXDCMakeTool" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCBscMakeTool" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCFxCopTool" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCAppVerifierTool" | ||||
| 			/> | ||||
| 			<Tool | ||||
| 				Name="VCPostBuildEventTool" | ||||
| 			/> | ||||
| 		</Configuration> | ||||
| 	</Configurations> | ||||
| 	<References> | ||||
| 	</References> | ||||
| 	<Files> | ||||
| 		<Filter | ||||
| 			Name="Header Files" | ||||
| 			> | ||||
| 			<File | ||||
| 				RelativePath=".\src\PicrossFrame.h" | ||||
| 				> | ||||
| 			</File> | ||||
| 			<File | ||||
| 				RelativePath=".\src\PicrossPage.h" | ||||
| 				> | ||||
| 			</File> | ||||
| 			<File | ||||
| 				RelativePath=".\src\RAWReader.h" | ||||
| 				> | ||||
| 			</File> | ||||
| 		</Filter> | ||||
| 		<Filter | ||||
| 			Name="Source Files" | ||||
| 			> | ||||
| 			<File | ||||
| 				RelativePath=".\src\Picross.cpp" | ||||
| 				> | ||||
| 			</File> | ||||
| 			<File | ||||
| 				RelativePath=".\src\PicrossFrame.cpp" | ||||
| 				> | ||||
| 			</File> | ||||
| 			<File | ||||
| 				RelativePath=".\src\PicrossPage.cpp" | ||||
| 				> | ||||
| 			</File> | ||||
| 			<File | ||||
| 				RelativePath=".\src\RAWReader.cpp" | ||||
| 				> | ||||
| 			</File> | ||||
| 		</Filter> | ||||
| 	</Files> | ||||
| 	<Globals> | ||||
| 	</Globals> | ||||
| </VisualStudioProject> | ||||
							
								
								
									
										
											BIN
										
									
								
								WebWidgets/ExtJS/samples/Picross/bin/data/ok.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								WebWidgets/ExtJS/samples/Picross/bin/data/ok.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 167 B | 
							
								
								
									
										
											BIN
										
									
								
								WebWidgets/ExtJS/samples/Picross/bin/data/x.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								WebWidgets/ExtJS/samples/Picross/bin/data/x.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 126 B | 
							
								
								
									
										
											BIN
										
									
								
								WebWidgets/ExtJS/samples/Picross/bin/data/x_16x16.raw
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								WebWidgets/ExtJS/samples/Picross/bin/data/x_16x16.raw
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										206
									
								
								WebWidgets/ExtJS/samples/Picross/src/Picross.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										206
									
								
								WebWidgets/ExtJS/samples/Picross/src/Picross.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,206 @@ | ||||
| // | ||||
| // Server.cpp | ||||
| // | ||||
| // $Id: //poco/Main/WebWidgets/ExtJS/samples/Server/src/Server.cpp#4 $ | ||||
| // | ||||
| // This sample demonstrates the XYZ class. | ||||
| // | ||||
| // Copyright (c) 2007, Applied Informatics Software Engineering GmbH. | ||||
| // and Contributors. | ||||
| // | ||||
| // Permission is hereby granted, free of charge, to any person or organization | ||||
| // obtaining a copy of the software and accompanying documentation covered by | ||||
| // this license (the "Software") to use, reproduce, display, distribute, | ||||
| // execute, and transmit the Software, and to prepare derivative works of the | ||||
| // Software, and to permit third-parties to whom the Software is furnished to | ||||
| // do so, all subject to the following: | ||||
| //  | ||||
| // The copyright notices in the Software and this entire statement, including | ||||
| // the above license grant, this restriction and the following disclaimer, | ||||
| // must be included in all copies of the Software, in whole or in part, and | ||||
| // all derivative works of the Software, unless such copies or derivative | ||||
| // works are solely in the form of machine-executable object code generated by | ||||
| // a source language processor. | ||||
| //  | ||||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
| // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT | ||||
| // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE | ||||
| // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, | ||||
| // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||||
| // DEALINGS IN THE SOFTWARE. | ||||
| // | ||||
|  | ||||
|  | ||||
|  | ||||
| #include "Poco/Util/ServerApplication.h" | ||||
| #include "Poco/Util/Option.h" | ||||
| #include "Poco/Util/OptionException.h" | ||||
| #include "Poco/Util/OptionSet.h" | ||||
| #include "Poco/Util/HelpFormatter.h" | ||||
| #include "Poco/Net/HTTPRequestHandlerFactory.h" | ||||
| #include "Poco/Net/HTTPRequestHandler.h" | ||||
| #include "Poco/Net/ServerSocket.h" | ||||
| #include "Poco/Net/HTTPServer.h" | ||||
| #include "Poco/Net/HTTPServerRequest.h" | ||||
| #include "Poco/Net/HTTPServerParams.h" | ||||
| #include "Poco/WebWidgets/RequestHandler.h" | ||||
| #include "Poco/WebWidgets/WebApplication.h" | ||||
| #include "Poco/WebWidgets/ExtJS/Utility.h" | ||||
| #include "Poco/WebWidgets/Table.h" | ||||
| #include "Poco/WebWidgets/SubmitButton.h" | ||||
| #include "Poco/WebWidgets/CheckButton.h" | ||||
| #include "Poco/WebWidgets/CheckButtonCell.h" | ||||
| #include "Poco/WebWidgets/SimpleTableModel.h" | ||||
| #include "Poco/WebWidgets/Form.h" | ||||
| #include "Poco/WebWidgets/DataRetriever.h" | ||||
| #include "Poco/WebWidgets/TextField.h" | ||||
| #include "Poco/WebWidgets/TextFieldCell.h" | ||||
| #include "Poco/File.h" | ||||
| #include "Poco/Path.h" | ||||
| #include "Poco/SharedPtr.h" | ||||
| #include "PicrossPage.h" | ||||
| #include <iostream> | ||||
|  | ||||
|  | ||||
| using Poco::Util::Application; | ||||
| using Poco::Util::ServerApplication; | ||||
| using Poco::Util::Option; | ||||
| using Poco::Util::OptionSet; | ||||
| using Poco::Util::OptionCallback; | ||||
| using Poco::Util::HelpFormatter; | ||||
| using Poco::Net::HTTPRequestHandlerFactory; | ||||
| using Poco::Net::HTTPRequestHandler; | ||||
| using Poco::Net::HTTPServerRequest; | ||||
| using Poco::Net::ServerSocket; | ||||
| using Poco::Net::HTTPServer; | ||||
| using Poco::Net::HTTPServerParams; | ||||
| using Poco::SharedPtr; | ||||
|  | ||||
| using namespace Poco::WebWidgets; | ||||
|  | ||||
|  | ||||
| class WebAppHandlerFactory: public HTTPRequestHandlerFactory | ||||
| { | ||||
| public: | ||||
| 	WebAppHandlerFactory(SharedPtr<WebApplication> pApp, const Poco::Path& dataPath, Poco::Logger* pLogger): | ||||
| 		_pApp(pApp), | ||||
| 		_dataRoot(dataPath), | ||||
| 		_aliases(), | ||||
| 		_pLogger(pLogger) | ||||
| 	{ | ||||
| 		_aliases.insert(std::make_pair("", _dataRoot)); | ||||
| 	} | ||||
|  | ||||
| 	HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request) | ||||
| 	{ | ||||
| 		const std::string& uri = request.getURI(); | ||||
| 		Poco::URI url(uri); | ||||
| 		const std::string& path = url.getPath(); | ||||
| 		const std::string& appPath = _pApp->getURI().getPath(); | ||||
| 		if (path == appPath ||  | ||||
| 			(path.size() > appPath.size() && path.find(appPath) == 0 && path[appPath.size()] == ';') | ||||
| 			) | ||||
| 			return new RequestHandler(_pApp); | ||||
| 		return new DataRetriever(_aliases, _pLogger); | ||||
| 	} | ||||
| private: | ||||
| 	SharedPtr<WebApplication> _pApp; | ||||
| 	Poco::Path      _dataRoot; | ||||
| 	DataRetriever::Aliases   _aliases; | ||||
| 	Poco::Logger*   _pLogger; | ||||
| }; | ||||
|  | ||||
|  | ||||
| class WebServer: public ServerApplication | ||||
| { | ||||
| public: | ||||
| 	WebServer(): _helpRequested(false) | ||||
| 	{ | ||||
| 	} | ||||
| 	 | ||||
| 	~WebServer() | ||||
| 	{ | ||||
| 	} | ||||
|  | ||||
| protected: | ||||
| 	void initialize(Application& self) | ||||
| 	{ | ||||
| 		loadConfiguration(); // load default configuration files, if present | ||||
| 		ServerApplication::initialize(self); | ||||
| 		logger().information("starting up"); | ||||
| 	} | ||||
| 		 | ||||
| 	void uninitialize() | ||||
| 	{ | ||||
| 		logger().information("shutting down"); | ||||
| 		ServerApplication::uninitialize(); | ||||
| 	} | ||||
|  | ||||
| 	void defineOptions(OptionSet& options) | ||||
| 	{ | ||||
| 		ServerApplication::defineOptions(options); | ||||
| 		 | ||||
| 		options.addOption( | ||||
| 			Option("help", "h", "display help information on command line arguments") | ||||
| 				.required(false) | ||||
| 				.repeatable(false) | ||||
| 				.callback(OptionCallback<WebServer>(this, &WebServer::handleHelp))); | ||||
| 	} | ||||
|  | ||||
| 	void handleHelp(const std::string& name, const std::string& value) | ||||
| 	{ | ||||
| 		_helpRequested = true; | ||||
| 		displayHelp(); | ||||
| 		stopOptionsProcessing(); | ||||
| 	} | ||||
|  | ||||
| 	void displayHelp() | ||||
| 	{ | ||||
| 		HelpFormatter helpFormatter(options()); | ||||
| 		helpFormatter.setCommand(commandName()); | ||||
| 		helpFormatter.setUsage("OPTIONS"); | ||||
| 		helpFormatter.setHeader("A sample server application that demonstrates some of the features of the Util::ServerApplication class."); | ||||
| 		helpFormatter.format(std::cout); | ||||
| 	} | ||||
|  | ||||
| 	int main(const std::vector<std::string>& args) | ||||
| 	{ | ||||
| 		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); | ||||
| 			std::string data = config().getString("Picross.dataRoot", "."); | ||||
| 			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!"); | ||||
|  | ||||
| 			ServerSocket svs(port); | ||||
| 			HTTPServer srv(new WebAppHandlerFactory(pWebApp, aPath, &logger()), svs, new HTTPServerParams); | ||||
| 			srv.start(); | ||||
| 			waitForTerminationRequest(); | ||||
| 			srv.stop(); | ||||
| 		} | ||||
| 		return Application::EXIT_OK; | ||||
| 	} | ||||
| 	 | ||||
| private: | ||||
| 	bool _helpRequested; | ||||
| }; | ||||
|  | ||||
|  | ||||
| POCO_SERVER_MAIN(WebServer) | ||||
							
								
								
									
										228
									
								
								WebWidgets/ExtJS/samples/Picross/src/PicrossFrame.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										228
									
								
								WebWidgets/ExtJS/samples/Picross/src/PicrossFrame.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,228 @@ | ||||
| #include "PicrossFrame.h" | ||||
| #include "Poco/WebWidgets/NumberField.h" | ||||
| #include "Poco/WebWidgets/NumberFieldCell.h" | ||||
| #include "Poco/WebWidgets/ImageButtonCell.h" | ||||
| #include "Poco/WebWidgets/TextFieldCell.h" | ||||
| #include "Poco/WebWidgets/SimpleTableModel.h" | ||||
| #include "Poco/WebWidgets/Label.h" | ||||
| #include "Poco/WebWidgets/VerticalLayout.h" | ||||
| #include <sstream> | ||||
|  | ||||
|  | ||||
| using namespace Poco::WebWidgets; | ||||
|  | ||||
|  | ||||
| PicrossFrame::PicrossFrame(const Poco::File& bmp): | ||||
| 	_bmp(bmp) | ||||
| { | ||||
| 	setWidth(800); | ||||
| 	setHeight(700); | ||||
| 	createComponents(); | ||||
| 	initComponents(); | ||||
| } | ||||
|  | ||||
|  | ||||
| void PicrossFrame::createComponents() | ||||
| { | ||||
| 	GridLayout::Ptr pRoot(new GridLayout(2, 2)); | ||||
| 	createUpperTable(); | ||||
| 	createLeftTable(); | ||||
| 	createGameTable(); | ||||
| 	pRoot->set(_pUpperTable, 0, 1); | ||||
| 	pRoot->set(_pLeftTable, 1, 0); | ||||
| 	pRoot->set(_pGameTable, 1, 1); | ||||
| 	this->setChild (pRoot); | ||||
| } | ||||
|  | ||||
|  | ||||
| void PicrossFrame::initComponents() | ||||
| { | ||||
| 	initGameTable(); | ||||
| 	initLeftTable(); | ||||
| 	initUpperTable(); | ||||
| } | ||||
|  | ||||
|  | ||||
| void PicrossFrame::setupJavaScript(Page* pPage) | ||||
| { | ||||
| 	{ | ||||
| 		// setup cellclick event | ||||
| 		//cellclick : ( Grid this, Number rowIndex, Number columnIndex, Ext.EventObject e ) | ||||
| 		std::ostringstream str; | ||||
| 		str << "function(grid, row, col, e) {" << std::endl; | ||||
| 		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 = '<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; | ||||
| 		_pGameTable->cellClicked.add(jsDelegate(str.str())); | ||||
| 	} | ||||
| } | ||||
|  | ||||
|  | ||||
| void PicrossFrame::createUpperTable() | ||||
| { | ||||
| 	// the upper grid can have at most (height+1)/2 entries | ||||
| 	int w = _bmp.width(); | ||||
| 	int h = (_bmp.height()+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); | ||||
| 	} | ||||
| 	 | ||||
| 	_pUpperStore = new SimpleTableModel(tc.size()); | ||||
| 	_pUpperTable = new Table(tc, _pUpperStore); | ||||
| 	_pUpperTable->setWidth(w*(PI_CELLWIDTH+2)); | ||||
| 	_pUpperTable->setHeight(h*(PI_CELLHEIGHT)); | ||||
| 	_pUpperTable->hideHeaders(true); | ||||
| } | ||||
|  | ||||
|  | ||||
| void PicrossFrame::createLeftTable() | ||||
| { | ||||
| 	// the left grid can have at most (width+1)/2 entries | ||||
| 	int h = _bmp.height(); | ||||
| 	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); | ||||
| } | ||||
|  | ||||
|  | ||||
| void PicrossFrame::createGameTable() | ||||
| { | ||||
| 	Table::TableColumns tc; | ||||
| 	Image::Ptr pImg(new Image(Poco::URI("default.png"))); | ||||
| 	for (int i = 0; i < _bmp.width(); ++i) | ||||
| 	{ | ||||
| 		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 '<img src=\"default.png\" width=\""; | ||||
| 		str <<			"16\" height=\"13" << "\" border=\"0\" alt=\"\" />';"; | ||||
| 		str <<	"}"; | ||||
| 		pCol->setCustomRenderer(str.str()); | ||||
| 		tc.push_back(pCol); | ||||
| 	} | ||||
|  | ||||
| 	_pGameStore = new SimpleTableModel(tc.size()); | ||||
| 	_pGameTable = new Table(tc, _pGameStore); | ||||
| 	_pGameTable->setWidth(_bmp.width()*(PI_CELLWIDTH+2)); | ||||
| 	_pGameTable->setHeight(_bmp.height()*(PI_CELLHEIGHT)); | ||||
| 	_pGameTable->hideHeaders(true); | ||||
| 	_pGameTable->showBorder(false); | ||||
| 	_pGameTable->autoEdit(true); | ||||
| } | ||||
|  | ||||
|  | ||||
| void PicrossFrame::initGameTable() | ||||
| { | ||||
| 	for (int x = 0; x < _bmp.width(); ++x) | ||||
| 	{ | ||||
| 		for (int y = 0; y < _bmp.height(); ++y) | ||||
| 		{ | ||||
| 			std::string val; | ||||
| 			if (_bmp.get(x, y)) | ||||
| 				val = "O"; | ||||
| 			_pGameStore->setValue(val, y, x); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
|  | ||||
| void PicrossFrame::initUpperTable() | ||||
| { | ||||
| 	int rows = (_bmp.height()+1)/2; | ||||
| 	// count consecutive blocks in columns | ||||
| 	for (int x = 0; x < _bmp.width(); ++x) | ||||
| 	{ | ||||
| 		bool lastVal(false); | ||||
| 		int lastCnt(0); | ||||
| 		std::vector<int> cnt; | ||||
| 		for (int y = 0; y < _bmp.height(); ++y) | ||||
| 		{ | ||||
| 			if (lastVal) | ||||
| 			{ | ||||
| 				lastVal =_bmp.get(x, y); | ||||
| 				if (lastVal) ++lastCnt; | ||||
| 				else | ||||
| 				{ | ||||
| 					cnt.push_back(lastCnt); | ||||
| 					lastCnt = 0; | ||||
| 				} | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				lastVal =_bmp.get(x, y); | ||||
| 				if (lastVal) lastCnt = 1; | ||||
| 			} | ||||
| 		} | ||||
| 		if (lastCnt > 0) | ||||
| 			cnt.push_back(lastCnt); | ||||
| 		 | ||||
| 		int offset = rows - cnt.size(); | ||||
| 		for (int i = 0; i < cnt.size(); ++i) | ||||
| 			_pUpperTable->setValue(cnt[i], i+offset, x); | ||||
| 	} | ||||
| } | ||||
|  | ||||
|  | ||||
| void PicrossFrame::initLeftTable() | ||||
| { | ||||
| 	// count consecutive blocks in rows | ||||
| 	for (int y = 0; y < _bmp.height(); ++y) | ||||
| 	{ | ||||
| 		bool lastVal(false); | ||||
| 		int lastCnt(0); | ||||
| 		std::vector<int> cnt; | ||||
| 		for (int x = 0; x < _bmp.width(); ++x) | ||||
| 		{ | ||||
| 			if (lastVal) | ||||
| 			{ | ||||
| 				lastVal =_bmp.get(x, y); | ||||
| 				if (lastVal) ++lastCnt; | ||||
| 				else | ||||
| 				{ | ||||
| 					cnt.push_back(lastCnt); | ||||
| 					lastCnt = 0; | ||||
| 				} | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				lastVal =_bmp.get(x, y); | ||||
| 				if (lastVal) lastCnt = 1; | ||||
| 			} | ||||
| 		} | ||||
| 		if (lastCnt > 0) | ||||
| 			cnt.push_back(lastCnt); | ||||
|  | ||||
| 		int cols = (_bmp.width()+1)/2; | ||||
| 		int offset = cols - cnt.size(); | ||||
| 		for (int i = 0; i < cnt.size(); ++i) | ||||
| 			_pLeftTable->setValue(cnt[i], y, offset + i); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										51
									
								
								WebWidgets/ExtJS/samples/Picross/src/PicrossFrame.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								WebWidgets/ExtJS/samples/Picross/src/PicrossFrame.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,51 @@ | ||||
| // PicrossFrame | ||||
| // Copyright 2008 by Peter Schojer | ||||
|  | ||||
|  | ||||
| #ifndef PicrossFrame_H_INCLUDED | ||||
| #define PicrossFrame_H_INCLUDED | ||||
|  | ||||
|  | ||||
| #include "Poco/WebWidgets/Frame.h" | ||||
| #include "Poco/WebWidgets/Page.h" | ||||
| #include "Poco/WebWidgets/Table.h" | ||||
| #include "Poco/WebWidgets/GridLayout.h" | ||||
| #include "RAWReader.h" | ||||
|  | ||||
|  | ||||
| class PicrossFrame: public Poco::WebWidgets::Frame | ||||
| { | ||||
| public: | ||||
| 	typedef Poco::AutoPtr<PicrossFrame> Ptr; | ||||
| 	enum | ||||
| 	{ | ||||
| 		PI_CELLWIDTH = 22, | ||||
| 		PI_CELLHEIGHT = 22 | ||||
| 	}; | ||||
|  | ||||
| 	PicrossFrame(const Poco::File& bmp); | ||||
| 	 | ||||
| 	void setupJavaScript(Poco::WebWidgets::Page* pPage); | ||||
|  | ||||
| private: | ||||
| 	void createComponents(); | ||||
| 	void initComponents(); | ||||
| 	void createUpperTable(); | ||||
| 	void createLeftTable(); | ||||
| 	void createGameTable(); | ||||
|  | ||||
| 	void initGameTable(); | ||||
| 	void initUpperTable(); | ||||
| 	void initLeftTable(); | ||||
|  | ||||
| private: | ||||
| 	RAWReader                         _bmp; | ||||
| 	Poco::WebWidgets::Table::Ptr      _pUpperTable; | ||||
| 	Poco::WebWidgets::Table::Ptr      _pLeftTable; | ||||
| 	Poco::WebWidgets::Table::Ptr      _pGameTable; | ||||
| 	Poco::WebWidgets::TableModel::Ptr _pUpperStore; | ||||
| 	Poco::WebWidgets::TableModel::Ptr _pLeftStore; | ||||
| 	Poco::WebWidgets::TableModel::Ptr _pGameStore; | ||||
| }; | ||||
|  | ||||
| #endif | ||||
							
								
								
									
										26
									
								
								WebWidgets/ExtJS/samples/Picross/src/PicrossPage.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								WebWidgets/ExtJS/samples/Picross/src/PicrossPage.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | ||||
| #include "PicrossPage.h" | ||||
|  | ||||
|  | ||||
| PicrossPage::PicrossPage() | ||||
| { | ||||
| 	setWidth(800); | ||||
| 	setHeight(600); | ||||
| } | ||||
|  | ||||
| 	 | ||||
| void PicrossPage::createComponents() | ||||
| { | ||||
| 	_pFrame = new PicrossFrame(Poco::File("x_16x16.raw")); | ||||
| 	add (_pFrame); | ||||
| 	setupJavaScript(); | ||||
| } | ||||
|  | ||||
|  | ||||
| void PicrossPage::initComponents() | ||||
| { | ||||
| } | ||||
|  | ||||
| void PicrossPage::setupJavaScript() | ||||
| { | ||||
| 	_pFrame->setupJavaScript(this); | ||||
| } | ||||
							
								
								
									
										28
									
								
								WebWidgets/ExtJS/samples/Picross/src/PicrossPage.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								WebWidgets/ExtJS/samples/Picross/src/PicrossPage.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,28 @@ | ||||
| // PicrossPage | ||||
| // Copyright 2008 by Peter Schojer | ||||
|  | ||||
|  | ||||
| #ifndef PicrossPage_H_INCLUDED | ||||
| #define PicrossPage_H_INCLUDED | ||||
|  | ||||
|  | ||||
| #include "Poco/WebWidgets/Page.h" | ||||
| #include "PicrossFrame.h" | ||||
|  | ||||
| class PicrossPage: public Poco::WebWidgets::Page | ||||
| { | ||||
| public: | ||||
| 	typedef Poco::AutoPtr<PicrossPage> Ptr; | ||||
| 	PicrossPage(); | ||||
| 	 | ||||
| 	void createComponents(); | ||||
| 	void initComponents(); | ||||
|  | ||||
| private: | ||||
| 	void setupJavaScript(); | ||||
|  | ||||
| private: | ||||
| 	PicrossFrame::Ptr _pFrame; | ||||
| }; | ||||
|  | ||||
| #endif | ||||
							
								
								
									
										85
									
								
								WebWidgets/ExtJS/samples/Picross/src/RAWReader.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										85
									
								
								WebWidgets/ExtJS/samples/Picross/src/RAWReader.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,85 @@ | ||||
| #include "RAWReader.h" | ||||
| #include "Poco/FileStream.h" | ||||
| #include "Poco/StringTokenizer.h" | ||||
| #include "Poco/NumberParser.h" | ||||
|  | ||||
|  | ||||
| RAWReader::RAWReader(std::istream& in, int width, int height): | ||||
| 	_data(), | ||||
| 	_width(width), | ||||
| 	_height(height) | ||||
| { | ||||
| 	init(in); | ||||
| } | ||||
|  | ||||
|  | ||||
| RAWReader::RAWReader(const Poco::File& f, int width, int height): | ||||
| 	_data(), | ||||
| 	_width(width), | ||||
| 	_height(height) | ||||
| { | ||||
| 	if (_width <= 0 || _height <= 0) | ||||
| 		poco_assert (extractFromName(f.path(), _width, _height)); | ||||
| 	poco_assert (f.exists()); | ||||
| 	Poco::FileInputStream fis(f.path()); | ||||
| 	init(fis); | ||||
| } | ||||
|  | ||||
|  | ||||
| RAWReader::RAWReader(const std::string& file, int width, int height): | ||||
| 	_data(), | ||||
| 	_width(width), | ||||
| 	_height(height) | ||||
| { | ||||
| 	if (_width <= 0 || _height <= 0) | ||||
| 		poco_assert (extractFromName(file, _width, _height)); | ||||
| 	Poco::FileInputStream fis(file); | ||||
| 	init(fis); | ||||
| } | ||||
|  | ||||
| 	 | ||||
| void RAWReader::init(std::istream& in) | ||||
| { | ||||
| 	poco_assert (in.good()); | ||||
| 	poco_assert (_width > 0); | ||||
| 	poco_assert (_height > 0); | ||||
| 	Poco::BinaryReader br(in, Poco::BinaryReader::LITTLE_ENDIAN_BYTE_ORDER); | ||||
| 	 | ||||
| 	for (int i = 0; i < _height; ++i) | ||||
| 		readRow(br); | ||||
| } | ||||
|  | ||||
|  | ||||
| void RAWReader::readRow(Poco::BinaryReader& in) | ||||
| { | ||||
| 	poco_assert (_width > 0); | ||||
| 	unsigned char r,g,b; | ||||
| 	for (int j = 0; j < _width; ++j) | ||||
| 	{ | ||||
| 		in >> r; | ||||
| 		in >> g; | ||||
| 		in >> b; | ||||
| 		// we shoul do a conversion to YUB and then judge dependening on the luminace value | ||||
| 		// simple check r only | ||||
| 		if (r >= 0x80u) | ||||
| 			_data.push_back(true); | ||||
| 		else | ||||
| 			_data.push_back(false); | ||||
| 	} | ||||
| } | ||||
|  | ||||
|  | ||||
| bool RAWReader::extractFromName(const std::string& fileName, int& width, int& height) const | ||||
| { | ||||
| 	std::size_t pos = fileName.rfind('_'); | ||||
| 	if (pos == std::string::npos) | ||||
| 		return false; | ||||
|  | ||||
| 	std::string dim(fileName.substr(pos+1)); | ||||
| 	Poco::StringTokenizer tok(dim, "xX. ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM); | ||||
| 	if (tok.count() < 2) | ||||
| 		return false; | ||||
| 	bool ret = Poco::NumberParser::tryParse(tok[0], width); | ||||
| 	ret &= Poco::NumberParser::tryParse(tok[1], height); | ||||
| 	return ret; | ||||
| } | ||||
							
								
								
									
										79
									
								
								WebWidgets/ExtJS/samples/Picross/src/RAWReader.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										79
									
								
								WebWidgets/ExtJS/samples/Picross/src/RAWReader.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,79 @@ | ||||
| // RAWReader | ||||
| // Copyright 2008 by Peter Schojer | ||||
|  | ||||
|  | ||||
| #ifndef RAWReader_H_INCLUDED | ||||
| #define RAWReader_H_INCLUDED | ||||
|  | ||||
|  | ||||
| #include "Poco/BinaryReader.h" | ||||
| #include "Poco/File.h" | ||||
| #include <istream> | ||||
| #include <vector> | ||||
|  | ||||
| class RAWReader | ||||
| 	/// class to read raw files in format RGB | ||||
| { | ||||
| public: | ||||
| 	RAWReader(std::istream& in, int width, int height); | ||||
|  | ||||
| 	RAWReader(const Poco::File& f, int width = -1, int height = -1); | ||||
| 		/// tries to extract from the filename a string _{width}x{height] to get the | ||||
| 		/// dimension | ||||
|  | ||||
| 	RAWReader(const std::string& file, int width = -1, int height = -1); | ||||
| 		/// tries to extract from the filename a string _{width}x{height] to get the | ||||
| 		/// dimension | ||||
| 	 | ||||
| 	bool get(int posX, int posY) const; | ||||
|  | ||||
| 	int width() const; | ||||
|  | ||||
| 	int height() const; | ||||
|  | ||||
| private: | ||||
| 	int pos(int x, int y) const; | ||||
|  | ||||
| 	void init(std::istream& in); | ||||
|  | ||||
| 	void readRow(Poco::BinaryReader& in); | ||||
| 		/// Reads a complete row from in | ||||
| 		/// skips bytes  | ||||
|  | ||||
| 	bool extractFromName(const std::string& fileName, int& width, int& height) const; | ||||
|  | ||||
| private: | ||||
| 	std::vector<bool> _data; | ||||
| 	int _width; | ||||
| 	int _height; | ||||
| }; | ||||
|  | ||||
|  | ||||
| inline bool RAWReader::get(int posX, int posY) const | ||||
| { | ||||
| 	return _data[pos(posX, posY)]; | ||||
| } | ||||
|  | ||||
|  | ||||
| inline int RAWReader::pos(int x, int y) const | ||||
| { | ||||
| 	// stored column after column! | ||||
| 	poco_assert_dbg (x < _width); | ||||
| 	poco_assert_dbg (y < _height); | ||||
| 	return x + (_width*y); | ||||
| } | ||||
|  | ||||
|  | ||||
| inline int RAWReader::width() const | ||||
| { | ||||
| 	return _width; | ||||
| } | ||||
|  | ||||
|  | ||||
| inline int RAWReader::height() const | ||||
| { | ||||
| 	return _height; | ||||
| } | ||||
|  | ||||
|  | ||||
| #endif | ||||
		Reference in New Issue
	
	Block a user
	 Peter Schojer
					Peter Schojer