OSDN Git Service

src初コミット
[yurina/yurina.git] / src / core / widget / ConsoleWindow.cpp
diff --git a/src/core/widget/ConsoleWindow.cpp b/src/core/widget/ConsoleWindow.cpp
new file mode 100755 (executable)
index 0000000..651eb71
--- /dev/null
@@ -0,0 +1,126 @@
+/*\r
+ *     “yurina”: yurina unpretentious renderer is not an anathema\r
+ *\r
+ *     This software is distributed under a BSD-style license.\r
+ *     See license.txt for more information.\r
+ */\r
+\r
+#include "widget/ConsoleWindow.h"\r
+#include <fltk/run.h>\r
+#include <fltk/x.h>\r
+#include <string>\r
+\r
+using namespace fltk;\r
+namespace yurina\r
+{\r
+       ConsoleWindow::ConsoleWindow( void ) : Window( 480,360 )\r
+       {\r
+               for( size_t i = 0; i < STYLE_MAX; ++i )\r
+               {\r
+                       styles[i].color = WHITE;\r
+                       styles[i].font = SCREEN_FONT;\r
+                       styles[i].size = 14;\r
+                       styles[i].attr = 0;\r
+               }\r
+               definedColorNum = 1;\r
+               currentStyle = 'A';\r
+\r
+               resizable();\r
+               buffer = new TextBuffer( 256 * 1024 );\r
+               styleBuffer = new TextBuffer( buffer->length() ); \r
+               begin();\r
+               textDisplay = new TextDisplay( 0, 0, 480, 360 );\r
+               textDisplay->align( ALIGN_LEFT| ALIGN_CENTER | ALIGN_INSIDE | ALIGN_WRAP );\r
+               resizable( textDisplay );\r
+               textDisplay->buffer( buffer );\r
+               textDisplay->highlight_data( styleBuffer, styles, STYLE_MAX, 'A', styleUnfinishedCallback, 0);\r
+               end();\r
+               show();\r
+               setCaption( L"Console" );\r
+               setBackgroundColor( BLACK );\r
+\r
+       }\r
+\r
+       ConsoleWindow::~ConsoleWindow( void )\r
+       {\r
+               textDisplay->buffer( NULL );\r
+\r
+               destroy();\r
+               textDisplay = NULL;\r
+               if ( NULL != buffer ) \r
+               {\r
+                       delete buffer;\r
+                       buffer = NULL;\r
+               }\r
+               if ( NULL != styleBuffer ) \r
+               {\r
+                       delete buffer;\r
+                       buffer = NULL;\r
+               }\r
+       }\r
+\r
+       void ConsoleWindow::clear( void )\r
+       {\r
+               buffer->text( "" );\r
+               styleBuffer->text( "" );\r
+       }\r
+\r
+       void ConsoleWindow::setTextColor( Color color )\r
+       {\r
+               int i;\r
+               for( i = 0;i < definedColorNum; ++i )\r
+               {\r
+                       if (color == styles[i].color) break;\r
+               }\r
+               if ( i >= STYLE_MAX ) \r
+               {\r
+                       i = 0;\r
+               }\r
+               else\r
+               {\r
+                       styles[definedColorNum++].color = color;\r
+               }\r
+               currentStyle = static_cast<char>( i + 'A' );\r
+               return;\r
+       }\r
+\r
+       Color ConsoleWindow::getTextColor( void ) const\r
+       {\r
+               return styles[currentStyle - 'A'].color;\r
+       }\r
+\r
+       void ConsoleWindow::setBackgroundColor( Color color )  \r
+       {\r
+               textDisplay->color( color );\r
+       }\r
+\r
+       void ConsoleWindow::write( const YuriString &text )\r
+       {\r
+               Encoding enc( Encoding::UTF8 );\r
+               size_t len = enc.countBytes( text.utf8() );\r
+               std::string s( len, currentStyle );\r
+               styleBuffer->append( s.c_str() );\r
+               buffer->append( text.utf8c() );\r
+       }\r
+\r
+       void ConsoleWindow::writeLine( const YuriString &text )\r
+       {\r
+               Encoding enc( Encoding::UTF8 );\r
+               size_t len = enc.countBytes( text.utf8() ) + 1;\r
+               std::string s( len, currentStyle );\r
+               styleBuffer->append( s.c_str() );\r
+               buffer->append( text.utf8c() );\r
+               buffer->append( "\n" );\r
+       }\r
+\r
+       void ConsoleWindow::setCaption( const YuriString &caption )\r
+       {\r
+#if defined( _WIN32 ) || defined( _WIN64 )\r
+               CreatedWindow *w = CreatedWindow::find( this );\r
+               if ( NULL != w ) SetWindowTextW( w->xid, caption.c_str() );\r
+#else\r
+               label( caption.utf8c() );\r
+#endif\r
+       }\r
+\r
+}\r