<commit_before>/*!
    @file
    @author     <NAME>
    @date       08/2008
    @module
*/

#include "precompiled.h"
#include "DemoKeeper.h"

#include "agg_scanline_p.h"
#include "agg_renderer_scanline.h"
#include "agg_pixfmt_rgba.h"

#include "agg_scanline_u.h"
#include "agg_rasterizer_scanline_aa.h"
#include "agg_pixfmt_rgb.h"
#include "agg_path_storage.h"
#include "agg_curves.h"
#include "agg_conv_stroke.h"

#include "RenderBox/RenderBoxWrap.h"

namespace demo
{
	PaintInfo createPaintPrimitive(const MyGUI::IntSize& _size)
	{
		PaintInfo info;
		info.vert = rand() % 2 != 0;
		info.x = rand() % _size.width;
		info.y = rand() % _size.height;
		info.len = rand() % 32;
		info.colour = Ogre::ColourValue(
			rand()%256 / float(255),
			rand()%256 / float(255),
			rand()%256 / float(255),
			rand()%256 / float(255));
		return info;
	}

	void drawPaintPrimitive(const PaintInfo& _data, MyGUI::CanvasPtr _canvas)
	{
		const MyGUI::IntSize& size = _canvas->getTextureRealSize();
		int xdelta = _data.vert ? 0 : 1;
		int ydelta = _data.vert ? 1 : 0;
		int x = _data.x;
		int y = _data.y;
		int count = _data.len;
		while (count != 0) {
			if (x < size.width && y < size.height) {
				_canvas->setPixel(x, y, _data.colour);
			}
			x += xdelta;
			y += ydelta;
			count--;
		}
	}

	bool DemoKeeper::frameStarted( const Ogre::FrameEvent & evt )
	{
		bool res = BaseManager::frameStarted( evt );

		mSceneMgr->getRootSceneNode()->getChildIterator().peekNextValue()->yaw( Ogre::Radian( 10 )* evt.timeSinceLastFrame );

		return res;
	}

	void DemoKeeper::notifyMouseButtonPressed(MyGUI::WidgetPtr _sender, int _left, int _top, MyGUI::MouseButton _id)
	{
		if (_id == MyGUI::MouseButton::Left)
		{
			if ( ! mIsDrug )
			{
				mIsDrug = true;

				mDrugLine.colour.set(1, 1, 1, 1);
				mDrugLine.end_offset = 0;
				mDrugLine.start_offset = _sender->getLeft() < 10 ? -1 : 1;
				mDrugLine.point_start.set(
					_sender->getAbsoluteLeft() - _sender->getParent()->getParent()->getAbsoluteLeft() + 4,
					_sender->getAbsoluteTop() - _sender->getParent()->getParent()->getAbsoluteTop() + 4
					);
				mDrugLine.point_end = mDrugLine.point_start;

				mCanvas3->updateTexture();
			}
		}
	}

	void DemoKeeper::notifyMouseButtonReleased(MyGUI::WidgetPtr _sender, int _left, int _top, MyGUI::MouseButton _id)
	{
		//    
		if (mIsDrug)
		{
			mIsDrug = false;
			mCanvas3->updateTexture();
		}
	}

	void DemoKeeper::notifyMouseDrag(MyGUI::WidgetPtr _sender, int _left, int _top)
	{
		if (mIsDrug)
		{
			mDrugLine.point_end.set(_left - _sender->getParent()->getParent()->getAbsoluteLeft(), _top - _sender->getParent()->getParent()->getAbsoluteTop());

			//     
			double distance = ((mDrugLine.point_end.left - mDrugLine.point_start.left) * (mDrugLine.point_end.left - mDrugLine.point_start.left)) +
				((mDrugLine.point_end.top - mDrugLine.point_start.top) * (mDrugLine.point_end.top - mDrugLine.point_start.top));
			distance = std::sqrt(distance);

			distance *= 0.5;
			if (distance < 1) distance = 1;
			else if (distance > 100) distance = 100;
			if (mDrugLine.start_offset < 0) mDrugLine.start_offset = distance * -1;
			else  mDrugLine.start_offset = distance;

			//    
			MyGUI::WidgetPtr widget = MyGUI::LayerManager::getInstance().getWidgetFromPoint(_left, _top);
			if (widget != nullptr && widget->isUserString("NodeLink"))
			{
				bool accept = MyGUI::utility::parseBool(widget->getUserString("NodeLink"));
				if (accept)
					mDrugLine.colour = MyGUI::Colour::Green;
				else
					mDrugLine.colour = MyGUI::Colour::Red;
			}
			else 
			{
				mDrugLine.colour = MyGUI::Colour::White;
			}


			mCanvas3->updateTexture();
		}
	}

	void DemoKeeper::createScene()
    {
		//  
		//mGUI->load("core_theme_black_orange.xml");
		//mGUI->load("core_skin.xml");
		mNodeWindow1 = mNodeWindow2 = mNodeWindow3 = nullptr;
		mIsDrug = false;

		mCanvas1Size = 350;
		mCanvas2Size = 300;
		mCanvas3Size = 300;

		//mCanvasFactory = new MyGUI::factory::CanvasFactory();
		//mTestRenderBoxFactory = new MyGUI::factory::TestRenderBoxFactory();

		MyGUI::WindowPtr wnd = mGUI->createWidget<MyGUI::Window>("WindowCS", MyGUI::IntCoord(400, 400, 400, 400), MyGUI::Align::Default, "Overlapped");
		mTestRenderBox1 = wnd->createWidget<MyGUI::RenderBox>( "TestRenderBox", MyGUI::IntCoord( MyGUI::IntPoint(), wnd->getClientCoord().size() ), MyGUI::Align::Stretch );
		//mTestRenderBox1->setCamera( mCamera );
		//mTestRenderBox1->setBackgroungColour(Ogre::ColourValue::ZERO);

		mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject( mSceneMgr->createEntity( "axes", "axes.mesh" ) );

		mSceneMgr->getRootSceneNode()->getChildIterator().peekNextValue()->scale( Ogre::Vector3( 4 ) );

		wraps::RenderBoxWrap * box = new wraps::RenderBoxWrap(mTestRenderBox1);
		box->injectObject("axes.mesh");
		box->setAutoRotation(true);
		box->setMouseRotation(true);
		box->setViewScale(true);

		//   
		//           
		// Re:  
		mPanel1 = mGUI->createWidget<MyGUI::Window>("WindowCS", MyGUI::IntCoord(10, 10, mCanvas1Size, mCanvas1Size), MyGUI::Align::Default, "Overlapped");
		mPanel1->setCaption( Ogre::UTFString( "Const size - stretches" ) );
		mCanvas1 = mPanel1->createWidget< MyGUI::Canvas >( "Canvas", MyGUI::IntCoord(0, 0, 256, 256), MyGUI::Align::Stretch);
		mCanvas1->createTexture( 256, 256, MyGUI::Canvas::TRM_PT_CONST_SIZE ); //   ,  
		mCanvas1->requestUpdateCanvas = MyGUI::newDelegate( this, &DemoKeeper::requestUpdateCanvas1 );

		mPanel1->setAutoAlpha(true);<commit_msg>update demo<commit_after>/*!
    @file
    @author     <NAME>
    @date       08/2008
    @module
*/

#include "precompiled.h"
#include "DemoKeeper.h"

#include "agg_scanline_p.h"
#include "agg_renderer_scanline.h"
#include "agg_pixfmt_rgba.h"

#include "agg_scanline_u.h"
#include "agg_rasterizer_scanline_aa.h"
#include "agg_pixfmt_rgb.h"
#include "agg_path_storage.h"
#include "agg_curves.h"
#include "agg_conv_stroke.h"

#include "RenderBox/RenderBoxWrap.h"

namespace demo
{
	PaintInfo createPaintPrimitive(const MyGUI::IntSize& _size)
	{
		PaintInfo info;
		info.vert = rand() % 2 != 0;
		info.x = rand() % _size.width;
		info.y = rand() % _size.height;
		info.len = rand() % 32;
		info.colour = Ogre::ColourValue(
			rand()%256 / float(255),
			rand()%256 / float(255),
			rand()%256 / float(255),
			rand()%256 / float(255));
		return info;
	}

	void drawPaintPrimitive(const PaintInfo& _data, MyGUI::CanvasPtr _canvas)
	{
		const MyGUI::IntSize& size = _canvas->getTextureRealSize();
		int xdelta = _data.vert ? 0 : 1;
		int ydelta = _data.vert ? 1 : 0;
		int x = _data.x;
		int y = _data.y;
		int count = _data.len;
		while (count != 0) {
			if (x < size.width && y < size.height) {
				_canvas->setPixel(x, y, _data.colour);
			}
			x += xdelta;
			y += ydelta;
			count--;
		}
	}

	bool DemoKeeper::frameStarted( const Ogre::FrameEvent & evt )
	{
		bool res = BaseManager::frameStarted( evt );

		mSceneMgr->getRootSceneNode()->getChildIterator().peekNextValue()->yaw( Ogre::Radian( 10 )* evt.timeSinceLastFrame );

		return res;
	}

	void DemoKeeper::notifyMouseButtonPressed(MyGUI::WidgetPtr _sender, int _left, int _top, MyGUI::MouseButton _id)
	{
		if (_id == MyGUI::MouseButton::Left)
		{
			if ( ! mIsDrug )
			{
				mIsDrug = true;

				mDrugLine.colour.set(1, 1, 1, 1);
				mDrugLine.end_offset = 0;
				mDrugLine.start_offset = _sender->getLeft() < 10 ? -1 : 1;
				mDrugLine.point_start.set(
					_sender->getAbsoluteLeft() - _sender->getParent()->getParent()->getAbsoluteLeft() + 4,
					_sender->getAbsoluteTop() - _sender->getParent()->getParent()->getAbsoluteTop() + 4
					);
				mDrugLine.point_end = mDrugLine.point_start;

				mCanvas3->updateTexture();
			}
		}
	}

	void DemoKeeper::notifyMouseButtonReleased(MyGUI::WidgetPtr _sender, int _left, int _top, MyGUI::MouseButton _id)
	{
		//    
		if (mIsDrug)
		{
			mIsDrug = false;
			mCanvas3->updateTexture();
		}
	}

	void DemoKeeper::notifyMouseDrag(MyGUI::WidgetPtr _sender, int _left, int _top)
	{
		if (mIsDrug)
		{
			mDrugLine.point_end.set(_left - _sender->getParent()->getParent()->getAbsoluteLeft(), _top - _sender->getParent()->getParent()->getAbsoluteTop());

			//     
			double distance = ((mDrugLine.point_end.left - mDrugLine.point_start.left) * (mDrugLine.point_end.left - mDrugLine.point_start.left)) +
				((mDrugLine.point_end.top - mDrugLine.point_start.top) * (mDrugLine.point_end.top - mDrugLine.point_start.top));
			distance = std::sqrt(distance);

			distance *= 0.5;
			if (distance < 1) distance = 1;
			else if (distance > 100) distance = 100;
			if (mDrugLine.start_offset < 0) mDrugLine.start_offset = distance * -1;
			else  mDrugLine.start_offset = distance;

			//    
			MyGUI::WidgetPtr widget = MyGUI::LayerManager::getInstance().getWidgetFromPoint(_left, _top);
			if (widget != nullptr && widget->isUserString("NodeLink"))
			{
				bool accept = MyGUI::utility::parseBool(widget->getUserString("NodeLink"));
				if (accept)
					mDrugLine.colour = MyGUI::Colour::Green;
				else
					mDrugLine.colour = MyGUI::Colour::Red;
			}
			else 
			{
				mDrugLine.colour = MyGUI::Colour::White;
			}


			mCanvas3->updateTexture();
		}
	}

	void DemoKeeper::createScene()
    {
		//  
		//mGUI->load("core_theme_black_orange.xml");
		//mGUI->load("core_skin.xml");
		mNodeWindow1 = mNodeWindow2 = mNodeWindow3 = nullptr;
		mIsDrug = false;

		mCanvas1Size = 350;
		mCanvas2Size = 300;
		mCanvas3Size = 300;

		//mCanvasFactory = new MyGUI::factory::CanvasFactory();
		//mTestRenderBoxFactory = new MyGUI::factory::TestRenderBoxFactory();
		MyGUI::EditPtr edit = mGUI->createWidget<MyGUI::Edit>("EditStretch", MyGUI::IntCoord(40, 600, 200, 50), MyGUI::Align::Default, "Overlapped");
		edit->setEditMultiLine(true);
		edit->setOverflowToTheLeft(true);
		edit->setMaxTextLength(60);
		edit->addText("1234jkdfhgkjahgsdkjfagsdkjfgakjdhgkfajhgsdkjsdhgkajgksdjjsdghf");
		edit->setTextIntervalColour(2, 10, MyGUI::Colour::Red);

		MyGUI::WindowPtr wnd = mGUI->createWidget<MyGUI::Window>("WindowCS", MyGUI::IntCoord(400, 400, 400, 400), MyGUI::Align::Default, "Overlapped");
		mTestRenderBox1 = wnd->createWidget<MyGUI::RenderBox>( "TestRenderBox", MyGUI::IntCoord( MyGUI::IntPoint(), wnd->getClientCoord().size() ), MyGUI::Align::Stretch );
		//mTestRenderBox1->setCamera( mCamera );
		//mTestRenderBox1->setBackgroungColour(Ogre::ColourValue::ZERO);

		mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject( mSceneMgr->createEntity( "axes", "axes.mesh" ) );

		mSceneMgr->getRootSceneNode()->getChildIterator().peekNextValue()->scale( Ogre::Vector3( 4 ) );

		wraps::RenderBoxWrap * box = new wraps::RenderBoxWrap(mTestRenderBox1);
		box->injectObject("axes.mesh");
		box->setAutoRotation(true);
		box->setMouseRotation(true);
		box->setViewScale(true);

		//   
		//           
		// Re:  
		mPanel1 = mGUI->createWidget<MyGUI::Window>("WindowCS", MyGUI::IntCoord(10, 10, mCanvas1Size, mCanvas1Size), MyGUI::Align::Default, "Overlapped");
		mPanel1->setCaption( Ogre::UTFString( "Const size - stretches" ) );
		mCanvas1 = mPanel1->createWidget< MyGUI::Canvas >( "Canvas", MyGUI::IntCoord(0, 0, 256, 256), MyGUI::Align::Stretch);
		mCanvas1->createTexture( 256, 256, MyGUI::Canvas::TRM_PT_CONST_SIZE ); //   ,  
		mCanvas1->requestUpdateCanvas = MyGUI::newDelegate( this, &DemoKeeper::requestUpdateCanvas1 );

		mPanel1->setAutoAlpha(true);
{'fraction_non_alphanumeric': 0.1610401057734685, 'fraction_numerical': 0.024239753195240195, 'mean_word_length': 4.309312119794104, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 120, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6874678', 'n_tokens_mistral': 4782, 'n_tokens_neox': 4153, 'n_words': 680}