コード例 #1
0
// Draw fog on the small bitmap
void MapControl::DrawFog(unsigned short XWin, unsigned short YWin)
{
	Video *video = core->GetVideoDriver();

	Region old_clip;
	video->GetClipRect(old_clip);

	Region r( XWin + XPos, YWin + YPos, Width, Height );
	video->SetClipRect(&r);

	// FIXME: this is ugly, the knowledge of Map and ExploredMask
	//   sizes should be in Map.cpp
	int w = MyMap->GetWidth() / 2;
	int h = MyMap->GetHeight() / 2;

	for (int y = 0; y < h; y++) {
		for (int x = 0; x < w; x++) {
			Point p( (short) (MAP_MULT * x), (short) (MAP_MULT * y) );
			bool visible = MyMap->IsVisible( p, true );
			if (! visible) {
				Region rgn = Region ( MAP_TO_SCREENX(MAP_DIV * x), MAP_TO_SCREENY(MAP_DIV * y), MAP_DIV, MAP_DIV );
				video->DrawRect( rgn, colors[black] );
			}
		}
	}

	video->SetClipRect(&old_clip);
}
コード例 #2
0
/** This function Draws the Window on the Output Screen */
void Window::DrawWindow()
{
	Video* video = core->GetVideoDriver();
	Region clip( XPos, YPos, Width, Height );
	//Frame && Changed
	if ( (Flags & (WF_FRAME|WF_CHANGED) )== (WF_FRAME|WF_CHANGED) ) {
		Region screen( 0, 0, core->Width, core->Height );
		video->SetClipRect( NULL );
		//removed this?
		Color black = { 0, 0, 0, 255 };
		video->DrawRect( screen, black );
		if (core->WindowFrames[0])
			video->BlitSprite( core->WindowFrames[0], 0, 0, true );
		if (core->WindowFrames[1])
			video->BlitSprite( core->WindowFrames[1], core->Width - core->WindowFrames[1]->Width, 0, true );
		if (core->WindowFrames[2])
			video->BlitSprite( core->WindowFrames[2], (core->Width - core->WindowFrames[2]->Width) / 2, 0, true );
		if (core->WindowFrames[3])
			video->BlitSprite( core->WindowFrames[3], (core->Width - core->WindowFrames[3]->Width) / 2, core->Height - core->WindowFrames[3]->Height, true );
	} else if (clip_regions.size()) {
		// clip drawing (we only do Background right now) for InvalidateForControl
		for (unsigned int i = 0; i < clip_regions.size(); i++) {
			Region to_clip = clip_regions[i];
			to_clip.x += XPos;
			to_clip.y += YPos;
			video->SetClipRect(&to_clip);
			if (BackGround) {
				video->BlitSprite( BackGround, XPos, YPos, true );
			}
		}
	}
	clip_regions.clear();
	video->SetClipRect( &clip );
	//Float || Changed
	if (BackGround && (Flags & (WF_FLOAT|WF_CHANGED) ) ) {
		video->BlitSprite( BackGround, XPos, YPos, true );
	}
	std::vector< Control*>::iterator m;
	for (m = Controls.begin(); m != Controls.end(); ++m) {
		( *m )->Draw( XPos, YPos );
	}
	if ( (Flags&WF_CHANGED) && (Visible == WINDOW_GRAYED) ) {
		Color black = { 0, 0, 0, 128 };
		video->DrawRect(clip, black);
	}
	video->SetClipRect( NULL );
	Flags &= ~WF_CHANGED;
}
コード例 #3
0
void TextArea::Draw(unsigned short x, unsigned short y)
{
	/** Don't come back recursively */
	if (InternalFlags&TA_BITEMYTAIL) {
		return;
	}
	int tx=x+XPos;
	int ty=y+YPos;
	Region clip( tx, ty, Width, Height );
	Video *video = core->GetVideoDriver();

	if (Flags&IE_GUI_TEXTAREA_SPEAKER) {
		if (AnimPicture) {
			video->BlitSprite(AnimPicture, tx,ty, true, &clip);
			clip.x+=AnimPicture->Width;
			clip.w-=AnimPicture->Width;
		}
	}

	//this might look better in GlobalTimer
	//or you might want to change the animated button to work like this
	if (Flags &IE_GUI_TEXTAREA_SMOOTHSCROLL)
	{
		unsigned long thisTime;

		GetTime( thisTime);
		if (thisTime>starttime) {
			starttime = thisTime+ticks;
			smooth--;
			while (smooth<=0) {
				smooth+=ftext->maxHeight;
				if (startrow<rows) {
					startrow++;
				}
			}

			/** Forcing redraw of whole screen before drawing text*/
			Owner->Invalidate();
			InternalFlags |= TA_BITEMYTAIL;
			Owner->DrawWindow();
			InternalFlags &= ~TA_BITEMYTAIL;
		}
	}

	if (!Changed && !(Owner->Flags&WF_FLOAT) ) {
		return;
	}
	Changed = false;

	if (XPos == 65535) {
		return;
	}
	size_t linesize = lines.size();
	if (linesize == 0) {
		return;
	}

	//smooth vertical scrolling up
	if (Flags & IE_GUI_TEXTAREA_SMOOTHSCROLL) {
		clip.y+=smooth;
		clip.h-=smooth;
	}

	//if textarea is 'selectable' it actually means, it is a listbox
	//in this case the selected value equals the line number
	//if it is 'not selectable' it can still have selectable lines
	//but then it is like the dialog window in the main game screen:
	//the selected value is encoded into the line
	if (!(Flags & IE_GUI_TEXTAREA_SELECTABLE) ) {
		char* Buffer = (char *) malloc( 1 );
		Buffer[0] = 0;
		int len = 0;
		int lastlen = 0;
		for (size_t i = 0; i < linesize; i++) {
			if (strnicmp( "[s=", lines[i], 3 ) == 0) {
				int tlen;
				unsigned long idx, acolor, bcolor;
				char* rest;
				idx = strtoul( lines[i] + 3, &rest, 0 );
				if (*rest != ',')
					goto notmatched;
				acolor = strtoul( rest + 1, &rest, 16 );
				if (*rest != ',')
					goto notmatched;
				bcolor = strtoul( rest + 1, &rest, 16 );
				if (*rest != ']')
					goto notmatched;
				tlen = (int)(strstr( rest + 1, "[/s]" ) - rest - 1);
				if (tlen < 0)
					goto notmatched;
				len += tlen + 23;
				Buffer = (char *) realloc( Buffer, len + 2 );
				if (seltext == (int) i) {
					sprintf( Buffer + lastlen, "[color=%6.6lX]%.*s[/color]",
						acolor, tlen, rest + 1 );
				} else {
					sprintf( Buffer + lastlen, "[color=%6.6lX]%.*s[/color]",
						bcolor, tlen, rest + 1 );
				}
			} else {
				notmatched:
				len += ( int ) strlen( lines[i] ) + 1;
				Buffer = (char *) realloc( Buffer, len + 2 );
				memcpy( &Buffer[lastlen], lines[i], len - lastlen );
			}
			lastlen = len;
			if (i != linesize - 1) {
				Buffer[lastlen - 1] = '\n';
				Buffer[lastlen] = 0;
			}
		}
		video->SetClipRect( &clip );

		int pos;

		if (startrow==CurLine) {
			pos = CurPos;
		} else {
			pos = -1;
		}
		ftext->PrintFromLine( startrow, clip,
			( unsigned char * ) Buffer, palette,
			IE_FONT_ALIGN_LEFT, finit, Cursor, pos );
		free( Buffer );
		video->SetClipRect( NULL );
		//streaming text
		if (linesize>50) {
			//the buffer is filled enough
			return;
		}
		if (core->GetAudioDrv()->IsSpeaking() ) {
			//the narrator is still talking
			return;
		}
		if (RunEventHandler( TextAreaOutOfText )) {
			return;
		}
		if (linesize==lines.size()) {
			ResetEventHandler( TextAreaOutOfText );
			return;
		}
		AppendText("\n",-1);
		return;
	}
	// normal scrolling textarea
	int rc = 0;
	int sr = startrow;
	unsigned int i;
	int yl;
	for (i = 0; i < linesize; i++) {
		if (rc + lrows[i] <= sr) {
			rc += lrows[i];
			continue;
		}
		sr -= rc;
		Palette* pal = NULL;
		if (seltext == (int) i)
			pal = selected;
		else if (Value == i)
			pal = lineselpal;
		else
			pal = palette;
		ftext->PrintFromLine( sr, clip,
			( unsigned char * ) lines[i], pal,
			IE_FONT_ALIGN_LEFT, finit, NULL );
		yl = ftext->size[1].h*(lrows[i]-sr);
		clip.y+=yl;
		clip.h-=yl;
		break;
	}
	for (i++; i < linesize; i++) {
		Palette* pal = NULL;
		if (seltext == (int) i)
			pal = selected;
		else if (Value == i)
			pal = lineselpal;
		else
			pal = palette;
		ftext->Print( clip, ( unsigned char * ) lines[i], pal,
			IE_FONT_ALIGN_LEFT, true );
		yl = ftext->size[1].h*lrows[i];
		clip.y+=yl;
		clip.h-=yl;

	}
}
コード例 #4
0
ファイル: WorldMapControl.cpp プロジェクト: jadeatucker/gemrb
/** Draws the Control on the Output Display */
void WorldMapControl::Draw(unsigned short XWin, unsigned short YWin)
{
	WorldMap* worldmap = core->GetWorldMap();
	if (!Width || !Height) {
		return;
	}
	if(!Changed)
		return;
	Changed = false;
	Video* video = core->GetVideoDriver();
	Region r( XWin+XPos, YWin+YPos, Width, Height );
	Region clipbackup;
	video->GetClipRect(clipbackup);
	video->SetClipRect(&r);
	video->BlitSprite( worldmap->GetMapMOS(), MAP_TO_SCREENX(0), MAP_TO_SCREENY(0), true, &r );

	unsigned int i;
	unsigned int ec = worldmap->GetEntryCount();
	for(i=0;i<ec;i++) {
		WMPAreaEntry *m = worldmap->GetEntry(i);
		if (! (m->GetAreaStatus() & WMP_ENTRY_VISIBLE)) continue;

		int xOffs = MAP_TO_SCREENX(m->X);
		int yOffs = MAP_TO_SCREENY(m->Y);
		Sprite2D* icon = m->GetMapIcon(worldmap->bam);
		if( icon ) {
			if (m == Area) {
				Palette *pal = icon->GetPalette();
				icon->SetPalette(pal_selected);
				video->BlitSprite( icon, xOffs, yOffs, true, &r );
				icon->SetPalette(pal);
				pal->Release();
			} else {
				video->BlitSprite( icon, xOffs, yOffs, true, &r );
			}
			video->FreeSprite( icon );
		}

		if (AnimPicture && !strnicmp(m->AreaResRef, currentArea, 8) ) {
			video->BlitSprite( AnimPicture, xOffs, yOffs, true, &r );
		}
	}

	// Draw WMP entry labels
	if (ftext==NULL) {
		video->SetClipRect(&clipbackup);
		return;
	}
	for(i=0;i<ec;i++) {
		WMPAreaEntry *m = worldmap->GetEntry(i);
		if (! (m->GetAreaStatus() & WMP_ENTRY_VISIBLE)) continue;
		Sprite2D *icon=m->GetMapIcon(worldmap->bam);
		int h=0,w=0,xpos=0,ypos=0;
		if (icon) {
			h=icon->Height;
			w=icon->Width;
			xpos=icon->XPos;
			ypos=icon->YPos;
			video->FreeSprite( icon );
		}

		Region r2 = Region( MAP_TO_SCREENX(m->X-xpos), MAP_TO_SCREENY(m->Y-ypos), w, h );
		if (!m->GetCaption())
			continue;

		int tw = ftext->CalcStringWidth( (unsigned char*)m->GetCaption() ) + 5;
		int th = ftext->maxHeight;
		
		Palette* text_pal = pal_normal;
		
		if (Area == m) {
			text_pal = pal_selected;
		} else {
			if (! (m->GetAreaStatus() & WMP_ENTRY_VISITED)) {
				text_pal = pal_notvisited;
			}
		}

		ftext->Print( Region( r2.x + (r2.w - tw)/2, r2.y + r2.h, tw, th ),
				( const unsigned char * ) m->GetCaption(), text_pal, 0, true );
	}
	video->SetClipRect(&clipbackup);
}