• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revision2ca2f98d0fe6ccaac01b4049feb614307660a265 (tree)
Time2012-11-18 23:42:55
Authorshom5xg <shom@.(no...>
Commitershom5xg

Log Message

util
--メーター単位クラス追加
--utf8、SJIS変換関数追加
--タイマークラス追加

Change Summary

Incremental Difference

--- a/util/src/util/util.cpp
+++ b/util/src/util/util.cpp
@@ -113,26 +113,29 @@ u32 get_color_b( u32 color )
113113 mm( namespace )
114114 ****************************************************************************/
115115
116-color_t::color_t()
116+color_t::color_t( u32 in_color )
117+:
118+m_color( in_color )
117119 {
118120 }
119121
120122 color_t::color_t( u32 in_r, u32 in_g, u32 in_b, u32 in_a )
123+:
124+m_color( set_color_rgba( in_r, in_g, in_b, in_a ) )
121125 {
122- m_color = set_color_rgba( in_r, in_g, in_b, in_a );
123126 }
124127
125128 color_t::color_t( f32 in_r, f32 in_g, f32 in_b, f32 in_a )
129+:
130+m_color( set_color_rgba(
131+ SCAST< u32 >( in_r * SCAST< f32 >( 0xff ) ),
132+ SCAST< u32 >( in_g * SCAST< f32 >( 0xff ) ),
133+ SCAST< u32 >( in_b * SCAST< f32 >( 0xff ) ),
134+ SCAST< u32 >( in_a * SCAST< f32 >( 0xff ) )
135+ ) )
126136 {
127- color_t(
128- SCAST< u32 >( in_r * SCAST< f32 >( 0xff ) ),
129- SCAST< u32 >( in_g * SCAST< f32 >( 0xff ) ),
130- SCAST< u32 >( in_b * SCAST< f32 >( 0xff ) ),
131- SCAST< u32 >( in_a * SCAST< f32 >( 0xff ) )
132- );
133137 }
134138
135-
136139 void color_t::set( u32 in_r, u32 in_g, u32 in_b, u32 in_a )
137140 {
138141 m_color = set_color_rgba( in_r, in_g, in_b, in_a );
@@ -242,3 +245,35 @@ f32 meter_to_dot( f32 meter )
242245 return ( meter * 7.0f );
243246 }
244247
248+void util_chara_code::ConvUtf8toSJis( ct char* ct in_pSrc, TCHAR* out_pDst, int* out_pSize )
249+{
250+ *out_pSize = 0;
251+
252+ //UTF-8からUTF-16へ変換
253+ const int nSize = ::MultiByteToWideChar( CP_UTF8, 0, in_pSrc, -1, NULL, 0 );
254+
255+ LPWSTR buffUtf16 = reinterpret_cast< LPWSTR >( new BYTE[ nSize * 2 + 2 ] );
256+ ::MultiByteToWideChar( CP_UTF8, 0, in_pSrc, -1, buffUtf16, nSize );
257+
258+ //UTF-16からShift-JISへ変換
259+ *out_pSize = ::WideCharToMultiByte( CP_ACP, 0, buffUtf16, -1, NULL, 0, NULL, NULL );
260+ if( !out_pDst ){
261+ delete buffUtf16;
262+ }
263+
264+ LPSTR buffSJis = new char[ *out_pSize * 2 ];
265+ my_memzero( buffSJis, *out_pSize * 2 );
266+ ::WideCharToMultiByte( CP_ACP, 0, buffUtf16, -1, buffSJis, *out_pSize, NULL, NULL );
267+
268+#ifdef UNICODE
269+ MultiByteToWideChar( CP_OEMCP, MB_PRECOMPOSED, buffSJis, strlen( buffSJis ), out_pDst, 256 );
270+#else
271+ strcpy( out_pDst, buffSJis );
272+#endif
273+
274+ delete buffUtf16;
275+ delete buffSJis;
276+}
277+
278+
279+
--- a/util/src/util/util.h
+++ b/util/src/util/util.h
@@ -70,7 +70,7 @@ extern u32 get_color_b( u32 color );
7070 class color_t
7171 {
7272 public:
73- color_t();
73+ color_t( u32 in_color );
7474 color_t( u32 in_r, u32 in_g, u32 in_b, u32 in_a = 0xff );
7575 color_t( f32 in_r, f32 in_g, f32 in_b, f32 in_a = 1.f );
7676
@@ -109,6 +109,19 @@ extern u32 get_time();
109109 ///-- "convert unit"
110110 extern f32 dot_to_meter( f32 dot );
111111 extern f32 meter_to_dot( f32 meter );
112+
113+class meter_t
114+{
115+public:
116+ meter_t();
117+};
118+///--
119+
120+///-- "char-code"
121+namespace util_chara_code
122+{
123+ extern void ConvUtf8toSJis( ct char* ct in_pSrc, TCHAR* out_pDst, int* out_pSize );
124+}
112125 ///--
113126
114127 ///-- "enum definition"
@@ -129,3 +142,33 @@ enum BOOST_PP_CAT( e, ENUM_KIND ) \
129142 BOOST_PP_CAT( e, ENUM_KIND )##_Invalid = U32_INVALID, \
130143 };
131144 ///--
145+
146+///-- "timer"
147+class CTimer
148+{
149+public:
150+ CTimer() : m_uTime( U32_INVALID ), m_bPause( FALSE ) {}
151+
152+ void Update( u32 in_uTimeProceed )
153+ {
154+ if( IsProceed() && !IsPause() )
155+ {
156+ m_uTime += in_uTimeProceed;
157+ }
158+ }
159+
160+ void Start() { m_uTime = 0; }
161+ void Stop() { m_uTime = U32_INVALID; }
162+ void Reset() { if( IsProceed() ){ m_uTime = 0; } }
163+ void Pause() { m_bPause = TRUE; }
164+ void Resume() { m_bPause = FALSE; }
165+
166+ u32 GetTime() const { return m_uTime; }
167+ b32 IsProceed() const { return ( m_uTime != U32_INVALID ); }
168+ b32 IsPause() const { return m_bPause; }
169+
170+private:
171+ u32 m_uTime;
172+ b32 m_bPause;
173+};
174+///--