2 ==============================================================================
4 This file is part of the mini timer
5 Copyright 2005-11 by Satoshi Fujiwara.
7 mini timer can be redistributed and/or modified under the terms of the
8 GNU General Public License, as published by the Free Software Foundation;
9 either version 2 of the License, or (at your option) any later version.
11 mini timer is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with mini timer; if not, visit www.gnu.org/licenses or write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19 Boston, MA 02111-1307 USA
21 ==============================================================================
27 #define _CRTDBG_MAP_ALLOC
29 #define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
32 #include "sf_windows.h"
34 #include "application.h"
37 bitmap_holder icon::default_mono_bitmap(CreateBitmap(32,32,1,1,NULL));
39 icon::icon(uint32_t id)
40 : icon_((HICON)::LoadImageW(application::instance()->instance_handle(),MAKEINTRESOURCE(id),IMAGE_ICON,0,0,LR_DEFAULTCOLOR))
45 icon::icon(icon_holder& ic)
47 icon_.reset(::CopyIcon(ic.get()));
51 icon::icon(icon_holder&& ic)
57 icon::icon(bitmap_holder& bmp_color,int width,int height)
58 : width_(width),height_(height)
62 ::GetObjectW(bmp_color.get(),sizeof(BITMAP),&bmp);
63 bits_per_pixel_ = bmp.bmBitsPixel;
68 ii.hbmColor = bmp_color.get();
70 if(width == 32 && height == 32){
71 ii.hbmMask = default_mono_bitmap.get();
72 icon_.reset(::CreateIconIndirect(&ii));
74 bitmap_holder hmb(::CreateBitmap(width,height,1,1,NULL));
75 ii.hbmMask = hmb.get();
76 icon_.reset(::CreateIconIndirect(&ii));
81 icon::icon(ID2D1BitmapPtr& ptr)
83 ID2D1FactoryPtr factory;
84 ptr->GetFactory(&factory);
86 D2D1_SIZE_U size(ptr->GetPixelSize());
88 BITMAPV5HEADER bi = {0};
89 bi.bV5Size = sizeof(BITMAPV5HEADER);
90 bi.bV5Width = size.width;
91 bi.bV5Height = size.height;
94 bi.bV5Compression = BI_BITFIELDS;
95 bi.bV5RedMask = 0x00FF0000;
96 bi.bV5GreenMask = 0x0000FF00;
97 bi.bV5BlueMask = 0x000000FF;
98 bi.bV5AlphaMask = 0xFF000000;
104 void *bits;// 得られるビットマップ
107 dc.get(),reinterpret_cast<BITMAPINFO *>(&bi),DIB_RGB_COLORS,&bits,NULL,0));
110 compatible_dc cdc(dc.get());
113 select_object s(cdc.get(),bmp.get());
115 // DC互換レンダーターゲットのセットアップ
116 D2D1_RENDER_TARGET_PROPERTIES
117 props = D2D1::RenderTargetProperties(
118 D2D1_RENDER_TARGET_TYPE_DEFAULT,
120 DXGI_FORMAT_B8G8R8A8_UNORM,
121 D2D1_ALPHA_MODE_PREMULTIPLIED),
124 D2D1_RENDER_TARGET_USAGE_NONE,
125 D2D1_FEATURE_LEVEL_DEFAULT
128 ID2D1DCRenderTargetPtr dcr;
129 throw_if_err<>()(factory->CreateDCRenderTarget(&props,&dcr));
130 RECT rect = {0,0,size.width,size.height};
132 throw_if_err<>()(dcr->BindDC(cdc.get(),&rect));
133 dcr->DrawBitmap(ptr);
136 icon(bmp,size.width,size.height);
140 icon::icon(boost::filesystem3::wpath& path)
143 reinterpret_cast<HICON>(
144 LoadImageW(NULL,path.native().c_str(),IMAGE_ICON,0,0,LR_DEFAULTSIZE | LR_LOADFROMFILE)));
155 ::GetIconInfoExW(icon_.get(),&info);
157 ::GetObjectW(info.hbmColor,sizeof(BITMAP),&bmp);
158 width_ = bmp.bmWidth;
159 height_ = bmp.bmHeight;
160 bits_per_pixel_ = bmp.bmBitsPixel;
163 icon& icon::operator= (icon& i)
165 BOOST_ASSERT(icon_ != i.icon_);
166 if(icon_ == i.icon_) return *this;
167 icon_.reset(::CopyIcon(i.icon_.get()));
170 bits_per_pixel_ = i.bits_per_pixel_;
174 //icon_ptr icon::create_icon()
177 // // ビットマップヘッダのセットアップ
178 // BITMAPV5HEADER bi = {0};
179 // bi.bV5Size = sizeof(BITMAPV5HEADER);
180 // bi.bV5Width = width_;
181 // bi.bV5Height = height_;
183 // bi.bV5BitCount = 32;
184 // bi.bV5Compression = BI_BITFIELDS;
185 // bi.bV5RedMask = 0x00FF0000;
186 // bi.bV5GreenMask = 0x0000FF00;
187 // bi.bV5BlueMask = 0x000000FF;
188 // bi.bV5AlphaMask = 0xFF000000;
194 // void *bits;// 得られるビットマップ
195 // gdi_object<HBITMAP> bmp(
196 // ::CreateDIBSection(
197 // dc.get(),reinterpret_cast<BITMAPINFO *>(&bi),DIB_RGB_COLORS,&bits,NULL,0));
200 // compatible_dc cdc(dc.get());
203 // select_object s(cdc.get(),bmp);
205 // // DC互換レンダーターゲットのセットアップ
206 // D2D1_RENDER_TARGET_PROPERTIES
207 // props = D2D1::RenderTargetProperties(
208 // D2D1_RENDER_TARGET_TYPE_DEFAULT,
209 // D2D1::PixelFormat(
210 // DXGI_FORMAT_B8G8R8A8_UNORM,
211 // D2D1_ALPHA_MODE_PREMULTIPLIED),
214 // D2D1_RENDER_TARGET_USAGE_NONE,
215 // D2D1_FEATURE_LEVEL_DEFAULT
218 // ID2D1DCRenderTargetPtr dcr;
219 // throw_if_err<>()(factory_->CreateDCRenderTarget(&props,&dcr));
220 // RECT rect = {0,0,w,h};
222 // throw_if_err<>()(dcr->BindDC(cdc.get(),&rect));
224 // // ブラシのセットアップ(背景の赤丸)
225 // ID2D1SolidColorBrushPtr brush_e;
227 // dcr->CreateSolidColorBrush(
228 // D2D1::ColorF(D2D1::ColorF::Red,0.8f), &brush_e));
231 // std::wstring t(L"S.F.\nTimer");
232 // D2D1_RECT_F l = D2D1::RectF(0.0f,0.0f,width_,height_);
234 // IDWriteTextFormatPtr f;
235 // write_factory_->CreateTextFormat(
236 // L"メイリオ", // Font family name.
237 // NULL, // Font collection (NULL sets it to use the system font collection).
238 // DWRITE_FONT_WEIGHT_REGULAR,
239 // DWRITE_FONT_STYLE_NORMAL,
240 // DWRITE_FONT_STRETCH_NORMAL,
245 // f->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER);
246 // f->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER);
248 // // 文字描画用ブラシのセットアップ
249 // ID2D1SolidColorBrushPtr brush;
250 // dcr->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black), &brush);
254 // dcr->Clear(D2D1::ColorF(D2D1::ColorF::Black,0.0f));
256 // dcr->FillEllipse(D2D1::Ellipse(D2D1::Point2F(16.0f,16.0f),14,14),brush_e);
258 // dcr->DrawTextW(t.c_str(),t.size(),f,&l,brush);