text:
#include "MemoryCardView.h"
#include "win32/DeviceContext.h"
#include "StdStream.h"
#include "StdStreamUtils.h"
#include <boost/bind.hpp>
#include <exception>
#include <gl/gl.h>
#include <gl/glu.h>
#include <math.h>

#define CLSNAME		_T("CMemoryCardView")

const PIXELFORMATDESCRIPTOR CMemoryCardView::CRender::m_PFD =
{
	sizeof(PIXELFORMATDESCRIPTOR),
	1,
	PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
	PFD_TYPE_RGBA,
	32,
	0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0,
	0,
	32,
	0,
	0,
	PFD_MAIN_PLANE,
	0,
	0, 0, 0
};

CMemoryCardView::CMemoryCardView(HWND hParent, const RECT& rect)
: m_itemCount(0)
, m_memoryCard(NULL)
, m_render(NULL)
{
	if(!DoesWindowClassExist(CLSNAME))
	{
		WNDCLASSEX wc;
		memset(&wc, 0, sizeof(WNDCLASSEX));
		wc.cbSize			= sizeof(WNDCLASSEX);
		wc.hCursor			= LoadCursor(NULL, IDC_ARROW);
		wc.hbrBackground	= NULL;
		wc.hInstance		= GetModuleHandle(NULL);
		wc.lpszClassName	= CLSNAME;
		wc.lpfnWndProc		= CWindow::WndProc;
		wc.style			= CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
		RegisterClassEx(&wc);
	}

	Create(WS_EX_CLIENTEDGE, CLSNAME, _T(""), WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, rect, hParent, NULL);
	SetClassPtr();

	UpdateGeometry();

	m_render = new CRender(m_hWnd, &m_viewState);
}

CMemoryCardView::~CMemoryCardView()
{
	delete m_render;
}

void CMemoryCardView::SetMemoryCard(CMemoryCard* memoryCard)
{
	m_memoryCard = memoryCard;

	if(m_memoryCard != NULL)
	{
		m_itemCount = static_cast<unsigned int>(m_memoryCard->GetSaveCount());
	}
	else
	{
		m_itemCount = 0;
	}

	m_viewState.m_nScrollPosition = 0;
	UpdateScroll();
	m_render->SetMemoryCard(memoryCard);
	SetSelection(0);
}

long CMemoryCardView::OnPaint()
{
	return TRUE;
}

long CMemoryCardView::OnVScroll(unsigned int nType, unsigned int nThumb)
{
	switch(nType)
	{
	case SB_LINEDOWN:
		m_viewState.m_nScrollPosition += 5;
		break;
	case SB_LINEUP:
		m_viewState.m_nScrollPosition -= 5;
		break;
	case SB_PAGEDOWN:
		m_viewState.m_nScrollPosition += 35;
		break;
	case SB_PAGEUP:
		m_viewState.m_nScrollPosition -= 35;
		break;
	case SB_THUMBPOSITION:
	case SB_THUMBTRACK:
		m_viewState.m_nScrollPosition = GetVerticalScrollBar().GetThumbPosition();
		break;
	default:
		return FALSE;
		break;
	}

	UpdateScrollPosition();

	return TRUE;
}

long CMemoryCardView::OnLeftButtonDown(int nX, int nY)
{
	SetFocus();
	SetSelection((nY + m_viewState.m_nScrollPosition) / m_viewState.m_nItemHeight);
	return TRUE;
}

long CMemoryCardView::OnMouseWheel(int x, int y, short z)
{
	if(z < 0)
	{
		m_viewState.m_nScrollPosition += 35;
	}
	else
	{
		m_viewState.m_nScrollPosition -= 35;
	}

	UpdateScrollPosition();
	return TRUE;
}

long CMemoryCardView::OnSize(unsigned int nX, unsigned int nY, unsigned int nType)
{
	UpdateGeometry();
	return TRUE;
}

long CMemoryCardView::OnKeyDown(WPARAM nKey, LPARAM)
{
	switch(nKey)
	{
	case VK_DOWN:
		SetSelection(std::min<int>(m_viewState.m_nSelection + 1, m_itemCount - 1));
		EnsureItemFullyVisible(m_viewState.m_nSelection);
		break;
	case VK_UP:
		SetSelection(std::max<int>(m_viewState.m_nSelection - 1, 0));
		EnsureItemFullyVisible(m_viewState.m_nSelection);
		break;
	}

	return TRUE;
}

void CMemoryCardView::UpdateScroll()
{
	SCROLLINFO si;

	memset(&si, 0, sizeof(SCROLLINFO));
	si.cbSize	= sizeof(SCROLLINFO);
	si.fMask	= SIF_RANGE | SIF_DISABLENOSCROLL;
	si.nMin		= 0;
	si.nMax		= m_viewState.GetCanvasSize(m_itemCount);
	SetScrollInfo(m_hWnd, SB_VERT, &si, TRUE);
}

void CMemoryCardView::UpdateScrollPosition()
{
	m_viewState.m_nScrollPosition = std::max<int>(0,										m_viewState.m_nScrollPosition);
	m_viewState.m_nScrollPosition = std::min<int>(m_viewState.GetCanvasSize(m_itemCount),	m_viewState.m_nScrollPosition);

	SCROLLINFO si;
	memset(&si, 0, sizeof(SCROLLINFO));
	si.cbSize		= sizeof(SCROLLINFO);
	si.nPos			= m_viewState.m_nScrollPosition;
	si.fMask		= SIF_POS;
	SetScrollInfo(m_hWnd, SB_VERT, &si, TRUE);
}

void CMemoryCardView::UpdateGeometry()
{
	RECT clientRect = GetClientRect();
	m_viewState.Reset(&clientRect);
	UpdateScroll();
}

void CMemoryCardView::SetSelection(unsigned int nSelection)
{
	m_viewState.m_nSelection = nSelection;

	if((m_viewState.m_nSelection < m_itemCount) && (m_memoryCard != NULL))
	{
		OnSelectionChange(m_memoryCard->GetSaveByIndex(m_viewState.m_nSelection));
	}
	else
	{
		OnSelectionChange(NULL);
	}
}

void CMemoryCardView::EnsureItemFullyVisible(unsigned int nItem)
{
	m_viewState.EnsureItemFullyVisible(nItem);
	UpdateScrollPosition();
}

//////////////////////////////////////
// CViewState implementation

int CMemoryCardView::CViewState::GetCanvasSize(unsigned int nItemCount)
{
	int nCanvasSize = (nItemCount * m_nItemHeight) - m_ClientRect.bottom;
	if(nCanvasSize < 0) nCanvasSize = 0;

	return nCanvasSize;
}

void CMemoryCardView::CViewState::Reset(RECT* pClientRect)
{
	CopyRect(&m_ClientRect, pClientRect);

	m_nItemHeight		= m_ClientRect.right;
	m_nItemWidth		= m_ClientRect.right;
	m_nSelection		= 0;
	m_nScrollPosition	= 0;
}

void CMemoryCardView::CViewState::EnsureItemFullyVisible(unsigned int nItem)
{
	int nWindowTop, nWindowBottom;
	int nItemTop, nItemBottom;

	nWindowTop		= m_nScrollPosition;
	nWindowBottom	= m_nScrollPosition + m_ClientRect.bottom;

	nItemTop		= nItem * m_nItemHeight;
	nItemBottom		= nItemTop + m_nItemHeight;

	if(nItemTop < nWindowTop)
	{
		m_nScrollPosition -= (nWindowTop - nItemTop);
	}
	else if(nItemBottom > nWindowBottom)
	{
		m_nScrollPosition += (nItemBottom - nWindowBottom);
	}
}

//////////////////////////////////////
// CRender implementation

CMemoryCardView::CRender::CRender(HWND hWnd, const CViewState* pViewState)
: m_deviceContext(hWnd)
, m_viewState(pViewState)
, m_memoryCard(NULL)
, m_threadOver(false)
, m_thread(NULL)
{
	m_thread = new std::thread(std::tr1::bind(&CRender::ThreadProc, this));
}

CMemoryCardView::CRender::~CRender()
{
	m_threadOver = true;
	m_thread->join();
	delete m_thread;
}

void CMemoryCardView::CRender::ThreadProc()
{
	unsigned int nPixelFormat = ChoosePixelFormat(m_deviceContext, &m_PFD);
	SetPixelFormat(m_deviceContext, nPixelFormat, &m_PFD);
	m_hRC = wglCreateContext(m_deviceContext);
	wglMakeCurrent(m_deviceContext, m_hRC);

	glEnable(GL_TEXTURE_2D);
	glClearColor(1.0, 1.0, 1.0, 1.0);

	while(!m_threadOver)
	{
		while(m_mailBox.IsPending())
		{
			m_mailBox.ReceiveCall();
		}

		Animate();
		DrawScene();
		Sleep(16);
	}

	m_icons.clear();
	wglMakeCurrent(NULL, NULL);
	wglDeleteContext(m_hRC);
}

void CMemoryCardView::CRender::SetMemoryCard(const CMemoryCard* memoryCard)
{
	m_mailBox.SendCall(std::tr1::bind(&CRender::ThreadSetMemoryCard, this, memoryCard));
}

void CMemoryCardView::CRender::ThreadSetMemoryCard(const CMemoryCard* memoryCard)
{
	m_icons.clear();
	m_memoryCard = memoryCard;
}

void CMemoryCardView::CRender::Animate()
{
	for(IconList::iterator iconIterator(m_icons.begin());
		m_icons.end() != iconIterator; ++iconIterator)
	{
		const IconMeshPtr& iconMesh(iconIterator->second);
		if(iconMesh)
		{
			iconMesh->Update(16.f / 1000.f);
		}
	}
}

void CMemoryCardView::CRender::DrawScene()
{
	RECT ClientRect;

	glClear(GL_COLOR_BUFFER_BIT);

	if(m_memoryCard == NULL) return;

	unsigned int nItemCount = static_cast<unsigned int>(m_memoryCard->GetSaveCount());
	CopyRect(&ClientRect, &m_viewState->m_ClientRect);

	int nY = 0;
	int nUpperClip = (int)(m_viewState->m_nScrollPosition - m_viewState->m_nItemHeight);
	int nLowerClip = nUpperClip + ClientRect.bottom + m_viewState->m_nItemHeight;

	for(unsigned int i = 0; i < nItemCount; i++)
	{
		if(nY >= nLowerClip) break;

		if(nY > nUpperClip)
		{
			glClear(GL_DEPTH_BUFFER_BIT);

			glViewport(0,
				(ClientRect.bottom - nY - m_viewState->m_nItemHeight + m_viewState->m_nScrollPosition),
				m_viewState->m_nItemWidth,
				m_viewState->m_nItemHeight);

			if(nY == (m_viewState->m_nSelection * m_viewState->m_nItemHeight))
			{
				glMatrixMode(GL_PROJECTION);
				glLoadIdentity();
				glOrtho(0, 1, 1, 0, 0, 1);

				glMatrixMode(GL_MODELVIEW);
				glLoadIdentity();

				glDisable(GL_DEPTH_TEST);

				glColor4f(0.0f, 0.0f, 0.0f, 1.0f);

				glBegin(GL_QUADS);
				{
					glVertex2f(0.0, 0.0);
					glVertex2f(1.0, 0.0);
					glVertex2f(1.0, 1.0);
					glVertex2f(0.0, 1.0);
				}
				glEnd();
			}

			glEnable(GL_DEPTH_TEST);

			glMatrixMode(GL_MODELVIEW);
			glLoadIdentity();

			glTranslatef(0.0f, -2.0f, -7.0f);
			glScalef(1.0f, -1.0f, -1.0f);

			glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

			glMatrixMode(GL_PROJECTION);
			glLoadIdentity();
			gluPerspective(45.0f, (float)m_viewState->m_nItemWidth / (float)m_viewState->m_nItemHeight, 0.1f, 100.0f);

			IconMeshPtr iconMesh;
			IconList::iterator itIcon = m_icons.find(i);
			if(itIcon == m_icons.end())
			{
				const CSave* pSave = m_memoryCard->GetSaveByIndex(i);
				try
				{
					auto iconStream(Framework::CreateInputStdStream(pSave->GetNormalIconPath().native()));
					IconPtr iconData(new CIcon(iconStream));
					iconMesh = IconMeshPtr(new CIconMesh(iconData));
				}
				catch(...)
				{

				}
				m_icons[i] = iconMesh;
			}
			else
			{
				iconMesh = itIcon->second;
			}

			if(iconMesh)
			{
				iconMesh->Render();
			}
		}

		nY += m_viewState->m_nItemHeight;
	}

	SwapBuffers(m_deviceContext);
}

max_stars_repo_name: MaddTheSane/Play-

max_issues_repo_name: MaddTheSane/Play-

max_forks_repo_name: MaddTheSane/Play-


text:
//
// detail/variadic_templates.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//

#ifndef BOOST_ASIO_DETAIL_VARIADIC_TEMPLATES_HPP
#define BOOST_ASIO_DETAIL_VARIADIC_TEMPLATES_HPP

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)

#include <boost/asio/detail/config.hpp>

#if !defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)

# define BOOST_ASIO_VARIADIC_TPARAMS(n) BOOST_ASIO_VARIADIC_TPARAMS_##n

# define BOOST_ASIO_VARIADIC_TPARAMS_1 \
  typename T1
# define BOOST_ASIO_VARIADIC_TPARAMS_2 \
  typename T1, typename T2
# define BOOST_ASIO_VARIADIC_TPARAMS_3 \
  typename T1, typename T2, typename T3
# define BOOST_ASIO_VARIADIC_TPARAMS_4 \
  typename T1, typename T2, typename T3, typename T4
# define BOOST_ASIO_VARIADIC_TPARAMS_5 \
  typename T1, typename T2, typename T3, typename T4, typename T5

# define BOOST_ASIO_VARIADIC_TARGS(n) BOOST_ASIO_VARIADIC_TARGS_##n

# define BOOST_ASIO_VARIADIC_TARGS_1 T1
# define BOOST_ASIO_VARIADIC_TARGS_2 T1, T2
# define BOOST_ASIO_VARIADIC_TARGS_3 T1, T2, T3
# define BOOST_ASIO_VARIADIC_TARGS_4 T1, T2, T3, T4
# define BOOST_ASIO_VARIADIC_TARGS_5 T1, T2, T3, T4, T5

# define BOOST_ASIO_VARIADIC_BYVAL_PARAMS(n) \
  BOOST_ASIO_VARIADIC_BYVAL_PARAMS_##n

# define BOOST_ASIO_VARIADIC_BYVAL_PARAMS_1 T1 x1
# define BOOST_ASIO_VARIADIC_BYVAL_PARAMS_2 T1 x1, T2 x2
# define BOOST_ASIO_VARIADIC_BYVAL_PARAMS_3 T1 x1, T2 x2, T3 x3
# define BOOST_ASIO_VARIADIC_BYVAL_PARAMS_4 T1 x1, T2 x2, T3 x3, T4 x4
# define BOOST_ASIO_VARIADIC_BYVAL_PARAMS_5 T1 x1, T2 x2, T3 x3, T4 x4, T5 x5

# define BOOST_ASIO_VARIADIC_BYVAL_ARGS(n) \
  BOOST_ASIO_VARIADIC_BYVAL_ARGS_##n

# define BOOST_ASIO_VARIADIC_BYVAL_ARGS_1 x1
# define BOOST_ASIO_VARIADIC_BYVAL_ARGS_2 x1, x2
# define BOOST_ASIO_VARIADIC_BYVAL_ARGS_3 x1, x2, x3
# define BOOST_ASIO_VARIADIC_BYVAL_ARGS_4 x1, x2, x3, x4
# define BOOST_ASIO_VARIADIC_BYVAL_ARGS_5 x1, x2, x3, x4, x5

# define BOOST_ASIO_VARIADIC_CONSTREF_PARAMS(n) \
  BOOST_ASIO_VARIADIC_CONSTREF_PARAMS_##n

# define BOOST_ASIO_VARIADIC_CONSTREF_PARAMS_1 \
  const T1& x1
# define BOOST_ASIO_VARIADIC_CONSTREF_PARAMS_2 \
  const T1& x1, const T2& x2
# define BOOST_ASIO_VARIADIC_CONSTREF_PARAMS_3 \
  const T1& x1, const T2& x2, const T3& x3
# define BOOST_ASIO_VARIADIC_CONSTREF_PARAMS_4 \
  const T1& x1, const T2& x2, const T3& x3, const T4& x4
# define BOOST_ASIO_VARIADIC_CONSTREF_PARAMS_5 \
  const T1& x1, const T2& x2, const T3& x3, const T4& x4, const T5& x5

# define BOOST_ASIO_VARIADIC_MOVE_PARAMS(n) \
  BOOST_ASIO_VARIADIC_MOVE_PARAMS_##n

# define BOOST_ASIO_VARIADIC_MOVE_PARAMS_1 \
  BOOST_ASIO_MOVE_ARG(T1) x1
# define BOOST_ASIO_VARIADIC_MOVE_PARAMS_2 \
  BOOST_ASIO_MOVE_ARG(T1) x1, BOOST_ASIO_MOVE_ARG(T2) x2
# define BOOST_ASIO_VARIADIC_MOVE_PARAMS_3 \
  BOOST_ASIO_MOVE_ARG(T1) x1, BOOST_ASIO_MOVE_ARG(T2) x2, \
  BOOST_ASIO_MOVE_ARG(T3) x3
# define BOOST_ASIO_VARIADIC_MOVE_PARAMS_4 \
  BOOST_ASIO_MOVE_ARG(T1) x1, BOOST_ASIO_MOVE_ARG(T2) x2, \
  BOOST_ASIO_MOVE_ARG(T3) x3, BOOST_ASIO_MOVE_ARG(T4) x4
# define BOOST_ASIO_VARIADIC_MOVE_PARAMS_5 \
  BOOST_ASIO_MOVE_ARG(T1) x1, BOOST_ASIO_MOVE_ARG(T2) x2, \
  BOOST_ASIO_MOVE_ARG(T3) x3, BOOST_ASIO_MOVE_ARG(T4) x4, \
  BOOST_ASIO_MOVE_ARG(T5) x5

# define BOOST_ASIO_VARIADIC_MOVE_ARGS(n) \
  BOOST_ASIO_VARIADIC_MOVE_ARGS_##n

# define BOOST_ASIO_VARIADIC_MOVE_ARGS_1 \
  BOOST_ASIO_MOVE_CAST(T1)(x1)
# define BOOST_ASIO_VARIADIC_MOVE_ARGS_2 \
  BOOST_ASIO_MOVE_CAST(T1)(x1), BOOST_ASIO_MOVE_CAST(T2)(x2)
# define BOOST_ASIO_VARIADIC_MOVE_ARGS_3 \
  BOOST_ASIO_MOVE_CAST(T1)(x1), BOOST_ASIO_MOVE_CAST(T2)(x2), \
  BOOST_ASIO_MOVE_CAST(T3)(x3)
# define BOOST_ASIO_VARIADIC_MOVE_ARGS_4 \
  BOOST_ASIO_MOVE_CAST(T1)(x1), BOOST_ASIO_MOVE_CAST(T2)(x2), \
  BOOST_ASIO_MOVE_CAST(T3)(x3), BOOST_ASIO_MOVE_CAST(T4)(x4)
# define BOOST_ASIO_VARIADIC_MOVE_ARGS_5 \
  BOOST_ASIO_MOVE_CAST(T1)(x1), BOOST_ASIO_MOVE_CAST(T2)(x2), \
  BOOST_ASIO_MOVE_CAST(T3)(x3), BOOST_ASIO_MOVE_CAST(T4)(x4), \
  BOOST_ASIO_MOVE_CAST(T5)(x5)

# define BOOST_ASIO_VARIADIC_DECAY(n) \
  BOOST_ASIO_VARIADIC_DECAY_##n

# define BOOST_ASIO_VARIADIC_DECAY_1 \
  typename decay<T1>::type
# define BOOST_ASIO_VARIADIC_DECAY_2 \
  typename decay<T1>::type, typename decay<T2>::type
# define BOOST_ASIO_VARIADIC_DECAY_3 \
  typename decay<T1>::type, typename decay<T2>::type, \
  typename decay<T3>::type
# define BOOST_ASIO_VARIADIC_DECAY_4 \
  typename decay<T1>::type, typename decay<T2>::type, \
  typename decay<T3>::type, typename decay<T4>::type
# define BOOST_ASIO_VARIADIC_DECAY_5 \
  typename decay<T1>::type, typename decay<T2>::type, \
  typename decay<T3>::type, typename decay<T4>::type, \
  typename decay<T5>::type

# define BOOST_ASIO_VARIADIC_GENERATE(m) m(1) m(2) m(3) m(4) m(5)

#endif // !defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)

#endif // BOOST_ASIO_DETAIL_VARIADIC_TEMPLATES_HPP

ext: hpp


text: #include <boost/geometry/arithmetic/dot_product.hpp>

max_stars_repo_name: miathedev/BoostForArduino

max_issues_repo_name: miathedev/BoostForArduino

max_forks_repo_name: miathedev/BoostForArduino


text:
///////////////////////////////////////////////////////////////////////////////
// lost_df.hpp                                                               //
//                                                                           //
//  Copyright 2010 Erwann Rogard. Distributed under the Boost                //
//  Software License, Version 1.0. (See accompanying file                    //
//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
///////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_PEARSON_CHISQ_INDEPENDENCE_LOST_DF_HPP_ER_2010
#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_PEARSON_CHISQ_INDEPENDENCE_LOST_DF_HPP_ER_2010
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/detail/wrapper.hpp>
#include <boost/range.hpp>
#include <boost/accumulators/framework/depends_on.hpp> //contains_feature_of
#include <boost/accumulators/framework/accumulator_set.hpp> //visit_if
#include <boost/statistics/detail/non_parametric/contingency_table/factor/vec_levels.hpp>
#include <boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/independence/tag.hpp>

namespace boost {
namespace statistics{
namespace detail{
namespace contingency_table{
namespace pearson_chisq_statistic{
namespace independence_between_aux{

    template<typename A>
    struct lost_df_accumulator{

        lost_df_accumulator(const A& acc,std::size_t& df)
            :acc_(acc),df_(df){}

        template<typename Key>
        void operator()(const boost::mpl::detail::wrapper<Key>& wrapper)const{
            namespace ns = contingency_table::extract;
            this->df_ += (ns::levels<Key>( this->acc_ ).size() - 1);
        }

        private:
        const A& acc_;
        mutable std::size_t& df_;
    };

    template<typename A>
    independence_between_aux::lost_df_accumulator<A>
    make_lost_df_accumulator(const A& acc,std::size_t& df){
        return independence_between_aux::lost_df_accumulator<A>(acc,df);
    }

}// independence_between_aux

  	template<typename Keys,typename AccSet>
    std::size_t lost_degrees_of_freedom(
        const boost::mpl::detail::wrapper<
            pearson_chisq_statistic::tag::independence_between<Keys>
        >& statistic,
        const AccSet& acc
    )
    {
        typedef boost::mpl::detail::wrapper<boost::mpl::_> op_;
        std::size_t result = 0;
        boost::mpl::for_each<Keys,op_>(
            independence_between_aux::make_lost_df_accumulator(acc, result)
        );
        return result;
  	}

}// pearson_chisq_statistic
}// contingency_table
}// detail
}// statistics
}// boost

#endif