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 std::filesystem::path 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(const 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 BYTE wid, hgt, twid, thgt, ox, oy;
82 std::string name_mask("");
84 infGraph.delete_bitmap();
86 if (arg == graphics_mode::GRAPHICS_ORIGINAL) {
95 } else if (arg == graphics_mode::GRAPHICS_ADAM_BOLT) {
103 name_mask = "16x16-mask.bmp";
105 ANGBAND_GRAF = "new";
106 } else if (arg == graphics_mode::GRAPHICS_HENGBAND) {
114 name_mask = "mask32.bmp";
116 ANGBAND_GRAF = "ne2";
118 ANGBAND_GRAF = "ascii";
119 current_graphics_mode = graphics_mode::GRAPHICS_NONE;
120 return current_graphics_mode;
123 const auto &path = path_build(ANGBAND_DIR_XTRA_GRAF, name);
124 const auto &filename = path.string();
125 infGraph.hBitmap = read_graphic(filename.data());
126 if (!infGraph.hBitmap) {
127 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name.data());
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;
140 if (name_mask.empty()) {
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 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name_mask.data());
146 ANGBAND_GRAF = "ascii";
147 current_graphics_mode = graphics_mode::GRAPHICS_NONE;
148 return current_graphics_mode;
152 current_graphics_mode = arg;
157 graphics_mode Graphics::get_mode(void)
159 return current_graphics_mode;
162 graphics_mode Graphics::change_graphics(graphics_mode arg)
164 return Impl::change_graphics(arg);
167 const tile_info &Graphics::get_tile_info(void)
172 void Graphics::init(void)
177 void Graphics::finalize()
179 infGraph.delete_bitmap();