예제 #1
0
void Blitter_32bppSimple::DrawColourMappingRect(void *dst, int width, int height, PaletteID pal)
{
	uint32 *udst = (uint32 *)dst;

	if (pal == PALETTE_TO_TRANSPARENT) {
		do {
			for (int i = 0; i != width; i++) {
				*udst = MakeTransparent(*udst, 154);
				udst++;
			}
			udst = udst - width + _screen.pitch;
		} while (--height);
		return;
	}
	if (pal == PALETTE_TO_STRUCT_GREY) {
		do {
			for (int i = 0; i != width; i++) {
				*udst = MakeGrey(*udst);
				udst++;
			}
			udst = udst - width + _screen.pitch;
		} while (--height);
		return;
	}

	DEBUG(misc, 0, "32bpp blitter doesn't know how to draw this colour table ('%d')", pal);
}
예제 #2
0
void CGras::DrawUI(LPDIRECT3DDEVICE7 lpDevice)
{
	if (lpVertices==NULL)return;
	if (game->lpTexture[40]==NULL)
	{	// Gras Textur nachladen
		game->lpTexture[40]=CreateTextureFromResource(lpDevice,game->lpDD,NULL,"grass.bmp",4,FALSE,TRUE); 
		MakeTransparent(game->lpTexture[40],FALSE);	// Gras
	}

	lpDevice->SetRenderState(D3DRENDERSTATE_LIGHTING,FALSE);

	DWORD old;
	lpDevice->GetRenderState(D3DRENDERSTATE_CULLMODE,&old);
	lpDevice->SetRenderState(D3DRENDERSTATE_CULLMODE,D3DCULL_NONE);
	if (Config.alpha)
	{
		lpDevice->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
		lpDevice->SetRenderState(D3DRENDERSTATE_ALPHATESTENABLE,TRUE);
		lpDevice->SetRenderState(D3DRENDERSTATE_ALPHAREF,192);
		lpDevice->SetRenderState(D3DRENDERSTATE_ALPHAFUNC,D3DCMP_GREATEREQUAL);
	}

	lpDevice->SetTexture(0,game->lpTexture[40]);

	D3DMATRIX m;
	D3DUtil_SetIdentityMatrix(m);
	lpDevice->SetTransform(D3DTRANSFORMSTATE_WORLD,&m);

	for (int i=0;i<vertexbuffers;i++)
		lpDevice->DrawIndexedPrimitiveVB(D3DPT_TRIANGLELIST,lpVertices[i],0,vertexnum[i],Indices,vertexnum[i]/4*6,0);

	lpDevice->SetRenderState(D3DRENDERSTATE_ALPHATESTENABLE,0);
	lpDevice->SetRenderState(D3DRENDERSTATE_LIGHTING,TRUE);
	lpDevice->SetRenderState(D3DRENDERSTATE_CULLMODE,old);
}
예제 #3
0
void Blitter_16bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom)
{
	const Pixel *src, *src_line;
	Colour16 *dst, *dst_line;
	Anim *anim, *anim_line;

	/* Find where to start reading in the source sprite */
	src_line = (const Pixel *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom);
	dst_line = (Colour16 *)bp->dst + bp->top * bp->pitch + bp->left;
	anim_line = this->anim_buf + ((Colour16 *)bp->dst - (Colour16 *)_screen.dst_ptr) + bp->top * this->anim_buf_width + bp->left;

	for (int y = 0; y < bp->height; y++) {
		dst = dst_line;
		dst_line += bp->pitch;

		src = src_line;
		src_line += bp->sprite_width * ScaleByZoom(1, zoom);

		anim = anim_line;
		anim_line += this->anim_buf_width;

		for (int x = 0; x < bp->width; x++) {
			switch (mode) {
				case BM_COLOUR_REMAP:
					/* In case the m-channel is zero, do not remap this pixel in any way */
					anim->m = 0;
					anim->v = 0;
					if (src->m == 0) {
						if (src->a != 0) *dst = ComposeColourPA(src->c, src->a, *dst);
					} else {
						uint8 r = bp->remap[src->m];
						if (r != 0) {
							*dst = ComposeColourPA(AdjustBrightness(LookupColourInPalette(r), src->v), src->a, *dst);
							if (src->a == 15 && r >= PALETTE_ANIM_START) {
								anim->m = r - PALETTE_ANIM_START + 1;
								anim->v = src->v >> 1;
							}
						}
					}
					break;

				case BM_TRANSPARENT:
					/* TODO -- We make an assumption here that the remap in fact is transparency, not some colour.
					 *  This is never a problem with the code we produce, but newgrfs can make it fail... or at least:
					 *  we produce a result the newgrf maker didn't expect ;) */

					/* Make the current colour a bit more black, so it looks like this image is transparent */
					if (src->a != 0) *dst = MakeTransparent(*dst, 192);
					anim->m = 0;
					anim->v = 0;
					break;

				default:
					if (src->a == 15 && src->m >= PALETTE_ANIM_START) {
						*dst = AdjustBrightness(LookupColourInPalette(src->m), src->v);
						anim->m = src->m - PALETTE_ANIM_START + 1;
						anim->v = src->v >> 1;
					} else {
						if (src->a != 0) {
예제 #4
0
const BOOLEAN CSprite::Load(const PCHAR name)
{
    Clear();

    const HPACKAGE package=LoadPackage(name);
    if (package.p==NULL)return FALSE;

    DWORD size;
    // Erst Anzahl in Package testen
    LPVOID data=LoadNextPackageData(&package,NULL,&size);
    anzahl=0;
    while (data)
    {
        anzahl++;
        data=LoadNextPackageData(&package,data,&size);
    }
    if (anzahl==0)
    {
        FreePackage(&package);
        return FALSE;
    }
    // Speicher reservieren

    lpImages=new LPDIRECTDRAWSURFACE7[anzahl];

    // Dann Bilder laden
    data=LoadNextPackageData(&package,NULL,&size);
    anzahl=0;
    while (data)
    {
        HBITMAP bitmap=LoadPictureFromMemory(data,size);
        if (bitmap==0)
        {
            FreePackage(&package);
            return FALSE;
        }

        lpImages[anzahl]=CreateTextureFromBitmap(game->lpDevice,game->lpDD,NULL,bitmap,3,TRUE,TRUE,FALSE);
        if (lpImages[anzahl]!=NULL)
            MakeTransparent(lpImages[anzahl],FALSE);

        DeleteObject(bitmap);

        anzahl++;
        data=LoadNextPackageData(&package,data,&size);
    }

    FreePackage(&package);

#ifdef _DEBUG
    CHAR c[200];
    sprintf(&c[0],"Sprite geladen: %s",name);
    DebugOut(&c[0]);
#endif

    return TRUE;
}
예제 #5
0
void Blitter_32bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
{
	const Blitter_32bppSimple::Pixel *src, *src_line;
	Colour *dst, *dst_line;

	/* Find where to start reading in the source sprite */
	src_line = (const Blitter_32bppSimple::Pixel *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom);
	dst_line = (Colour *)bp->dst + bp->top * bp->pitch + bp->left;

	for (int y = 0; y < bp->height; y++) {
		dst = dst_line;
		dst_line += bp->pitch;

		src = src_line;
		src_line += bp->sprite_width * ScaleByZoom(1, zoom);

		for (int x = 0; x < bp->width; x++) {
			switch (mode) {
				case BM_COLOUR_REMAP:
					/* In case the m-channel is zero, do not remap this pixel in any way */
					if (src->m == 0) {
						if (src->a != 0) *dst = ComposeColourRGBA(src->r, src->g, src->b, src->a, *dst);
					} else {
						if (bp->remap[src->m] != 0) *dst = ComposeColourPA(this->AdjustBrightness(this->LookupColourInPalette(bp->remap[src->m]), src->v), src->a, *dst);
					}
					break;

				case BM_CRASH_REMAP:
					if (src->m == 0) {
						if (src->a != 0) {
							uint8 g = MakeDark(src->r, src->g, src->b);
							*dst = ComposeColourRGBA(g, g, g, src->a, *dst);
						}
					} else {
						if (bp->remap[src->m] != 0) *dst = ComposeColourPA(this->AdjustBrightness(this->LookupColourInPalette(bp->remap[src->m]), src->v), src->a, *dst);
					}
					break;

				case BM_TRANSPARENT:
					/* TODO -- We make an assumption here that the remap in fact is transparency, not some colour.
					 *  This is never a problem with the code we produce, but newgrfs can make it fail... or at least:
					 *  we produce a result the newgrf maker didn't expect ;) */

					/* Make the current colour a bit more black, so it looks like this image is transparent */
					if (src->a != 0) *dst = MakeTransparent(*dst, 192);
					break;

				default:
					if (src->a != 0) *dst = ComposeColourRGBA(src->r, src->g, src->b, src->a, *dst);
					break;
			}
			dst++;
			src += ScaleByZoom(1, zoom);
		}
	}
}
예제 #6
0
void Blitter_32bppAnim::DrawColourMappingRect(void *dst, int width, int height, PaletteID pal)
{
	if (_screen_disable_anim) {
		/* This means our output is not to the screen, so we can't be doing any animation stuff, so use our parent DrawColourMappingRect() */
		Blitter_32bppOptimized::DrawColourMappingRect(dst, width, height, pal);
		return;
	}

	Colour *udst = (Colour *)dst;
	uint16 *anim;

	anim = this->anim_buf + ((uint32 *)dst - (uint32 *)_screen.dst_ptr);

	if (pal == PALETTE_TO_TRANSPARENT) {
		do {
			for (int i = 0; i != width; i++) {
				*udst = MakeTransparent(*udst, 154);
				*anim = 0;
				udst++;
				anim++;
			}
			udst = udst - width + _screen.pitch;
			anim = anim - width + this->anim_buf_width;
		} while (--height);
		return;
	}
	if (pal == PALETTE_NEWSPAPER) {
		do {
			for (int i = 0; i != width; i++) {
				*udst = MakeGrey(*udst);
				*anim = 0;
				udst++;
				anim++;
			}
			udst = udst - width + _screen.pitch;
			anim = anim - width + this->anim_buf_width;
		} while (--height);
		return;
	}

	DEBUG(misc, 0, "32bpp blitter doesn't know how to draw this colour table ('%d')", pal);
}
예제 #7
0
inline void Blitter_32bppOptimized::Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom)
{
	const SpriteData *src = (const SpriteData *)bp->sprite;

	/* src_px : each line begins with uint32 n = 'number of bytes in this line',
	 *          then n times is the Colour struct for this line */
	const Colour *src_px = (const Colour *)(src->data + src->offset[zoom][0]);
	/* src_n  : each line begins with uint32 n = 'number of bytes in this line',
	 *          then interleaved stream of 'm' and 'n' channels. 'm' is remap,
	 *          'n' is number of bytes with the same alpha channel class */
	const uint8  *src_n  = (const uint8  *)(src->data + src->offset[zoom][1]);

	/* skip upper lines in src_px and src_n */
	for (uint i = bp->skip_top; i != 0; i--) {
		src_px = (const Colour *)((const byte *)src_px + *(const uint32 *)src_px);
		src_n += *(uint32 *)src_n;
	}

	/* skip lines in dst */
	uint32 *dst = (uint32 *)bp->dst + bp->top * bp->pitch + bp->left;

	/* store so we don't have to access it via bp everytime (compiler assumes pointer aliasing) */
	const byte *remap = bp->remap;

	for (int y = 0; y < bp->height; y++) {
		/* next dst line begins here */
		uint32 *dst_ln = dst + bp->pitch;

		/* next src line begins here */
		const Colour *src_px_ln = (const Colour *)((const byte *)src_px + *(const uint32 *)src_px);
		src_px++;

		/* next src_n line begins here */
		const uint8 *src_n_ln = src_n + *(uint32 *)src_n;
		src_n += 4;

		/* we will end this line when we reach this point */
		uint32 *dst_end = dst + bp->skip_left;

		/* number of pixels with the same aplha channel class */
		uint n;

		while (dst < dst_end) {
			n = *src_n++;

			if (src_px->a == 0) {
				dst += n;
				src_px ++;
				src_n++;
			} else {
				if (dst + n > dst_end) {
					uint d = dst_end - dst;
					src_px += d;
					src_n += d;

					dst = dst_end - bp->skip_left;
					dst_end = dst + bp->width;

					n = min<uint>(n - d, (uint)bp->width);
					goto draw;
				}
				dst += n;
				src_px += n;
				src_n += n;
			}
		}

		dst -= bp->skip_left;
		dst_end -= bp->skip_left;

		dst_end += bp->width;

		while (dst < dst_end) {
			n = min<uint>(*src_n++, (uint)(dst_end - dst));

			if (src_px->a == 0) {
				dst += n;
				src_px++;
				src_n++;
				continue;
			}

			draw:;

			switch (mode) {
				case BM_COLOUR_REMAP:
					if (src_px->a == 255) {
						do {
							uint m = *src_n;
							/* In case the m-channel is zero, do not remap this pixel in any way */
							if (m == 0) {
								*dst = src_px->data;
							} else {
								uint r = remap[m];
								if (r != 0) *dst = this->LookupColourInPalette(r);
							}
							dst++;
							src_px++;
							src_n++;
						} while (--n != 0);
					} else {
						do {
							uint m = *src_n;
							if (m == 0) {
								*dst = ComposeColourRGBANoCheck(src_px->r, src_px->g, src_px->b, src_px->a, *dst);
							} else {
								uint r = remap[m];
								if (r != 0) *dst = ComposeColourPANoCheck(this->LookupColourInPalette(r), src_px->a, *dst);
							}
							dst++;
							src_px++;
							src_n++;
						} while (--n != 0);
					}
					break;

				case BM_TRANSPARENT:
					/* TODO -- We make an assumption here that the remap in fact is transparency, not some colour.
					 *  This is never a problem with the code we produce, but newgrfs can make it fail... or at least:
					 *  we produce a result the newgrf maker didn't expect ;) */

					/* Make the current colour a bit more black, so it looks like this image is transparent */
					src_n += n;
					if (src_px->a == 255) {
						src_px += n;
						do {
							*dst = MakeTransparent(*dst, 3, 4);
							dst++;
						} while (--n != 0);
					} else {
						do {
							*dst = MakeTransparent(*dst, (256 * 4 - src_px->a), 256 * 4);
							dst++;
							src_px++;
						} while (--n != 0);
					}
					break;

				default:
					if (src_px->a == 255) {
						/* faster than memcpy(), n is usually low */
						src_n += n;
						do {
							*dst = src_px->data;
							dst++;
							src_px++;
						} while (--n != 0);
					} else {
						src_n += n;
						do {
							*dst = ComposeColourRGBANoCheck(src_px->r, src_px->g, src_px->b, src_px->a, *dst);
							dst++;
							src_px++;
						} while (--n != 0);
					}
					break;
			}
		}

		dst = dst_ln;
		src_px = src_px_ln;
		src_n  = src_n_ln;
	}
}
예제 #8
0
inline void Blitter_32bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom)
{
	const SpriteData *src = (const SpriteData *)bp->sprite;

	const Colour *src_px = (const Colour *)(src->data + src->offset[zoom][0]);
	const uint16 *src_n  = (const uint16 *)(src->data + src->offset[zoom][1]);

	for (uint i = bp->skip_top; i != 0; i--) {
		src_px = (const Colour *)((const byte *)src_px + *(const uint32 *)src_px);
		src_n  = (const uint16 *)((const byte *)src_n  + *(const uint32 *)src_n);
	}

	Colour *dst = (Colour *)bp->dst + bp->top * bp->pitch + bp->left;
	uint16 *anim = this->anim_buf + ((uint32 *)bp->dst - (uint32 *)_screen.dst_ptr) + bp->top * this->anim_buf_width + bp->left;

	const byte *remap = bp->remap; // store so we don't have to access it via bp everytime

	for (int y = 0; y < bp->height; y++) {
		Colour *dst_ln = dst + bp->pitch;
		uint16 *anim_ln = anim + this->anim_buf_width;

		const Colour *src_px_ln = (const Colour *)((const byte *)src_px + *(const uint32 *)src_px);
		src_px++;

		const uint16 *src_n_ln = (const uint16 *)((const byte *)src_n + *(const uint32 *)src_n);
		src_n += 2;

		Colour *dst_end = dst + bp->skip_left;

		uint n;

		while (dst < dst_end) {
			n = *src_n++;

			if (src_px->a == 0) {
				dst += n;
				src_px ++;
				src_n++;

				if (dst > dst_end) anim += dst - dst_end;
			} else {
				if (dst + n > dst_end) {
					uint d = dst_end - dst;
					src_px += d;
					src_n += d;

					dst = dst_end - bp->skip_left;
					dst_end = dst + bp->width;

					n = min<uint>(n - d, (uint)bp->width);
					goto draw;
				}
				dst += n;
				src_px += n;
				src_n += n;
			}
		}

		dst -= bp->skip_left;
		dst_end -= bp->skip_left;

		dst_end += bp->width;

		while (dst < dst_end) {
			n = min<uint>(*src_n++, (uint)(dst_end - dst));

			if (src_px->a == 0) {
				anim += n;
				dst += n;
				src_px++;
				src_n++;
				continue;
			}

			draw:;

			switch (mode) {
				case BM_COLOUR_REMAP:
					if (src_px->a == 255) {
						do {
							uint m = *src_n;
							/* In case the m-channel is zero, do not remap this pixel in any way */
							if (m == 0) {
								*dst = src_px->data;
								*anim = 0;
							} else {
								uint r = remap[GB(m, 0, 8)];
								*anim = r | (m & 0xFF00);
								if (r != 0) *dst = this->AdjustBrightness(this->LookupColourInPalette(r), GB(m, 8, 8));
							}
							anim++;
							dst++;
							src_px++;
							src_n++;
						} while (--n != 0);
					} else {
						do {
							uint m = *src_n;
							if (m == 0) {
								*dst = ComposeColourRGBANoCheck(src_px->r, src_px->g, src_px->b, src_px->a, *dst);
								*anim = 0;
							} else {
								uint r = remap[GB(m, 0, 8)];
								*anim = 0;
								if (r != 0) *dst = ComposeColourPANoCheck(this->AdjustBrightness(this->LookupColourInPalette(r), GB(m, 8, 8)), src_px->a, *dst);
							}
							anim++;
							dst++;
							src_px++;
							src_n++;
						} while (--n != 0);
					}
					break;

				case BM_TRANSPARENT:
					/* TODO -- We make an assumption here that the remap in fact is transparency, not some colour.
					 *  This is never a problem with the code we produce, but newgrfs can make it fail... or at least:
					 *  we produce a result the newgrf maker didn't expect ;) */

					/* Make the current colour a bit more black, so it looks like this image is transparent */
					src_n += n;
					if (src_px->a == 255) {
						src_px += n;
						do {
							*dst = MakeTransparent(*dst, 3, 4);
							*anim = 0;
							anim++;
							dst++;
						} while (--n != 0);
					} else {
						do {
							*dst = MakeTransparent(*dst, (256 * 4 - src_px->a), 256 * 4);
							*anim = 0;
							anim++;
							dst++;
							src_px++;
						} while (--n != 0);
					}
					break;

				default:
					if (src_px->a == 255) {
						do {
							/* Compiler assumes pointer aliasing, can't optimise this on its own */
							uint m = GB(*src_n, 0, 8);
							/* Above PALETTE_ANIM_START is palette animation */
							*anim++ = *src_n;
							*dst++ = (m >= PALETTE_ANIM_START) ? this->AdjustBrightness(this->LookupColourInPalette(m), GB(*src_n, 8, 8)) : src_px->data;
							src_px++;
							src_n++;
						} while (--n != 0);
					} else {
						do {
							uint m = GB(*src_n, 0, 8);
							*anim++ = 0;
							if (m >= PALETTE_ANIM_START) {
								*dst = ComposeColourPANoCheck(this->AdjustBrightness(this->LookupColourInPalette(m), GB(*src_n, 8, 8)), src_px->a, *dst);
							} else {
								*dst = ComposeColourRGBANoCheck(src_px->r, src_px->g, src_px->b, src_px->a, *dst);
							}
							dst++;
							src_px++;
							src_n++;
						} while (--n != 0);
					}
					break;
			}
		}

		anim = anim_ln;
		dst = dst_ln;
		src_px = src_px_ln;
		src_n  = src_n_ln;
	}
}
예제 #9
0
void wxSpeedButton::SplitGlyphs(const wxBitmap &inBitmap, int inCount) {
int         n;
int         bw,bh;
int         sw,sh;
wxRect      rr;
wxImage     img;
wxBitmap    *bmp;

// no images yet

    mGlyphUp       = wxNullBitmap;
    mGlyphDown     = wxNullBitmap;
    mGlyphDisabled = wxNullBitmap;

// if no bitmap, then we are done

    if (! inBitmap.Ok()) return;

// size of the bitmap

    bw = inBitmap.GetWidth();
    bh = inBitmap.GetHeight();
    if ((bw <= 0) || (bh <= 0)) return;

// determine the number of images in the source bitmap
// if inCount > 0, then that is the count specified by the user
// else, count number of square sub-images

    if      (inCount > 0) n = inCount;
    else if (bw >= bh)    n = (int) bw / bh;
    else                  n = (int) bh / bw;

// extract sub-images, either vertically or horizontally

    if (n == 1) {
        mGlyphUp   = inBitmap;
        mGlyphDown = inBitmap;

        img = inBitmap.ConvertToImage();
        img = img.ConvertToGreyscale();
        bmp = new wxBitmap(img);
        mGlyphDisabled = *bmp;
    }
    else if ((n == 2) && (bw >= bh)) {
        sw = (int) bw / n;
        sh = bh;

        rr.SetX(0);
        rr.SetY(0);
        rr.SetWidth(sw);
        rr.SetHeight(sh);
        mGlyphUp = inBitmap.GetSubBitmap(rr);
        mGlyphDown = inBitmap.GetSubBitmap(rr);
        rr.SetX(sw);
        mGlyphDisabled = inBitmap.GetSubBitmap(rr);
    }
    else if ((n == 2) && (bh > bw)) {
        sw = bw;
        sh = (int) bh / n;

        rr.SetX(0);
        rr.SetY(0);
        rr.SetWidth(sw);
        rr.SetHeight(sh);
        mGlyphUp = inBitmap.GetSubBitmap(rr);
        mGlyphDown = inBitmap.GetSubBitmap(rr);
        rr.SetY(sh);
        mGlyphDisabled = inBitmap.GetSubBitmap(rr);
    }
    else if ((n >= 3) && (bw >= bh)) {
        sw = (int) bw / n;
        sh = bh;

        rr.SetX(0);
        rr.SetY(0);
        rr.SetWidth(sw);
        rr.SetHeight(sh);
        mGlyphUp = inBitmap.GetSubBitmap(rr);
        rr.SetX(sw);
        mGlyphDown = inBitmap.GetSubBitmap(rr);
        rr.SetX(sw+sw);
        mGlyphDisabled = inBitmap.GetSubBitmap(rr);
    }
    else { // (n >= 3) && (bh > bw)
        sw = bw;
        sh = (int) bh / n;

        rr.SetX(0);
        rr.SetY(0);
        rr.SetWidth(sw);
        rr.SetHeight(sh);
        mGlyphUp = inBitmap.GetSubBitmap(rr);
        rr.SetY(sh);
        mGlyphDown = inBitmap.GetSubBitmap(rr);
        rr.SetY(sh+sh);;
        mGlyphDisabled = inBitmap.GetSubBitmap(rr);
    };

// make them all transparent

    MakeTransparent(mGlyphUp);
    MakeTransparent(mGlyphDown);
    MakeTransparent(mGlyphDisabled);
}
예제 #10
0
void CRadar::Update()
{
	HDC dc;
	if (SUCCEEDED(lpSurface->GetDC(&dc)))
	{
		HBRUSH oldbrush;
		{	// Löschen / Auf Farbe setzen
			PatBlt(dc,0,0,size,size,BLACKNESS);
			SelectObject(dc,GetStockObject(WHITE_PEN));
			const HBRUSH green=CreateSolidBrush(RGB(0,64,0));
			oldbrush=(HBRUSH)SelectObject(dc,green);
			Ellipse(dc,0,0,size,size);
			SelectObject(dc,oldbrush);
			DeleteObject(green);
		}

		const float sx=parent->pos.x,sy=parent->pos.z;
		const float mx=size/2.0f,my=size/2.0f;

		const float InvRation=1.0f/((0.4f)*(256.0f/float(size)));

		D3DMATRIX m;
		if (parent->IsType(IDChicken))
			D3DUtil_SetRotateYMatrix(m,-parent->ang.y);
		else D3DUtil_SetRotateYMatrix(m,parent->ang.y);
	
		D3DVECTOR v;
		const HRGN rgn=CreateEllipticRgn(1,1,size-1,size-1);
		SelectClipRgn(dc,rgn);

		{	// Begrenzung rendern
			D3DVECTOR b[4]={
				D3DVECTOR(world->minx(),0,world->minz())-parent->pos,
				D3DVECTOR(world->maxx(),0,world->minz())-parent->pos,
				D3DVECTOR(world->maxx(),0,world->maxz())-parent->pos,
				D3DVECTOR(world->minx(),0,world->maxz())-parent->pos};

			POINT p[4];
			for (int i=0;i<4;i++)
			{
				D3DMath_VectorMatrixMultiply(b[i],b[i],m);

				b[i].x=b[i].x*InvRation+mx;
				b[i].z=-b[i].z*InvRation+my;
				p[i].x=(int)b[i].x;
				p[i].y=(int)b[i].z;
			}

			SelectObject(dc,GetStockObject(WHITE_PEN));
			const HBRUSH green=CreateSolidBrush(RGB(0,128,0));
			oldbrush=(HBRUSH)SelectObject(dc,green);

			Polygon(dc,&p[0],4);
			SelectObject(dc,oldbrush);
			DeleteObject(green);
		}

//	Grid rendern

		{
			D3DVECTOR v2;
			const HPEN pen1=CreatePen(PS_SOLID,1,RGB(0,192,0)),pen2=CreatePen(PS_SOLID,1,RGB(128,128,0)),pen3=CreatePen(PS_SOLID,1,RGB(0,128,128)),oldpen=(HPEN)SelectObject(dc,pen1);

#define Grid 20

			int ox=0,oy=0,oz=0,x,z;
			int num=int((size)/(Grid*InvRation))/2;

			if (parent->pos.x>0)
				while (ox<parent->pos.x)ox+=Grid;

			if (parent->pos.x<0)
				while (ox>parent->pos.x)ox-=Grid;

			if (parent->pos.z>0)
				while (oz<parent->pos.z)oz+=Grid;

			if (parent->pos.z<0)
				while (oz>parent->pos.z)oz-=Grid;


			if (TRUE)
			{	// x/z
				SelectObject(dc,pen1);
				for (x=-num-1;x<=num+1;x++)	// x-Achse
				{
					v.x=float(x*(Grid*InvRation))-(parent->pos.x*InvRation)+(ox*InvRation);
					v.y=0;
					v.z=size*0.5f;

					v2.x=float(x*(Grid*InvRation))-(parent->pos.x*InvRation)+(ox*InvRation);
					v2.y=0;
					v2.z=-int(size)*0.5f;
					D3DMath_VectorMatrixMultiply(v,v,m);
					D3DMath_VectorMatrixMultiply(v2,v2,m);
					MoveToEx(dc,int(mx+(v.x)),int(my+(-v.z)),NULL);
					LineTo(dc,int(mx+(v2.x)),int(my+(-v2.z)));
				}
	
				for (z=-num-1;z<=num+1;z++)	// z-Achse
				{
					v.x=size*0.5f;
					v.y=0;
					v.z=float(z*(Grid*InvRation))-(parent->pos.z*InvRation)+(oz*InvRation);
		
					v2.x=-int(size)*0.5f;
					v2.y=0;
					v2.z=float(z*(Grid*InvRation))-(parent->pos.z*InvRation)+(oz*InvRation);
					D3DMath_VectorMatrixMultiply(v,v,m);
					D3DMath_VectorMatrixMultiply(v2,v2,m);
					MoveToEx(dc,int(mx+(v.x)),int(my+(-v.z)),NULL);
					LineTo(dc,int(mx+(v2.x)),int(my+(-v2.z)));
				}
			}
	
	
	
			SelectObject(dc,oldpen);
			::DeleteObject(pen1);
			::DeleteObject(pen2);
			::DeleteObject(pen3);
		}

//	---


		COLORREF c;
		float s,x,y;
		D3DVECTOR p;
		HBRUSH brush;

		// Objekte rendern

		CObject* akt=game->chain->GetFirst();
		while (akt)
		{
			c=RGB(255,0,0);
			s=3;
			switch(GetType(akt->id))
			{
			case IDChicken:
				if (((CChicken*)akt)->dead!=0.0f)goto weiter;
				p=((CChicken*)akt)->pos;
				c=RGB(255,255,255);
				s=3;
				break;
			case IDBauer:
				if (((CBauer*)akt)->dead!=0.0f)goto weiter;
				if (((CBauer*)akt)->HasObject(IDDrescher))goto weiter;
				p=((CBauer*)akt)->pos;
				c=RGB(192,128,0);
				s=5;
				break;
			case IDStall:
				p=((CStall*)akt)->pos;
				c=RGB(214,160,32);
				s=7;
				break;
			case IDTree:
				p=((CTree*)akt)->pos;
				c=RGB(0,230,0);
				s=4;
				break;
			case IDGartenkralle:
				p=((CGartenkralle*)akt)->pos;
				c=RGB(255,214,0);
				s=2;
				break;
			case IDDrescher:
				p=((CDrescher*)akt)->pos;
				c=RGB(255,0,0);
				s=7;
				break;
			case IDGolfer:
				p=((CGolfer*)akt)->pos;
				c=RGB(192,192,192);
				s=2;
				break;
			case IDPlasmaCannon:
				p=((CPlasmaCannon*)akt)->pos;
				c=RGB(255,255,0);
				s=3;
				break;



			default:goto weiter;
			}
	
			p=p-parent->pos;
			D3DMath_VectorMatrixMultiply(p,p,m);
			x=p.x*InvRation;
			y=-p.z*InvRation;

			if ((x)*(x)+(y)*(y)<((size*0.5f)*(size*0.5f))-(4.0f*4.0f*4.0f*4.0f))
			{
				x+=mx;
				y+=my;

				SelectObject(dc,brush=CreateSolidBrush(c));

				SelectObject(dc,GetStockObject(NULL_PEN));
				Ellipse(dc,int(x-s),int(y-s),int(x+s),int(y+s));
	
				SelectObject(dc,oldbrush);
				::DeleteObject(brush);
			}	


weiter:
			akt=akt->next;
		}

		SelectObject(dc,GetStockObject(WHITE_PEN));
		Line(dc,size/2,(size*10)/18,size/2,(size*8)/18);
		Line(dc,(size*10)/18,size/2,(size*8)/18,size/2);

		SelectClipRgn(dc,NULL);
		::DeleteObject(rgn);

		lpSurface->ReleaseDC(dc);
	}

	MakeTransparent(lpSurface,FALSE);
}
예제 #11
0
// Handles a menu item selection
LRESULT CNoteDlg::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	switch (LOWORD(wParam))
	{
	case IDR_MENU_NEWNOTE:
		OnNewNote();
		break;
	case IDR_MENU_SAVE:
		OnSave(true);
		break;
	case IDR_MENU_SAVETOFILE:
		OnSaveToFile();
		break;
	case IDR_MENU_IMPORTFROMFILE:
		OnImportFromFile();
		break;
	case IDR_MENU_DELETE:
		OnDelete();
		break;
	case IDR_MENU_SETFONT:
		OnSetFont();
		break;
	case ID_EDIT_SETTITLE:
		OnSetTitle();
		break;
	case IDR_MENU_CLOSE:
		CloseDialog(0);
		break;
	case IDR_MENU_BLUE:
		OnChangeBkgndColor(BLUE);
		break;
	case IDR_MENU_GREEN:
		OnChangeBkgndColor(GREEN);
		break;
	case IDR_MENU_PINK:
		OnChangeBkgndColor(PINK);
		break;
	case IDR_MENU_YELLOW:
		OnChangeBkgndColor(YELLOW);
		break;
	case IDR_MENU_WHITE:
		OnChangeBkgndColor(WHITE);
		break;
	case IDR_MENU_0:
		MakeTransparent(255);
		break;
	case IDR_MENU_10:
		MakeTransparent(225);
		break;
	case IDR_MENU_20:
		MakeTransparent(200);
		break;
	case IDR_MENU_30:
		MakeTransparent(175);
		break;
	case IDR_MENU_40:
		MakeTransparent(150);
		break;
	case IDR_MENU_50:
		MakeTransparent(125);
		break;
	case IDR_MENU_60:
		MakeTransparent(100);
		break;
	case IDR_MENU_70:
		MakeTransparent(75);
		break;
	case IDR_MENU_80:
		MakeTransparent(50);
		break;
	case IDR_MENU_90:
		MakeTransparent(25);
		break;
	case ID_FILE_PAGE_SETUP:
		OnPageSetup();
		break;
	case ID_FILE_PRINT:
		OnPrint();
		break;
	default:
		break;
	}

	return 0;
}
예제 #12
0
LRESULT CNoteDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	BOOL bRet;
	HWND hWnd;
	DWORD dwStyle;

	// Create the brush 
	m_brBkgnd.CreateSolidBrush(GetNoteColor());
	
	// Set the sizing border width/height
	m_nSizeFrame = GetSystemMetrics(SM_CXSIZEFRAME);
	
	// Center the dialog on the screen
	CenterWindow();
	
	// Retrieve the coordinates of a dialog's client area
	CRect rectDlg; 
	GetClientRect(&rectDlg);
	
	// Subclass the static control displaying current date and time and 
	// attach it to the CStaticDateTime object
	bRet = m_wndStaticDateTime.SubclassWindow(GetDlgItem(IDC_STATIC_TIME));
	ATLASSERT(bRet);
	// Set the size and position of the control
	m_wndStaticDateTime.MoveWindow(5, rectDlg.Height() - 14, rectDlg.Width() / 2, 14);
	// Set the current date and time
	m_wndStaticDateTime.SetCurrentDateTime(GetTimestamp());
	// Set the background color
	m_wndStaticDateTime.SetBkgndColor(GetNoteColor());
	
	// Subclass the bar static control and attach it to the CGradientStatic object
	bRet = m_wndStaticBar.SubclassWindow(GetDlgItem(IDC_STATIC_BAR));
	ATLASSERT(bRet);
	// Set the size and position of the control
	m_wndStaticBar.MoveWindow(42, 2, rectDlg.Width() - 66, 16);
	// Change the font
	m_wndStaticBar.ChangeFont();
	// Set the note's title
	m_wndStaticBar.SetWindowText(GetNoteTitle().c_str());

	// Subclass the edit control and attach it to the CNoteEdit object
	bRet = m_wndEdit.SubclassWindow(GetDlgItem(IDC_EDIT));
	ATLASSERT(bRet);
	// Set the ENM_LINK mask for a rich edit control to receive 
	// EN_LINK notifications
	m_wndEdit.SetEventMask(ENM_LINK);		
	// Enable automatic detection of URLs by a rich edit control
	m_wndEdit.SetAutoURLDetect();
	// Set the edit control's background color
	m_wndEdit.SetBackgroundColor(GetNoteColor());
	// Sets the initial character formatting attributes
	m_wndEdit.SetDefaultFont();
	// Set the edit control's text
	if (GetNoteRTF().length() != 0)
		m_wndEdit.SetRTF(GetNoteRTF().c_str());
	else
		m_wndEdit.SetWindowText(GetNoteText().c_str());
	// Set the size and position of the control
	m_wndEdit.MoveWindow(5, 20, rectDlg.Width() - 10, rectDlg.Height() - 40);
	
	// Create the static control holding the 'Note' bitmap
	CRect rectStatic(1, 2, 17, 18);
	hWnd = m_wndStaticNote.Create(m_hWnd, rectStatic, NULL,
		WS_CHILD|WS_VISIBLE|SS_BITMAP|SS_CENTERIMAGE|SS_NOTIFY);
	ATLASSERT(hWnd);
	
	// Create the button with the 'Close' bitmap
	rectStatic.SetRect(rectDlg.right - 21, 1, rectDlg.right - 1, 20);
	hWnd = m_wndBtnClose.Create(m_hWnd, rectStatic, NULL, 0, 0);
	ATLASSERT(hWnd);

	m_hFontClose = ::CreateFont(15, 0, 0, 0, FW_SEMIBOLD, 0, 0, 0, 1, 0, 0, 4, 
					FF_DONTCARE, _T("Marlett"));
	ATLASSERT(m_hFontClose);
	m_wndBtnClose.SetFont(m_hFontClose);
	m_wndBtnClose.SetTextColor(BLACK);
	m_wndBtnClose.SetColor(GetNoteColor());
	m_wndBtnClose.SetWindowText((TCHAR*)"\x72");		// 'x' sign
	m_wndBtnClose.SetToolTipText(_T("Close the note"));

	// Create the button with the 'Pin' bitmap
	rectStatic.SetRect(19, 1, 39, 21);
	hWnd = m_wndBtnPin.Create(m_hWnd, rectStatic, NULL, 0, 0);
	ATLASSERT(hWnd);
	// Change the button extended style
	dwStyle = BMPBTN_AUTOSIZE | BMPBTN_AUTO3D_SINGLE | BMPBTN_HOVER | BTNEX_CHECKBUTTON;
	m_wndBtnPin.SetBitmapButtonExtendedStyle(dwStyle);

	// Load the 'Pinopen' bitmap from the application's resources
	HBITMAP hBmpTemp2 = ::LoadBitmap(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDB_PINOPEN));
	ATLASSERT(hBmpTemp2);
	// Load the 'Pinclose' bitmap from the application's resources
	HBITMAP hBmpTemp3 = ::LoadBitmap(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDB_PINCLOSE));
	ATLASSERT(hBmpTemp3);
	// Load the 'Pinhoover' bitmap from the application's resources
	HBITMAP hBmpTemp4 = ::LoadBitmap(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDB_PINHOOVER));
	ATLASSERT(hBmpTemp4);
	
	// Replace the white background color with the saved or default (yellow) note's color
	m_hBmpPinopen = ReplaceColor(hBmpTemp2, WHITE, GetNoteColor());
	ATLASSERT(m_hBmpPinopen);
	// Replace the white background color with the saved or default (yellow) note's color
	m_hBmpPinclose = ReplaceColor(hBmpTemp3, WHITE, GetNoteColor());
	ATLASSERT(m_hBmpPinclose);
	// Replace the white background color with the saved or default (yellow) note's color
	m_hBmpPinhoover = ReplaceColor(hBmpTemp4, WHITE, GetNoteColor());
	ATLASSERT(m_hBmpPinhoover);
	
	// Create the pin button's imagelist
	m_wndBtnPin.m_ImageList.Create(20, 20, ILC_COLORDDB | ILC_MASK, 3, 1);
	// Add images to the image list.
	m_wndBtnPin.m_ImageList.Add(m_hBmpPinopen);
	m_wndBtnPin.m_ImageList.Add(m_hBmpPinclose);
	m_wndBtnPin.m_ImageList.Add(m_hBmpPinhoover);
	// Set normal, pressed and hover images
	m_wndBtnPin.SetImages(0, 1, 2);
	// ToolTip text
	m_wndBtnPin.SetToolTipText(_T("Keep the Note Visible"));

	// Load the 'Note' bitmap from the application's resources
	HBITMAP hBmpTemp1 = ::LoadBitmap(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDB_NOTE));
	ATLASSERT(hBmpTemp1);

	// Replace the white background color with the saved or default (yellow) note's color
	m_hBmpNote = ReplaceColor(hBmpTemp1, WHITE, GetNoteColor());
	ATLASSERT(m_hBmpNote);

	// Delete the original bitmaps
	DeleteObject(hBmpTemp1);
	DeleteObject(hBmpTemp2);
	DeleteObject(hBmpTemp3);
	DeleteObject(hBmpTemp4);

	// Draw the 'Note' bitmap in the static control
	m_wndStaticNote.SetBitmap(m_hBmpNote);
	
	// To support a transparency try to get a SetLayeredWindowAttributes function address
	// and set WS_EX_LAYERED style
	HMODULE hUser32 = GetModuleHandle(_T("User32.dll"));
	if (hUser32)
	{
		m_pfSetLayeredWindowAttributes = 
			(PFUNCSETLAYEREDWINDOWATTR)::GetProcAddress(hUser32, "SetLayeredWindowAttributes");
		if (m_pfSetLayeredWindowAttributes)
		{
			::SetWindowLong(m_hWnd, GWL_EXSTYLE, GetWindowLong(GWL_EXSTYLE)^WS_EX_LAYERED);
			// After the SetWindowLong call, the layered window will not become visible 
			// until the SetLayeredWindowAttributes function has been called for this window
			m_pfSetLayeredWindowAttributes(m_hWnd, 0, (BYTE)255, LWA_ALPHA);

			// Set the transparency of the note dialog
			MakeTransparent(GetNoteAlpha());
		}
	}

	// Register object for message filtering and idle updates
	CMessageLoop* pLoop = _Module.GetMessageLoop();
	ATLASSERT(pLoop != NULL);
	pLoop->AddMessageFilter(this);
	pLoop->AddIdleHandler(this);

	return TRUE;
}