2 * @file graphics-win.cpp
3 * @brief Windows版固有実装(タイル、イメージファイルの読み込み)
6 #include "main-win/graphics-win.h"
7 #include "main-win/main-win-define.h"
8 #include "main-win/main-win-utils.h"
9 #include "system/system-variables.h"
10 #include "util/angband-files.h"
13 #pragma warning(disable : 4458)
17 // Flag set once "GDI+" has been initialized
18 bool gdi_plus_started = false;
20 ULONG_PTR gdiplusToken;
25 concptr ANGBAND_DIR_XTRA_GRAF;
28 * 現在使用中のタイルID(0ならば未使用)
30 static graphics_mode current_graphics_mode = graphics_mode::GRAPHICS_NONE;
35 static tile_info infGraph;
38 * @brief Initialize GDI+
40 static inline void init_gdi_plus()
42 if (!gdi_plus_started) {
43 Gdiplus::GdiplusStartupInput gdiplusStartupInput;
44 Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
45 gdi_plus_started = true;
50 * @brief Cleans up resources used by GDI+
52 static void finalize_gdi_plus()
54 if (gdi_plus_started) {
55 Gdiplus::GdiplusShutdown(gdiplusToken);
56 gdi_plus_started = false;
60 HBITMAP read_graphic(char *filename)
62 HBITMAP result = NULL;
65 Gdiplus::Bitmap bitmap(to_wchar(filename).wc_str());
67 COLORREF bgcolor = RGB(0x00, 0x00, 0x00);
68 bitmap.GetHBITMAP(bgcolor, &result);
74 graphics_mode change_graphics(graphics_mode arg)
76 if (current_graphics_mode == arg) {
77 return current_graphics_mode;
80 char buf[MAIN_WIN_MAX_PATH];
81 BYTE wid, hgt, twid, thgt, ox, oy;
83 concptr name_mask = nullptr;
85 infGraph.delete_bitmap();
87 if (arg == graphics_mode::GRAPHICS_ORIGINAL) {
96 } else if (arg == graphics_mode::GRAPHICS_ADAM_BOLT) {
104 name_mask = "mask.bmp";
106 ANGBAND_GRAF = "new";
107 } else if (arg == graphics_mode::GRAPHICS_HENGBAND) {
115 name_mask = "mask32.bmp";
117 ANGBAND_GRAF = "ne2";
119 ANGBAND_GRAF = "ascii";
120 current_graphics_mode = graphics_mode::GRAPHICS_NONE;
121 return current_graphics_mode;
124 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
125 infGraph.hBitmap = read_graphic(buf);
126 if (!infGraph.hBitmap) {
127 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
128 ANGBAND_GRAF = "ascii";
129 current_graphics_mode = graphics_mode::GRAPHICS_NONE;
130 return current_graphics_mode;
133 infGraph.CellWidth = wid;
134 infGraph.CellHeight = hgt;
135 infGraph.TileWidth = twid;
136 infGraph.TileHeight = thgt;
137 infGraph.OffsetX = ox;
138 infGraph.OffsetY = oy;
141 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name_mask);
142 infGraph.hBitmapMask = read_graphic(buf);
143 if (!infGraph.hBitmapMask) {
144 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name_mask);
145 ANGBAND_GRAF = "ascii";
146 current_graphics_mode = graphics_mode::GRAPHICS_NONE;
147 return current_graphics_mode;
151 current_graphics_mode = arg;
156 graphics_mode Graphics::get_mode(void)
158 return current_graphics_mode;
161 graphics_mode Graphics::change_graphics(graphics_mode arg)
163 return Impl::change_graphics(arg);
166 const tile_info &Graphics::get_tile_info(void)
171 void Graphics::init(void)
176 void Graphics::finalize()
178 infGraph.delete_bitmap();