| Revision | 2ca2f98d0fe6ccaac01b4049feb614307660a265 (tree) |
|---|---|
| Time | 2012-11-18 23:42:55 |
| Author | shom5xg <shom@.(no...> |
| Commiter | shom5xg |
util
--メーター単位クラス追加
--utf8、SJIS変換関数追加
--タイマークラス追加
| @@ -113,26 +113,29 @@ u32 get_color_b( u32 color ) | ||
| 113 | 113 | mm( namespace ) |
| 114 | 114 | ****************************************************************************/ |
| 115 | 115 | |
| 116 | -color_t::color_t() | |
| 116 | +color_t::color_t( u32 in_color ) | |
| 117 | +: | |
| 118 | +m_color( in_color ) | |
| 117 | 119 | { |
| 118 | 120 | } |
| 119 | 121 | |
| 120 | 122 | 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 ) ) | |
| 121 | 125 | { |
| 122 | - m_color = set_color_rgba( in_r, in_g, in_b, in_a ); | |
| 123 | 126 | } |
| 124 | 127 | |
| 125 | 128 | 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 | + ) ) | |
| 126 | 136 | { |
| 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 | - ); | |
| 133 | 137 | } |
| 134 | 138 | |
| 135 | - | |
| 136 | 139 | void color_t::set( u32 in_r, u32 in_g, u32 in_b, u32 in_a ) |
| 137 | 140 | { |
| 138 | 141 | m_color = set_color_rgba( in_r, in_g, in_b, in_a ); |
| @@ -242,3 +245,35 @@ f32 meter_to_dot( f32 meter ) | ||
| 242 | 245 | return ( meter * 7.0f ); |
| 243 | 246 | } |
| 244 | 247 | |
| 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 | + |
| @@ -70,7 +70,7 @@ extern u32 get_color_b( u32 color ); | ||
| 70 | 70 | class color_t |
| 71 | 71 | { |
| 72 | 72 | public: |
| 73 | - color_t(); | |
| 73 | + color_t( u32 in_color ); | |
| 74 | 74 | color_t( u32 in_r, u32 in_g, u32 in_b, u32 in_a = 0xff ); |
| 75 | 75 | color_t( f32 in_r, f32 in_g, f32 in_b, f32 in_a = 1.f ); |
| 76 | 76 |
| @@ -109,6 +109,19 @@ extern u32 get_time(); | ||
| 109 | 109 | ///-- "convert unit" |
| 110 | 110 | extern f32 dot_to_meter( f32 dot ); |
| 111 | 111 | 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 | +} | |
| 112 | 125 | ///-- |
| 113 | 126 | |
| 114 | 127 | ///-- "enum definition" |
| @@ -129,3 +142,33 @@ enum BOOST_PP_CAT( e, ENUM_KIND ) \ | ||
| 129 | 142 | BOOST_PP_CAT( e, ENUM_KIND )##_Invalid = U32_INVALID, \ |
| 130 | 143 | }; |
| 131 | 144 | ///-- |
| 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 | +///-- |