変愚蛮怒のメインリポジトリです
Revision | 7fe8cb9c26c10d275d82ea3e19d618fa230c5e6c (tree) |
---|---|
Zeit | 2016-11-06 21:27:03 |
Autor | Deskull <desull@user...> |
Commiter | Deskull |
壁紙機能をGDI+で拡張 / Extend background function by GDI+.
@@ -163,7 +163,6 @@ | ||
163 | 163 | <ClCompile Include="..\..\src\obj_kind.c" /> |
164 | 164 | <ClCompile Include="..\..\src\object1.c" /> |
165 | 165 | <ClCompile Include="..\..\src\object2.c" /> |
166 | - <ClCompile Include="..\..\src\png-util.cpp" /> | |
167 | 166 | <ClCompile Include="..\..\src\racial.c" /> |
168 | 167 | <ClCompile Include="..\..\src\readdib.c" /> |
169 | 168 | <ClCompile Include="..\..\src\report.c" /> |
@@ -204,7 +203,6 @@ | ||
204 | 203 | <ClInclude Include="..\..\src\init.h" /> |
205 | 204 | <ClInclude Include="..\..\src\kajitips.h" /> |
206 | 205 | <ClInclude Include="..\..\src\mindtips.h" /> |
207 | - <ClInclude Include="..\..\src\png-util.h" /> | |
208 | 206 | <ClInclude Include="..\..\src\readdib.h" /> |
209 | 207 | <ClInclude Include="..\..\src\rooms.h" /> |
210 | 208 | <ClInclude Include="..\..\src\streams.h" /> |
@@ -81,8 +81,8 @@ | ||
81 | 81 | #include <locale.h> |
82 | 82 | #include "z-term.h" |
83 | 83 | #include "png-util.h" |
84 | -using namespace Gdiplus; | |
85 | 84 | |
85 | +using namespace Gdiplus; | |
86 | 86 | |
87 | 87 | /* |
88 | 88 | * Extract the "WIN32" flag from the compiler |
@@ -502,6 +502,10 @@ static char bg_bitmap_file[1024] = "bg.bmp"; | ||
502 | 502 | |
503 | 503 | static int use_new_gmode = 0; |
504 | 504 | |
505 | +/* GDI+ image */ | |
506 | +static Image* gdi_images[100]; | |
507 | +static Image* background_image; | |
508 | + | |
505 | 509 | #ifdef USE_SAVER |
506 | 510 | |
507 | 511 | /* |
@@ -765,6 +769,9 @@ static byte special_key_list[] = | ||
765 | 769 | }; |
766 | 770 | #endif |
767 | 771 | |
772 | +bool load_image(Image **image, char *filename); | |
773 | +void draw_image(HDC hdc, Image *image, int x, int y); | |
774 | + | |
768 | 775 | /* bg */ |
769 | 776 | static void delete_bg(void) |
770 | 777 | { |
@@ -777,36 +784,21 @@ static void delete_bg(void) | ||
777 | 784 | |
778 | 785 | static int init_bg(void) |
779 | 786 | { |
780 | - char * bmfile = bg_bitmap_file; | |
787 | + wchar_t wchar[200]; | |
788 | + size_t r; | |
781 | 789 | |
782 | 790 | delete_bg(); |
783 | 791 | if (use_bg == 0) return 0; |
784 | - | |
785 | - hBG = (HBITMAP)LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); | |
786 | - if (!hBG) { | |
787 | - plog_fmt(_("壁紙用ビットマップ '%s' を読み込めません。", "Can't load the bitmap file '%s'."), bmfile); | |
792 | + mbstowcs_s(&r, wchar, 200, bg_bitmap_file, _TRUNCATE); | |
793 | + background_image = new Image(wchar); | |
794 | + | |
795 | + if (!background_image || background_image->GetWidth() <= 0 || background_image->GetHeight() <= 0) { | |
796 | + plog_fmt(_("壁紙用画像 '%s' を読み込めません。", "Can't load the image file '%s'."), bg_bitmap_file); | |
788 | 797 | use_bg = 0; |
798 | + if(background_image) delete(background_image); | |
789 | 799 | return 0; |
790 | 800 | } |
791 | -#if 0 /* gomi */ | |
792 | - HDC wnddc, dcimage, dcbg; | |
793 | - HBITMAP bmimage, bmimage_old, bmbg_old; | |
794 | - int i, j; | |
795 | 801 | |
796 | - delete_bg(); | |
797 | - | |
798 | - wnddc = GetDC(hwnd); | |
799 | - dcimage = CreateCompatibleDC(wnddc); | |
800 | - dcbg = CreateCompatibleDC(wnddc); | |
801 | - | |
802 | - bmimage = LoadImage(NULL, "bg.bmp", LR_LOADFROMFILE, 0, 0, 0); | |
803 | - if (!bmimage) quit("bg.bmpが読みこめない!"); | |
804 | - bmimage_old = SelectObject(dcimage, bmimage); | |
805 | - | |
806 | - CreateCompatibleBitmap(); | |
807 | - | |
808 | - ReleaseDC(hwnd, wnddc); | |
809 | -#endif | |
810 | 802 | use_bg = 1; |
811 | 803 | return 1; |
812 | 804 | } |
@@ -815,103 +807,41 @@ static void DrawBG(HDC hdc, RECT *r) | ||
815 | 807 | { |
816 | 808 | HDC hdcSrc; |
817 | 809 | HBITMAP hOld; |
818 | - BITMAP bm; | |
819 | 810 | int x = r->left, y = r->top; |
820 | 811 | int nx, ny, sx, sy, swid, shgt, cwid, chgt; |
821 | - | |
822 | - if (!use_bg || !hBG) | |
823 | - return; | |
812 | + Gdiplus::Rect rec; | |
813 | + if(!background_image) return; | |
824 | 814 | |
825 | 815 | nx = x; ny = y; |
826 | - GetObject(hBG, sizeof(bm), &bm); | |
827 | - swid = bm.bmWidth; shgt = bm.bmHeight; | |
828 | - | |
816 | + swid = background_image->GetWidth(); shgt = background_image->GetHeight(); | |
817 | + if(swid == 0 || shgt == 0) | |
818 | + { | |
819 | + return; | |
820 | + } | |
821 | + Graphics graphics(hdc); | |
829 | 822 | hdcSrc = CreateCompatibleDC(hdc); |
830 | 823 | hOld = (HBITMAP)SelectObject(hdcSrc, hBG); |
831 | - | |
824 | + Unit srcunit = UnitPixel; | |
832 | 825 | do { |
833 | 826 | sx = nx % swid; |
834 | 827 | cwid = MIN(swid - sx, r->right - nx); |
835 | 828 | do { |
836 | 829 | sy = ny % shgt; |
837 | 830 | chgt = MIN(shgt - sy, r->bottom - ny); |
838 | - BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY); | |
831 | + | |
832 | + rec = Gdiplus::Rect(sx, sy, cwid, chgt); | |
833 | + graphics.DrawImage(background_image, rec, nx, ny, cwid, chgt, srcunit); | |
834 | +// graphics.DrawImage(background_image, nx, ny, sx, sy, swid, shgt, srcunit); | |
839 | 835 | ny += chgt; |
840 | 836 | } while (ny < r->bottom); |
841 | 837 | ny = y; |
842 | 838 | nx += cwid; |
843 | 839 | } while (nx < r->right); |
844 | - | |
840 | + | |
845 | 841 | SelectObject(hdcSrc, hOld); |
846 | 842 | DeleteDC(hdcSrc); |
847 | 843 | } |
848 | 844 | |
849 | -#if 0 | |
850 | -/* | |
851 | - * Hack -- given a pathname, point at the filename | |
852 | - */ | |
853 | -static cptr extract_file_name(cptr s) | |
854 | -{ | |
855 | - cptr p; | |
856 | - | |
857 | - /* Start at the end */ | |
858 | - p = s + strlen(s) - 1; | |
859 | - | |
860 | - /* Back up to divider */ | |
861 | - while ((p >= s) && (*p != ':') && (*p != '\\')) p--; | |
862 | - | |
863 | - /* Return file name */ | |
864 | - return (p+1); | |
865 | -} | |
866 | -#endif | |
867 | - | |
868 | - | |
869 | -/* | |
870 | - * Hack -- given a simple filename, extract the "font size" info | |
871 | - * | |
872 | - * Return a pointer to a static buffer holding the capitalized base name. | |
873 | - */ | |
874 | -#if 0 /* #ifndef JP */ | |
875 | -static char *analyze_font(char *path, int *wp, int *hp) | |
876 | -{ | |
877 | - int wid, hgt; | |
878 | - | |
879 | - char *s, *p; | |
880 | - | |
881 | - /* Start at the end */ | |
882 | - p = path + strlen(path) - 1; | |
883 | - | |
884 | - /* Back up to divider */ | |
885 | - while ((p >= path) && (*p != ':') && (*p != '\\')) --p; | |
886 | - | |
887 | - /* Advance to file name */ | |
888 | - ++p; | |
889 | - | |
890 | - /* Capitalize */ | |
891 | - for (s = p; *s; ++s) | |
892 | - { | |
893 | - /* Capitalize (be paranoid) */ | |
894 | - if (islower(*s)) *s = toupper(*s); | |
895 | - } | |
896 | - | |
897 | - /* Find first 'X' */ | |
898 | - s = my_strchr(p, 'X'); | |
899 | - | |
900 | - /* Extract font width */ | |
901 | - wid = atoi(p); | |
902 | - | |
903 | - /* Extract height */ | |
904 | - hgt = s ? atoi(s+1) : 0; | |
905 | - | |
906 | - /* Save results */ | |
907 | - (*wp) = wid; | |
908 | - (*hp) = hgt; | |
909 | - | |
910 | - /* Result */ | |
911 | - return (p); | |
912 | -} | |
913 | -#endif | |
914 | - | |
915 | 845 | |
916 | 846 | /* |
917 | 847 | * Check for existance of a file |
@@ -1053,17 +983,25 @@ static void validate_dir(cptr s, bool vital) | ||
1053 | 983 | } |
1054 | 984 | } |
1055 | 985 | |
1056 | -bool load_image(HWND hwnd, Image *image, char *filename) | |
986 | +bool load_image(Image **image, char *filename) | |
1057 | 987 | { |
1058 | 988 | size_t r; |
1059 | 989 | char buf[200]; |
1060 | 990 | wchar_t wchar[200]; |
1061 | 991 | path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, filename); |
1062 | 992 | mbstowcs_s(&r, wchar, 200, buf, _TRUNCATE); |
1063 | - image = new Image(wchar); | |
993 | + *image = new Image(wchar); | |
1064 | 994 | return true; |
1065 | 995 | } |
1066 | 996 | |
997 | +void draw_image(HDC hdc, Image *image, int x, int y) | |
998 | +{ | |
999 | + if(image == NULL) return; | |
1000 | + Graphics graphics(hdc); | |
1001 | + graphics.DrawImage(image, x, y); | |
1002 | +} | |
1003 | + | |
1004 | + | |
1067 | 1005 | /* |
1068 | 1006 | * Get the "size" for a window |
1069 | 1007 | */ |
@@ -2826,7 +2764,9 @@ static errr Term_wipe_win(int x, int y, int n) | ||
2826 | 2764 | SelectObject(hdc, td->font_id); |
2827 | 2765 | /* bg */ |
2828 | 2766 | if (use_bg) |
2767 | + { | |
2829 | 2768 | DrawBG(hdc, &rc); |
2769 | + } | |
2830 | 2770 | else |
2831 | 2771 | ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL); |
2832 | 2772 | ReleaseDC(td->w, hdc); |
@@ -2909,7 +2849,10 @@ static errr Term_text_win(int x, int y, int n, byte a, const char *s) | ||
2909 | 2849 | ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL); |
2910 | 2850 | |
2911 | 2851 | /* bg */ |
2912 | - if (use_bg) DrawBG(hdc, &rc); | |
2852 | + if (use_bg) | |
2853 | + { | |
2854 | + DrawBG(hdc, &rc); | |
2855 | + } | |
2913 | 2856 | |
2914 | 2857 | /* New rectangle */ |
2915 | 2858 | rc.left += ((td->tile_wid - td->font_wid) / 2); |
@@ -4437,7 +4380,7 @@ static void process_menus(WORD wCmd) | ||
4437 | 4380 | memset(&ofn, 0, sizeof(ofn)); |
4438 | 4381 | ofn.lStructSize = sizeof(ofn); |
4439 | 4382 | ofn.hwndOwner = data[0].w; |
4440 | - ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0"; | |
4383 | + ofn.lpstrFilter = "Image Files (*.bmp, *.png, *.jpg, *.jpeg)\0*.*\0"; | |
4441 | 4384 | ofn.nFilterIndex = 1; |
4442 | 4385 | ofn.lpstrFile = bg_bitmap_file; |
4443 | 4386 | ofn.nMaxFile = 1023; |
@@ -0,0 +1,4 @@ | ||
1 | +#include <windows.h> | |
2 | +#include <gdiplus.h> | |
3 | +using namespace Gdiplus; | |
4 | + |
@@ -0,0 +1 @@ | ||
1 | +bool paint_test(HWND hwnd); |