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 // Flag set once "GDI+" has been initialized
14 bool gdi_plus_started = false;
16 ULONG_PTR gdiplusToken;
21 std::filesystem::path ANGBAND_DIR_XTRA_GRAF;
24 * 現在使用中のタイルID(0ならば未使用)
26 static graphics_mode current_graphics_mode = graphics_mode::GRAPHICS_NONE;
31 static tile_info infGraph;
34 * @brief Initialize GDI+
36 static inline void init_gdi_plus()
38 if (!gdi_plus_started) {
39 Gdiplus::GdiplusStartupInput gdiplusStartupInput;
40 Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
41 gdi_plus_started = true;
46 * @brief Cleans up resources used by GDI+
48 static void finalize_gdi_plus()
50 if (gdi_plus_started) {
51 Gdiplus::GdiplusShutdown(gdiplusToken);
52 gdi_plus_started = false;
56 HBITMAP read_graphic(const char *filename)
58 HBITMAP result = NULL;
61 Gdiplus::Bitmap bitmap(to_wchar(filename).wc_str());
63 COLORREF bgcolor = RGB(0x00, 0x00, 0x00);
64 bitmap.GetHBITMAP(bgcolor, &result);
70 graphics_mode change_graphics(graphics_mode arg)
72 if (current_graphics_mode == arg) {
73 return current_graphics_mode;
76 BYTE wid, hgt, twid, thgt, ox, oy;
78 std::string name_mask("");
80 infGraph.delete_bitmap();
82 if (arg == graphics_mode::GRAPHICS_ORIGINAL) {
91 } else if (arg == graphics_mode::GRAPHICS_ADAM_BOLT) {
99 name_mask = "16x16-mask.bmp";
101 ANGBAND_GRAF = "new";
102 } else if (arg == graphics_mode::GRAPHICS_HENGBAND) {
110 name_mask = "mask32.bmp";
112 ANGBAND_GRAF = "ne2";
114 ANGBAND_GRAF = "ascii";
115 current_graphics_mode = graphics_mode::GRAPHICS_NONE;
116 return current_graphics_mode;
119 const auto &path = path_build(ANGBAND_DIR_XTRA_GRAF, name);
120 const auto &filename = path.string();
121 infGraph.hBitmap = read_graphic(filename.data());
122 if (!infGraph.hBitmap) {
123 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name.data());
124 ANGBAND_GRAF = "ascii";
125 current_graphics_mode = graphics_mode::GRAPHICS_NONE;
126 return current_graphics_mode;
129 infGraph.CellWidth = wid;
130 infGraph.CellHeight = hgt;
131 infGraph.TileWidth = twid;
132 infGraph.TileHeight = thgt;
133 infGraph.OffsetX = ox;
134 infGraph.OffsetY = oy;
136 if (name_mask.empty()) {
137 current_graphics_mode = arg;
141 const auto &path_mask = path_build(ANGBAND_DIR_XTRA_GRAF, name_mask);
142 const auto &filename_mask = path_mask.string();
143 infGraph.hBitmapMask = read_graphic(filename_mask.data());
144 if (infGraph.hBitmapMask) {
145 current_graphics_mode = arg;
149 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name_mask.data());
150 ANGBAND_GRAF = "ascii";
151 current_graphics_mode = graphics_mode::GRAPHICS_NONE;
152 return current_graphics_mode;
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();