<commit_before>//////////////////////////////////////////////////////////////////////////////////
/// ARGSS - Copyright (c) 2009 - 2010, Alejandro Marzini (vgvgf)
///         All rights reserved.
///
/// Redistribution and use in source and binary forms, with or without
/// modification, are permitted provided that the following conditions are met:
///     * Redistributions of source code must retain the above copyright
///       notice, this list of conditions and the following disclaimer.
///     * Redistributions in binary form must reproduce the above copyright
///       notice, this list of conditions and the following disclaimer in the
///       documentation and/or other materials provided with the distribution.
///
/// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY
/// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
/// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
/// DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
/// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
/// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
/// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
/// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
/// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
/// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////
/// Headers
////////////////////////////////////////////////////////////
#include <string>

#include "argss_bitmap.hxx"
#include "argss_color.hxx"
#include "argss_error.hxx"
#include "argss_rect.hxx"
#include "argss_viewport.hxx"
#include "argss_window_xp.hxx"

#include "window_xp.hxx"

////////////////////////////////////////////////////////////
/// Cap opacity value between 0 and 255
////////////////////////////////////////////////////////////
int CapOpacityValue(int v)
{
	return (v > 255) ? 255 : (v < 0) ? 0 : v;
}

namespace ARGSS
{
	namespace AWindow
	{
		namespace
		{
			////////////////////////////////////////////////////////////
			/// Global Variables
			////////////////////////////////////////////////////////////
			VALUE id;
		} // namespace

		////////////////////////////////////////////////////////////
		/// ARGSS Window ruby functions
		////////////////////////////////////////////////////////////
		VALUE rinitialize(int argc, VALUE *argv, VALUE self)
		{
			if (argc == 1) {
				Check_Classes_N(argv[0], ARGSS::AViewport::getID());
				rb_iv_set(self, "@viewport", argv[0]);
			}
			else if (argc == 0) {
				rb_iv_set(self, "@viewport", Qnil);
			}
			else raise_argn(argc, 1);
			rb_iv_set(self, "@windowskin", Qnil);
			rb_iv_set(self, "@contents", Qnil);
			rb_iv_set(self, "@stretch", Qtrue);
			rb_iv_set(self, "@cursor_rect", ARGSS::ARect::New(0, 0, 0, 0));
			rb_iv_set(self, "@active", Qtrue);
			rb_iv_set(self, "@visible", Qtrue);
			rb_iv_set(self, "@pause", Qfalse);
			rb_iv_set(self, "@x", INT2NUM(0));
			rb_iv_set(self, "@y", INT2NUM(0));
			rb_iv_set(self, "@width", INT2NUM(0));
			rb_iv_set(self, "@height", INT2NUM(0));
			rb_iv_set(self, "@z", INT2NUM(0));
			rb_iv_set(self, "@ox", INT2NUM(0));
			rb_iv_set(self, "@oy", INT2NUM(0));
			rb_iv_set(self, "@opacity", INT2NUM(255));
			rb_iv_set(self, "@back_opacity", INT2NUM(255));
			rb_iv_set(self, "@contents_opacity", INT2NUM(255));
			Window::New(self);
			ARGSS::ARuby::AddObject(self);
			return self;
		}
		VALUE rdispose(VALUE self)
		{
			if (!Window::IsDisposed(self)) {
				CheckDisposed(self);
				Window::Dispose(self);
				ARGSS::ARuby::RemoveObject(self);
				rb_gc_start();
			}
			return self;
		}
		VALUE rdisposedQ(VALUE self)
		{
			return INT2BOOL(Window::IsDisposed(self));
		}
		VALUE rupdate(VALUE self)
		{
			CheckDisposed(self);
			Window::Get(self)->Update();
			return Qnil;
		}
		VALUE rviewport(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@viewport");
		}
		VALUE rviewportE(VALUE self, VALUE viewport)
		{
			CheckDisposed(self);
			Check_Classes_N(viewport, ARGSS::AViewport::getID());
			Window::Get(self)->SetViewport(viewport);
			return rb_iv_set(self, "@viewport", viewport);
		}
		VALUE rwindowskin(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@windowskin");
		}
		VALUE rwindowskinE(VALUE self, VALUE windowskin)
		{
			CheckDisposed(self);
			Check_Classes_N(windowskin, ARGSS::ABitmap::getID());
			Window::Get(self)->SetWindowskin(windowskin);
			return rb_iv_set(self, "@windowskin", windowskin);
		}
		VALUE rcontents(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@contents");
		}
		VALUE rcontentsE(VALUE self, VALUE contents)
		{
			CheckDisposed(self);
			Check_Classes_N(contents, ARGSS::ABitmap::getID());
			Window::Get(self)->SetContents(contents);
			return rb_iv_set(self, "@contents", contents);
		}
		VALUE rstretch(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@stretch");
		}
		VALUE rstretchE(VALUE self, VALUE stretch)
		{
			CheckDisposed(self);
			Window::Get(self)->SetStretch(NUM2BOOL(stretch));
			return rb_iv_set(self, "@stretch", stretch);
		}
		VALUE rcursor_rect(VALUE self) {
			CheckDisposed(self);
			return rb_iv_get(self, "@cursor_rect");
		}
		VALUE rcursor_rectE(VALUE self, VALUE cursor_rect)
		{
			CheckDisposed(self);
			Check_Class(cursor_rect, ARGSS::ARect::getID());
			Window::Get(self)->SetCursorRect(cursor_rect);
			return rb_iv_set(self, "@cursor_rect", cursor_rect);
		}
		VALUE ractive(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@active");
		}
		VALUE ractiveE(VALUE self, VALUE active)
		{
			CheckDisposed(self);
			Window::Get(self)->SetActive(NUM2BOOL(active));
			return rb_iv_set(self, "@active", active);
		}
		VALUE rvisible(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@visible");
		}
		VALUE rvisibleE(VALUE self, VALUE visible)
		{
			CheckDisposed(self);
			Window::Get(self)->SetVisible(NUM2BOOL(visible));
			return rb_iv_set(self, "@visible", visible);
		}
		VALUE rpause(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@pause");
		}
		VALUE rpauseE(VALUE self, VALUE pause)
		{
			CheckDisposed(self);
			Window::Get(self)->SetPause(NUM2BOOL(pause));
			return rb_iv_set(self, "@pause", pause);
		}
		VALUE rx(VALUE self)
		{
			CheckDisposed(self);
			return rb_to_int(rb_iv_get(self, "@x"));
		}
		VALUE rfx(VALUE self)
		{
			CheckDisposed(self);
			return rb_Float(rb_iv_get(self, "@x"));
		}
		VALUE rxE(VALUE self, VALUE x)
		{
			CheckDisposed(self);
			Window::Get(self)->SetX(NUM2INT(x));
			return rb_iv_set(self, "@x", x);
		}
		VALUE ry(VALUE self)
		{
			CheckDisposed(self);
			return rb_to_int(rb_iv_get(self, "@y"));
		}
		VALUE rfy(VALUE self)
		{
			CheckDisposed(self);
			return rb_Float(rb_iv_get(self, "@y"));
		}
		VALUE ryE(VALUE self, VALUE y)
		{
			CheckDisposed(self);
			Window::Get(self)->SetY(NUM2INT(y));
			return rb_iv_set(self, "@y", y);
		}
		VALUE rwidth(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@width");
		}
		VALUE rwidthE(VALUE self, VALUE width)
		{
			CheckDisposed(self);
			int w = NUM2INT(width);
			if (w < 0) w = 0;
			Window::Get(self)->SetWidth(w);
			return rb_iv_set(self, "@width", INT2NUM(w));
		}
		VALUE rheight(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@height");
		}
		VALUE rheightE(VALUE self, VALUE height)
		{
			CheckDisposed(self);
			int h = NUM2INT(height);
			if (h < 0) h = 0;
			Window::Get(self)->SetHeight(h);
			return rb_iv_set(self, "@height", INT2NUM(h));
		}
		VALUE rz(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@z");
		}
		VALUE rzE(VALUE self, VALUE z)
		{
			CheckDisposed(self);
			Window::Get(self)->SetZ(NUM2INT(z));
			return rb_iv_set(self, "@z", z);
		}
		VALUE rox(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@ox");
		}
		VALUE roxE(VALUE self, VALUE ox)
		{
			CheckDisposed(self);
			Window::Get(self)->SetOx(NUM2INT(ox));
			return rb_iv_set(self, "@ox", ox);
		}
		VALUE roy(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@oy");
		}
		VALUE royE(VALUE self, VALUE oy)
		{
			CheckDisposed(self);
			Window::Get(self)->SetOy(NUM2INT(oy));
			return rb_iv_set(self, "@oy", oy);
		}
		VALUE ropacity(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@opacity");
		}
		VALUE ropacityE(VALUE self, VALUE opacity)
		{
			CheckDisposed(self);
			opacity = CapOpacityValue(NUM2INT(opacity));
			Window::Get(self)->SetOpacity(opacity);
			return rb_iv_set(self, "@opacity", INT2NUM(opacity));
		}
		VALUE rback_opacity(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@back_opacity");
		}
		VALUE rback_opacityE(VALUE self, VALUE back_opacity)
		{
			CheckDisposed(self);
			back_opacity = CapOpacityValue(NUM2INT(back_opacity));
			Window::Get(self)->SetBackOpacity(back_opacity);
			return rb_iv_set(self, "@back_opacity", INT2NUM(back_opacity));
		}
		VALUE rcontents_opacity(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@contents_opacity");
		}
		VALUE rcontents_opacityE(VALUE self, VALUE contents_opacity)
		{
			CheckDisposed(self);
			contents_opacity = CapOpacityValue(NUM2INT(contents_opacity));
			Window::Get(self)->SetContentsOpacity(contents_opacity);
			return rb_iv_set(self, "@contents_opacity", INT2NUM(contents_opacity));
		}

		////////////////////////////////////////////////////////////
		/// ARGSS Window initialize
		////////////////////////////////////////////////////////////
		void Init()
		{
			id = rb_define_class("Window", rb_cObject);
			static FuncTable funcTable =
			{
				{ ARGSS_FUNC(initialize), -1 },
				{ ARGSS_FUNC(dispose), 0 }, { ARGSS_Q(disposed), 0 },
				{ ARGSS_FUNC(update), 0 },
				ARGSS_GETTER_SETTER(viewport),
				ARGSS_GETTER_SETTER(windowskin),
				ARGSS_GETTER_SETTER(contents),
				ARGSS_GETTER_SETTER(stretch),
				ARGSS_GETTER_SETTER(cursor_rect),
				ARGSS_GETTER_SETTER(active),
				ARGSS_GETTER_SETTER(visible),
				ARGSS_GETTER_SETTER(pause),
				ARGSS_GETTER_SETTER(x), { "fx", RubyFunc(rx), 0 },
				ARGSS_GETTER_SETTER(y), { "fy", RubyFunc(ry), 0 },
				ARGSS_GETTER_SETTER(width),
				ARGSS_GETTER_SETTER(height),
				ARGSS_GETTER_SETTER(z),
				ARGSS_GETTER_SETTER(ox),
				ARGSS_GETTER_SETTER(oy),
				ARGSS_GETTER_SETTER(opacity),
				ARGSS_GETTER_SETTER(back_opacity),
				ARGSS_GETTER_SETTER(contents_opacity),
			};
			defineMethods(id, funcTable);
		}

		////////////////////////////////////////////////////////////
		/// Check if window isn't disposed
		////////////////////////////////////////////////////////////
		void CheckDisposed(VALUE self)
		{
			if (Window::IsDisposed(self)) {
				rb_raise(ARGSS::AError::getID(), "disposed window <%i>", (int)self);
			}
		}
	} // namespace AWindow
} // namespace ARGSS
<commit_msg>fix of src/argss_window_xp.cxx<commit_after>//////////////////////////////////////////////////////////////////////////////////
/// ARGSS - Copyright (c) 2009 - 2010, Alejandro Marzini (vgvgf)
///         All rights reserved.
///
/// Redistribution and use in source and binary forms, with or without
/// modification, are permitted provided that the following conditions are met:
///     * Redistributions of source code must retain the above copyright
///       notice, this list of conditions and the following disclaimer.
///     * Redistributions in binary form must reproduce the above copyright
///       notice, this list of conditions and the following disclaimer in the
///       documentation and/or other materials provided with the distribution.
///
/// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY
/// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
/// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
/// DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
/// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
/// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
/// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
/// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
/// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
/// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////
/// Headers
////////////////////////////////////////////////////////////
#include <string>

#include "argss_bitmap.hxx"
#include "argss_color.hxx"
#include "argss_error.hxx"
#include "argss_rect.hxx"
#include "argss_viewport.hxx"
#include "argss_window_xp.hxx"

#include "window_xp.hxx"

////////////////////////////////////////////////////////////
/// Cap opacity value between 0 and 255
////////////////////////////////////////////////////////////
int CapOpacityValue(int v)
{
	return (v > 255) ? 255 : (v < 0) ? 0 : v;
}

namespace ARGSS
{
	namespace AWindow
	{
		namespace
		{
			////////////////////////////////////////////////////////////
			/// Global Variables
			////////////////////////////////////////////////////////////
			VALUE id;
		} // namespace

		////////////////////////////////////////////////////////////
		/// ARGSS Window ruby functions
		////////////////////////////////////////////////////////////
		VALUE rinitialize(int argc, VALUE *argv, VALUE self)
		{
			if (argc == 1) {
				Check_Classes_N(argv[0], ARGSS::AViewport::getID());
				rb_iv_set(self, "@viewport", argv[0]);
			}
			else if (argc == 0) {
				rb_iv_set(self, "@viewport", Qnil);
			}
			else raise_argn(argc, 1);
			rb_iv_set(self, "@windowskin", Qnil);
			rb_iv_set(self, "@contents", Qnil);
			rb_iv_set(self, "@stretch", Qtrue);
			rb_iv_set(self, "@cursor_rect", ARGSS::ARect::New(0, 0, 0, 0));
			rb_iv_set(self, "@active", Qtrue);
			rb_iv_set(self, "@visible", Qtrue);
			rb_iv_set(self, "@pause", Qfalse);
			rb_iv_set(self, "@x", INT2NUM(0));
			rb_iv_set(self, "@y", INT2NUM(0));
			rb_iv_set(self, "@width", INT2NUM(0));
			rb_iv_set(self, "@height", INT2NUM(0));
			rb_iv_set(self, "@z", INT2NUM(0));
			rb_iv_set(self, "@ox", INT2NUM(0));
			rb_iv_set(self, "@oy", INT2NUM(0));
			rb_iv_set(self, "@opacity", INT2NUM(255));
			rb_iv_set(self, "@back_opacity", INT2NUM(255));
			rb_iv_set(self, "@contents_opacity", INT2NUM(255));
			Window::New(self);
			ARGSS::ARuby::AddObject(self);
			return self;
		}
		VALUE rdispose(VALUE self)
		{
			if (!Window::IsDisposed(self)) {
				CheckDisposed(self);
				Window::Dispose(self);
				ARGSS::ARuby::RemoveObject(self);
				rb_gc_start();
			}
			return self;
		}
		VALUE rdisposedQ(VALUE self)
		{
			return INT2BOOL(Window::IsDisposed(self));
		}
		VALUE rupdate(VALUE self)
		{
			CheckDisposed(self);
			Window::Get(self).Update();
			return Qnil;
		}
		VALUE rviewport(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@viewport");
		}
		VALUE rviewportE(VALUE self, VALUE viewport)
		{
			CheckDisposed(self);
			Check_Classes_N(viewport, ARGSS::AViewport::getID());
			Window::Get(self).SetViewport(viewport);
			return rb_iv_set(self, "@viewport", viewport);
		}
		VALUE rwindowskin(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@windowskin");
		}
		VALUE rwindowskinE(VALUE self, VALUE windowskin)
		{
			CheckDisposed(self);
			Check_Classes_N(windowskin, ARGSS::ABitmap::getID());
			Window::Get(self).SetWindowskin(windowskin);
			return rb_iv_set(self, "@windowskin", windowskin);
		}
		VALUE rcontents(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@contents");
		}
		VALUE rcontentsE(VALUE self, VALUE contents)
		{
			CheckDisposed(self);
			Check_Classes_N(contents, ARGSS::ABitmap::getID());
			Window::Get(self).SetContents(contents);
			return rb_iv_set(self, "@contents", contents);
		}
		VALUE rstretch(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@stretch");
		}
		VALUE rstretchE(VALUE self, VALUE stretch)
		{
			CheckDisposed(self);
			Window::Get(self).SetStretch(NUM2BOOL(stretch));
			return rb_iv_set(self, "@stretch", stretch);
		}
		VALUE rcursor_rect(VALUE self) {
			CheckDisposed(self);
			return rb_iv_get(self, "@cursor_rect");
		}
		VALUE rcursor_rectE(VALUE self, VALUE cursor_rect)
		{
			CheckDisposed(self);
			Check_Class(cursor_rect, ARGSS::ARect::getID());
			Window::Get(self).SetCursorRect(cursor_rect);
			return rb_iv_set(self, "@cursor_rect", cursor_rect);
		}
		VALUE ractive(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@active");
		}
		VALUE ractiveE(VALUE self, VALUE active)
		{
			CheckDisposed(self);
			Window::Get(self).SetActive(NUM2BOOL(active));
			return rb_iv_set(self, "@active", active);
		}
		VALUE rvisible(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@visible");
		}
		VALUE rvisibleE(VALUE self, VALUE visible)
		{
			CheckDisposed(self);
			Window::Get(self).SetVisible(NUM2BOOL(visible));
			return rb_iv_set(self, "@visible", visible);
		}
		VALUE rpause(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@pause");
		}
		VALUE rpauseE(VALUE self, VALUE pause)
		{
			CheckDisposed(self);
			Window::Get(self).SetPause(NUM2BOOL(pause));
			return rb_iv_set(self, "@pause", pause);
		}
		VALUE rx(VALUE self)
		{
			CheckDisposed(self);
			return rb_to_int(rb_iv_get(self, "@x"));
		}
		VALUE rfx(VALUE self)
		{
			CheckDisposed(self);
			return rb_Float(rb_iv_get(self, "@x"));
		}
		VALUE rxE(VALUE self, VALUE x)
		{
			CheckDisposed(self);
			Window::Get(self).SetX(NUM2INT(x));
			return rb_iv_set(self, "@x", x);
		}
		VALUE ry(VALUE self)
		{
			CheckDisposed(self);
			return rb_to_int(rb_iv_get(self, "@y"));
		}
		VALUE rfy(VALUE self)
		{
			CheckDisposed(self);
			return rb_Float(rb_iv_get(self, "@y"));
		}
		VALUE ryE(VALUE self, VALUE y)
		{
			CheckDisposed(self);
			Window::Get(self).SetY(NUM2INT(y));
			return rb_iv_set(self, "@y", y);
		}
		VALUE rwidth(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@width");
		}
		VALUE rwidthE(VALUE self, VALUE width)
		{
			CheckDisposed(self);
			int w = NUM2INT(width);
			if (w < 0) w = 0;
			Window::Get(self).SetWidth(w);
			return rb_iv_set(self, "@width", INT2NUM(w));
		}
		VALUE rheight(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@height");
		}
		VALUE rheightE(VALUE self, VALUE height)
		{
			CheckDisposed(self);
			int h = NUM2INT(height);
			if (h < 0) h = 0;
			Window::Get(self).SetHeight(h);
			return rb_iv_set(self, "@height", INT2NUM(h));
		}
		VALUE rz(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@z");
		}
		VALUE rzE(VALUE self, VALUE z)
		{
			CheckDisposed(self);
			Window::Get(self).SetZ(NUM2INT(z));
			return rb_iv_set(self, "@z", z);
		}
		VALUE rox(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@ox");
		}
		VALUE roxE(VALUE self, VALUE ox)
		{
			CheckDisposed(self);
			Window::Get(self).SetOx(NUM2INT(ox));
			return rb_iv_set(self, "@ox", ox);
		}
		VALUE roy(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@oy");
		}
		VALUE royE(VALUE self, VALUE oy)
		{
			CheckDisposed(self);
			Window::Get(self).SetOy(NUM2INT(oy));
			return rb_iv_set(self, "@oy", oy);
		}
		VALUE ropacity(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@opacity");
		}
		VALUE ropacityE(VALUE self, VALUE opacity)
		{
			CheckDisposed(self);
			opacity = CapOpacityValue(NUM2INT(opacity));
			Window::Get(self).SetOpacity(opacity);
			return rb_iv_set(self, "@opacity", INT2NUM(opacity));
		}
		VALUE rback_opacity(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@back_opacity");
		}
		VALUE rback_opacityE(VALUE self, VALUE back_opacity)
		{
			CheckDisposed(self);
			back_opacity = CapOpacityValue(NUM2INT(back_opacity));
			Window::Get(self).SetBackOpacity(back_opacity);
			return rb_iv_set(self, "@back_opacity", INT2NUM(back_opacity));
		}
		VALUE rcontents_opacity(VALUE self)
		{
			CheckDisposed(self);
			return rb_iv_get(self, "@contents_opacity");
		}
		VALUE rcontents_opacityE(VALUE self, VALUE contents_opacity)
		{
			CheckDisposed(self);
			contents_opacity = CapOpacityValue(NUM2INT(contents_opacity));
			Window::Get(self).SetContentsOpacity(contents_opacity);
			return rb_iv_set(self, "@contents_opacity", INT2NUM(contents_opacity));
		}

		////////////////////////////////////////////////////////////
		/// ARGSS Window initialize
		////////////////////////////////////////////////////////////
		void Init()
		{
			id = rb_define_class("Window", rb_cObject);
			static FuncTable funcTable =
			{
				{ ARGSS_FUNC(initialize), -1 },
				{ ARGSS_FUNC(dispose), 0 }, { ARGSS_Q(disposed), 0 },
				{ ARGSS_FUNC(update), 0 },
				ARGSS_GETTER_SETTER(viewport),
				ARGSS_GETTER_SETTER(windowskin),
				ARGSS_GETTER_SETTER(contents),
				ARGSS_GETTER_SETTER(stretch),
				ARGSS_GETTER_SETTER(cursor_rect),
				ARGSS_GETTER_SETTER(active),
				ARGSS_GETTER_SETTER(visible),
				ARGSS_GETTER_SETTER(pause),
				ARGSS_GETTER_SETTER(x), { "fx", RubyFunc(rx), 0 },
				ARGSS_GETTER_SETTER(y), { "fy", RubyFunc(ry), 0 },
				ARGSS_GETTER_SETTER(width),
				ARGSS_GETTER_SETTER(height),
				ARGSS_GETTER_SETTER(z),
				ARGSS_GETTER_SETTER(ox),
				ARGSS_GETTER_SETTER(oy),
				ARGSS_GETTER_SETTER(opacity),
				ARGSS_GETTER_SETTER(back_opacity),
				ARGSS_GETTER_SETTER(contents_opacity),
			};
			defineMethods(id, funcTable);
		}

		////////////////////////////////////////////////////////////
		/// Check if window isn't disposed
		////////////////////////////////////////////////////////////
		void CheckDisposed(VALUE self)
		{
			if (Window::IsDisposed(self)) {
				rb_raise(ARGSS::AError::getID(), "disposed window <%i>", (int)self);
			}
		}
	} // namespace AWindow
} // namespace ARGSS
<|endoftext|>


<commit_before>#include <stdio.h>
#include <string>

#include "cll.h"
#include "util.h"

CL::CL()
{
    printf("Initialize OpenCL object and context\n");
    //setup devices and context

    //this function is defined in util.cpp
    //it comes from the NVIDIA SDK example code
    err = oclGetPlatformID(&platform);
    //oclErrorString is also defined in util.cpp and comes from the NVIDIA SDK
    printf("oclGetPlatformID: %s\n", oclErrorString(err));

    // Get the number of GPU devices available to the platform
    // we should probably expose the device type to the user
    // the other common option is CL_DEVICE_TYPE_CPU
    err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, NULL, &numDevices);
    printf("clGetDeviceIDs (get number of devices): %s\n", oclErrorString(err));

    // Create the device list
    devices = new cl_device_id [numDevices];
    err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, numDevices, devices, NULL);
    printf("clGetDeviceIDs (create device list): %s\n", oclErrorString(err));

    //create the context
    context = clCreateContext(0, 1, devices, NULL, NULL, &err);

    //for right now we just use the first available device
    //later you may have criteria (such as support for different extensions)
    //that you want to use to select the device
    deviceUsed = 0;

    //create the command queue we will use to execute OpenCL commands
    command_queue = clCreateCommandQueue(context, devices[deviceUsed], 0, &err);

    cl_a = 0;
    cl_b = 0;
    cl_c = 0;
}

CL::~CL()
{
    printf("Releasing OpenCL memory\n");
    if(kernel)clReleaseKernel(kernel);
    if(program)clReleaseProgram(program);
    if(command_queue)clReleaseCommandQueue(command_queue);

    //need to release any other OpenCL memory objects here
    if(cl_a)clReleaseMemObject(cl_a);
    if(cl_b)clReleaseMemObject(cl_b);
    if(cl_c)clReleaseMemObject(cl_c);

    if(context)clReleaseContext(context);

    if(devices)delete(devices);
    printf("OpenCL memory released\n");
}

void CL::loadProgram(const char* relative_path)
{
 // Program Setup
    int pl;
    size_t program_length;
    printf("load the program\n");

    //CL_SOURCE_DIR is set in the CMakeLists.txt
    std::string path(CL_SOURCE_DIR);
    path += "/" + std::string(relative_path);
    printf("path: %s\n", path.c_str());

    //file_contents is defined in util.cpp
    //it loads the contents of the file at the given path
    char* cSourceCL = file_contents(path.c_str(), &pl);
    //printf("file: %s\n", cSourceCL);
    program_length = (size_t)pl;

    // create the program
    program = clCreateProgramWithSource(context, 1,
                      (const char **) &cSourceCL, &program_length, &err);
    printf("clCreateProgramWithSource: %s\n", oclErrorString(err));

    buildExecutable();

    //Free buffer returned by file_contents
    free(cSourceCL);
}

//----------------------------------------------------------------------
void CL::buildExecutable()
{
    // Build the program executable

    printf("building the program\n");
    // build the program
    //err = clBuildProgram(program, 0, NULL, "-cl-nv-verbose", NULL, NULL);
    err = clBuildProgram(program, 0, NULL, NULL, NULL, NULL);
    printf("clBuildProgram: %s\n", oclErrorString(err));
	//if(err != CL_SUCCESS){
		cl_build_status build_status;
		err = clGetProgramBuildInfo(program, devices[deviceUsed], CL_PROGRAM_BUILD_STATUS, sizeof(cl_build_status), &build_status, NULL);

		char *build_log;
		size_t ret_val_size;
		err = clGetProgramBuildInfo(program, devices[deviceUsed], CL_PROGRAM_BUILD_LOG, 0, NULL, &ret_val_size);

		build_log = new char[ret_val_size+1];
		err = clGetProgramBuildInfo(program, devices[deviceUsed], CL_PROGRAM_BUILD_LOG, ret_val_size, build_log, NULL);
		build_log[ret_val_size] = '\0';
		printf("BUILD LOG: \n %s", build_log);
	//}
    printf("program built\n");
}

<commit_msg>Part1: Include cstdlib to provide free.<commit_after>#include <stdio.h>
#include <string>
#include <cstdlib>

#include "cll.h"
#include "util.h"

CL::CL()
{
    printf("Initialize OpenCL object and context\n");
    //setup devices and context

    //this function is defined in util.cpp
    //it comes from the NVIDIA SDK example code
    err = oclGetPlatformID(&platform);
    //oclErrorString is also defined in util.cpp and comes from the NVIDIA SDK
    printf("oclGetPlatformID: %s\n", oclErrorString(err));

    // Get the number of GPU devices available to the platform
    // we should probably expose the device type to the user
    // the other common option is CL_DEVICE_TYPE_CPU
    err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, NULL, &numDevices);
    printf("clGetDeviceIDs (get number of devices): %s\n", oclErrorString(err));

    // Create the device list
    devices = new cl_device_id [numDevices];
    err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, numDevices, devices, NULL);
    printf("clGetDeviceIDs (create device list): %s\n", oclErrorString(err));

    //create the context
    context = clCreateContext(0, 1, devices, NULL, NULL, &err);

    //for right now we just use the first available device
    //later you may have criteria (such as support for different extensions)
    //that you want to use to select the device
    deviceUsed = 0;

    //create the command queue we will use to execute OpenCL commands
    command_queue = clCreateCommandQueue(context, devices[deviceUsed], 0, &err);

    cl_a = 0;
    cl_b = 0;
    cl_c = 0;
}

CL::~CL()
{
    printf("Releasing OpenCL memory\n");
    if(kernel)clReleaseKernel(kernel);
    if(program)clReleaseProgram(program);
    if(command_queue)clReleaseCommandQueue(command_queue);

    //need to release any other OpenCL memory objects here
    if(cl_a)clReleaseMemObject(cl_a);
    if(cl_b)clReleaseMemObject(cl_b);
    if(cl_c)clReleaseMemObject(cl_c);

    if(context)clReleaseContext(context);

    if(devices)delete(devices);
    printf("OpenCL memory released\n");
}

void CL::loadProgram(const char* relative_path)
{
 // Program Setup
    int pl;
    size_t program_length;
    printf("load the program\n");

    //CL_SOURCE_DIR is set in the CMakeLists.txt
    std::string path(CL_SOURCE_DIR);
    path += "/" + std::string(relative_path);
    printf("path: %s\n", path.c_str());

    //file_contents is defined in util.cpp
    //it loads the contents of the file at the given path
    char* cSourceCL = file_contents(path.c_str(), &pl);
    //printf("file: %s\n", cSourceCL);
    program_length = (size_t)pl;

    // create the program
    program = clCreateProgramWithSource(context, 1,
                      (const char **) &cSourceCL, &program_length, &err);
    printf("clCreateProgramWithSource: %s\n", oclErrorString(err));

    buildExecutable();

    //Free buffer returned by file_contents
    free(cSourceCL);
}

//----------------------------------------------------------------------
void CL::buildExecutable()
{
    // Build the program executable

    printf("building the program\n");
    // build the program
    //err = clBuildProgram(program, 0, NULL, "-cl-nv-verbose", NULL, NULL);
    err = clBuildProgram(program, 0, NULL, NULL, NULL, NULL);
    printf("clBuildProgram: %s\n", oclErrorString(err));
	//if(err != CL_SUCCESS){
		cl_build_status build_status;
		err = clGetProgramBuildInfo(program, devices[deviceUsed], CL_PROGRAM_BUILD_STATUS, sizeof(cl_build_status), &build_status, NULL);

		char *build_log;
		size_t ret_val_size;
		err = clGetProgramBuildInfo(program, devices[deviceUsed], CL_PROGRAM_BUILD_LOG, 0, NULL, &ret_val_size);

		build_log = new char[ret_val_size+1];
		err = clGetProgramBuildInfo(program, devices[deviceUsed], CL_PROGRAM_BUILD_LOG, ret_val_size, build_log, NULL);
		build_log[ret_val_size] = '\0';
		printf("BUILD LOG: \n %s", build_log);
	//}
    printf("program built\n");
}

<|endoftext|>


<commit_before><commit_msg>discard previous http reply on execute if not fully read in http client<commit_after><|endoftext|>


<commit_before>#include <nic.h>
#include "rgb_led_controller.h"
#include "tools.h"

__USING_SYS

int sender() {
	NIC nic;
	RGBLEDController led_ctrl;

	while (true) {
		RGB color = getColor();
		led_ctrl.writeColor(color);
	}

	return 0;
}

int main() {
	return sender();
}
<commit_msg>Turn default LED off on start<commit_after>#include <nic.h>
#include "rgb_led_controller.h"
#include "tools.h"

__USING_SYS

int sender() {
	NIC nic;
	RGBLEDController led_ctrl;

	GPIO_Pin red_led(23);
	red_led.put(0);

	while (true) {
		RGB color = getColor();
		led_ctrl.writeColor(color);
	}

	return 0;
}

int main() {
	return sender();
}
<|endoftext|>


<commit_before>/**
* @file PostEffectNull.h
*
* Copyright (c) 2015 by Gruzdev Alexey
*
* Code covered by the MIT License
* The authors make no representations about the suitability of this software
* for any purpose. It is provided "as is" without express or implied warranty.
*/

#include "PostEffectFactory.h"
#include "PostEffectManager.h"

#include <OgreMaterial.h>
#include <OgreMaterialManager.h>
#include <OgreHighLevelGpuProgram.h>
#include <OgreHighLevelGpuProgramManager.h>
#include <OgreTechnique.h>
#include <OgrePass.h>

namespace
{
    static const char Shader_GL_Blur_V[] = ""
        "#version 120                                                              \n"
        "                                                                          \n"
        "                                                                          \n"
        "void main()                                                               \n"
        "{                                                                         \n"
        "    gl_TexCoord[0] = gl_MultiTexCoord0;                                   \n"
        "    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;               \n"
        "}                                                                         \n"
        "";

#if 0
    //Gaussian values in points [-2, -1, 0, 1, 2] with sigma = 1.2
#define GAUSS0 "0.343406"
#define GAUSS1 "0.242667"
#define GAUSS2 "0.085629"
#else
    //Gaussian values in points [-2, -1, 0, 1, 2] with sigma = 2.0
#define GAUSS0 "0.251379"
#define GAUSS1 "0.221841"
#define GAUSS2 "0.152469"
#endif

    static const char Shader_GL_Blur_Horz_F[] = ""
        "#version 120                                                                                \n"
        "                                                                                \n"
        "uniform sampler2D texture;                                                                         \n"
        "uniform vec4 offset;                                                                               \n"
        "                                                                                \n"
        "void main()                                                                                \n"
        "{                                                                                \n"
        "    vec2 coords  = gl_TexCoord[0].st;                                                              \n"
        "    float step = offset.z;                                                                         \n"
        "    gl_FragColor = "GAUSS2" * texture2D(texture, coords  - vec2(step + step, 0.0)) +               \n"
        "                   "GAUSS1" * texture2D(texture, coords  - vec2(step, 0.0)) +                      \n"
        "                   "GAUSS0" * texture2D(texture, coords) +                                         \n"
        "                   "GAUSS1" * texture2D(texture, coords  + vec2(step, 0.0)) +                      \n"
        "                   "GAUSS2" * texture2D(texture, coords  + vec2(step + step, 0.0));                \n"
        "}                                                                                \n"
        "";

    static const char Shader_GL_Blur_Vert_F[] = ""
        "#version 120                                                                                \n"
        "                                                                                \n"
        "uniform sampler2D texture;                                                                         \n"
        "uniform vec4 offset;                                                                               \n"
        "                                                                                \n"
        "void main()                                                                                \n"
        "{                                                                                \n"
        "    vec2 coords  = gl_TexCoord[0].st;                                                              \n"
        "    float step = offset.w;                                                                         \n"
        "    gl_FragColor = "GAUSS2" * texture2D(texture, coords  - vec2(0.0, step + step)) +               \n"
        "                   "GAUSS1" * texture2D(texture, coords  - vec2(0.0, step)) +                      \n"
        "                   "GAUSS0" * texture2D(texture, coords) +                                         \n"
        "                   "GAUSS1" * texture2D(texture, coords  + vec2(0.0, step)) +                      \n"
        "                   "GAUSS2" * texture2D(texture, coords  + vec2(0.0, step + step));                \n"
        "}                                                                                \n"
        "";
}

namespace OgreEffect
{

    class PostEffectBlur : public PostEffect
    {
    public:
        PostEffectBlur(const Ogre::String& name, size_t id) :
            PostEffect(name, id)
        {

        }
        virtual ~PostEffectBlur()
        {

        }

        virtual MaterialsVector CreateEffectMaterialPrototypes() override
        {
            Ogre::MaterialPtr material_horz = Ogre::MaterialManager::getSingleton().create(
                "Material/PostEffect/" + GetUniquePostfix() + "/Horz", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

            {
                Ogre::Technique* techniqueGL = material_horz->getTechnique(0);
                Ogre::Pass* pass = techniqueGL->getPass(0);

                {
                    auto vprogram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram("Shader/GL/V/H/" + GetUniquePostfix(),
                        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsl", Ogre::GPT_VERTEX_PROGRAM);
                    vprogram->setSource(Shader_GL_Blur_V);

                    pass->setVertexProgram(vprogram->getName());
                }

                {
                    auto fprogram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram("Shader/GL/F/H/" + GetUniquePostfix(),
                        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsl", Ogre::GPT_FRAGMENT_PROGRAM);
                    fprogram->setSource(Shader_GL_Blur_Horz_F);

                    auto unit0 = pass->createTextureUnitState(TEXTURE_MARKER_SCENE);
                    unit0->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
                    unit0->setTextureFiltering(Ogre::TFO_NONE);

                    pass->setFragmentProgram(fprogram->getName());

                    auto fparams = pass->getFragmentProgramParameters();
                    fparams->setNamedConstant("texture", 0);
                    fparams->setNamedAutoConstant("offset", Ogre::GpuProgramParameters::ACT_VIEWPORT_SIZE);
                }
            }
            material_horz->load();

            Ogre::MaterialPtr material_vert = Ogre::MaterialManager::getSingleton().create(
                "Material/PostEffect/" + GetUniquePostfix() + "/Vert", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

            {
                Ogre::Technique* techniqueGL = material_vert->getTechnique(0);
                Ogre::Pass* pass = techniqueGL->getPass(0);

                {
                    auto vprogram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram("Shader/GL/V/V/" + GetUniquePostfix(),
                        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsl", Ogre::GPT_VERTEX_PROGRAM);
                    vprogram->setSource(Shader_GL_Blur_V);

                    pass->setVertexProgram(vprogram->getName());
                }

                {
                    auto fprogram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram("Shader/GL/F/V/" + GetUniquePostfix(),
                        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsl", Ogre::GPT_FRAGMENT_PROGRAM);
                    fprogram->setSource(Shader_GL_Blur_Vert_F);

                    auto unit0 = pass->createTextureUnitState(TEXTURE_MARKER_PREVIOUS);
                    unit0->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
                    unit0->setTextureFiltering(Ogre::TFO_NONE);

                    pass->setFragmentProgram(fprogram->getName());

                    auto fparams = pass->getFragmentProgramParameters();
                    fparams->setNamedConstant("texture", 0);
                    fparams->setNamedAutoConstant("offset", Ogre::GpuProgramParameters::ACT_VIEWPORT_SIZE);
                }
            }
            material_vert->load();

            return{ material_horz.get(), material_vert.get() };
        }
    };

    IMPLEMENT_REGISTRATION_FUNCTION(EffectBlur)
    {
        Ogre::SharedPtr<PostEffectFactory> factory(new DefaultPostEffectFactory<PostEffectBlur>(PostEffectManager::PE_BLUR));
        manager->RegisterPostEffectFactory(factory);
    }

}//OgreEffect
<commit_msg>PostEffectBlur: fixed file header<commit_after>/**
* @file PostEffectBlur.h
*
* Copyright (c) 2015 by Gruzdev Alexey
*
* Code covered by the MIT License
* The authors make no representations about the suitability of this software
* for any purpose. It is provided "as is" without express or implied warranty.
*/

#include "PostEffectFactory.h"
#include "PostEffectManager.h"

#include <OgreMaterial.h>
#include <OgreMaterialManager.h>
#include <OgreHighLevelGpuProgram.h>
#include <OgreHighLevelGpuProgramManager.h>
#include <OgreTechnique.h>
#include <OgrePass.h>

namespace
{
    static const char Shader_GL_Blur_V[] = ""
        "#version 120                                                              \n"
        "                                                                          \n"
        "                                                                          \n"
        "void main()                                                               \n"
        "{                                                                         \n"
        "    gl_TexCoord[0] = gl_MultiTexCoord0;                                   \n"
        "    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;               \n"
        "}                                                                         \n"
        "";

#if 0
    //Gaussian values in points [-2, -1, 0, 1, 2] with sigma = 1.2
#define GAUSS0 "0.343406"
#define GAUSS1 "0.242667"
#define GAUSS2 "0.085629"
#else
    //Gaussian values in points [-2, -1, 0, 1, 2] with sigma = 2.0
#define GAUSS0 "0.251379"
#define GAUSS1 "0.221841"
#define GAUSS2 "0.152469"
#endif

    static const char Shader_GL_Blur_Horz_F[] = ""
        "#version 120                                                                                \n"
        "                                                                                \n"
        "uniform sampler2D texture;                                                                         \n"
        "uniform vec4 offset;                                                                               \n"
        "                                                                                \n"
        "void main()                                                                                \n"
        "{                                                                                \n"
        "    vec2 coords  = gl_TexCoord[0].st;                                                              \n"
        "    float step = offset.z;                                                                         \n"
        "    gl_FragColor = "GAUSS2" * texture2D(texture, coords  - vec2(step + step, 0.0)) +               \n"
        "                   "GAUSS1" * texture2D(texture, coords  - vec2(step, 0.0)) +                      \n"
        "                   "GAUSS0" * texture2D(texture, coords) +                                         \n"
        "                   "GAUSS1" * texture2D(texture, coords  + vec2(step, 0.0)) +                      \n"
        "                   "GAUSS2" * texture2D(texture, coords  + vec2(step + step, 0.0));                \n"
        "}                                                                                \n"
        "";

    static const char Shader_GL_Blur_Vert_F[] = ""
        "#version 120                                                                                \n"
        "                                                                                \n"
        "uniform sampler2D texture;                                                                         \n"
        "uniform vec4 offset;                                                                               \n"
        "                                                                                \n"
        "void main()                                                                                \n"
        "{                                                                                \n"
        "    vec2 coords  = gl_TexCoord[0].st;                                                              \n"
        "    float step = offset.w;                                                                         \n"
        "    gl_FragColor = "GAUSS2" * texture2D(texture, coords  - vec2(0.0, step + step)) +               \n"
        "                   "GAUSS1" * texture2D(texture, coords  - vec2(0.0, step)) +                      \n"
        "                   "GAUSS0" * texture2D(texture, coords) +                                         \n"
        "                   "GAUSS1" * texture2D(texture, coords  + vec2(0.0, step)) +                      \n"
        "                   "GAUSS2" * texture2D(texture, coords  + vec2(0.0, step + step));                \n"
        "}                                                                                \n"
        "";
}

namespace OgreEffect
{

    class PostEffectBlur : public PostEffect
    {
    public:
        PostEffectBlur(const Ogre::String& name, size_t id) :
            PostEffect(name, id)
        {

        }
        virtual ~PostEffectBlur()
        {

        }

        virtual MaterialsVector CreateEffectMaterialPrototypes() override
        {
            Ogre::MaterialPtr material_horz = Ogre::MaterialManager::getSingleton().create(
                "Material/PostEffect/" + GetUniquePostfix() + "/Horz", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

            {
                Ogre::Technique* techniqueGL = material_horz->getTechnique(0);
                Ogre::Pass* pass = techniqueGL->getPass(0);

                {
                    auto vprogram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram("Shader/GL/V/H/" + GetUniquePostfix(),
                        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsl", Ogre::GPT_VERTEX_PROGRAM);
                    vprogram->setSource(Shader_GL_Blur_V);

                    pass->setVertexProgram(vprogram->getName());
                }

                {
                    auto fprogram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram("Shader/GL/F/H/" + GetUniquePostfix(),
                        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsl", Ogre::GPT_FRAGMENT_PROGRAM);
                    fprogram->setSource(Shader_GL_Blur_Horz_F);

                    auto unit0 = pass->createTextureUnitState(TEXTURE_MARKER_SCENE);
                    unit0->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
                    unit0->setTextureFiltering(Ogre::TFO_NONE);

                    pass->setFragmentProgram(fprogram->getName());

                    auto fparams = pass->getFragmentProgramParameters();
                    fparams->setNamedConstant("texture", 0);
                    fparams->setNamedAutoConstant("offset", Ogre::GpuProgramParameters::ACT_VIEWPORT_SIZE);
                }
            }
            material_horz->load();

            Ogre::MaterialPtr material_vert = Ogre::MaterialManager::getSingleton().create(
                "Material/PostEffect/" + GetUniquePostfix() + "/Vert", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

            {
                Ogre::Technique* techniqueGL = material_vert->getTechnique(0);
                Ogre::Pass* pass = techniqueGL->getPass(0);

                {
                    auto vprogram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram("Shader/GL/V/V/" + GetUniquePostfix(),
                        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsl", Ogre::GPT_VERTEX_PROGRAM);
                    vprogram->setSource(Shader_GL_Blur_V);

                    pass->setVertexProgram(vprogram->getName());
                }

                {
                    auto fprogram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram("Shader/GL/F/V/" + GetUniquePostfix(),
                        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsl", Ogre::GPT_FRAGMENT_PROGRAM);
                    fprogram->setSource(Shader_GL_Blur_Vert_F);

                    auto unit0 = pass->createTextureUnitState(TEXTURE_MARKER_PREVIOUS);
                    unit0->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
                    unit0->setTextureFiltering(Ogre::TFO_NONE);

                    pass->setFragmentProgram(fprogram->getName());

                    auto fparams = pass->getFragmentProgramParameters();
                    fparams->setNamedConstant("texture", 0);
                    fparams->setNamedAutoConstant("offset", Ogre::GpuProgramParameters::ACT_VIEWPORT_SIZE);
                }
            }
            material_vert->load();

            return{ material_horz.get(), material_vert.get() };
        }
    };

    IMPLEMENT_REGISTRATION_FUNCTION(EffectBlur)
    {
        Ogre::SharedPtr<PostEffectFactory> factory(new DefaultPostEffectFactory<PostEffectBlur>(PostEffectManager::PE_BLUR));
        manager->RegisterPostEffectFactory(factory);
    }

}//OgreEffect
<|endoftext|>


<commit_before>/*
* ECDSA Signature
* (C) 2007 Falko Strenzke, FlexSecure GmbH
* (C) 2008-2010 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/

#include <botan/ecdsa_sig.h>

namespace Botan {

ECDSA_Signature::ECDSA_Signature(const MemoryRegion<byte>& ber)
   {
   BER_Decoder(ber)
      .start_cons(SEQUENCE)
         .decode(m_r)
         .decode(m_s)
      .end_cons()
      .verify_end();
   }

MemoryVector<byte> ECDSA_Signature::DER_encode() const
   {
   return DER_Encoder()
      .start_cons(SEQUENCE)
        .encode(get_r())
        .encode(get_s())
      .end_cons()
      .get_contents();
   }

MemoryVector<byte> ECDSA_Signature::get_concatenation() const
   {
   u32bit enc_len = m_r > m_s ? m_r.bytes() : m_s.bytes(); // use the larger

   SecureVector<byte> sv_r = BigInt::encode_1363(m_r, enc_len);
   SecureVector<byte> sv_s = BigInt::encode_1363(m_s, enc_len);

   SecureVector<byte> result(sv_r);
   result += sv_s;
   return result;
   }

ECDSA_Signature decode_concatenation(const MemoryRegion<byte>& concat)
   {
   if(concat.size() % 2 != 0)
      throw Invalid_Argument("Erroneous length of signature");

   const u32bit rs_len = concat.size() / 2;

   BigInt r = BigInt::decode(&concat[0], rs_len);
   BigInt s = BigInt::decode(&concat[rs_len], rs_len);

   return ECDSA_Signature(r, s);
   }

}
<commit_msg>Overflow warning in MSVC<commit_after>/*
* ECDSA Signature
* (C) 2007 Falko Strenzke, FlexSecure GmbH
* (C) 2008-2010 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/

#include <botan/ecdsa_sig.h>

namespace Botan {

ECDSA_Signature::ECDSA_Signature(const MemoryRegion<byte>& ber)
   {
   BER_Decoder(ber)
      .start_cons(SEQUENCE)
         .decode(m_r)
         .decode(m_s)
      .end_cons()
      .verify_end();
   }

MemoryVector<byte> ECDSA_Signature::DER_encode() const
   {
   return DER_Encoder()
      .start_cons(SEQUENCE)
        .encode(get_r())
        .encode(get_s())
      .end_cons()
      .get_contents();
   }

MemoryVector<byte> ECDSA_Signature::get_concatenation() const
   {
   // use the larger
   const size_t enc_len = m_r > m_s ? m_r.bytes() : m_s.bytes();

   SecureVector<byte> sv_r = BigInt::encode_1363(m_r, enc_len);
   SecureVector<byte> sv_s = BigInt::encode_1363(m_s, enc_len);

   SecureVector<byte> result(sv_r);
   result += sv_s;
   return result;
   }

ECDSA_Signature decode_concatenation(const MemoryRegion<byte>& concat)
   {
   if(concat.size() % 2 != 0)
      throw Invalid_Argument("Erroneous length of signature");

   const u32bit rs_len = concat.size() / 2;

   BigInt r = BigInt::decode(&concat[0], rs_len);
   BigInt s = BigInt::decode(&concat[rs_len], rs_len);

   return ECDSA_Signature(r, s);
   }

}
<|endoftext|>


<commit_before>/**
 * @file eventAggregator.cc
 * @author Michal Sitko
 * @copyright (C) 2014 ACK CYFRONET AGH
 * @copyright This software is released under the MIT license cited in 'LICENSE.txt'
 */

#include "events/eventAggregator.h"

#include "events/event.h"
#include "fuse_messages.pb.h"

#include <list>
#include <map>

using namespace one::client::events;
using namespace std;
using namespace one::clproto::fuse_messages;

constexpr const char *FILE_PATH = "filePath";

EventAggregator::EventAggregator(long long threshold, const string & sumFieldName) :
    IEventStream(), m_fieldName(""), m_threshold(threshold), m_sumFieldName(sumFieldName)
{
}

EventAggregator::EventAggregator(const string & fieldName, long long threshold, const string & sumFieldName) :
    IEventStream(), m_fieldName(fieldName), m_threshold(threshold), m_sumFieldName(sumFieldName)
{
}

EventAggregator::EventAggregator(std::shared_ptr<IEventStream> wrappedStream, long long threshold, const string & sumFieldName) :
    IEventStream(wrappedStream), m_threshold(threshold), m_sumFieldName(sumFieldName)
{
}

EventAggregator::EventAggregator(std::shared_ptr<IEventStream> wrappedStream, const string & fieldName, long long threshold, const string & sumFieldName) :
    IEventStream(wrappedStream), m_fieldName(fieldName), m_threshold(threshold), m_sumFieldName(sumFieldName)
{
}

std::shared_ptr<IEventStream> EventAggregator::fromConfig(const EventAggregatorConfig & config)
{
    return std::make_shared<EventAggregator>(config.field_name(), config.threshold(), config.sum_field_name());
}

std::shared_ptr<Event> EventAggregator::actualProcessEvent(std::shared_ptr<Event> event)
{
    string value;
    if(m_fieldName.empty())
        value = "";
    else{
        value = event->getStringProperty(m_fieldName, "");

        // we simply ignores events without field on which we aggregate
        if(value == "")
            return std::shared_ptr<Event>();
    }

    std::lock_guard<std::mutex> guard{m_substreamsMutex};
    return m_substreams[value].processEvent(event, m_threshold, m_fieldName, m_sumFieldName);
}

string EventAggregator::getFieldName()
{
    return m_fieldName;
}

string EventAggregator::getSumFieldName()
{
    return m_sumFieldName;
}

long long EventAggregator::getThreshold()
{
    return m_threshold;
}

std::shared_ptr<Event> EventAggregator::ActualEventAggregator::processEvent(std::shared_ptr<Event> event, long long threshold, const string & fieldName, const string & sumFieldName)
{
    std::lock_guard<std::mutex> guard{m_aggregatorStateMutex};
    NumericProperty count = event->getNumericProperty(sumFieldName, 1);
    const auto& blocks = event->getBlocks();

    std::string path = event->getStringProperty(FILE_PATH, "");
    auto resultCounter = m_counters.emplace(path, 0);
    resultCounter.first->second += count;

    auto resultBlocks = m_blocks.emplace(path, boost::icl::interval_set<off_t>());

    for(const auto& block : blocks) {
        resultBlocks.first->second += boost::icl::discrete_interval<off_t>::right_open(block.first, block.first + block.second);
    }

    bool forward = resultCounter.first->second >= threshold;

    if(forward){
        auto newEvent = std::make_shared<Event>();
        newEvent->setStringProperty(SUM_FIELD_NAME, sumFieldName);
        newEvent->setNumericProperty(sumFieldName, resultCounter.first->second);
        if(!fieldName.empty()){
            string value = event->getStringProperty(fieldName, "");
            newEvent->setStringProperty(fieldName, value);
        }
        std::list< std::pair<off_t, size_t> > blocks;
        for(const auto& block : resultBlocks.first->second) {
            blocks.push_back(std::pair<off_t, size_t>(block.lower(), block.upper() - block.lower()));
        }
        newEvent->setBlocks(blocks);
        newEvent->setStringProperty(FILE_PATH, path);

        m_blocks.erase(path);
        m_counters.erase(path);

        return newEvent;
    }

    return std::shared_ptr<Event>();
}

std::shared_ptr<Event> EventAggregator::ActualEventAggregator::getEventByProperty(const string & path, const string & value, const string & fieldName, const string & sumFieldName)
{
    auto counter = m_counters[path];
    auto blocks = m_blocks[path];

    auto newEvent = std::make_shared<Event>();
    newEvent->setStringProperty(SUM_FIELD_NAME, sumFieldName);
    newEvent->setNumericProperty(sumFieldName, counter);

    newEvent->setStringProperty(fieldName, value);
    std::list< std::pair<off_t, size_t> > newBlocks;
    for(const auto& block : blocks)
    {
        newBlocks.push_back(std::pair<off_t, size_t>(block.lower(), block.upper() - block.lower()));
    }

    newEvent->setBlocks(newBlocks);
    newEvent->setStringProperty(FILE_PATH, path);

    return newEvent;
}

std::list<std::shared_ptr<Event> > EventAggregator::ActualEventAggregator::getPendingEvents(const string & value, const string & fieldName, const string & sumFieldName)
{
    std::list<std::shared_ptr<Event> > processedEvents;
    for(auto & entry : m_counters)
    {
         auto processedEvent = getEventByProperty(entry.first, value, fieldName, sumFieldName);
         if(processedEvent)
             processedEvents.push_back(processedEvent);
    }
    m_blocks.clear();
    m_counters.clear();
    return processedEvents;
}

std::list<std::shared_ptr<Event> > EventAggregator::getPendingEvents(std::list<std::shared_ptr<Event> > events)
{
    std::list<std::shared_ptr<Event> > processedEvents;
    for(auto & event : events)
    {
        auto processedEvent = actualProcessEvent(event);
        if(processedEvent)
            processedEvents.push_back(processedEvent);
    }

    for(auto & entry : m_substreams)
    {
        auto result = entry.second.getPendingEvents(entry.first, m_fieldName, m_sumFieldName);
        processedEvents.insert(processedEvents.end(), result.begin(), result.end());
    }

    return processedEvents;
}

void EventAggregator::ActualEventAggregator::resetState()
{
    m_counters.clear();
    m_blocks.clear();
}
<commit_msg>Added lock in eventAggregator.<commit_after>/**
 * @file eventAggregator.cc
 * @author Michal Sitko
 * @copyright (C) 2014 ACK CYFRONET AGH
 * @copyright This software is released under the MIT license cited in 'LICENSE.txt'
 */

#include "events/eventAggregator.h"

#include "events/event.h"
#include "fuse_messages.pb.h"

#include <list>
#include <map>

using namespace one::client::events;
using namespace std;
using namespace one::clproto::fuse_messages;

constexpr const char *FILE_PATH = "filePath";

EventAggregator::EventAggregator(long long threshold, const string & sumFieldName) :
    IEventStream(), m_fieldName(""), m_threshold(threshold), m_sumFieldName(sumFieldName)
{
}

EventAggregator::EventAggregator(const string & fieldName, long long threshold, const string & sumFieldName) :
    IEventStream(), m_fieldName(fieldName), m_threshold(threshold), m_sumFieldName(sumFieldName)
{
}

EventAggregator::EventAggregator(std::shared_ptr<IEventStream> wrappedStream, long long threshold, const string & sumFieldName) :
    IEventStream(wrappedStream), m_threshold(threshold), m_sumFieldName(sumFieldName)
{
}

EventAggregator::EventAggregator(std::shared_ptr<IEventStream> wrappedStream, const string & fieldName, long long threshold, const string & sumFieldName) :
    IEventStream(wrappedStream), m_fieldName(fieldName), m_threshold(threshold), m_sumFieldName(sumFieldName)
{
}

std::shared_ptr<IEventStream> EventAggregator::fromConfig(const EventAggregatorConfig & config)
{
    return std::make_shared<EventAggregator>(config.field_name(), config.threshold(), config.sum_field_name());
}

std::shared_ptr<Event> EventAggregator::actualProcessEvent(std::shared_ptr<Event> event)
{
    string value;
    if(m_fieldName.empty())
        value = "";
    else{
        value = event->getStringProperty(m_fieldName, "");

        // we simply ignores events without field on which we aggregate
        if(value == "")
            return std::shared_ptr<Event>();
    }

    std::lock_guard<std::mutex> guard{m_substreamsMutex};
    return m_substreams[value].processEvent(event, m_threshold, m_fieldName, m_sumFieldName);
}

string EventAggregator::getFieldName()
{
    return m_fieldName;
}

string EventAggregator::getSumFieldName()
{
    return m_sumFieldName;
}

long long EventAggregator::getThreshold()
{
    return m_threshold;
}

std::shared_ptr<Event> EventAggregator::ActualEventAggregator::processEvent(std::shared_ptr<Event> event, long long threshold, const string & fieldName, const string & sumFieldName)
{
    std::lock_guard<std::mutex> guard{m_aggregatorStateMutex};
    NumericProperty count = event->getNumericProperty(sumFieldName, 1);
    const auto& blocks = event->getBlocks();

    std::string path = event->getStringProperty(FILE_PATH, "");
    auto resultCounter = m_counters.emplace(path, 0);
    resultCounter.first->second += count;

    auto resultBlocks = m_blocks.emplace(path, boost::icl::interval_set<off_t>());

    for(const auto& block : blocks) {
        resultBlocks.first->second += boost::icl::discrete_interval<off_t>::right_open(block.first, block.first + block.second);
    }

    bool forward = resultCounter.first->second >= threshold;

    if(forward){
        auto newEvent = std::make_shared<Event>();
        newEvent->setStringProperty(SUM_FIELD_NAME, sumFieldName);
        newEvent->setNumericProperty(sumFieldName, resultCounter.first->second);
        if(!fieldName.empty()){
            string value = event->getStringProperty(fieldName, "");
            newEvent->setStringProperty(fieldName, value);
        }
        std::list< std::pair<off_t, size_t> > blocks;
        for(const auto& block : resultBlocks.first->second) {
            blocks.push_back(std::pair<off_t, size_t>(block.lower(), block.upper() - block.lower()));
        }
        newEvent->setBlocks(blocks);
        newEvent->setStringProperty(FILE_PATH, path);

        m_blocks.erase(path);
        m_counters.erase(path);

        return newEvent;
    }

    return std::shared_ptr<Event>();
}

std::shared_ptr<Event> EventAggregator::ActualEventAggregator::getEventByProperty(const string & path, const string & value, const string & fieldName, const string & sumFieldName)
{
    auto counter = m_counters[path];
    auto blocks = m_blocks[path];

    auto newEvent = std::make_shared<Event>();
    newEvent->setStringProperty(SUM_FIELD_NAME, sumFieldName);
    newEvent->setNumericProperty(sumFieldName, counter);

    newEvent->setStringProperty(fieldName, value);
    std::list< std::pair<off_t, size_t> > newBlocks;
    for(const auto& block : blocks)
    {
        newBlocks.push_back(std::pair<off_t, size_t>(block.lower(), block.upper() - block.lower()));
    }

    newEvent->setBlocks(newBlocks);
    newEvent->setStringProperty(FILE_PATH, path);

    return newEvent;
}

std::list<std::shared_ptr<Event> > EventAggregator::ActualEventAggregator::getPendingEvents(const string & value, const string & fieldName, const string & sumFieldName)
{
    std::lock_guard<std::mutex> guard{m_aggregatorStateMutex};
    std::list<std::shared_ptr<Event> > processedEvents;
    for(auto & entry : m_counters)
    {
         auto processedEvent = getEventByProperty(entry.first, value, fieldName, sumFieldName);
         if(processedEvent)
             processedEvents.push_back(processedEvent);
    }
    m_blocks.clear();
    m_counters.clear();
    return processedEvents;
}

std::list<std::shared_ptr<Event> > EventAggregator::getPendingEvents(std::list<std::shared_ptr<Event> > events)
{
    std::list<std::shared_ptr<Event> > processedEvents;
    for(auto & event : events)
    {
        auto processedEvent = actualProcessEvent(event);
        if(processedEvent)
            processedEvents.push_back(processedEvent);
    }

    for(auto & entry : m_substreams)
    {
        auto result = entry.second.getPendingEvents(entry.first, m_fieldName, m_sumFieldName);
        processedEvents.insert(processedEvents.end(), result.begin(), result.end());
    }

    return processedEvents;
}

void EventAggregator::ActualEventAggregator::resetState()
{
    m_counters.clear();
    m_blocks.clear();
}
<|endoftext|>


<commit_before>// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/child/runtime_features.h"

#include "base/command_line.h"
#include "content/common/content_switches_internal.h"
#include "content/public/common/content_switches.h"
#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
#include "ui/native_theme/native_theme_switches.h"

#if defined(OS_ANDROID)
#include <cpu-features.h>
#include "base/android/build_info.h"
#include "media/base/android/media_codec_bridge.h"
#endif

using blink::WebRuntimeFeatures;

namespace content {

static void SetRuntimeFeatureDefaultsForPlatform() {
#if defined(OS_ANDROID)
  // MSE/EME implementation needs Android MediaCodec API.
  if (!media::MediaCodecBridge::IsAvailable()) {
    WebRuntimeFeatures::enableMediaSource(false);
    WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
    WebRuntimeFeatures::enableEncryptedMedia(false);
  }
  // WebAudio is enabled by default on ARM and X86 and only when the
  // MediaCodec API is available.
  WebRuntimeFeatures::enableWebAudio(
      media::MediaCodecBridge::IsAvailable() &&
      ((android_getCpuFamily() == ANDROID_CPU_FAMILY_ARM) ||
       (android_getCpuFamily() == ANDROID_CPU_FAMILY_X86)));

  // Android supports gamepad API for JellyBean and beyond
  WebRuntimeFeatures::enableGamepad(
      base::android::BuildInfo::GetInstance()->sdk_int() >= 16);
  // Android does not have support for PagePopup
  WebRuntimeFeatures::enablePagePopup(false);
  // Android does not yet support the Web Notification API. crbug.com/115320
  WebRuntimeFeatures::enableNotifications(false);
  // Android does not yet support SharedWorker. crbug.com/154571
  WebRuntimeFeatures::enableSharedWorker(false);
  // Android does not yet support NavigatorContentUtils.
  WebRuntimeFeatures::enableNavigatorContentUtils(false);
  WebRuntimeFeatures::enableTouchIconLoading(true);
  WebRuntimeFeatures::enableOrientationEvent(true);
#else
  WebRuntimeFeatures::enableNavigatorContentUtils(true);
#endif  // defined(OS_ANDROID)
}

void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
    const CommandLine& command_line) {
  if (command_line.HasSwitch(switches::kEnableExperimentalWebPlatformFeatures))
    WebRuntimeFeatures::enableExperimentalFeatures(true);

  SetRuntimeFeatureDefaultsForPlatform();

  if (command_line.HasSwitch(switches::kDisableDatabases))
    WebRuntimeFeatures::enableDatabase(false);

  if (command_line.HasSwitch(switches::kDisableApplicationCache))
    WebRuntimeFeatures::enableApplicationCache(false);

  if (command_line.HasSwitch(switches::kDisableDesktopNotifications))
    WebRuntimeFeatures::enableNotifications(false);

  if (command_line.HasSwitch(switches::kDisableNavigatorContentUtils))
    WebRuntimeFeatures::enableNavigatorContentUtils(false);

  if (command_line.HasSwitch(switches::kDisableLocalStorage))
    WebRuntimeFeatures::enableLocalStorage(false);

  if (command_line.HasSwitch(switches::kDisableSessionStorage))
    WebRuntimeFeatures::enableSessionStorage(false);

  if (command_line.HasSwitch(switches::kDisableMediaSource))
    WebRuntimeFeatures::enableMediaSource(false);

  if (command_line.HasSwitch(switches::kDisableSharedWorkers))
    WebRuntimeFeatures::enableSharedWorker(false);

#if defined(OS_ANDROID)
  if (command_line.HasSwitch(switches::kDisableWebRTC)) {
    WebRuntimeFeatures::enableMediaStream(false);
    WebRuntimeFeatures::enablePeerConnection(false);
  }

  if (!command_line.HasSwitch(switches::kEnableSpeechRecognition))
    WebRuntimeFeatures::enableScriptedSpeech(false);
#endif

  if (command_line.HasSwitch(switches::kEnableServiceWorker))
    WebRuntimeFeatures::enableServiceWorker(true);

#if defined(OS_ANDROID)
  // WebAudio is enabled by default on ARM and X86, if the MediaCodec
  // API is available.
  WebRuntimeFeatures::enableWebAudio(
      !command_line.HasSwitch(switches::kDisableWebAudio) &&
      media::MediaCodecBridge::IsAvailable());
#else
  if (command_line.HasSwitch(switches::kDisableWebAudio))
    WebRuntimeFeatures::enableWebAudio(false);
#endif

  if (command_line.HasSwitch(switches::kEnableEncryptedMedia))
    WebRuntimeFeatures::enableEncryptedMedia(true);

  if (command_line.HasSwitch(switches::kDisablePrefixedEncryptedMedia))
    WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);

  if (command_line.HasSwitch(switches::kEnableWebAnimationsSVG))
    WebRuntimeFeatures::enableWebAnimationsSVG(true);

  if (command_line.HasSwitch(switches::kEnableWebMIDI))
    WebRuntimeFeatures::enableWebMIDI(true);

  if (command_line.HasSwitch(switches::kDisableFileSystem))
    WebRuntimeFeatures::enableFileSystem(false);

  if (command_line.HasSwitch(switches::kEnableExperimentalCanvasFeatures))
    WebRuntimeFeatures::enableExperimentalCanvasFeatures(true);

  if (command_line.HasSwitch(switches::kEnableSpeechSynthesis))
    WebRuntimeFeatures::enableSpeechSynthesis(true);

  if (command_line.HasSwitch(switches::kEnableWebGLDraftExtensions))
    WebRuntimeFeatures::enableWebGLDraftExtensions(true);

  if (command_line.HasSwitch(switches::kEnableWebGLImageChromium))
    WebRuntimeFeatures::enableWebGLImageChromium(true);

  if (command_line.HasSwitch(switches::kEnableOverlayFullscreenVideo))
    WebRuntimeFeatures::enableOverlayFullscreenVideo(true);

  if (ui::IsOverlayScrollbarEnabled())
    WebRuntimeFeatures::enableOverlayScrollbars(true);

  if (command_line.HasSwitch(switches::kEnableFastTextAutosizing))
    WebRuntimeFeatures::enableFastTextAutosizing(true);

  if (command_line.HasSwitch(switches::kDisableFastTextAutosizing))
    WebRuntimeFeatures::enableFastTextAutosizing(false);

  if (command_line.HasSwitch(switches::kDisableRepaintAfterLayout))
    WebRuntimeFeatures::enableRepaintAfterLayout(false);

  if (command_line.HasSwitch(switches::kEnableRepaintAfterLayout))
    WebRuntimeFeatures::enableRepaintAfterLayout(true);

  if (command_line.HasSwitch(switches::kEnableTargetedStyleRecalc))
    WebRuntimeFeatures::enableTargetedStyleRecalc(true);

  if (command_line.HasSwitch(switches::kEnableBleedingEdgeRenderingFastPaths))
    WebRuntimeFeatures::enableBleedingEdgeFastPaths(true);

  if (command_line.HasSwitch(switches::kEnablePreciseMemoryInfo))
    WebRuntimeFeatures::enablePreciseMemoryInfo(true);

  if (command_line.HasSwitch(switches::kEnableLayerSquashing))
    WebRuntimeFeatures::enableLayerSquashing(true);
}

}  // namespace content
<commit_msg>Enable FastMobileScrolling runtime flag for Android to match the command-line flag.<commit_after>// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/child/runtime_features.h"

#include "base/command_line.h"
#include "content/common/content_switches_internal.h"
#include "content/public/common/content_switches.h"
#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
#include "ui/native_theme/native_theme_switches.h"

#if defined(OS_ANDROID)
#include <cpu-features.h>
#include "base/android/build_info.h"
#include "media/base/android/media_codec_bridge.h"
#endif

using blink::WebRuntimeFeatures;

namespace content {

static void SetRuntimeFeatureDefaultsForPlatform() {
#if defined(OS_ANDROID)
  // MSE/EME implementation needs Android MediaCodec API.
  if (!media::MediaCodecBridge::IsAvailable()) {
    WebRuntimeFeatures::enableMediaSource(false);
    WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
    WebRuntimeFeatures::enableEncryptedMedia(false);
  }
  // WebAudio is enabled by default on ARM and X86 and only when the
  // MediaCodec API is available.
  WebRuntimeFeatures::enableWebAudio(
      media::MediaCodecBridge::IsAvailable() &&
      ((android_getCpuFamily() == ANDROID_CPU_FAMILY_ARM) ||
       (android_getCpuFamily() == ANDROID_CPU_FAMILY_X86)));

  // Android supports gamepad API for JellyBean and beyond
  WebRuntimeFeatures::enableGamepad(
      base::android::BuildInfo::GetInstance()->sdk_int() >= 16);
  // Android does not have support for PagePopup
  WebRuntimeFeatures::enablePagePopup(false);
  // Android does not yet support the Web Notification API. crbug.com/115320
  WebRuntimeFeatures::enableNotifications(false);
  // Android does not yet support SharedWorker. crbug.com/154571
  WebRuntimeFeatures::enableSharedWorker(false);
  // Android does not yet support NavigatorContentUtils.
  WebRuntimeFeatures::enableNavigatorContentUtils(false);
  WebRuntimeFeatures::enableTouchIconLoading(true);
  WebRuntimeFeatures::enableOrientationEvent(true);
  WebRuntimeFeatures::enableFastMobileScrolling(true);
#else
  WebRuntimeFeatures::enableNavigatorContentUtils(true);
#endif  // defined(OS_ANDROID)
}

void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
    const CommandLine& command_line) {
  if (command_line.HasSwitch(switches::kEnableExperimentalWebPlatformFeatures))
    WebRuntimeFeatures::enableExperimentalFeatures(true);

  SetRuntimeFeatureDefaultsForPlatform();

  if (command_line.HasSwitch(switches::kDisableDatabases))
    WebRuntimeFeatures::enableDatabase(false);

  if (command_line.HasSwitch(switches::kDisableApplicationCache))
    WebRuntimeFeatures::enableApplicationCache(false);

  if (command_line.HasSwitch(switches::kDisableDesktopNotifications))
    WebRuntimeFeatures::enableNotifications(false);

  if (command_line.HasSwitch(switches::kDisableNavigatorContentUtils))
    WebRuntimeFeatures::enableNavigatorContentUtils(false);

  if (command_line.HasSwitch(switches::kDisableLocalStorage))
    WebRuntimeFeatures::enableLocalStorage(false);

  if (command_line.HasSwitch(switches::kDisableSessionStorage))
    WebRuntimeFeatures::enableSessionStorage(false);

  if (command_line.HasSwitch(switches::kDisableMediaSource))
    WebRuntimeFeatures::enableMediaSource(false);

  if (command_line.HasSwitch(switches::kDisableSharedWorkers))
    WebRuntimeFeatures::enableSharedWorker(false);

#if defined(OS_ANDROID)
  if (command_line.HasSwitch(switches::kDisableWebRTC)) {
    WebRuntimeFeatures::enableMediaStream(false);
    WebRuntimeFeatures::enablePeerConnection(false);
  }

  if (!command_line.HasSwitch(switches::kEnableSpeechRecognition))
    WebRuntimeFeatures::enableScriptedSpeech(false);
#endif

  if (command_line.HasSwitch(switches::kEnableServiceWorker))
    WebRuntimeFeatures::enableServiceWorker(true);

#if defined(OS_ANDROID)
  // WebAudio is enabled by default on ARM and X86, if the MediaCodec
  // API is available.
  WebRuntimeFeatures::enableWebAudio(
      !command_line.HasSwitch(switches::kDisableWebAudio) &&
      media::MediaCodecBridge::IsAvailable());
#else
  if (command_line.HasSwitch(switches::kDisableWebAudio))
    WebRuntimeFeatures::enableWebAudio(false);
#endif

  if (command_line.HasSwitch(switches::kEnableEncryptedMedia))
    WebRuntimeFeatures::enableEncryptedMedia(true);

  if (command_line.HasSwitch(switches::kDisablePrefixedEncryptedMedia))
    WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);

  if (command_line.HasSwitch(switches::kEnableWebAnimationsSVG))
    WebRuntimeFeatures::enableWebAnimationsSVG(true);

  if (command_line.HasSwitch(switches::kEnableWebMIDI))
    WebRuntimeFeatures::enableWebMIDI(true);

  if (command_line.HasSwitch(switches::kDisableFileSystem))
    WebRuntimeFeatures::enableFileSystem(false);

  if (command_line.HasSwitch(switches::kEnableExperimentalCanvasFeatures))
    WebRuntimeFeatures::enableExperimentalCanvasFeatures(true);

  if (command_line.HasSwitch(switches::kEnableSpeechSynthesis))
    WebRuntimeFeatures::enableSpeechSynthesis(true);

  if (command_line.HasSwitch(switches::kEnableWebGLDraftExtensions))
    WebRuntimeFeatures::enableWebGLDraftExtensions(true);

  if (command_line.HasSwitch(switches::kEnableWebGLImageChromium))
    WebRuntimeFeatures::enableWebGLImageChromium(true);

  if (command_line.HasSwitch(switches::kEnableOverlayFullscreenVideo))
    WebRuntimeFeatures::enableOverlayFullscreenVideo(true);

  if (ui::IsOverlayScrollbarEnabled())
    WebRuntimeFeatures::enableOverlayScrollbars(true);

  if (command_line.HasSwitch(switches::kEnableFastTextAutosizing))
    WebRuntimeFeatures::enableFastTextAutosizing(true);

  if (command_line.HasSwitch(switches::kDisableFastTextAutosizing))
    WebRuntimeFeatures::enableFastTextAutosizing(false);

  if (command_line.HasSwitch(switches::kDisableRepaintAfterLayout))
    WebRuntimeFeatures::enableRepaintAfterLayout(false);

  if (command_line.HasSwitch(switches::kEnableRepaintAfterLayout))
    WebRuntimeFeatures::enableRepaintAfterLayout(true);

  if (command_line.HasSwitch(switches::kEnableTargetedStyleRecalc))
    WebRuntimeFeatures::enableTargetedStyleRecalc(true);

  if (command_line.HasSwitch(switches::kEnableBleedingEdgeRenderingFastPaths))
    WebRuntimeFeatures::enableBleedingEdgeFastPaths(true);

  if (command_line.HasSwitch(switches::kEnablePreciseMemoryInfo))
    WebRuntimeFeatures::enablePreciseMemoryInfo(true);

  if (command_line.HasSwitch(switches::kEnableLayerSquashing))
    WebRuntimeFeatures::enableLayerSquashing(true);
}

}  // namespace content
<|endoftext|>


<commit_before>#include <debug.hpp>
#include <item.hpp>
#include <dish.hpp>
#include <food.hpp>

#include <QString>

#include <mainWindow.hpp>
#include "ui_mainWindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow {parent},
    ui {new Ui::MainWindow},
    itemStringList {new QStringList},
    dishStringList {new QStringList},
    itemListModel {new QStringListModel {*itemStringList, NULL}},
    dishListModel {new QStringListModel {*dishStringList, NULL}},
    itemForm {new ItemForm} {

    ui->setupUi(this);

    ui->listView_1->setModel(itemListModel);
    ui->listView_2->setModel(dishListModel);

    for ( auto& entry: itemForm->avaliableItems ) {
        itemStringList->append(QString::fromStdString(entry->getName()));
    }

    for ( auto& entry: itemForm->avaliableDish ) {
        dishStringList->append(QString::fromStdString(entry->getName()));
    }

    itemListModel->setStringList(*itemStringList);
    dishListModel->setStringList(*dishStringList);

    PRINT_OBJ("MainWindow created");
}

MainWindow::~MainWindow() {
    delete ui;
    delete itemStringList;
    delete dishStringList;
    delete itemListModel;
    delete dishListModel;

    PRINT_OBJ("MainWindow destroyed");
}

void MainWindow::on_pushButton_1_clicked() {
    NewIngridientWindow newIngridientWindow;

    QObject::connect(&newIngridientWindow, SIGNAL(itemObjectReady(Item *)), this, SLOT(addNewItemObject(Item *)));
    QObject::connect(&newIngridientWindow, SIGNAL(foodObjectReady(Food *)), this, SLOT(addNewFoodObject(Food *)));

    newIngridientWindow.exec();
}

void MainWindow::on_pushButton_2_clicked() {
    QModelIndexList selected = ui->listView_1->selectionModel()->selectedIndexes();

    if ( !selected.isEmpty() ) {
        int row = selected.first().row();

        const QModelIndex index = itemListModel->index(row?row-1:0);
        std::list<Item *>::iterator item = itemForm->avaliableItems.begin();

        std::advance(item, row);
        itemForm->avaliableItems.erase(item);

        itemStringList->removeAt(row);
        itemListModel->setStringList(*itemStringList);

        if ( itemStringList->size() ) {
            ui->listView_1->setCurrentIndex(index);
            displayListViewInfoItem(index);
        } else {
            ui->textEdit_1->clear();
        }
   }
}

void MainWindow::on_pushButton_3_clicked() {
    NewDishWindow newDishWindow;

    QObject::connect(&newDishWindow, SIGNAL(itemObjectReady(Dish *)), this, SLOT(addNewDishObject(Dish *)));
    QObject::connect(this, SIGNAL(newDishRequest(std::list<Item *> *)), &newDishWindow, SLOT(fillItemList(std::list<Item *> *)));

    emit newDishRequest(&itemForm->avaliableItems);

    newDishWindow.exec();
}

void MainWindow::on_pushButton_4_clicked() {
    QModelIndexList selected = ui->listView_2->selectionModel()->selectedIndexes();

    if ( !selected.isEmpty() ) {
        int row = selected.first().row();

        const QModelIndex index = dishListModel->index(row?row-1:0);
        std::list<Dish *>::iterator dish = itemForm->avaliableDish.begin();

        std::advance(dish, row);
        itemForm->avaliableDish.erase(dish);

        dishStringList->removeAt(row);
        dishListModel->setStringList(*dishStringList);

        if ( dishStringList->size() ) {
            ui->listView_2->setCurrentIndex(index);
            displayListViewInfoDish(index);
        } else {
            ui->textEdit_1->clear();
        }
   }
}

void MainWindow::on_pushButton_5_clicked() {
    if ( infoWindowType == ITEM || infoWindowType == FOOD ) {
        NewIngridientWindow newIngridientWindow;

        newIngridientWindow.exec();
    } else if ( infoWindowType == DISH ) {
        NewDishWindow newDishWindow;

        newDishWindow.exec();
    }
}

void MainWindow::on_listView_1_clicked(const QModelIndex &index) {
    displayListViewInfoItem(index);

    PRINT_DEBUG("Clicked item/food: " << index.data().toString().toStdString());
}

void MainWindow::on_listView_2_clicked(const QModelIndex &index) {
    displayListViewInfoDish(index);

    PRINT_DEBUG("Clicked dish: " << index.data().toString().toStdString());
}

void MainWindow::on_listView_1_entered(const QModelIndex &index) {
    displayListViewInfoItem(index);

    PRINT_DEBUG("Entered item/food: " << index.data().toString().toStdString());
}

void MainWindow::on_listView_2_entered(const QModelIndex &index) {
    displayListViewInfoDish(index);

    PRINT_DEBUG("Entered dish: " << index.data().toString().toStdString());
}

void MainWindow::addNewItemObject(Item *item) {
    QModelIndex index;

    itemStringList->append(QString::fromStdString(item->getName()));
    itemListModel->setStringList(*itemStringList);

    itemForm->avaliableItems.push_back(item);

    index = itemListModel->index(itemForm->avaliableItems.size()-1);
    ui->listView_1->setCurrentIndex(index);
    displayListViewInfoItem(index);

    PRINT_DEBUG("New item added");
}

void MainWindow::addNewFoodObject(Food *food) {
    QModelIndex index;

    itemStringList->append(QString::fromStdString(food->getName()));
    itemListModel->setStringList(*itemStringList);

    itemForm->avaliableItems.push_back(food);

    index = itemListModel->index(itemForm->avaliableItems.size()-1);
    ui->listView_1->setCurrentIndex(index);
    displayListViewInfoItem(index);

    PRINT_DEBUG("New food added");
}

void MainWindow::addNewDishObject(Dish *dish) {
    dishStringList->append(QString::fromStdString(dish->getName()));
    dishListModel->setStringList(*dishStringList);

    itemForm->avaliableDish.push_back(dish);

    PRINT_DEBUG("New dish added");
}

void MainWindow::displayListViewInfoItem(const QModelIndex &index) {
    std::list<Item *>::iterator item = itemForm->avaliableItems.begin();
    QString itemInfo;

    std::advance(item, index.row());

    if ( dynamic_cast<Food *>(*item) ) {
        infoWindowType = FOOD;
    } else {
        infoWindowType = ITEM;
    }

    itemInfo += "Name: " + QString::fromStdString((*item)->getName()) + "\n";
    itemInfo += "Price: " + QString::number((*item)->getPrice()) + "\n";
    itemInfo += "Mass: " + QString::number((*item)->getMass()) + "\n";

    if ( infoWindowType == FOOD ) {
       itemInfo += "Fats: " + QString::number((*item)->getFats()) + "\n";
       itemInfo += "Proteins: "+ QString::number((*item)->getProteins()) + "\n";
       itemInfo += "Carbohydrates: " + QString::number((*item)->getCarbohydrates()) + "\n";
       itemInfo += "Calories: " + QString::number((*item)->getCalories()) + "\n";
    }

    ui->textEdit_1->setText(itemInfo);
}

void MainWindow::displayListViewInfoDish(const QModelIndex &index) {
    std::list<Dish *>::iterator item = itemForm->avaliableDish.begin();
    QString itemInfo;

    std::advance(item, index.row());

    infoWindowType = DISH;

    itemInfo += "Name: " + QString::fromStdString((*item)->getName()) + "\n";
    itemInfo += "Price: " + QString::number((*item)->getPrice()) + "\n";
    itemInfo += "Mass: " + QString::number((*item)->getMass()) + "\n";
    itemInfo += "Fats: " + QString::number((*item)->getFats()) + "\n";
    itemInfo += "Proteins: " + QString::number((*item)->getProteins()) + "\n";
    itemInfo += "Carbohydrates: " + QString::number((*item)->getCarbohydrates()) + "\n";
    itemInfo += "Calories: " + QString::number((*item)->getCalories()) + "\n\n";
    itemInfo += "Amount of people: " + QString::number((*item)->getAmountOfPeople()) + "\n\n";
    itemInfo += "Ingridients:\n";

    for ( auto& entry: (*item)->getIngridientMap() ) {
        itemInfo += QString::fromStdString(entry.first.getName()) + " (";
        itemInfo += QString::number(entry.second) + ")\n";
    }

    ui->textEdit_1->setText(itemInfo);
}

void MainWindow::on_actionAbout_triggered() {
    AboutWindow aboutWindow;

    aboutWindow.exec();
}
<commit_msg>mainWindow: Fix memory leaks<commit_after>#include <debug.hpp>
#include <item.hpp>
#include <dish.hpp>
#include <food.hpp>

#include <QString>

#include <mainWindow.hpp>
#include "ui_mainWindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow {parent},
    ui {new Ui::MainWindow},
    itemStringList {new QStringList},
    dishStringList {new QStringList},
    itemListModel {new QStringListModel {*itemStringList, NULL}},
    dishListModel {new QStringListModel {*dishStringList, NULL}},
    itemForm {new ItemForm} {

    ui->setupUi(this);

    ui->listView_1->setModel(itemListModel);
    ui->listView_2->setModel(dishListModel);

    for ( auto& entry: itemForm->avaliableItems ) {
        itemStringList->append(QString::fromStdString(entry->getName()));
    }

    for ( auto& entry: itemForm->avaliableDish ) {
        dishStringList->append(QString::fromStdString(entry->getName()));
    }

    itemListModel->setStringList(*itemStringList);
    dishListModel->setStringList(*dishStringList);

    PRINT_OBJ("MainWindow created");
}

MainWindow::~MainWindow() {
    delete ui;
    delete itemStringList;
    delete dishStringList;
    delete itemListModel;
    delete dishListModel;
    delete itemForm;

    PRINT_OBJ("MainWindow destroyed");
}

void MainWindow::on_pushButton_1_clicked() {
    NewIngridientWindow newIngridientWindow;

    QObject::connect(&newIngridientWindow, SIGNAL(itemObjectReady(Item *)), this, SLOT(addNewItemObject(Item *)));
    QObject::connect(&newIngridientWindow, SIGNAL(foodObjectReady(Food *)), this, SLOT(addNewFoodObject(Food *)));

    newIngridientWindow.exec();
}

void MainWindow::on_pushButton_2_clicked() {
    QModelIndexList selected = ui->listView_1->selectionModel()->selectedIndexes();

    if ( !selected.isEmpty() ) {
        int row = selected.first().row();

        const QModelIndex index = itemListModel->index(row?row-1:0);
        std::list<Item *>::iterator item = itemForm->avaliableItems.begin();

        std::advance(item, row);
        itemForm->avaliableItems.erase(item);

        delete *item;

        itemStringList->removeAt(row);
        itemListModel->setStringList(*itemStringList);

        if ( itemStringList->size() ) {
            ui->listView_1->setCurrentIndex(index);
            displayListViewInfoItem(index);
        } else {
            ui->textEdit_1->clear();
        }
   }
}

void MainWindow::on_pushButton_3_clicked() {
    NewDishWindow newDishWindow;

    QObject::connect(&newDishWindow, SIGNAL(itemObjectReady(Dish *)), this, SLOT(addNewDishObject(Dish *)));
    QObject::connect(this, SIGNAL(newDishRequest(std::list<Item *> *)), &newDishWindow, SLOT(fillItemList(std::list<Item *> *)));

    emit newDishRequest(&itemForm->avaliableItems);

    newDishWindow.exec();
}

void MainWindow::on_pushButton_4_clicked() {
    QModelIndexList selected = ui->listView_2->selectionModel()->selectedIndexes();

    if ( !selected.isEmpty() ) {
        int row = selected.first().row();

        const QModelIndex index = dishListModel->index(row?row-1:0);
        std::list<Dish *>::iterator dish = itemForm->avaliableDish.begin();

        std::advance(dish, row);
        itemForm->avaliableDish.erase(dish);

        delete *dish;

        dishStringList->removeAt(row);
        dishListModel->setStringList(*dishStringList);

        if ( dishStringList->size() ) {
            ui->listView_2->setCurrentIndex(index);
            displayListViewInfoDish(index);
        } else {
            ui->textEdit_1->clear();
        }
   }
}

void MainWindow::on_pushButton_5_clicked() {
    if ( infoWindowType == ITEM || infoWindowType == FOOD ) {
        NewIngridientWindow newIngridientWindow;

        newIngridientWindow.exec();
    } else if ( infoWindowType == DISH ) {
        NewDishWindow newDishWindow;

        newDishWindow.exec();
    }
}

void MainWindow::on_listView_1_clicked(const QModelIndex &index) {
    displayListViewInfoItem(index);

    PRINT_DEBUG("Clicked item/food: " << index.data().toString().toStdString());
}

void MainWindow::on_listView_2_clicked(const QModelIndex &index) {
    displayListViewInfoDish(index);

    PRINT_DEBUG("Clicked dish: " << index.data().toString().toStdString());
}

void MainWindow::on_listView_1_entered(const QModelIndex &index) {
    displayListViewInfoItem(index);

    PRINT_DEBUG("Entered item/food: " << index.data().toString().toStdString());
}

void MainWindow::on_listView_2_entered(const QModelIndex &index) {
    displayListViewInfoDish(index);

    PRINT_DEBUG("Entered dish: " << index.data().toString().toStdString());
}

void MainWindow::addNewItemObject(Item *item) {
    QModelIndex index;

    itemStringList->append(QString::fromStdString(item->getName()));
    itemListModel->setStringList(*itemStringList);

    itemForm->avaliableItems.push_back(item);

    index = itemListModel->index(itemForm->avaliableItems.size()-1);
    ui->listView_1->setCurrentIndex(index);
    displayListViewInfoItem(index);

    PRINT_DEBUG("New item added");
}

void MainWindow::addNewFoodObject(Food *food) {
    QModelIndex index;

    itemStringList->append(QString::fromStdString(food->getName()));
    itemListModel->setStringList(*itemStringList);

    itemForm->avaliableItems.push_back(food);

    index = itemListModel->index(itemForm->avaliableItems.size()-1);
    ui->listView_1->setCurrentIndex(index);
    displayListViewInfoItem(index);

    PRINT_DEBUG("New food added");
}

void MainWindow::addNewDishObject(Dish *dish) {
    dishStringList->append(QString::fromStdString(dish->getName()));
    dishListModel->setStringList(*dishStringList);

    itemForm->avaliableDish.push_back(dish);

    PRINT_DEBUG("New dish added");
}

void MainWindow::displayListViewInfoItem(const QModelIndex &index) {
    std::list<Item *>::iterator item = itemForm->avaliableItems.begin();
    QString itemInfo;

    std::advance(item, index.row());

    if ( dynamic_cast<Food *>(*item) ) {
        infoWindowType = FOOD;
    } else {
        infoWindowType = ITEM;
    }

    itemInfo += "Name: " + QString::fromStdString((*item)->getName()) + "\n";
    itemInfo += "Price: " + QString::number((*item)->getPrice()) + "\n";
    itemInfo += "Mass: " + QString::number((*item)->getMass()) + "\n";

    if ( infoWindowType == FOOD ) {
       itemInfo += "Fats: " + QString::number((*item)->getFats()) + "\n";
       itemInfo += "Proteins: "+ QString::number((*item)->getProteins()) + "\n";
       itemInfo += "Carbohydrates: " + QString::number((*item)->getCarbohydrates()) + "\n";
       itemInfo += "Calories: " + QString::number((*item)->getCalories()) + "\n";
    }

    ui->textEdit_1->setText(itemInfo);
}

void MainWindow::displayListViewInfoDish(const QModelIndex &index) {
    std::list<Dish *>::iterator item = itemForm->avaliableDish.begin();
    QString itemInfo;

    std::advance(item, index.row());

    infoWindowType = DISH;

    itemInfo += "Name: " + QString::fromStdString((*item)->getName()) + "\n";
    itemInfo += "Price: " + QString::number((*item)->getPrice()) + "\n";
    itemInfo += "Mass: " + QString::number((*item)->getMass()) + "\n";
    itemInfo += "Fats: " + QString::number((*item)->getFats()) + "\n";
    itemInfo += "Proteins: " + QString::number((*item)->getProteins()) + "\n";
    itemInfo += "Carbohydrates: " + QString::number((*item)->getCarbohydrates()) + "\n";
    itemInfo += "Calories: " + QString::number((*item)->getCalories()) + "\n\n";
    itemInfo += "Amount of people: " + QString::number((*item)->getAmountOfPeople()) + "\n\n";
    itemInfo += "Ingridients:\n";

    for ( auto& entry: (*item)->getIngridientMap() ) {
        itemInfo += QString::fromStdString(entry.first.getName()) + " (";
        itemInfo += QString::number(entry.second) + ")\n";
    }

    ui->textEdit_1->setText(itemInfo);
}

void MainWindow::on_actionAbout_triggered() {
    AboutWindow aboutWindow;

    aboutWindow.exec();
}
<|endoftext|>