/********************************************************************** Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. ***********************************************************************/ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include "game.h" #include "log.h" #include "mem.h" #include "shared.h" #include "support.h" #include "unit.h" #include "version.h" #include "climisc.h" #include "colors.h" #include "mapview_g.h" #include "tilespec.h" #include "graphics.h" extern HINSTANCE freecivhinst; extern HWND root_window; static HDC hdc_dst; static HDC hdc_src; static SPRITE *sprcache; static HBITMAP bitmapcache; SPRITE *intro_gfx_sprite=NULL; SPRITE *radar_gfx_sprite=NULL; static SPRITE fog_sprite; /************************************************************************** **************************************************************************/ void load_intro_gfx(void) { intro_gfx_sprite=load_gfxfile(main_intro_filename); radar_gfx_sprite=load_gfxfile(minimap_intro_filename); } /************************************************************************** **************************************************************************/ void load_cursors(void) { /* PORTME */ } /************************************************************************** **************************************************************************/ void free_intro_radar_sprites(void) { if (intro_gfx_sprite) { free_sprite(intro_gfx_sprite); intro_gfx_sprite=NULL; } if (radar_gfx_sprite) { free_sprite(radar_gfx_sprite); radar_gfx_sprite=NULL; } } /************************************************************************** **************************************************************************/ char ** gfx_fileextensions(void) { static char *ext[] = { "png", NULL }; return ext; } /************************************************************************** **************************************************************************/ static void HBITMAP2BITMAP(HBITMAP hbm, HANDLE *bmp) { BITMAPINFO bi; BITMAP bm; HDC hdc; void *bits; if (!hbm) { MessageBox(NULL, "HBITMAP2BITMAP()", "Error", MB_OK|MB_ICONINFORMATION); return; } GetObject(hbm, sizeof(bm), &bm); bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bi.bmiHeader.biWidth = bm.bmWidth; bi.bmiHeader.biHeight = bm.bmHeight; bi.bmiHeader.biPlanes = 1; bi.bmiHeader.biBitCount = 32; bi.bmiHeader.biCompression = BI_RGB; bi.bmiHeader.biSizeImage = 0; bi.bmiHeader.biXPelsPerMeter = 0; bi.bmiHeader.biYPelsPerMeter = 0; bi.bmiHeader.biClrUsed = 0; bi.bmiHeader.biClrImportant = 0; hdc=CreateCompatibleDC(NULL); *bmp=CreateDIBSection(hdc, &bi, DIB_RGB_COLORS, &bits, NULL, 0); GetDIBits(hdc, hbm, 0L, bm.bmHeight, bits, &bi, DIB_RGB_COLORS); DeleteObject(hdc); } /*************************************************************************** ... ***************************************************************************/ int is_transparent(png_byte index, png_bytep trans, int ntrans) { int i; for (i=0; ijmpbuf)) { freelog(LOG_FATAL, "Failed while reading PNG file: %s", filename); exit(1); } png_init_io(pngp, fp); png_set_sig_bytes(pngp, sig_read); png_read_info(pngp, infop); png_set_strip_16(pngp); png_set_gray_to_rgb(pngp); png_set_packing(pngp); png_set_palette_to_rgb(pngp); png_set_tRNS_to_alpha(pngp); png_set_filler(pngp, 0xFF, PNG_FILLER_AFTER); png_set_bgr(pngp); png_set_invert_alpha(pngp); png_read_update_info(pngp, infop); png_get_IHDR(pngp, infop, &width, &height, &bit_depth, &color_type, &interlace_type, NULL, NULL); has_mask=(color_type & PNG_COLOR_MASK_ALPHA); row_pointers=fc_malloc(sizeof(png_bytep)*height); for (row=0; row=0; row--) { for (col=0, p=row_pointers[row]; colbmp=dib; if (has_mask) { hdc=CreateCompatibleDC(NULL); dib=CreateDIBSection(hdc, &bi, DIB_RGB_COLORS, &buf, NULL, 0); DeleteObject(hdc); for (row=height-1, pb=buf; row>=0; row--) { for (col=0, p=row_pointers[row]; colmask=dib; } mysprite->has_mask=has_mask; mysprite->width=width; mysprite->height=height; for (row=0; rowmask); old=SelectObject(hdc,fog); for(x=0;xwidth = width; dst->height = height; /* init DIB BITMAPINFOHEADER */ bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bi.bmiHeader.biWidth = width; bi.bmiHeader.biHeight = height; bi.bmiHeader.biPlanes = 1; bi.bmiHeader.biBitCount = 32; bi.bmiHeader.biCompression = BI_RGB; bi.bmiHeader.biSizeImage = 0; bi.bmiHeader.biXPelsPerMeter = 0; bi.bmiHeader.biYPelsPerMeter = 0; bi.bmiHeader.biClrUsed = 0; bi.bmiHeader.biClrImportant = 0; dib=CreateDIBSection(hdc, &bi, DIB_RGB_COLORS, NULL, NULL, 0); SelectObject(hdc_src, src->bmp); SelectObject(hdc_dst, dib); BitBlt(hdc_dst, 0, 0, width, height, hdc_src, x, y, SRCCOPY); dst->bmp=dib; dst->has_mask=0; if (src->has_mask) { hdc=CreateCompatibleDC(NULL); dib=CreateDIBSection(hdc, &bi, DIB_RGB_COLORS, NULL, NULL, 0); DeleteObject(hdc); SelectObject(hdc_src, src->mask); SelectObject(hdc_dst, dib); BitBlt(hdc_dst, 0, 0, width, height, hdc_src, x, y, SRCCOPY); dst->mask=dib; dst->has_mask=1; } ReleaseDC(root_window,hdc); return dst; } /************************************************************************** **************************************************************************/ void draw_sprite(struct Sprite *sprite, HDC hdc, int x, int y) { draw_sprite_part(sprite,hdc,x,y,sprite->width,sprite->height,0,0); } /************************************************************************** **************************************************************************/ void draw_sprite_part_with_mask(struct Sprite *sprite, struct Sprite *sprite_mask, HDC hdc, int x, int y,int w, int h, int xsrc, int ysrc) { static HDC hdccomp; static HDC hdcmask; if (!sprite) return; if (!hdccomp) hdccomp=CreateCompatibleDC(hdc); if (!hdcmask) hdcmask=CreateCompatibleDC(hdc); SelectObject(hdccomp, sprite->bmp); if (sprite_mask->has_mask) { SelectObject(hdcmask, sprite_mask->mask); BitBlt(hdc, x, y, w, h, hdccomp, xsrc, ysrc, SRCINVERT); BitBlt(hdc, x, y, w, h, hdcmask, xsrc, ysrc, SRCAND); BitBlt(hdc, x, y, w, h, hdccomp, xsrc, ysrc, SRCINVERT); } else { BitBlt(hdc, x, y, w, h, hdccomp, xsrc, ysrc, SRCCOPY); } } /************************************************************************** **************************************************************************/ void draw_sprite_part(struct Sprite *sprite,HDC hdc, int x,int y,int w,int h,int xsrc,int ysrc) { draw_sprite_part_with_mask(sprite,sprite,hdc,x,y,w,h,xsrc,ysrc); } /************************************************************************** **************************************************************************/ void draw_fog_part(HDC hdc,int x, int y,int w, int h, int xsrc, int ysrc) { draw_sprite_part(&fog_sprite,hdc,x,y,w,h,xsrc,ysrc); } /************************************************************************** **************************************************************************/ void crop_sprite_real(struct Sprite *source) { } /************************************************************************** **************************************************************************/ void free_sprite(struct Sprite *s) { DeleteObject(s->bmp); if (s->has_mask) DeleteObject(s->mask); free(s); if (bitmapcache) DeleteObject(bitmapcache); sprcache=NULL; } /************************************************************************** **************************************************************************/ int isometric_view_supported(void) { return 1; } /************************************************************************** **************************************************************************/ int overhead_view_supported(void) { return 1; }