EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4ADABFBD-B4BB-4E2A-BE95-8C604DC783D3}.Debug|Win32.ActiveCfg = Debug|x64
+ {4ADABFBD-B4BB-4E2A-BE95-8C604DC783D3}.Debug|Win32.Build.0 = Debug|x64
{4ADABFBD-B4BB-4E2A-BE95-8C604DC783D3}.Release|Win32.ActiveCfg = Release|x64
{4ADABFBD-B4BB-4E2A-BE95-8C604DC783D3}.Release|Win32.Build.0 = Release|x64
EndGlobalSection
--- /dev/null
+#include "stdafx.h"
+
+namespace sf
+{
+
+ code_converter<char,wchar_t>::code_converter(const char*p)
+ {
+ int len = ::MultiByteToWideChar(CP_ACP,0,p,-1,NULL,0);
+ m_dest.reset(new wchar_t[len]);
+ ::MultiByteToWideChar(CP_ACP,0,p,-1,&m_dest[0],len);
+ };
+
+ code_converter<char,wchar_t>::code_converter(const std::string& p)
+ {
+ int len = ::MultiByteToWideChar(CP_ACP,0,p.c_str(),-1,NULL,0);
+ m_dest.reset(new wchar_t[len]);
+ ::MultiByteToWideChar(CP_ACP,0,p.c_str(),-1,&m_dest[0],len);
+ };
+
+ code_converter<wchar_t,char>::code_converter(const wchar_t*p)
+ {
+ int len = ::WideCharToMultiByte(CP_ACP,0,p,-1,NULL,0,NULL,NULL);
+ m_dest.reset(new char[len]);
+ ::WideCharToMultiByte(CP_ACP,0,p,-1,&m_dest[0],len,NULL,NULL);
+ };
+
+ code_converter<wchar_t,char>::code_converter(const std::wstring & p)
+ {
+ int len = ::WideCharToMultiByte(CP_ACP,0,p.c_str(),-1,NULL,0,NULL,NULL);
+ m_dest.reset(new char[len]);
+ ::WideCharToMultiByte(CP_ACP,0,p.c_str(),-1,&m_dest[0],len,NULL,NULL);
+ };
+
+};
\ No newline at end of file
--- /dev/null
+#pragma once
+
+
+/** @file
+ * @author S.F. (Satoshi Fujiwara)
+ * @brief wchar_t <--> char \82Ì\95Ï\8a·\83\86\81[\83e\83B\83\8a\83e\83B
+ * \88ø\90\94\82Æ\82µ\82Ä\95¶\8e\9a\97ñ\82ð\88ø\82«\93n\82·\8dÛ\81A\95Ï\8a·\82ª\95K\97v\82È\8fê\8d\87\81A\89º\8bL\82Ì\82æ\82¤\82É\83A\83_\83v\83^\93I\82É\8eg\97p\82·\82é\82±\82Æ\82ð\91z\92è\82µ\82Ä\82¢\82é\81B
+ * std::wstring a(L"abcd");
+ * std::wstring b((sf::code_converter<wcha_t,char>(a)));
+ *
+ *\81@\8cã\81AATL\83R\81[\83h\8d·\82µ\91Ö\82¦\97p\82Ìtypedef\82à\97p\88Ó\82µ\82Ä\82¢\82é\81B
+ * \82±\82ê\82Í\81A\83A\83_\83v\83^\82Æ\82µ\82Ä\82Ì\97\98\97p\82Ì\82Ý\82É\8cÀ\92è\82³\82ê\82é\81B
+ * sf::ct2a hoge_(L"abcef"); // \91z\92è\82µ\82Ä\82¢\82È\82¢\81i\93®\8dì\82·\82é\8fê\8d\87\82à\82 \82é\82µ\81A\83_\83\81\82È\8fê\8d\87\82à\82 \82é\81j
+ */
+
+namespace sf
+{
+ /** \90\97\8c` */
+ template <typename SrcChar,typename DestChar>
+ struct code_converter
+ {
+ public:
+ explicit code_converter(SrcChar* p);
+ explicit code_converter(std::basic_string<SrcChar> & p);
+ operator DestChar*();
+ };
+
+ /** char -> wchar_t\82Ö\82Ì\95Ï\8a· */
+ template <>
+ struct code_converter<char,wchar_t>
+ {
+ explicit code_converter(const char* p);
+ explicit code_converter(const std::string& p);
+
+ operator wchar_t*() const {return m_dest.get();}
+ private:
+ boost::scoped_array<wchar_t> m_dest;
+ };
+
+ /** wchar_t -> char */
+ template <>
+ struct code_converter<wchar_t,char>
+ {
+ explicit code_converter(const wchar_t* p);
+ explicit code_converter(const std::wstring& p);
+ operator char* () const {return m_dest.get();}
+ private:
+ boost::scoped_array<char> m_dest;
+ };
+
+ /** ATL\83R\81[\83h\8d·\82µ\91Ö\82¦\82Ì\82½\82ß\82Ì\83G\83C\83\8a\83A\83X */
+ typedef sf::code_converter<char,wchar_t> ca2w;
+
+ /** ATL\83R\81[\83h\8d·\82µ\91Ö\82¦\82Ì\82½\82ß\82Ì\83G\83C\83\8a\83A\83X */
+ typedef sf::code_converter<wchar_t,char> cw2a;
+
+ #ifdef _UNICODE
+
+ /** ATL\83R\81[\83h\8d·\82µ\91Ö\82¦\82Ì\82½\82ß\82Ì\83G\83C\83\8a\83A\83X */
+ typedef sf::code_converter<char,wchar_t> ca2t;
+ /** ATL\83R\81[\83h\8d·\82µ\91Ö\82¦\82Ì\82½\82ß\82Ì\83G\83C\83\8a\83A\83X */
+ typedef sf::code_converter<wchar_t,char> ct2a;
+
+ /** ATL\83R\81[\83h\8d·\82µ\91Ö\82¦\82Ì\82½\82ß\82Ì\83G\83C\83\8a\83A\83X */
+ inline const wchar_t* ct2w(const wchar_t* p) { return p;};
+ /** ATL\83R\81[\83h\8d·\82µ\91Ö\82¦\82Ì\82½\82ß\82Ì\83G\83C\83\8a\83A\83X */
+ inline const wchar_t* cw2t(const wchar_t* p) { return p;};
+
+ #else
+
+ /** ATL\83R\81[\83h\8d·\82µ\91Ö\82¦\82Ì\82½\82ß\82Ì\83G\83C\83\8a\83A\83X */
+ inline const char* ct2a(const char* p) { return p;};
+ /** ATL\83R\81[\83h\8d·\82µ\91Ö\82¦\82Ì\82½\82ß\82Ì\83G\83C\83\8a\83A\83X */
+ inline const char* ca2t(const char* p) { return p;};
+
+ #endif
+}
+
+
--- /dev/null
+#pragma once
+
+/* http://vision.kuee.kyoto-u.ac.jp/~nob/doc/win32/win32.html#doc1_42
+ \82æ\82è\94q\8eØ
+*/
+
+
+#ifndef STDX_DSTREAM_H
+
+#define STDX_DSTREAM_H
+
+namespace sf
+{
+
+// VC++ \82Å STLport \82¾\82Æ using std::char_traits; \82Ý\82½\82¢\82È\82Ì\82ª\95K\97v\82©\82à
+template <typename Ch_T, typename Tr_T = std::char_traits<Ch_T> >
+class basic_dbg_streambuf: public std::basic_stringbuf<Ch_T, Tr_T>
+{
+public:
+ basic_dbg_streambuf()
+ {
+#ifndef STDX_DSTREAM_BUFFERING
+ setbuf(0,0);
+#endif
+ }
+
+ virtual ~basic_dbg_streambuf()
+ {
+ sync();
+ }
+
+protected:
+ int sync(void)
+ {
+ dbg_out(str().c_str());
+ pbump(static_cast<int>(pbase() - pptr()));
+ return 0;
+ }
+
+ void dbg_out(const Ch_T*);
+};
+
+template <>
+inline void basic_dbg_streambuf<char>::dbg_out(const char *str)
+{
+ ::OutputDebugStringA(str);
+}
+
+template <>
+inline void basic_dbg_streambuf<wchar_t>::dbg_out(const wchar_t *str)
+{
+ ::OutputDebugStringW(str);
+}
+
+template <typename Ch_T, typename Tr_T = std::char_traits<Ch_T> >
+class basic_dbg_ostream: public std::basic_ostream<Ch_T, Tr_T>
+{
+public:
+ basic_dbg_ostream() : std::basic_ostream<Ch_T, Tr_T>(new basic_dbg_streambuf<Ch_T, Tr_T>())
+ {
+ }
+
+ virtual ~basic_dbg_ostream()
+ {
+ // flush(); // \95s\97v\82ç\82µ\82¢\81Dhttp://www.tietew.jp/cppll/archive/607
+ delete rdbuf();
+ }
+};
+
+typedef basic_dbg_streambuf<wchar_t> wdbg_streambuf;
+typedef basic_dbg_ostream<wchar_t> wdstream;
+
+// \82±\82ê\82ð\92è\8b`\82µ\82Ä\82¨\82\82Æ\81C dout \82Ì\90é\8c¾\82ª\82¢\82ç\82È\82\82È\82é\81D
+static wdstream wdout;
+
+}
+
+#endif // STDX_DSTREAM_
\ No newline at end of file
--- /dev/null
+#include "stdafx.h"
+#include "exception.h"
+#include <objbase.h>
+#include <wtypes.h>
+#include <winerror.h>
+#include <avrt.h>
+#include <strsafe.h>
+#include <audioclient.h>
+#include <audiopolicy.h>
+
+
+
+#define BOOST_ASSIGN_MAX_PARAMS 7
+#include <boost/assign.hpp>
+#include <boost/assign/ptr_list_of.hpp>
+#include <boost/assign/ptr_list_inserter.hpp>
+#include <boost/foreach.hpp>
+#include "sf_memory.h"
+
+using namespace boost;
+
+namespace sf
+{
+//typedef CComPtr<IAudioClient> IAudioClientPtr;
+std::map<HRESULT,std::wstring> com_error_ = boost::assign::list_of<std::pair<HRESULT,std::wstring> >
+ (E_POINTER,L"E_POINTER")
+ (E_INVALIDARG,L"E_INVALIDARG")
+ (DWRITE_E_FILEFORMAT,L"DWRITE_E_FILEFORMAT")
+ (DWRITE_E_UNEXPECTED,L"DWRITE_E_UNEXPECTED")
+ (DWRITE_E_NOFONT,L"DWRITE_E_NOFONT")
+ (DWRITE_E_FILENOTFOUND,L"DWRITE_E_FILENOTFOUND")
+ (DWRITE_E_FILEACCESS,L"DWRITE_E_FILEACCESS")
+ (DWRITE_E_FONTCOLLECTIONOBSOLETE,L"DWRITE_E_FONTCOLLECTIONOBSOLETE")
+ (DWRITE_E_ALREADYREGISTERED,L"DWRITE_E_ALREADYREGISTERED")
+ (AUDCLNT_E_NOT_INITIALIZED,L"AUDCLNT_E_NOT_INITIALIZED")
+ (AUDCLNT_E_ALREADY_INITIALIZED,L"AUDCLNT_E_ALREADY_INITIALIZED")
+ (AUDCLNT_E_WRONG_ENDPOINT_TYPE,L"AUDCLNT_E_WRONG_ENDPOINT_TYPE")
+ (AUDCLNT_E_DEVICE_INVALIDATED,L"AUDCLNT_E_DEVICE_INVALIDATED")
+ (AUDCLNT_E_NOT_STOPPED,L"AUDCLNT_E_NOT_STOPPED")
+ (AUDCLNT_E_BUFFER_TOO_LARGE,L"AUDCLNT_E_BUFFER_TOO_LARGE")
+ (AUDCLNT_E_OUT_OF_ORDER,L"AUDCLNT_E_OUT_OF_ORDER")
+ (AUDCLNT_E_UNSUPPORTED_FORMAT,L"AUDCLNT_E_UNSUPPORTED_FORMAT")
+ (AUDCLNT_E_INVALID_SIZE,L"AUDCLNT_E_INVALID_SIZE")
+ (AUDCLNT_E_DEVICE_IN_USE,L"AUDCLNT_E_DEVICE_IN_USE")
+ (AUDCLNT_E_BUFFER_OPERATION_PENDING,L"AUDCLNT_E_BUFFER_OPERATION_PENDING")
+ (AUDCLNT_E_THREAD_NOT_REGISTERED,L"AUDCLNT_E_THREAD_NOT_REGISTERED")
+ (AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED,L"AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED")
+ (AUDCLNT_E_ENDPOINT_CREATE_FAILED,L"AUDCLNT_E_ENDPOINT_CREATE_FAILED")
+ (AUDCLNT_E_SERVICE_NOT_RUNNING,L"AUDCLNT_E_SERVICE_NOT_RUNNING")
+ (AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED,L"AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED")
+ (AUDCLNT_E_EXCLUSIVE_MODE_ONLY,L"AUDCLNT_E_EXCLUSIVE_MODE_ONLY")
+ (AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL,L"AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL")
+ (AUDCLNT_E_EVENTHANDLE_NOT_SET,L"AUDCLNT_E_EVENTHANDLE_NOT_SET")
+ (AUDCLNT_E_INCORRECT_BUFFER_SIZE,L"AUDCLNT_E_INCORRECT_BUFFER_SIZE")
+ (AUDCLNT_E_BUFFER_SIZE_ERROR,L"AUDCLNT_E_BUFFER_SIZE_ERROR")
+ (AUDCLNT_S_BUFFER_EMPTY,L"AUDCLNT_S_BUFFER_EMPTY")
+ (AUDCLNT_S_THREAD_ALREADY_REGISTERED,L"AUDCLNT_S_THREAD_ALREADY_REGISTERED");
+
+
+win32_error_exception::win32_error_exception(boost::uint32_t hr)
+: std::exception("HRESULT ERROR"),hresult_(hr)
+{
+ local_memory<wchar_t> mem;
+ DWORD 結果 = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,0,hr,0,(LPWSTR)&mem,0,0);
+ if(結果 != 0){
+ error_ = mem.get();
+ } else {
+ std::map<HRESULT,std::wstring>::iterator it = com_error_.find(hr);
+ if(it != com_error_.end())
+ {
+ error_ = it->second;
+ } else {
+ error_ = (boost::wformat(L"0x%x 不明なCOMエラー") % hr).str();
+ }
+
+ }
+};
+
+win32_error_exception::win32_error_exception()
+{
+ hresult_ = ::GetLastError();
+ local_memory<wchar_t> mem;
+ DWORD rv = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,0,hresult_,0,(LPWSTR)&mem,0,0);
+ error_ = mem.get();
+ //Logger::outputDebugPrintf(L"Win32 Error %x %s",hresult_,mem.Get() );
+};
+
+}
\ No newline at end of file
--- /dev/null
+#pragma once
+
+namespace sf
+{
+///Exception
+ class exception : public std::exception
+ {
+ public:
+ explicit exception(const std::wstring& reason)
+ {
+ m_reason = reason;
+ };
+ const wchar_t * what() {return m_reason.c_str();};
+ const std::wstring& what_str() { return m_reason;};
+ protected:
+ std::wstring m_reason;
+ };
+
+ class win32_error_exception : std::exception
+ {
+ public:
+ win32_error_exception(boost::uint32_t hr);
+ win32_error_exception();
+
+ virtual ~win32_error_exception() {};
+ boost::uint32_t hresult() {return hresult_;}
+ std::wstring& error() {return error_;}
+ private:
+ boost::uint32_t hresult_;
+ std::wstring error_;
+ };
+
+
+}
\ No newline at end of file
--- /dev/null
+/*
+==============================================================================
+
+This file is part of the S.F.Tracker
+Copyright 2005-7 by Satoshi Fujiwara.
+
+S.F.Tracker can be redistributed and/or modified under the terms of the
+GNU General Public License, as published by the Free Software Foundation;
+either version 2 of the License, or (at your option) any later version.
+
+S.F.Tracker is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with S.F.Tracker; if not, visit www.gnu.org/licenses or write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+Boston, MA 02111-1307 USA
+
+==============================================================================
+*/
+/** @file
+* @author S.F. (Satoshi Fujiwara)
+*/
+
+#include "stdafx.h"
+
+namespace sf {
+
+ struct logger::impl
+ {
+ impl() : m_log_file("sftracker.log",std::ios_base::out | std::ios_base::trunc ){};
+ ~impl() {m_log_file.close();}
+
+ void write(const boost::wformat & fmt)
+ {
+ write(fmt.str());
+ };
+
+ void write(const std::wistream & st)
+ {
+ {
+ //mutex_type::scoped_lock lock_(m_mutex);
+ m_log_file << st << std::endl;
+ }
+ boost::gregorian::date dt = boost::gregorian::day_clock::local_day();
+
+ };
+
+ void write(const std::wstring & mes)
+ {
+ write(mes.c_str());
+ }
+
+ void write(const TCHAR * mes)
+ {
+ //mutex_type::scoped_lock lock_(m_mutex);
+ m_log_file << mes << std::endl;
+ m_log_file.flush();
+ }
+ private:
+ std::wofstream m_log_file;
+ //mutex_type m_mutex;
+ };
+
+ logger::logger() : m_impl(new logger::impl())
+ {
+ }
+ void logger::write(const boost::wformat & fmt)
+ {
+ m_impl->write(fmt);
+ };
+
+ void logger::write(const std::wstring & mes)
+ {
+ m_impl->write(mes);
+ }
+
+ void logger::write(const TCHAR * mes)
+ {
+ m_impl->write(mes);
+ }
+
+ void logger::write(const std::wistream & st)
+ {
+ m_impl->write(st);
+ }
+
+ logger::~logger()
+ {
+
+ }
+
+ void debug_out(const char * file_name,const int line,boost::wformat& fmt)
+ {
+ OutputDebugString((boost::wformat(_T("%s(%d) %s \n")) % std::wstring(sf::code_converter<char,wchar_t>(file_name)) % line % fmt).str().c_str());
+ };
+
+ void debug_out(const char * file_name,const int line,const std::wstring& str)
+ {
+ OutputDebugString((boost::wformat(_T("%s(%d) %s \n")) % std::wstring(sf::code_converter<char,wchar_t>(file_name)) % line % str).str().c_str());
+ };
+
+ void debug_out(const char * file_name,const int line,const char* str)
+ {
+ OutputDebugString((boost::wformat(_T("%s(%d) %s \n")) % std::wstring(sf::code_converter<char,wchar_t>(file_name)) % line % sf::code_converter<char,wchar_t>(str)).str().c_str());
+ }
+
+ void debug_outW(const char * file_name,const int line,const wchar_t* str)
+ {
+ OutputDebugString((boost::wformat(_T("%s(%d) %s \n")) % std::wstring(sf::code_converter<char,wchar_t>(file_name)) % line % str).str().c_str());
+ };
+
+}
--- /dev/null
+#pragma once
+
+#include "boost/date_time/gregorian/gregorian.hpp"
+#include "boost/date_time/posix_time/posix_time.hpp"
+#include "singleton.h"
+
+namespace sf {
+
+ struct logger : public singleton<logger>
+ {
+ public:
+ logger();
+ ~logger();
+ void write(const boost::wformat & fmt);
+ void write(const std::wstring & mes);
+ void write(const TCHAR * mes);
+ void write(const std::wistream & st);
+ private:
+ struct impl;
+ boost::shared_ptr<impl> m_impl;
+ };
+
+ void debug_out(const char * file_name,const int line,boost::wformat& fmt);
+ void debug_out(const char * file_name,const int line,const std::wstring& str);
+ void debug_out(const char * file_name,const int line,const char* str);
+ void debug_out(const char * file_name,const int line,const wchar_t* str);
+}
+
+#define WRITE_LOG(s) \
+ sf::logger::instance()->write(boost::wformat(_T("%s %s %6d %s")) % boost::posix_time::second_clock::local_time() % (TCHAR*)sf::ca2t(__FILE__) % __LINE__ % (s))
+
+#ifdef _DEBUG
+#define SFTRACE(x) sf::debug_out(__FILE__,__LINE__,(x))
+#else
+#define SFTRACE(x)
+#endif
+
--- /dev/null
+#pragma once
+/*
+ ==============================================================================
+
+ This file is part of the S.F.Tracker
+ Copyright 2005-7 by Satoshi Fujiwara.
+
+ S.F.Tracker can be redistributed and/or modified under the terms of the
+ GNU General Public License, as published by the Free Software Foundation;
+ either version 2 of the License, or (at your option) any later version.
+
+ S.F.Tracker is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with S.F.Tracker; if not, visit www.gnu.org/licenses or write to the
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ Boston, MA 02111-1307 USA
+
+ ==============================================================================
+*/
+/** @file
+ * @brief
+ * @author S.F. (Satoshi Fujiwara)
+ */
+namespace sf {
+ struct run_message_loop
+ {
+ run_message_loop(){};
+ inline WPARAM operator()()
+ {
+ MSG msg;
+ while (GetMessage(&msg, NULL, 0, 0))
+ {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ return msg.wParam;
+ }
+
+ ~run_message_loop(void){};
+ };
+
+ struct peek_message_loop
+ {
+ typedef boost::function<void ()> func_type;
+ explicit peek_message_loop(func_type func) {func_ = func;};
+ inline WPARAM operator()()
+ {
+ MSG msg = {0};
+ while( WM_QUIT != msg.message )
+ {
+ if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
+ {
+ TranslateMessage( &msg );
+ DispatchMessage( &msg );
+ }
+ else
+ {
+ func_(); // Do some rendering
+ }
+ }
+ return msg.wParam;
+ };
+ private:
+ func_type func_;
+ };
+}
--- /dev/null
+#pragma once
+/*
+ ==============================================================================
+
+ This file is part of the Shooting3
+ Copyright 2005-7 by Satoshi Fujiwara.
+
+ S.F.Tracker can be redistributed and/or modified under the terms of the
+ GNU General Public License, as published by the Free Software Foundation;
+ either version 2 of the License, or (at your option) any later version.
+
+ S.F.Tracker is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with S.F.Tracker; if not, visit www.gnu.org/licenses or write to the
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ Boston, MA 02111-1307 USA
+
+ ==============================================================================
+*/
+/** @file
+ * @brief util
+ * @author S.F. (Satoshi Fujiwara)
+ */
+#include "objbase.h"
+namespace sf
+{
+ enum com_init
+ {
+ multi_threaded = 0x0,
+ apartment_threaded = 0x2,
+ disable_ole1dde = 0x4,
+ speed_over_memory = 0x8
+ };
+
+ struct com_initialize
+ {
+ struct impl;
+ com_initialize(void * reserved = NULL,unsigned int init = multi_threaded);
+ ~com_initialize() {};
+ private:
+ boost::shared_ptr<impl> m_impl;
+ };
+
+ template <typename ComClass,typename ComInterface>
+ boost::intrusive_ptr<ComInterface> create_instance()
+ {
+ ComInterface * com_ptr;
+ CoCreateInstance( __uuidof(ComClass), NULL,
+ CLSCTX_ALL, __uuidof(ComInterface),
+ (void**)&com_ptr);
+ return boost::intrusive_ptr<ComInterface>(com_ptr,false);
+
+ };
+ template <typename COMInterface>
+ struct IUnknownImpl : public COMInterface
+ {
+ IUnknownImpl() : ref_(1) {};
+ virtual ~IUnknownImpl() {};
+ ULONG __stdcall AddRef()
+ {
+ return InterlockedIncrement(&ref_);
+ }
+
+ ULONG __stdcall Release()
+ {
+ ULONG ref = InterlockedDecrement(&ref_);
+ if (0 == ref)
+ {
+ delete this;
+ }
+ return ref;
+ }
+
+ HRESULT __stdcall QueryInterface(REFIID riid, VOID **ppObj)
+ {
+ if (IID_IUnknown == riid)
+ {
+ AddRef();
+ *ppObj = (IUnknown*)this;
+ }
+ else if (__uuidof(COMInterface) == riid)
+ {
+ AddRef();
+ *ppObj = (COMInterface*)this;
+ }
+ else
+ {
+ *ppObj = NULL;
+ return E_NOINTERFACE;
+ }
+ return S_OK;
+ }
+ private:
+ LONG ref_;
+ };
+}
\ No newline at end of file
--- /dev/null
+#pragma once
+namespace sf {
+// policy class
+struct heap_memory_free_policy
+{
+template< typename T >
+void operator()( const T* AMemory ) const
+{
+if( NULL != AMemory )
+::HeapFree( ::GetProcessHeap(), 0, AMemory );
+}
+};
+// policy class
+struct local_memory_free_policy
+{
+template< typename T >
+void operator()( const T* AMemory ) const
+{
+if( NULL != AMemory )
+::LocalFree( AMemory );
+}
+};
+// policy class
+struct co_task_memory_free_policy
+{
+template< typename T >
+void operator()( const T* AMemory ) const
+{
+if( NULL != AMemory )
+::CoTaskMemFree( AMemory );
+}
+};
+// base guard class
+template< typename T,class TFreePolicy >
+class base_memory
+{
+private:
+T *FMemory;
+
+public:
+base_memory( T* AMemory = NULL )
+: FMemory( AMemory ) {}
+
+virtual ~base_memory( void )
+{ reset(); }
+
+T* release( void )
+{
+T *tmp = FMemory;
+FMemory = NULL;
+return tmp;
+}
+
+void reset( T* AMemory = NULL )
+{
+if( AMemory != FMemory )
+{
+if( NULL != FMemory )
+TFreePolicy( FMemory );
+
+FMemory = AMemory;
+}
+}
+
+T* get( void )
+{ return FMemory; }
+
+T** operator&( void )
+{ return &FMemory; }
+
+};
+template< typename T >
+class heap_memory : public base_memory< T,
+heap_memory_free_policy >
+{
+public:
+heap_memory( T* AMemory = NULL )
+: base_memory< T, heap_memory_free_policy >( AMemory )
+{ }
+};
+template< typename T >
+class local_memory : public base_memory< T,
+local_memory_free_policy >
+{
+public:
+local_memory( T* AMemory = NULL )
+: base_memory< T, local_memory_free_policy >( AMemory )
+{ }
+};
+template< typename T >
+class co_task_memory : public base_memory< T,
+co_task_memory_free_policy >
+{
+public:
+co_task_memory( T* AMemory = NULL )
+: base_memory< T, co_task_memory_free_policy >( AMemory )
+{ }
+};
+
+};
--- /dev/null
+#include "stdafx.h"
+#define BOOST_ASSIGN_MAX_PARAMS 7
+#include <boost/assign.hpp>
+#include <boost/assign/ptr_list_of.hpp>
+#include <boost/assign/ptr_list_inserter.hpp>
+#include <boost/foreach.hpp>
+#include "sf_windows.h"
+#include "exception.h"
+
+#define エラーなら例外を投げる(hres) \
+ if (FAILED(hres)) { throw sf::win32_error_exception(hres); }
+
+#ifndef HINST_THISCOMPONENT
+EXTERN_C IMAGE_DOS_HEADER __ImageBase;
+#define HINST_THISCOMPONENT ((HINSTANCE)&__ImageBase)
+#endif
+
+namespace sf
+{
+ LRESULT base_window::window_proc(HWND hwnd,boost::uint32_t message, WPARAM wParam, LPARAM lParam)
+ {
+
+ LRESULT 結果 = 0;
+ switch (message)
+ {
+ case WM_CREATE:
+ {
+ // TODO:
+ create_device();
+ break;
+ }
+ case WM_SIZE:
+ {
+ //if (render_target_)
+ //{
+ // D2D1_SIZE_U size;
+ // size.width = lParam & 0xFFFF;
+ // size.height = (lParam >> 16) & 0xFFFF; ;
+
+ // // Note: This method can fail, but it's okay to ignore the
+ // // error here -- it will be repeated on the next call to
+ // // EndDraw.
+ // //render_target_->Resize(size);
+ //}
+ }
+ case WM_PAINT:
+ {
+ //create_device();
+
+ paint_struct begin_paint(hwnd);
+
+ //if (!(render_target_->CheckWindowState() & D2D1_WINDOW_STATE_OCCLUDED))
+ //{
+ // // Retrieve the size of the render target.
+ // D2D1_SIZE_F renderTargetSize = render_target_->GetSize();
+ // try {
+ // //render_target_->BeginDraw();
+ // base_->on_render();
+ // //エラーなら例外を投げる(render_target_->EndDraw());
+ // } catch (sf::win32_error_exception& e )
+ // {
+ // if(e.hresult() == D2DERR_RECREATE_TARGET)
+ // {
+ // discard_device();
+ // } else {
+ // throw;
+ // }
+ // }
+ //}
+ return FALSE;
+ }
+ case WM_DISPLAYCHANGE:
+ {
+ ::InvalidateRect(hwnd, NULL, FALSE);
+ }
+ case WM_ERASEBKGND:
+ {
+ return FALSE;
+ }
+ case WM_MOUSEMOVE:
+ {
+ // on_mouse_move(GET_X_LPARAM(lParam),GET_Y_LPARAM(lParam),wParam);
+ }
+ case WM_LBUTTONDOWN:
+ {
+ }
+ }
+ return ::DefWindowProcW(hwnd,message,wParam,lParam);
+ };
+
+
+ void base_window::create_device_independent_resources()
+ {
+
+ // Direct2DFactory の生成
+
+ if(!factory_){
+#if defined(DEBUG) || defined(_DEBUG)
+ D2D1_FACTORY_OPTIONS options;
+ options.debugLevel = D2D1_DEBUG_LEVEL_INFORMATION ;
+ エラーなら例外を投げる(D2D1CreateFactory(
+ D2D1_FACTORY_TYPE_SINGLE_THREADED,
+ options,
+ &factory_
+ ));
+#else
+ エラーなら例外を投げる(D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &factory_));
+#endif
+
+ }
+
+ if(!write_factory_){
+ エラーなら例外を投げる(::DWriteCreateFactory(
+ DWRITE_FACTORY_TYPE_SHARED,
+ __uuidof(IDWriteFactory),
+ reinterpret_cast<IUnknown**>(&write_factory_)
+ ));
+ }
+
+
+ //wic_imaging_factory_.CreateInstance(CLSID_WICImagingFactory);
+
+ //thunk_proc_ = (WNDPROC)thunk_.getCode();
+
+ };
+
+ void base_window::register_class (
+ wchar_t * menu_name,
+ boost::uint32_t style ,
+ boost::int32_t cbClsExtra,
+ HICON hIcon ,
+ HCURSOR hCursor,
+ HBRUSH hbrBackground ,
+ HICON hIconSm
+ )
+ {
+ wnd_class_.reset(new sf::window_class_ex(menu_name,名前_,HINST_THISCOMPONENT,thunk_proc_,style,cbClsExtra,hIcon,hCursor,hbrBackground,hIconSm));
+ }
+
+ /** デフォルト設定 */
+ void base_window::register_class()
+ {
+ wnd_class_.reset(new sf::window_class_ex(0,名前_,HINST_THISCOMPONENT,thunk_proc_));
+ }
+
+ void base_window::create_window()
+ {
+ // Create the application window.
+ //
+ // Because the CreateWindow function takes its size in pixels, we
+ // obtain the system DPI and use it to scale the window size.
+ FLOAT dpiX, dpiY;
+ //factory_->GetDesktopDpi(&dpiX, &dpiY);
+
+
+ // Windowを作成する
+ CreateWindow(
+ 名前_.c_str(),
+ title_.c_str(),
+ WS_OVERLAPPEDWINDOW,
+ CW_USEDEFAULT,
+ CW_USEDEFAULT,
+ static_cast<boost::uint32_t>(ceil(width_ /** dpiX / 96.f*/)),
+ static_cast<boost::uint32_t>(ceil(height_ /** dpiY / 96.f*/)),
+ NULL,
+ NULL,
+ HINST_THISCOMPONENT,
+ this
+ );
+ }
+
+ void base_window::create_device()
+ {
+
+ // 入力_.reset(new input(HINST_THISCOMPONENT,hwnd_));
+ HRESULT hr = S_OK;
+
+
+ //ウィンドウの現在の幅、高さを求める
+ RECT rc;
+ GetClientRect( hwnd_, &rc );
+ boost::uint32_t width = rc.right - rc.left;
+ boost::uint32_t height = rc.bottom - rc.top;
+
+ {
+ //wic_imaging_factory_.CreateInstance(CLSID_WICImagingFactory);
+ // bitmap_ = load_bitmap_from_file(render_target_,wic_imaging_factory_,L"myship.png");
+ }
+
+ if(!render_target_)
+ {
+ RECT rc;
+ GetClientRect(hwnd_, &rc);
+
+ D2D1_SIZE_U size = D2D1::SizeU(
+ rc.right - rc.left,
+ rc.bottom - rc.top
+ );
+
+ エラーなら例外を投げる(factory_->CreateHwndRenderTarget(
+ D2D1::RenderTargetProperties(),
+ D2D1::HwndRenderTargetProperties(hwnd_, size,D2D1_PRESENT_OPTIONS_IMMEDIATELY),
+ &render_target_
+ ));
+ // Create a DC render target
+ //D2D1_RENDER_TARGET_PROPERTIES props = D2D1::RenderTargetProperties(
+ // D2D1_RENDER_TARGET_TYPE_DEFAULT,
+ // D2D1::PixelFormat(
+ // DXGI_FORMAT_B8G8R8A8_UNORM,
+ // D2D1_ALPHA_MODE_IGNORE
+ // ) , 0.0, 0.0,
+ // D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE
+ // );
+
+ //エラーなら例外を投げる(factory_->CreateDCRenderTarget(
+ // &props,
+ // &render_target_
+ // ));
+ }
+ }
+
+
+ void base_window::discard_device()
+ {
+ /* if(render_target_)
+ {
+ render_target_.Release();
+ }*/
+ }
+
+ void base_window::show(boost::uint32_t show_flag)
+ {
+ //HRESULT hr = S_OK;
+ //BOOL enable;
+ //DwmIsCompositionEnabled (&enable);
+ //if(enable){
+ // //Create and populate the BlurBehind structre
+ // DWM_BLURBEHIND bb = {0};
+ // //Enable Blur Behind and Blur Region;
+ // bb.dwFlags = DWM_BB_ENABLE;
+ // bb.fEnable = true;
+ // bb.hRgnBlur = NULL;
+
+ // //Enable Blur Behind
+ // hr = DwmEnableBlurBehindWindow(hwnd_, &bb);
+ //}
+ ::ShowWindow(hwnd_,show_flag);
+ }
+ void base_window::update() {::UpdateWindow(hwnd_);}
+
+ base_window::~base_window()
+ {
+ safe_release(factory_);
+ safe_release(write_factory_);
+
+ }
+
+
+ base_window::base_window(const std::wstring& title,const std::wstring& name,bool fit_to_display,float width,float height)
+ : title_(title),名前_(name),fit_to_display_(fit_to_display),
+ width_(width),height_(height),thunk_(this,base_window::WndProc),hwnd_(0)
+ {
+ thunk_proc_ = (WNDPROC)thunk_.getCode();
+ //create_device_independent_resources();
+ }
+
+
+
+ base_window::operator HWND()
+ {
+ return hwnd_;
+ };
+
+ //ID2D1FactoryPtr base_window::factory() { return impl_->factory();};
+ //ID2D1HwndRenderTargetPtr base_window::render_target() { return impl_->render_target();};
+ //IDWriteFactoryPtr base_window::write_factory() {return impl_->write_factory();};
+
+ toplevel_window_ptr create_toplevel_window
+ (
+ const std::wstring& menu_name,
+ const std::wstring& name,
+ const boost::uint32_t show_flag,
+ bool fit_to_display,
+ float width,
+ float height
+ )
+ {
+ toplevel_window* p = new toplevel_window(menu_name,name,fit_to_display,width,height);
+ p->create_device_independent_resources();
+ p->register_class();
+ p->create_window();
+ p->show(show_flag);
+ p->update();
+ return toplevel_window_ptr(p);
+ }
+
+ LRESULT toplevel_window::window_proc(HWND hwnd,boost::uint32_t message, WPARAM wParam, LPARAM lParam)
+ {
+
+
+ switch (message)
+ {
+ case WM_CREATE:
+ {
+ // TODO:
+ create_device();
+ break;
+ }
+ case WM_SIZE:
+ {
+ //if (render_target_)
+ //{
+ // D2D1_SIZE_U size;
+ // size.width = lParam & 0xFFFF;
+ // size.height = (lParam >> 16) & 0xFFFF; ;
+
+ // // Note: This method can fail, but it's okay to ignore the
+ // // error here -- it will be repeated on the next call to
+ // // EndDraw.
+ // render_target_->Resize(size);
+ //}
+ }
+ case WM_PAINT:
+ {
+ //create_device();
+
+ {
+ paint_struct begin_paint(hwnd);
+ // 描画コードの呼び出し
+ render();
+ }
+ return FALSE;
+ }
+ case WM_DISPLAYCHANGE:
+ {
+ ::InvalidateRect(hwnd, NULL, FALSE);
+ }
+ case WM_ERASEBKGND:
+ {
+ return FALSE;
+ }
+ case WM_MOUSEMOVE:
+ {
+ // on_mouse_move(GET_X_LPARAM(lParam),GET_Y_LPARAM(lParam),wParam);
+ }
+ case WM_LBUTTONDOWN:
+ {
+ }
+ }
+
+ if(message == WM_CLOSE)
+ {
+ // 後始末
+ discard_device();
+ // レンダーターゲットのリリース
+ safe_release(render_target_);
+ // Windowの破棄
+ BOOL ret(::DestroyWindow(hwnd));
+ BOOST_ASSERT(ret != 0);
+ }
+
+ if(message == WM_DESTROY)
+ {
+ ::PostQuitMessage(0);
+ return 0;
+ }
+
+ return ::DefWindowProcW(hwnd,message,wParam,lParam);
+ }
+
+ void toplevel_window::main_loop()
+ {
+ render();
+ }
+
+ void toplevel_window::render()
+ {
+
+ static float t = 0.0f;
+
+ if (render_target_)
+ {
+ // Retrieve the size of the render target.
+ D2D1_SIZE_F renderTargetSize = render_target_->GetSize();
+ try {
+ render_target_->BeginDraw();
+ render_target_->Clear(D2D1::ColorF(D2D1::ColorF::White));
+ render_target_->SetTransform(D2D1::Matrix3x2F::Identity());
+ //render_target_->Clear(D2D1::ColorF(D2D1::ColorF::White));
+ ID2D1SolidColorBrushPtr brush;
+ render_target_->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black), &brush);
+ ID2D1SolidColorBrushPtr brushr;
+ render_target_->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Red), &brushr);
+
+ D2D1_RECT_F layoutRect = D2D1::RectF(50.f, 50.f, 600.f, 200.f);
+ IDWriteTextFormatPtr write_text_format;
+ // Text Formatの作成
+ エラーなら例外を投げる(write_factory_->CreateTextFormat(
+ L"メイリオ", // Font family name.
+ NULL, // Font collection (NULL sets it to use the system font collection).
+ DWRITE_FONT_WEIGHT_REGULAR,
+ DWRITE_FONT_STYLE_NORMAL,
+ DWRITE_FONT_STRETCH_NORMAL,
+ 48.0f,
+ L"ja-jp",
+ &write_text_format
+ ));
+ // Actually draw the text at the origin.
+ std::wstring m(L"こんにちは、64Bitの世界!By S.F.");
+ render_target_->DrawTextW(
+ m.c_str(),
+ m.size(),
+ write_text_format,
+ layoutRect,
+ brush);
+ エラーなら例外を投げる(render_target_->EndDraw());
+
+ } catch(...) {
+ throw;
+ }
+ }
+ };
+
+ //
+ // Creates a Direct2D bitmap from the specified
+ // file name.
+ //
+ ID2D1BitmapPtr load_bitmap_from_file(
+ ID2D1HwndRenderTargetPtr render_target,
+ IWICImagingFactoryPtr wic_factory,
+ std::wstring uri,
+ boost::uint32_t destination_width,
+ boost::uint32_t destination_height
+ )
+ {
+ HRESULT hr = S_OK;
+
+ IWICBitmapDecoderPtr decoder;
+ IWICBitmapFrameDecodePtr decoder_source;
+ IWICStreamPtr stream;
+ IWICFormatConverterPtr converter;
+ IWICBitmapScalerPtr scaler;
+ ID2D1BitmapPtr bitmap;
+
+ エラーなら例外を投げる(wic_factory->CreateDecoderFromFilename(
+ uri.c_str(),
+ NULL,
+ GENERIC_READ,
+ WICDecodeMetadataCacheOnLoad,
+ &decoder
+ ));
+
+ // Create the initial frame.
+ エラーなら例外を投げる(decoder->GetFrame(0, &decoder_source));
+
+ // Convert the image format to 32bppPBGRA
+ // (DXGI_FORMAT_B8G8R8A8_UNORM + D2D1_ALPHA_MODE_PREMULTIPLIED).
+ エラーなら例外を投げる(hr = wic_factory->CreateFormatConverter(&converter));
+
+ // If a new width or height was specified, create an
+ // IWICBitmapScaler and use it to resize the image.
+ if (destination_width != 0 || destination_height != 0)
+ {
+ boost::uint32_t originalWidth, originalHeight;
+ エラーなら例外を投げる(decoder_source->GetSize((UINT*)&originalWidth, (UINT*)&originalHeight));
+ if (destination_width == 0)
+ {
+ FLOAT scalar = static_cast<FLOAT>(destination_height) / static_cast<FLOAT>(originalHeight);
+ destination_width = static_cast<boost::uint32_t>(scalar * static_cast<FLOAT>(originalWidth));
+ }
+ else if (destination_height == 0)
+ {
+ FLOAT scalar = static_cast<FLOAT>(destination_width) / static_cast<FLOAT>(originalWidth);
+ destination_height = static_cast<boost::uint32_t>(scalar * static_cast<FLOAT>(originalHeight));
+ }
+
+ エラーなら例外を投げる(wic_factory->CreateBitmapScaler(&scaler));
+ エラーなら例外を投げる(scaler->Initialize(
+ decoder_source,
+ destination_width,
+ destination_height,
+ WICBitmapInterpolationModeCubic
+ ));
+ エラーなら例外を投げる(converter->Initialize(
+ scaler.GetInterfacePtr(),
+ GUID_WICPixelFormat32bppPBGRA,
+ WICBitmapDitherTypeNone,
+ NULL,
+ 0.f,
+ WICBitmapPaletteTypeMedianCut
+ ));
+ }
+ else // Don't scale the image.
+ {
+ エラーなら例外を投げる(converter->Initialize(
+ decoder_source.GetInterfacePtr(),
+ GUID_WICPixelFormat32bppPBGRA,
+ WICBitmapDitherTypeNone,
+ NULL,
+ 0.f,
+ WICBitmapPaletteTypeMedianCut
+ ));
+ }
+
+ // Create a Direct2D bitmap from the WIC bitmap.
+ エラーなら例外を投げる(render_target->CreateBitmapFromWicBitmap(
+ converter.GetInterfacePtr(),
+ NULL,
+ &bitmap
+ ));
+
+ return bitmap;
+ }
+
+
+}
+
--- /dev/null
+#pragma once
+/*
+*/
+// Windows Header Files:
+#include "exception.h"
+#define XBYAK64
+#include "xbyak.h"
+// DLLのリンク
+#pragma comment(lib,"d2d1.lib")
+#pragma comment(lib,"winmm.lib")
+#pragma comment(lib,"dwrite.lib")
+#pragma comment(lib,"dwmapi.lib")
+
+//#include "input.h"
+
+_COM_SMARTPTR_TYPEDEF(ID2D1Factory,__uuidof(ID2D1Factory));
+_COM_SMARTPTR_TYPEDEF(IWICImagingFactory, __uuidof(IWICImagingFactory));
+_COM_SMARTPTR_TYPEDEF(IDWriteFactory , __uuidof(IDWriteFactory));
+_COM_SMARTPTR_TYPEDEF(IDWriteGdiInterop , __uuidof(IDWriteGdiInterop));
+_COM_SMARTPTR_TYPEDEF(IDWriteFontFace , __uuidof(IDWriteFontFace));
+_COM_SMARTPTR_TYPEDEF(IDWriteFont , __uuidof(IDWriteFont));
+_COM_SMARTPTR_TYPEDEF(IDWriteFontFamily , __uuidof(IDWriteFontFamily));
+_COM_SMARTPTR_TYPEDEF(IDWriteFontCollection , __uuidof(IDWriteFontCollection));
+_COM_SMARTPTR_TYPEDEF(IDWriteLocalizedStrings , __uuidof(IDWriteLocalizedStrings));
+_COM_SMARTPTR_TYPEDEF(ID2D1HwndRenderTarget , __uuidof(ID2D1HwndRenderTarget));
+_COM_SMARTPTR_TYPEDEF(ID2D1BitmapRenderTarget , __uuidof(ID2D1BitmapRenderTarget));
+_COM_SMARTPTR_TYPEDEF(ID2D1GdiInteropRenderTarget , __uuidof(ID2D1GdiInteropRenderTarget));
+_COM_SMARTPTR_TYPEDEF(IDWriteTextFormat, __uuidof(IDWriteTextFormat));
+_COM_SMARTPTR_TYPEDEF(IDWriteTextLayout, __uuidof(IDWriteTextLayout));
+_COM_SMARTPTR_TYPEDEF(ID2D1PathGeometry , __uuidof(ID2D1PathGeometry));
+_COM_SMARTPTR_TYPEDEF(ID2D1LinearGradientBrush , __uuidof(ID2D1LinearGradientBrush));
+_COM_SMARTPTR_TYPEDEF(ID2D1GradientStopCollection , __uuidof(ID2D1GradientStopCollection));
+_COM_SMARTPTR_TYPEDEF(ID2D1SolidColorBrush , __uuidof(ID2D1SolidColorBrush));
+_COM_SMARTPTR_TYPEDEF(ID2D1BitmapBrush , __uuidof(ID2D1BitmapBrush));
+_COM_SMARTPTR_TYPEDEF(ID2D1Bitmap , __uuidof(ID2D1Bitmap));
+_COM_SMARTPTR_TYPEDEF(IWICBitmapDecoder,__uuidof(IWICBitmapDecoder));
+_COM_SMARTPTR_TYPEDEF(IWICBitmapFrameDecode,__uuidof(IWICBitmapFrameDecode));
+_COM_SMARTPTR_TYPEDEF(IWICStream,__uuidof(IWICStream));
+_COM_SMARTPTR_TYPEDEF(IWICFormatConverter,__uuidof(IWICFormatConverter));
+_COM_SMARTPTR_TYPEDEF(IWICBitmapScaler,__uuidof(IWICBitmapScaler));
+
+template <class COM_SMART_PTR > inline void safe_release(COM_SMART_PTR& ptr)
+{
+ if(ptr)
+ {
+ ptr.Release();
+ }
+};
+
+namespace sf{
+
+ ID2D1BitmapPtr load_bitmap_from_file(
+ ID2D1HwndRenderTargetPtr render_target,
+ IWICImagingFactoryPtr wic_factory,
+ std::wstring uri,
+ boost::uint32_t destination_width = 0,
+ boost::uint32_t destination_height = 0
+ );
+
+ /** WNDCLASSEXラッパクラス */
+ struct window_class_ex
+ {
+ window_class_ex(
+ const wchar_t* menu_name ,
+ const std::wstring& class_name ,
+ HINSTANCE hInstance = NULL,
+ WNDPROC lpfnWndProc = ::DefWindowProcW,
+ boost::uint32_t style = CS_HREDRAW | CS_VREDRAW,
+ boost::int32_t cbClsExtra = 0,
+ HICON hIcon = ::LoadIcon(NULL,IDI_APPLICATION),
+ HCURSOR hCursor = ::LoadCursor(NULL, IDC_ARROW),
+ HBRUSH hbrBackground = ::CreateSolidBrush(0xff000000),
+ HICON hIconSm = NULL
+ ) : is_register_(false)
+ {
+
+ if(::GetClassInfoExW(hInstance,class_name.c_str(),&wndclass_) == 0)
+ {
+ if(::GetLastError() == ERROR_CLASS_DOES_NOT_EXIST)
+ {
+ ::ZeroMemory(&wndclass_,sizeof(wndclass_));
+ wndclass_.lpszMenuName = (LPCWSTR)menu_name;
+ wndclass_.lpszClassName = class_name.c_str();
+ wndclass_.cbSize = sizeof(::WNDCLASSEXW);
+ wndclass_.cbWndExtra = sizeof(LONG_PTR);
+ wndclass_.hInstance = hInstance;
+ wndclass_.lpfnWndProc = lpfnWndProc;
+ wndclass_.style = style;
+ wndclass_.cbClsExtra = cbClsExtra;
+ wndclass_.hIcon = hIcon;
+ wndclass_.hCursor = hCursor;
+ wndclass_.hbrBackground = hbrBackground;
+ wndclass_.hIconSm = hIconSm;
+ atom_ = ::RegisterClassExW(&wndclass_) ;
+ BOOST_ASSERT(atom_ != 0);
+ is_register_ = true;
+ } else {
+ throw win32_error_exception();
+ }
+ } else {
+ is_register_ = false;
+ }
+ };
+
+ ~window_class_ex()
+ {
+ if(is_register_){
+ ::UnregisterClassW(wndclass_.lpszClassName,wndclass_.hInstance);
+ }
+ }
+
+ private:
+ bool is_register_;
+ ATOM atom_;
+ ::WNDCLASSEXW wndclass_;
+ };
+
+
+
+ struct get_dc {
+ get_dc(HWND hwnd) : hwnd_(hwnd),hdc_(GetDC(hwnd)) {}
+ HDC get(){return hdc_;}
+ ~get_dc(){::ReleaseDC(hwnd_,hdc_);}
+ private:
+ HDC hdc_;
+ HWND hwnd_;
+ };
+
+ struct compatible_dc {
+ compatible_dc(HDC hdc) : hdc_(::CreateCompatibleDC(hdc)){};
+ ~compatible_dc(){::DeleteDC(hdc_);};
+ HDC get() { return hdc_;};
+ private:
+ HDC hdc_;
+ };
+
+ struct ref_dc {
+ ref_dc(HDC& hdc) : hdc_(hdc) {};
+ ~ref_dc(){};
+ HDC get() { return hdc_;};
+ private:
+ HDC& hdc_;
+ };
+
+ struct d2_dc {
+ d2_dc(ID2D1GdiInteropRenderTargetPtr& ptr,D2D1_DC_INITIALIZE_MODE mode) :hdc_(0),ptr_(ptr)
+ {
+ hr_ = ptr->GetDC(mode,&hdc_);
+ };
+ ~d2_dc(){ptr_->ReleaseDC(NULL);};
+ HDC get() { return hdc_;};
+ private:
+ HRESULT hr_;
+ HDC hdc_;
+ ID2D1GdiInteropRenderTargetPtr& ptr_;
+ };
+
+ template <typename Holder>
+ struct device_context
+ {
+ explicit device_context(Holder* holder) : holder_(holder){};
+ ~device_context() {}
+ operator HDC(){return holder_->get();}
+ private:
+ boost::scoped_ptr<Holder> holder_;
+ };
+
+ typedef device_context<d2_dc> d2_dc_type;
+
+ struct paint_struct
+ {
+ paint_struct(HWND hwnd) : hwnd_(hwnd)
+ {
+ ::BeginPaint(hwnd,&paintstruct_);
+ }
+ ~paint_struct() {::EndPaint(hwnd_,&paintstruct_);}
+ PAINTSTRUCT* operator->(){return &paintstruct_;}
+ private:
+ HWND hwnd_;
+ PAINTSTRUCT paintstruct_;
+ };
+
+ template <typename T>
+ struct begin_draw
+ {
+ begin_draw(T& render_target) : render_target_(render_target) ,is_end_(false) {render_target->BeginDraw();}
+ HRESULT end_draw()
+ {
+ HRESULT hr = S_OK;
+ if(!is_end_) {
+ hr = render_target_->EndDraw();
+ is_end_ = true;
+ }
+
+ return hr;
+ };
+ ~begin_draw(){ if(!is_end_) { render_target_->EndDraw();}}
+ private:
+ T& render_target_;
+ bool is_end_;
+ };
+
+ struct mouse
+ {
+ mouse() : x_(0.0f),y_(0.0f),left_button_(false),middle_button_(false),right_button_(false){}
+ private:
+ float x_,y_;
+ bool left_button_,middle_button_,right_button_;
+ };
+
+ /** window ベースクラス */
+ struct base_window
+ {
+ typedef boost::signals2::signal<LRESULT (HWND,boost::uint32_t,WPARAM, LPARAM) > on_message_type;
+ on_message_type on_message;
+ typedef boost::signals2::signal<void ()> on_render_type;
+ on_render_type on_render;
+ operator HWND();
+ protected:
+ base_window(
+ const std::wstring& title,
+ const std::wstring& name,bool fit_to_display,
+ float width,float height);
+ ~base_window();
+ void register_class (
+ wchar_t* menu_name,
+ boost::uint32_t style,
+ boost::int32_t cbClsExtra = 0,
+ HICON hIcon = ::LoadIcon(NULL,IDI_APPLICATION),
+ HCURSOR hCursor = ::LoadCursor(NULL, IDC_ARROW),
+ HBRUSH hbrBackground = ::CreateSolidBrush(0xff000000),
+ HICON hIconSm = NULL
+ );
+
+ /** デフォルト設定 */
+ void register_class();
+ void create_window();
+ void update();
+ void show(boost::uint32_t show_flag);
+ virtual void discard_device();
+ virtual void create_device();
+ virtual void create_device_independent_resources();
+ public:
+ virtual LRESULT window_proc(HWND hwnd,boost::uint32_t message, WPARAM wParam, LPARAM lParam);
+ protected:
+ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
+ {
+ base_window* ptr = reinterpret_cast<base_window*>(hwnd);
+ hwnd = ptr->hwnd_;
+ return ptr->window_proc(hwnd,message,wParam,lParam);
+ };
+
+ // thisとhwndをつなぐthunkクラス
+ struct hwnd_this_thunk : public Xbyak::CodeGenerator {
+ hwnd_this_thunk(base_window* impl,WNDPROC proc)
+ {
+ // rcxにhwndが格納されているので、それをimpl->hwndに保存
+ mov(qword[&(impl->hwnd_)],rcx);
+ // 代わりにthisのアドレスをrcxに格納
+ mov(rcx,(LONG_PTR)impl);
+ // r10にproc(Window プロシージャ)へのアドレスを格納
+ mov(r10,(LONG_PTR)proc);
+ // Window プロシージャへへジャンプ
+ jmp(r10);
+ }
+ };
+
+ HWND hwnd_;
+ ID2D1FactoryPtr factory_;
+ ID2D1HwndRenderTargetPtr render_target_;
+ IDWriteFactoryPtr write_factory_;
+ IWICImagingFactoryPtr wic_imaging_factory_;
+ hwnd_this_thunk thunk_;
+ std::wstring title_;
+ std::wstring 名前_;
+ float width_,height_;
+ bool fit_to_display_;
+ boost::shared_ptr<sf::window_class_ex> wnd_class_;
+ WNDPROC thunk_proc_;
+ };
+
+ struct toplevel_window;
+ typedef boost::shared_ptr<toplevel_window> toplevel_window_ptr;
+
+ /** toplevel_window を生成する関数 */
+ toplevel_window_ptr create_toplevel_window (
+ const std::wstring& menu_name,
+ const std::wstring& name,
+ const boost::uint32_t show_flag = SW_SHOWNORMAL,
+ bool fit_to_display = false,
+ float width = 640,
+ float height = 480
+ );
+
+
+
+ /** toplevel ウィンドウクラス */
+ /* このクラスは、create_toplevel_window 関数からのみ生成可能 */
+ struct toplevel_window : public base_window
+ {
+ friend toplevel_window_ptr create_toplevel_window
+ (
+ const std::wstring& menu_name,
+ const std::wstring& name,
+ const boost::uint32_t show_flag,
+ bool fit_to_display ,
+ float width ,
+ float height
+ );
+ void main_loop();
+ protected:
+ void render();
+ toplevel_window(const std::wstring& menu_name,const std::wstring& name,bool fit_to_display,float width = 640,float height = 480) : base_window(menu_name,name,fit_to_display,width,height)
+ {
+ on_render.connect(boost::bind(&toplevel_window::render,this));
+ };
+ public:
+ LRESULT toplevel_window::window_proc(HWND hwnd,boost::uint32_t message, WPARAM wParam, LPARAM lParam);
+ };
+
+ struct av_mm_thread_characteristics
+ {
+ av_mm_thread_characteristics(std::wstring& str) : task_name_(str)
+ {
+ handle_ = ::AvSetMmThreadCharacteristicsW(str.c_str(),(LPDWORD)&task_index_);
+ }
+
+ bool set_priority(AVRT_PRIORITY p){return (::AvSetMmThreadPriority(handle_,p) == TRUE);}
+
+ ~av_mm_thread_characteristics()
+ {
+ ::AvRevertMmThreadCharacteristics(handle_);
+ }
+
+ private:
+ std::wstring task_name_;
+ boost::uint32_t task_index_;
+ HANDLE handle_;
+ };
+
+ struct widget
+ {
+ void draw();
+ float x_,y_;
+ };
+
+ typedef sf::begin_draw<ID2D1BitmapRenderTargetPtr> begin_draw_bitmap;
+ typedef sf::begin_draw<ID2D1HwndRenderTargetPtr> begin_draw_hwnd;
+
+}
\ No newline at end of file
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
- <CharacterSet>MultiByte</CharacterSet>
+ <CharacterSet>Unicode</CharacterSet>
+ <PlatformToolset>Windows7.1SDK</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
+ <ClInclude Include="code_converter.h" />
+ <ClInclude Include="dout.h" />
+ <ClInclude Include="exception.h" />
+ <ClInclude Include="logger.h" />
+ <ClInclude Include="message_loop.h" />
+ <ClInclude Include="sf_com.h" />
+ <ClInclude Include="sf_memory.h" />
+ <ClInclude Include="sf_windows.h" />
+ <ClInclude Include="singleton.h" />
+ <ClInclude Include="stdafx.h" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="code_converter.cpp" />
+ <ClCompile Include="exception.cpp" />
+ <ClCompile Include="logger.cpp" />
+ <ClCompile Include="sf_windows.cpp" />
+ <ClCompile Include="stdafx.cpp">
+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
+ </ClCompile>
+ <ClCompile Include="winmain.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
- <Filter Include="ソース ファイル">
- <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
- <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
- </Filter>
- <Filter Include="ヘッダー ファイル">
- <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
- <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
- </Filter>
- <Filter Include="リソース ファイル">
- <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
- <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
- </Filter>
+ <ClInclude Include="code_converter.h" />
+ <ClInclude Include="dout.h" />
+ <ClInclude Include="exception.h" />
+ <ClInclude Include="message_loop.h" />
+ <ClInclude Include="sf_com.h" />
+ <ClInclude Include="sf_memory.h" />
+ <ClInclude Include="sf_windows.h" />
+ <ClInclude Include="singleton.h" />
+ <ClInclude Include="stdafx.h" />
+ <ClInclude Include="logger.h" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="winmain.cpp" />
+ <ClCompile Include="stdafx.cpp" />
+ <ClCompile Include="code_converter.cpp" />
+ <ClCompile Include="exception.cpp" />
+ <ClCompile Include="logger.cpp" />
+ <ClCompile Include="sf_windows.cpp" />
</ItemGroup>
</Project>
\ No newline at end of file
--- /dev/null
+#pragma once
+/*
+ ==============================================================================
+
+ This file is part of the S.F.Tracker
+ Copyright 2005-7 by Satoshi Fujiwara.
+
+ S.F.Tracker can be redistributed and/or modified under the terms of the
+ GNU General Public License, as published by the Free Software Foundation;
+ either version 2 of the License, or (at your option) any later version.
+
+ S.F.Tracker is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with S.F.Tracker; if not, visit www.gnu.org/licenses or write to the
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ Boston, MA 02111-1307 USA
+
+ ==============================================================================
+*/
+/** @file
+ * @brief
+ * @author S.F. (Satoshi Fujiwara)
+ */
+#include <boost/thread.hpp>
+#include <boost/shared_ptr.hpp>
+namespace sf {
+ template<typename BaseClass,template <class> class PointerType = boost::shared_ptr > struct singleton
+ {
+ typedef PointerType<BaseClass> ptr;
+ friend BaseClass;
+
+ static ptr& instance()
+ {
+ boost::call_once(init,flag_);
+ return instance_;
+ };
+
+
+ singleton(){};
+ private:
+ singleton(const singleton& );
+ static void init(){instance_.reset(new BaseClass);};
+ static PointerType<BaseClass> instance_;
+ static boost::once_flag flag_;
+ };
+
+ template<class BaseClass,template <class> class PointerType> boost::once_flag singleton<BaseClass,PointerType>::flag_ = BOOST_ONCE_INIT;
+ template<class BaseClass,template <class> class PointerType> PointerType<BaseClass> singleton<BaseClass,PointerType>::instance_;
+};
+
+
--- /dev/null
+// stdafx.cpp : 標準インクルードのみを含むソース ファイルです。
+// STed2.pch は、プリコンパイル済みヘッダーになります。
+// stdafx.obj にはプリコンパイル型情報が含まれます。
+
+#include "stdafx.h"
+
+// TODO: このファイルではなく、STDAFX.H で必要な
+// 追加ヘッダーを参照してください。
--- /dev/null
+// stdafx.h : 標準のシステム インクルード ファイルのインクルード ファイル、または
+// 参照回数が多く、かつあまり変更されない、プロジェクト専用のインクルード ファイル
+// を記述します。
+//
+
+
+#pragma once
+#include <SDKDDKVer.h>
+
+#ifndef UNICODE
+#define UNICODE
+#endif
+// STL
+#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
+//
+// Modify the following defines if you have to target a platform prior to the ones specified below.
+// Refer to MSDN for the latest info on corresponding values for different platforms.
+#ifndef WINVER // Allow use of features specific to Windows 7 or later.
+#define WINVER 0x0700 // Change this to the appropriate value to target other versions of Windows.
+#endif
+
+#ifndef _WIN32_WINNT // Allow use of features specific to Windows 7 or later.
+#define _WIN32_WINNT 0x0700 // Change this to the appropriate value to target other versions of Windows.
+#endif
+#define DIRECTINPUT_VERSION 0x0800
+#include <tchar.h>
+#include <iostream>
+#include <fstream>
+#include <exception>
+#include <memory>
+#include <string>
+#include <map>
+#include <locale>
+#include <fstream>
+#include <algorithm>
+#include <functional>
+
+// Boost
+//#include <boost/archive/xml_woarchive.hpp>
+//#include <boost/archive/xml_wiarchive.hpp>
+//#include <boost/archive/text_woarchive.hpp>
+//#include <boost/archive/text_wiarchive.hpp>
+//#include <boost/archive/text_oarchive.hpp>
+//#include <boost/archive/text_iarchive.hpp>
+//#include <boost/archive/binary_woarchive.hpp>
+//#include <boost/archive/binary_wiarchive.hpp>
+//#include <boost/archive/binary_oarchive.hpp>
+//#include <boost/archive/binary_iarchive.hpp>
+
+//#include <boost/serialization/export.hpp>
+//#include <boost/serialization/is_abstract.hpp>
+//#include <boost/serialization/version.hpp>
+//#include <boost/serialization/serialization.hpp>
+//#include <boost/serialization/split_member.hpp>
+//#include <boost/serialization/string.hpp>
+//#include <boost/serialization/shared_ptr.hpp>
+//#include <boost/serialization/vector.hpp>
+//#include <boost/serialization/nvp.hpp>
+//#include <boost/serialization/void_cast.hpp>
+#include <boost/scoped_ptr.hpp>
+#include <boost/scoped_array.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/shared_array.hpp>
+#include <boost/intrusive_ptr.hpp>
+#include <boost/format.hpp>
+#include <boost/lexical_cast.hpp>
+#include <boost/array.hpp>
+#include <boost/thread.hpp>
+#include <boost/optional.hpp>
+#include <boost/bind.hpp>
+#include <boost/function.hpp>
+#include <boost/variant.hpp>
+#include <boost/any.hpp>
+#include <boost/signals2.hpp>
+#include <boost/tuple/tuple.hpp>
+#include <boost/ptr_container/ptr_container.hpp>
+#include <boost/thread/condition.hpp>
+//#include <boost/serialization/ptr_vector.hpp>
+#include <boost/ptr_container/ptr_array.hpp>
+#include <boost/ptr_container/serialize_ptr_container.hpp>
+//#include "serialization.h"
+#include <boost/filesystem/path.hpp>
+#include <boost/filesystem/operations.hpp>
+#include <boost/filesystem/convenience.hpp>
+#include "sf_com.h"
+//#include <d3d10_1.h>
+//#include <d3d10.h>
+//#include <d3d11.h>
+//#include <d3dx10.h>
+//#include <d3dx11.h>
+#include "dinput.h"
+#include <wincodec.h>
+#include <windows.h>
+#include <windowsx.h>
+#include <wincodec.h>
+#include <wincodecsdk.h>
+
+#include <comdef.h>
+#include "avrt.h"
+#include "mmsystem.h"
+#include <d2d1.h>
+#include <d2d1helper.h>
+#include <dwrite.h>
+#include "dwmapi.h"
+//#include <wincodec.h>
+//#include <wincodecsdk.h>
+//#include <d3dx11effect.h>
+//#include <d3dxGlobal.h>
+//#include "exception.h"
+//#include "singleton.h"
+//#include "code_converter.h"
+//#include "logger.h"
+
+
+// TODO: プログラムに必要な追加ヘッダーをここで参照してください。
+#include "code_converter.h"
+#include "logger.h"
+#include "dout.h"
--- /dev/null
+#include "stdafx.h"
+#include "sf_windows.h"
+#include "message_loop.h"
+#include "sf_com.h"
+
+void MIDIメッセージ到着時(const boost::uint32_t wMsg,const boost::uint32_t midi_message,const boost::uint32_t time_stamp);
+
+/** WinMain */
+int APIENTRY _tWinMain(HINSTANCE hInstance,
+ HINSTANCE hPrevInstance,
+ LPTSTR lpCmdLine,
+ int nCmdShow)
+{
+ UNREFERENCED_PARAMETER(hPrevInstance);
+ UNREFERENCED_PARAMETER(lpCmdLine);
+
+ std::wcout.imbue(std::locale(""));
+
+ // COMの初期化
+ sf::com_initialize init();
+
+ // ウィンドウの作成
+ sf::toplevel_window_ptr
+ window(
+ sf::create_toplevel_window(
+ std::wstring(L"Test Window"),std::wstring(L"Test Window")));
+
+ // メッセージループの実行
+
+ WPARAM ret = sf::run_message_loop()();
+
+ return ret;
+}