Esempio n. 1
0
void G_initializeGame()
{
	window.initialize();

	scene_rect = ScreenRect(0,0,window.videoModes[0].width,window.videoModes[0].height);
	client_rect = ScreenRect(0,0,window.currentWidth(),window.currentHeight());
	lmenuRect = ScreenRect(0,0,lmenuw,client_rect.h);
	rmenuRect = ScreenRect(client_rect.w - rmenuw,0,rmenuw,client_rect.h);
	aspect_ratio = client_rect.w / client_rect.h;

	camera.initialize(-(256 + 16) * (scene_rect.w/client_rect.w), -16, scene_rect.w , scene_rect.h );

	atlas_tile.initialize(&texture_sprite, 16, 16, 16, 16);
	atlas_collision.initialize(&texture_bga, 4, 4, 64, 64);
	atlas_font.initialize(&texture_bg, 16, 16, 8, 8);

	tilethumbsize = atlas_tile.imageFrameSize*2.0f;

	initializeTileAnimations();

	world_constraints = WorldRect(-10000, -10000,81000, 81000);

	smallfont.initialize(16, 16, 8, 8, 1.0f, &camera, &client_rect, &atlas_font);
	bigfont.initialize(16, 16, 8, 8, 2.0f, &camera, &client_rect, &atlas_font);
	InitSpacings();
}
Esempio n. 2
0
bool MenuBar::EventMouse(cevent_mouse* pEvent)
{
	int n;
	if (pEvent->Type() == EV_MOUSE_PRESS)
	{
		n = GetPointItem(pEvent->Point());
		if (n>=0) {
			SetSelect(n);
			OpenSub();
			return true;
		}
		if (sub.ptr())
		{
			crect rect = ScreenRect();
			crect sr = sub->ScreenRect();
			pEvent->Point().x += rect.left - sr.left;
			pEvent->Point().y += rect.top - sr.top;
			if (sub->EventMouse(pEvent)) return true;
			SetSelect(-1);
			if (Parent()) Parent()->Command(CMD_MENU_INFO, SCMD_MENU_CANCEL, this, 0);
		}
		return true;
	} else  if (pEvent->Type() == EV_MOUSE_MOVE) {
		n = GetPointItem(pEvent->Point());
		if (n>=0) {
			if (lastMouseSelect != n) {
				lastMouseSelect = n;
				SetSelect(n);
			}
			return true;
		}
		if (!sub.ptr() && !InFocus()) {
			lastMouseSelect = -1;
			SetSelect(-1);
			return true;
		}
		
		if (sub.ptr())
		{
			crect rect = ScreenRect();
			crect sr = sub->ScreenRect();
			pEvent->Point().x += rect.left - sr.left;
			pEvent->Point().y += rect.top - sr.top;
			return sub->EventMouse(pEvent);
		}
		
		return true;
	}
	return false;
}
Esempio n. 3
0
VideoEngine::VideoEngine():
    _fps_display(false),
    _fps_sum(0),
    _current_sample(0),
    _number_samples(0),
    _FPS_textimage(NULL),
    _gl_error_code(GL_NO_ERROR),
    _gl_blend_is_active(false),
    _gl_texture_2d_is_active(false),
    _gl_alpha_test_is_active(false),
    _gl_stencil_test_is_active(false),
    _gl_scissor_test_is_active(false),
    _gl_vertex_array_is_activated(false),
    _gl_color_array_is_activated(false),
    _gl_texture_coord_array_is_activated(false),
    _viewport_x_offset(0),
    _viewport_y_offset(0),
    _viewport_width(0),
    _viewport_height(0),
    _screen_width(0),
    _screen_height(0),
    _fullscreen(false),
    _x_cursor(0),
    _y_cursor(0),
    _debug_info(false),
    _x_shake(0),
    _y_shake(0),
    _brightness_value(1.0f),
    _temp_fullscreen(false),
    _temp_width(0),
    _temp_height(0),
    _smooth_pixel_art(true),
    _initialized(false)
{
    _current_context.blend = 0;
    _current_context.x_align = -1;
    _current_context.y_align = -1;
    _current_context.x_flip = 0;
    _current_context.y_flip = 0;
    _current_context.coordinate_system = CoordSys(0.0f, VIDEO_STANDARD_RES_WIDTH,
                                         0.0f, VIDEO_STANDARD_RES_HEIGHT);
    _current_context.viewport = ScreenRect(0, 0, VIDEO_STANDARD_RES_WIDTH, VIDEO_STANDARD_RES_HEIGHT);
    _current_context.scissor_rectangle = ScreenRect(0, 0, VIDEO_STANDARD_RES_WIDTH,
                                         VIDEO_STANDARD_RES_HEIGHT);
    _current_context.scissoring_enabled = false;

    for(uint32 sample = 0; sample < FPS_SAMPLES; sample++)
        _fps_samples[sample] = 0;
}
Esempio n. 4
0
void R_resize(int w, int h)
{
	client_rect.w = (float) w;
	client_rect.h = (float) h;
	aspect_ratio = client_rect.w / client_rect.h;
	camera.aspect = aspect_ratio;
	camera.size.y = camera.size.x / aspect_ratio;

	lmenuRect = ScreenRect(0,0,lmenuw,client_rect.h);
	rmenuRect = ScreenRect(client_rect.w - rmenuw,0,rmenuw,client_rect.h);

	debug_rendertarget.Resize(client_rect.w, client_rect.h);
	rt_temp0.Resize(client_rect.w, client_rect.h);
	rt_temp1.Resize(client_rect.w, client_rect.h);
}
Esempio n. 5
0
void ui_core::PushScissor(const Frect& r_tgt, bool overlapped)
{
//.	return;
	Frect r_top			= ScreenRect();
	Frect result		= r_tgt;
	if (!m_Scissors.empty()&&!overlapped){
		r_top			= m_Scissors.top();
	}
	if (!result.intersection(r_top,r_tgt))
			result.set	(0.0f,0.0f,0.0f,0.0f);

	if (!(result.x1>=0&&result.y1>=0&&result.x2<=UI_BASE_WIDTH&&result.y2<=UI_BASE_HEIGHT) )
	{
		Msg("! r_tgt [%.3f][%.3f][%.3f][%.3f]", r_tgt.x1, r_tgt.y1, r_tgt.x2, r_tgt.y2);
		Msg("! result [%.3f][%.3f][%.3f][%.3f]", result.x1, result.y1, result.x2, result.y2);
		VERIFY(result.x1>=0&&result.y1>=0&&result.x2<=UI_BASE_WIDTH&&result.y2<=UI_BASE_HEIGHT);
	}
	m_Scissors.push		(result);

	result.lt.x 		= ClientToScreenScaledX(result.lt.x);
	result.lt.y 		= ClientToScreenScaledY(result.lt.y);
	result.rb.x 		= ClientToScreenScaledX(result.rb.x);
	result.rb.y 		= ClientToScreenScaledY(result.rb.y);

	Irect				r;
	r.x1 				= iFloor(result.x1);
	r.x2 				= iFloor(result.x2+0.5f);
	r.y1 				= iFloor(result.y1);
	r.y2 				= iFloor(result.y2+0.5f);
	RCache.set_Scissor	(&r);
}
Esempio n. 6
0
void R_draw(HDC hDC)
{
	glGetUniformLocation(NULL,NULL);
	rt_back.Clear(0.2941f, 0.2941f, 0.2941f, 1.0f);
	rt_scene.Clear(0.3921f, 0.3921f, 0.3921f, 1.0f);
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_BLEND);

	glBindFramebuffer(GL_FRAMEBUFFER, rt_scene.fbo);
	glViewport(0, 0, rt_scene.width, rt_scene.height);
	camera.setOrthoMatrix();

	if(bdrawbglayer01)
		tilemap_back.draw(&camera);
	if(bdrawbglayer02)
		tilemap_front.draw(&camera);
	if(bdrawbglayer03 && tilemap_back.has_c_Map)
		DrawCollisionMap();

	R_drawWorldDebug();

	glViewport(0, 0, client_rect.w, client_rect.h);
	R_setScreenOrtho();
	s_srcRect = ScreenRect(lmenuw/client_rect.w,0,1.0 - ((lmenuw + rmenuw)/client_rect.w),1);
	s_dstRect = ScreenRect(lmenuw, 0, client_rect.w - (lmenuw + rmenuw), client_rect.h);
	DrawQuadDS(rt_back, rt_scene,&s_dstRect,&s_srcRect, NULL);

	glViewport(0, 0, client_rect.w, client_rect.h);
	glBindFramebuffer(GL_FRAMEBUFFER, debug_rendertarget.fbo);
	glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	R_setScreenOrtho();

	DrawLeftPanel();
	DrawRightPanel();	
	DrawClientBorder();

	R_setPostProcessingOrtho();
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	DrawFullscreenQuad(rt_back, debug_rendertarget, NULL);

	glFlush();
	bdoublebuffer ? SwapBuffers( hDC ) : glDrawBuffer(GL_FRONT);
}
Esempio n. 7
0
void VideoEngine::Clear(const Color &c)
{
    _current_context.viewport = ScreenRect(0, 0, _screen_width, _screen_height);
    glViewport(0, 0, _screen_width, _screen_height);
    glClearColor(c[0], c[1], c[2], c[3]);
    glClear(GL_COLOR_BUFFER_BIT);

    TextureManager->_debug_num_tex_switches = 0;
}
Esempio n. 8
0
void Font::initialize( int charsWide, int charsHigh, int charWidth, int charHeight,
				 float Scale, Camera* pCamera, ScreenRect* pScreen, TileAtlas* ptexatlas)
{
	atlas = ptexatlas;
	pcamera = pCamera;
	pscreen = pScreen;
	scaleValue = Scale;
	charsXYWH = ScreenRect(charsWide, charsHigh, charWidth, charHeight);
}
bool PapercraftBulletBehaviorDefault::IsBulletOffScreen(const Bullet& TestBullet) const
{
	HGE& HGEEngine = CheezePizzaEngine::Instance().GetHGE();

	const float ScreenWidth = static_cast<float>(HGEEngine.System_GetState(HGE_SCREENWIDTH));
	const float ScreenHeight = static_cast<float>(HGEEngine.System_GetState(HGE_SCREENHEIGHT));
	hgeRect ScreenRect(0.0f, 0.0f, ScreenWidth, ScreenHeight);

	hgeRect BulletRect;
	BulletAnim->GetBoundingBox(TestBullet.Position.X, TestBullet.Position.Y, &BulletRect);

	// A bullet is fully-off-screen when its collision rect is outside the screen rect
	return !ScreenRect.Intersect(&BulletRect);
}
Esempio n. 10
0
bool CWinSystemWin32::ResizeInternal(bool forceRefresh)
{
  DWORD dwStyle = WS_CLIPCHILDREN;
  HWND windowAfter;
  RECT rc;

  if(m_bFullScreen)
  {
    dwStyle |= WS_POPUP;
    windowAfter = HWND_TOP;
    rc = ScreenRect(m_nScreen);
  }
  else
  {
    dwStyle |= WS_OVERLAPPEDWINDOW;
    windowAfter = g_advancedSettings.m_alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST;

    if(m_nTop <= 0 || m_nLeft <= 0)
      CenterWindow();

    rc.left = m_nLeft;
    rc.right = m_nLeft + m_nWidth;
    rc.top = m_nTop;
    rc.bottom = m_nTop + m_nHeight;
    AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, false );
  }

  WINDOWINFO wi;
  GetWindowInfo(m_hWnd, &wi);
  RECT wr = wi.rcWindow;

  if (forceRefresh || wr.bottom  - wr.top != rc.bottom - rc.top || wr.right - wr.left != rc.right - rc.left ||
                     (wi.dwStyle & WS_CAPTION) != (dwStyle & WS_CAPTION))
  {
    CLog::Log(LOGDEBUG, "%s - resizing due to size change (%d,%d,%d,%d%s)->(%d,%d,%d,%d%s)",__FUNCTION__,wr.left, wr.top, wr.right, wr.bottom, (wi.dwStyle & WS_CAPTION) ? "" : " fullscreen",
                                                                                                         rc.left, rc.top, rc.right, rc.bottom, (dwStyle & WS_CAPTION) ? "" : " fullscreen");
    SetWindowRgn(m_hWnd, 0, false);
    SetWindowLong(m_hWnd, GWL_STYLE, dwStyle);

    // The SWP_DRAWFRAME is here because, perversely, without it win7 draws a
    // white frame plus titlebar around the xbmc splash
    SetWindowPos(m_hWnd, windowAfter, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_SHOWWINDOW|SWP_DRAWFRAME);

    // TODO: Probably only need this if switching screens
    ValidateRect(NULL, NULL);
  }
  return true;
}
Esempio n. 11
0
void MenuBar::OpenSub()
{
	ReleaseCapture();
	sub = 0; 
	if (select>=0 && select<list.count())
	{
		crect rect = ScreenRect();
		crect itemRect = ItemRect(select);
		int x = rect.left+itemRect.left;
		int y = rect.top+itemRect.bottom;
		sub = new PopupMenu(0, this, list[select].data, x, y, this ); //Parent() ? Parent() : 0);
		sub->Show(Win::SHOW_INACTIVE);
		sub->Enable(true);
		SetCapture();
	}
}
Esempio n. 12
0
void CreditsWindow::Draw() {
	_window.Draw();

	// Don't draw any contents of the window until the window is fully shown
	if (_window.GetState() != VIDEO_MENU_STATE_SHOWN)
		return;

	// Set clip region for the text and draw the visible part of it
	VideoManager->SetDrawFlags(VIDEO_X_CENTER, VIDEO_Y_TOP, 0);
	VideoManager->Move(512.0f, 384.0f + _scroll_offset);
	VideoManager->EnableScissoring();
	// TODO: This returns a bad scissor rect due to a known bug in the GUI code
// 	VideoManager->SetScissorRect(_window.GetScissorRect());
	VideoManager->SetScissorRect(ScreenRect(0.0f, 80.0f, 1024.0f, 610.0f));

	// Initially fade in the text from completely transparent to fully opaque
	float color_alpha = _scroll_offset * 0.025f;
	if (color_alpha >= 1.0f)
		_credits_text.Draw();
	else
		_credits_text.Draw(Color(1.0f, 1.0f, 1.0f, color_alpha));
	VideoManager->DisableScissoring();
}
Esempio n. 13
0
bool CWinSystemWin32::BlankNonActiveMonitors(bool bBlank)
{
  if(m_hBlankWindows.size() == 0)
    return false;

  if(bBlank == false)
  {
    for (unsigned int i=0; i < m_hBlankWindows.size(); i++)
      ShowWindow(m_hBlankWindows[i], SW_HIDE);
    return true;
  }

  // Move a blank window in front of every screen, except the current XBMC screen.
  int screen = 0;
  if (screen == m_nScreen)
    screen++;

  for (unsigned int i=0; i < m_hBlankWindows.size(); i++)
  {
    RECT rBounds = ScreenRect(screen);
    // move and resize the window
    SetWindowPos(m_hBlankWindows[i], NULL, rBounds.left, rBounds.top,
      rBounds.right - rBounds.left, rBounds.bottom - rBounds.top,
      SWP_NOACTIVATE);

    ShowWindow(m_hBlankWindows[i], SW_SHOW | SW_SHOWNOACTIVATE);

    screen++;
    if (screen == m_nScreen)
      screen++;
  }

  if(m_hWnd)
    SetForegroundWindow(m_hWnd);

  return true;
}
Esempio n. 14
0
bool CWinSystemWin32::ResizeInternal(bool forceRefresh)
{
  if (m_hWnd == NULL)
    return false;
  DWORD dwStyle = WS_CLIPCHILDREN;
  HWND windowAfter;
  RECT rc;

  if(m_bFullScreen)
  {
    dwStyle |= WS_POPUP;
    windowAfter = HWND_TOP;
    rc = ScreenRect(m_nScreen);
  }
  else
  {
    dwStyle |= WS_OVERLAPPEDWINDOW;
    windowAfter = g_advancedSettings.m_alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST;

    rc.left = m_nLeft;
    rc.right = m_nLeft + m_nWidth;
    rc.top = m_nTop;
    rc.bottom = m_nTop + m_nHeight;

    HMONITOR hMon = MonitorFromRect(&rc, MONITOR_DEFAULTTONULL);
    HMONITOR hMon2 = MonitorFromWindow(m_hWnd, MONITOR_DEFAULTTOPRIMARY);

    // hasn't been windowed yet, or windowed position would not fullscreen to the same screen we were fullscreen on?
    // -> center on the screen that we were fullscreen on
    if(!m_ValidWindowedPosition || hMon == NULL || hMon != hMon2)
    {
      RECT newScreenRect = ScreenRect(GetCurrentScreen());
      rc.left = m_nLeft = newScreenRect.left + ((newScreenRect.right - newScreenRect.left) / 2) - (m_nWidth / 2);
      rc.top  = m_nTop  =  newScreenRect.top + ((newScreenRect.bottom - newScreenRect.top) / 2) - (m_nHeight / 2);
      rc.right = m_nLeft + m_nWidth;
      rc.bottom = m_nTop + m_nHeight;
    }

    AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, false );
  }

  WINDOWINFO wi;
  wi.cbSize = sizeof (WINDOWINFO);
  GetWindowInfo(m_hWnd, &wi);
  RECT wr = wi.rcWindow;

  if (forceRefresh || wr.bottom  - wr.top != rc.bottom - rc.top || wr.right - wr.left != rc.right - rc.left ||
                     (wi.dwStyle & WS_CAPTION) != (dwStyle & WS_CAPTION))
  {
    CLog::Log(LOGDEBUG, "%s - resizing due to size change (%d,%d,%d,%d%s)->(%d,%d,%d,%d%s)",__FUNCTION__,wr.left, wr.top, wr.right, wr.bottom, (wi.dwStyle & WS_CAPTION) ? "" : " fullscreen",
                                                                                                         rc.left, rc.top, rc.right, rc.bottom, (dwStyle & WS_CAPTION) ? "" : " fullscreen");
    SetWindowRgn(m_hWnd, 0, false);
    SetWindowLong(m_hWnd, GWL_STYLE, dwStyle);

    // The SWP_DRAWFRAME is here because, perversely, without it win7 draws a
    // white frame plus titlebar around the xbmc splash
    SetWindowPos(m_hWnd, windowAfter, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_SHOWWINDOW|SWP_DRAWFRAME);

    // TODO: Probably only need this if switching screens
    ValidateRect(NULL, NULL);
  }
  return true;
}
Esempio n. 15
0
void DrawRightPanel()
{
	float x,y,w,h;
	float border = 2.0f;

	x = rmenuRect.x + border;
	y = rmenuRect.y + border - 1;
	w = rmenuRect.w - 2*border;
	h = rmenuRect.h - 2*border + 1;
	glDisable(GL_TEXTURE_2D);
	glColor4f(0.5882f, 0.5882f, 0.5882f, 1.0f);
	glBegin(GL_QUADS);
	{
		glVertex2f(x, y);
		glVertex2f(x + w, y);
		glVertex2f(x + w, y + h);
		glVertex2f(x, y + h);		
	}
	glEnd();

	glEnable(GL_TEXTURE_2D);

	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glBindTexture(GL_TEXTURE_2D, *(atlas_tile.texture));
	w = tilethumbsize.x;
	h = tilethumbsize.y;
	x = rmenuRect.x + border + 8.0f;
	y = (rmenuRect.y + border - 1 + 2.0f) + rmenuyoffset + h;	
	ScreenRect srcRect,dstRect,hl_dstRect,sel_dstRect;

	for(int i=0;i<atlas_tile.totalFrames;)
	{
		glBegin(GL_QUADS);
		{
			srcRect = atlas_tile.sourceRectangles[i];
			dstRect = ScreenRect(x,y,w,h);
			glTexCoord2d(srcRect.fLeft(), srcRect.fTop());	glVertex2f(dstRect.fLeft(), dstRect.fTop());
			glTexCoord2d(srcRect.fRight(), srcRect.fTop());	glVertex2f(dstRect.fRight(), dstRect.fTop());
			glTexCoord2d(srcRect.fRight(), srcRect.fBottom());	glVertex2f(dstRect.fRight(),  dstRect.fBottom());
			glTexCoord2d(srcRect.fLeft(), srcRect.fBottom());	glVertex2f(dstRect.fLeft(),  dstRect.fBottom());

		}
		glEnd();
		if(i == highlightedBrush)
			hl_dstRect = dstRect;
		if(i == selectedBrush)
			sel_dstRect = dstRect;
		x += w + 2.0f;
		i++;
		if(!fmod(i,tilesperrow))
		{
			x = rmenuRect.x + border + 8.0f;
			y += h + 2.0f;
		}		
	}

	//highlightedBrush
	float lw = 1.0f;
	glDisable(GL_TEXTURE_2D);
	//selected
	glColor4f(0.5f, 1.0f, 0.5f, 1.0f);
	R_DrawHorizontalLine(sel_dstRect.x - lw, sel_dstRect.y, sel_dstRect.w + 2*lw, lw);
	R_DrawVerticalLine(sel_dstRect.x, sel_dstRect.y , sel_dstRect.h, lw);
	R_DrawHorizontalLine(sel_dstRect.x - lw, sel_dstRect.y + sel_dstRect.h, sel_dstRect.w + 2*lw, lw);
	R_DrawVerticalLine(sel_dstRect.x + sel_dstRect.w, sel_dstRect.y + sel_dstRect.h, -sel_dstRect.h, lw);
	if(PointinRect(Point(input.mouse.lX,input.mouse.lY),rmenuRect))
	{
		x = rmenuRect.x + border + 8.0f;
		y = (rmenuRect.y + border - 1 + 2.0f) + rmenuyoffset + h;
		Point cursor(CLAMP(input.mouse.lX,rmenuw,client_rect.w),input.mouse.lY);
		cursor.x -= x;
		cursor.y -= y;
		highlightedBrush = ((int)(cursor.x/(w + 2.0f)) + tilesperrow*((int)((cursor.y)/(h + 2.0f))));
		highlightedBrush = CLAMP(highlightedBrush,0,atlas_tile.totalFrames-1);

		glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
		R_DrawHorizontalLine(hl_dstRect.x - lw, hl_dstRect.y, hl_dstRect.w + 2*lw, lw);
		R_DrawVerticalLine(hl_dstRect.x, hl_dstRect.y , hl_dstRect.h, lw);
		R_DrawHorizontalLine(hl_dstRect.x - lw, hl_dstRect.y + hl_dstRect.h, hl_dstRect.w + 2*lw, lw);
		R_DrawVerticalLine(hl_dstRect.x + hl_dstRect.w, hl_dstRect.y + hl_dstRect.h, -hl_dstRect.h, lw);
	}

	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glEnable(GL_TEXTURE_2D);

	x = rmenuRect.x + border;
	y = rmenuRect.y + border - 1;
	w = rmenuRect.w - 2*border;
	h = smallfont.charsXYWH.h * smallfont.scaleValue * 3;
	glDisable(GL_TEXTURE_2D);
	glColor4f(0.4882f, 0.4882f, 0.4882f, 1.0f);
	glBegin(GL_QUADS);
	{
		glVertex2f(x, y);
		glVertex2f(x + w, y);
		glVertex2f(x + w, y + h);
		glVertex2f(x, y + h);		
		glColor4f(0.2941f, 0.2941f, 0.2941f, 1.0f);
		glVertex2f(x, y - 1);
		glVertex2f(x + w, y - 1);
		glVertex2f(x + w, y);
		glVertex2f(x, y);
		glVertex2f(x, y + h - 2);
		glVertex2f(x + w, y + h - 2);
		glVertex2f(x + w, y + h);
		glVertex2f(x, y + h);
	}
	glEnd();
	glEnable(GL_TEXTURE_2D);

	char buffer[128];
	Vector4 color;

	int ty = y + 8; int dy = smallfont.charsXYWH.h * smallfont.scaleValue;
	color = Vector4(0.0f,0.0f,0.0f,1.0f);
	sprintf (buffer, "Tile Set = %s", "tiles03.bmp");
	ty += dy; smallfont.displayScreenTextSpacing(x + 8,ty,color.x,color.y,color.z,buffer);
}
void
ClientTiledThebesLayer::BeginPaint()
{
  if (ClientManager()->IsRepeatTransaction()) {
    return;
  }

  mPaintData.mLowPrecisionPaintCount = 0;
  mPaintData.mPaintFinished = false;

  // Get the metrics of the nearest scroll container.
  ContainerLayer* scrollParent = nullptr;
  for (ContainerLayer* parent = GetParent(); parent; parent = parent->GetParent()) {
    const FrameMetrics& metrics = parent->GetFrameMetrics();
    if (metrics.mScrollId != FrameMetrics::NULL_SCROLL_ID) {
      scrollParent = parent;
      break;
    }
  }

  if (!scrollParent) {
    // XXX I don't think this can happen, but if it does, warn and set the
    //     composition bounds to empty so that progressive updates are disabled.
    NS_WARNING("Tiled Thebes layer with no scrollable container parent");
    mPaintData.mCompositionBounds.SetEmpty();
    return;
  }

  const FrameMetrics& metrics = scrollParent->GetFrameMetrics();

  // Calculate the transform required to convert screen space into transformed
  // layout device space.
  gfx::Matrix4x4 effectiveTransform = GetEffectiveTransform();
  for (ContainerLayer* parent = GetParent(); parent; parent = parent->GetParent()) {
    if (parent->UseIntermediateSurface()) {
      effectiveTransform = effectiveTransform * parent->GetEffectiveTransform();
    }
  }
  gfx3DMatrix layoutToScreen;
  gfx::To3DMatrix(effectiveTransform, layoutToScreen);
  layoutToScreen.ScalePost(metrics.mCumulativeResolution.scale,
                           metrics.mCumulativeResolution.scale,
                           1.f);

  mPaintData.mTransformScreenToLayout = layoutToScreen.Inverse();

  // Compute the critical display port in layer space.
  mPaintData.mLayoutCriticalDisplayPort.SetEmpty();
  if (!metrics.mCriticalDisplayPort.IsEmpty()) {
    // Convert the display port to screen space first so that we can transform
    // it into layout device space.
    const ScreenRect& criticalDisplayPort = metrics.mCriticalDisplayPort * metrics.mZoom;
    LayoutDeviceRect transformedCriticalDisplayPort =
      ApplyScreenToLayoutTransform(mPaintData.mTransformScreenToLayout, criticalDisplayPort);
    mPaintData.mLayoutCriticalDisplayPort =
      LayoutDeviceIntRect::ToUntyped(RoundedOut(transformedCriticalDisplayPort));
  }

  // Calculate the frame resolution. Because this is Gecko-side, before any
  // async transforms have occurred, we can use mZoom for this.
  mPaintData.mResolution = metrics.mZoom;

  // Calculate the scroll offset since the last transaction, and the
  // composition bounds.
  mPaintData.mCompositionBounds.SetEmpty();
  mPaintData.mScrollOffset.MoveTo(0, 0);
  Layer* primaryScrollable = ClientManager()->GetPrimaryScrollableLayer();
  if (primaryScrollable) {
    const FrameMetrics& metrics = primaryScrollable->AsContainerLayer()->GetFrameMetrics();
    mPaintData.mScrollOffset = metrics.mScrollOffset * metrics.mZoom;
    mPaintData.mCompositionBounds =
      ApplyScreenToLayoutTransform(mPaintData.mTransformScreenToLayout,
                                   ScreenRect(metrics.mCompositionBounds));
  }
}
Esempio n. 17
0
void DrawLeftPanel()
{
	float x,y,w,h;
	float border = 2.0f;
	x = lmenuRect.x + border;
	y = lmenuRect.y + border - 1;
	w = lmenuRect.w - 2*border;
	h = lmenuRect.h - 2*border + 1;
	glDisable(GL_TEXTURE_2D);
	glColor4f(0.5882f, 0.5882f, 0.5882f, 1.0f);
	glBegin(GL_QUADS);
	{
		glVertex2f(x, y);
		glVertex2f(x + w, y);
		glVertex2f(x + w, y + h);
		glVertex2f(x, y + h);		
	}
	glEnd();

	glEnable(GL_TEXTURE_2D);

	ScreenRect srcRect,dstRect;
	float top = 210;
	float dx = 32;
	float dw = 120;
	float dh = 128;

	w = tilethumbsize.x*2;
	h = tilethumbsize.y*2;	
	x = lmenuRect.x + border + dx;
	y = lmenuRect.y + border - 1 + top;
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glBindTexture(GL_TEXTURE_2D, *(atlas_tile.texture));
	glBegin(GL_QUADS);
	{
		//brush
		srcRect = atlas_tile.sourceRectangles[selectedBrush];
		dstRect = ScreenRect(x,y,w,h);
		glTexCoord2d(srcRect.fLeft(), srcRect.fTop());	glVertex2f(dstRect.fLeft(), dstRect.fTop());
		glTexCoord2d(srcRect.fRight(), srcRect.fTop());	glVertex2f(dstRect.fRight(), dstRect.fTop());
		glTexCoord2d(srcRect.fRight(), srcRect.fBottom());	glVertex2f(dstRect.fRight(),  dstRect.fBottom());
		glTexCoord2d(srcRect.fLeft(), srcRect.fBottom());	glVertex2f(dstRect.fLeft(),  dstRect.fBottom());
	}
	glEnd();
	//cbrush
	glBindTexture(GL_TEXTURE_2D, *(atlas_collision.texture));
	glBegin(GL_QUADS);
	{
		srcRect = atlas_collision.sourceRectangles[selectedCBrush];
		dstRect = ScreenRect(x + dw, y ,w,h);
		glTexCoord2d(srcRect.fLeft(), srcRect.fTop());	glVertex2f(dstRect.fLeft(), dstRect.fTop());
		glTexCoord2d(srcRect.fRight(), srcRect.fTop());	glVertex2f(dstRect.fRight(), dstRect.fTop());
		glTexCoord2d(srcRect.fRight(), srcRect.fBottom());	glVertex2f(dstRect.fRight(),  dstRect.fBottom());
		glTexCoord2d(srcRect.fLeft(), srcRect.fBottom());	glVertex2f(dstRect.fLeft(),  dstRect.fBottom());
	}
	glEnd();

	float lw = 4.0f;
	glDisable(GL_TEXTURE_2D);
	x += -8.0f;
	w += 16.0f;
	y += -8.0f;
	h += 16.0f;
	//tile outline
	glColor4f(0.0f, 0.4f, 0.9f, 1.0f);
	R_DrawHorizontalLine(x - lw, y, w + 2*lw,lw);
	R_DrawVerticalLine(x, y , h, lw);
	R_DrawHorizontalLine(x - lw, y + h, w + 2*lw, lw);
	R_DrawVerticalLine(x + w, y + h, -h, lw);
	//brush outline
	glColor4f(0.0f, 0.9f, 0.4f, 1.0f);
	x += dw;
	R_DrawHorizontalLine(x - lw, y, w + 2*lw,lw);
	R_DrawVerticalLine(x, y , h, lw);
	R_DrawHorizontalLine(x - lw, y + h, w + 2*lw, lw);
	R_DrawVerticalLine(x + w, y + h, -h, lw);
	x -= dw;
	glEnable(GL_TEXTURE_2D);

	char buffer[128];
	Vector4 color;
	int ty = lmenuRect.y + border - 1 + top - 32; int dy = smallfont.charsXYWH.h * smallfont.scaleValue;
	color = Vector4(0.0f,0.0f,0.0f,1.0f);
	sprintf (buffer, "%s", "Image Brush");
	smallfont.displayScreenTextSpacing(x - 16,ty,color.x,color.y,color.z,buffer);
	sprintf (buffer, "index = %d", selectedBrush);
	smallfont.displayScreenTextSpacing(x - 16,ty +dy,color.x,color.y,color.z,buffer);
	sprintf (buffer, "%s", "Collision Brush");
	smallfont.displayScreenTextSpacing(x - 16 + dw, ty,color.x,color.y,color.z,buffer);
	sprintf (buffer, "index = %d", selectedCBrush);
	smallfont.displayScreenTextSpacing(x - 16 + dw, ty + dy,color.x,color.y,color.z,buffer);

	//CBrush icons
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glBindTexture(GL_TEXTURE_2D, *(atlas_collision.texture));

	w = 48.0f;
	h = 48.0f;
	x = lmenuRect.x + border + 8.0f;
	y = lmenuRect.y + border - 1 + top + dh;

	ScreenRect hl_dstRect,sel_dstRect;

	for(int i=0;i<atlas_collision.totalFrames;)
	{
		glBegin(GL_QUADS);
		{
			srcRect = atlas_collision.sourceRectangles[i];
			dstRect = ScreenRect(x,y,w,h);
			glTexCoord2d(srcRect.fLeft(), srcRect.fTop());	glVertex2f(dstRect.fLeft(), dstRect.fTop());
			glTexCoord2d(srcRect.fRight(), srcRect.fTop());	glVertex2f(dstRect.fRight(), dstRect.fTop());
			glTexCoord2d(srcRect.fRight(), srcRect.fBottom());	glVertex2f(dstRect.fRight(),  dstRect.fBottom());
			glTexCoord2d(srcRect.fLeft(), srcRect.fBottom());	glVertex2f(dstRect.fLeft(),  dstRect.fBottom());

		}
		glEnd();
		if(i == highlightedCBrush)
			hl_dstRect = dstRect;
		if(i == selectedCBrush)
			sel_dstRect = dstRect;
		x += w + 8.0f;
		i++;
		if(!fmod(i,4))
		{
			x = lmenuRect.x + border + 8.0f;
			y += h + 8.0f;
		}		
	}

	//highlightedCBrush
	lw = 1.0f;
	glDisable(GL_TEXTURE_2D);
	//selected
	glColor4f(0.5f, 1.0f, 0.5f, 1.0f);
	R_DrawHorizontalLine(sel_dstRect.x - lw, sel_dstRect.y, sel_dstRect.w + 2*lw, lw);
	R_DrawVerticalLine(sel_dstRect.x, sel_dstRect.y , sel_dstRect.h, lw);
	R_DrawHorizontalLine(sel_dstRect.x - lw, sel_dstRect.y + sel_dstRect.h, sel_dstRect.w + 2*lw, lw);
	R_DrawVerticalLine(sel_dstRect.x + sel_dstRect.w, sel_dstRect.y + sel_dstRect.h, -sel_dstRect.h, lw);
	if(PointinRect(Point(input.mouse.lX,input.mouse.lY),lmenuRect))
	{
		x = lmenuRect.x + border + 8.0f;
		y = lmenuRect.y + border - 1 + top + dh;
		Point cursor(CLAMP(input.mouse.lX,0,lmenuRect.fRight()),input.mouse.lY);
		cursor.x -= x;
		cursor.y -= y;
		highlightedCBrush = ((int)(cursor.x/(w + 8.0f)) + 4*((int)((cursor.y)/(h + 8.0f))));
		highlightedCBrush = CLAMP(highlightedCBrush,0,atlas_collision.totalFrames-1);

		glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
		R_DrawHorizontalLine(hl_dstRect.x - lw, hl_dstRect.y, hl_dstRect.w + 2*lw, lw);
		R_DrawVerticalLine(hl_dstRect.x, hl_dstRect.y , hl_dstRect.h, lw);
		R_DrawHorizontalLine(hl_dstRect.x - lw, hl_dstRect.y + hl_dstRect.h, hl_dstRect.w + 2*lw, lw);
		R_DrawVerticalLine(hl_dstRect.x + hl_dstRect.w, hl_dstRect.y + hl_dstRect.h, -hl_dstRect.h, lw);
	}

	glEnable(GL_TEXTURE_2D);
	R_drawScreenDebug();
}
Esempio n. 18
0
	bool PopupMenu::EventMouse( cevent_mouse* pEvent )
	{
		int N = -1;
		cpoint point = pEvent->Point();

		for ( int i = 0; i < list.count(); i++ )
		{
			crect* pr = &( list[i].rect );

			if ( point.x >= pr->left && point.x < pr->right && point.y >= pr->top && point.y < pr->bottom )
			{
				N = i;
				break;
			}
		}

		switch ( pEvent->Type() )
		{
			case EV_MOUSE_MOVE:
				if ( N < 0 )
				{
					if ( !sub.ptr() ) { return false; }

					crect rect = ScreenRect();
					crect sr = sub->ScreenRect();
					pEvent->Point().x += rect.left - sr.left;
					pEvent->Point().y += rect.top - sr.top;
					return sub->EventMouse( pEvent );
				}

				if ( SetSelected( N ) )
				{
					if ( this->IsSub( selected ) && IsEnabled( selected ) )
					{
						OpenSubmenu();
					}
				}

				return true;


			case EV_MOUSE_PRESS:
				if ( N < 0 )
				{
					if ( sub.ptr() )
					{
						crect rect = ScreenRect();
						crect sr = sub->ScreenRect();
						pEvent->Point().x += rect.left - sr.left;
						pEvent->Point().y += rect.top - sr.top;

						if ( sub->EventMouse( pEvent ) ) { return true; }
					}

					if ( IsModal() )
					{
						EndModal( 0 );
					}
					else if ( Parent() ) { Parent()->Command( CMD_MENU_INFO, SCMD_MENU_CANCEL, this, 0 ); }

					return true;
				}

				if ( SetSelected( N ) )
				{
					if ( IsCmd( selected ) && IsEnabled( selected ) )
					{
						int id = list[N].data->id;

						if ( IsModal() ) { EndModal( id ); }
						else if ( Parent() ) { Parent()->Command( id, 0, this, 0 ); }
					}
					else
					{
						OpenSubmenu();
					}
				}

				return true;
		}

		return false;
	}
template<class ContainerT> void
ContainerRender(ContainerT* aContainer,
                LayerManagerComposite* aManager,
                const nsIntRect& aClipRect)
{
  /**
   * Setup our temporary surface for rendering the contents of this container.
   */
  RefPtr<CompositingRenderTarget> surface;

  Compositor* compositor = aManager->GetCompositor();

  RefPtr<CompositingRenderTarget> previousTarget = compositor->GetCurrentRenderTarget();

  nsIntRect visibleRect = aContainer->GetEffectiveVisibleRegion().GetBounds();

  aContainer->mSupportsComponentAlphaChildren = false;

  float opacity = aContainer->GetEffectiveOpacity();

  bool needsSurface = aContainer->UseIntermediateSurface();
  if (needsSurface) {
    SurfaceInitMode mode = INIT_MODE_CLEAR;
    bool surfaceCopyNeeded = false;
    gfx::IntRect surfaceRect = gfx::IntRect(visibleRect.x, visibleRect.y,
                                            visibleRect.width, visibleRect.height);
    gfx::IntPoint sourcePoint = gfx::IntPoint(visibleRect.x, visibleRect.y);
    // we're about to create a framebuffer backed by textures to use as an intermediate
    // surface. What to do if its size (as given by framebufferRect) would exceed the
    // maximum texture size supported by the GL? The present code chooses the compromise
    // of just clamping the framebuffer's size to the max supported size.
    // This gives us a lower resolution rendering of the intermediate surface (children layers).
    // See bug 827170 for a discussion.
    int32_t maxTextureSize = compositor->GetMaxTextureSize();
    surfaceRect.width = std::min(maxTextureSize, surfaceRect.width);
    surfaceRect.height = std::min(maxTextureSize, surfaceRect.height);
    if (aContainer->GetEffectiveVisibleRegion().GetNumRects() == 1 &&
        (aContainer->GetContentFlags() & Layer::CONTENT_OPAQUE))
    {
      // don't need a background, we're going to paint all opaque stuff
      aContainer->mSupportsComponentAlphaChildren = true;
      mode = INIT_MODE_NONE;
    } else {
      const gfx3DMatrix& transform3D = aContainer->GetEffectiveTransform();
      gfxMatrix transform;
      // If we have an opaque ancestor layer, then we can be sure that
      // all the pixels we draw into are either opaque already or will be
      // covered by something opaque. Otherwise copying up the background is
      // not safe.
      if (HasOpaqueAncestorLayer(aContainer) &&
          transform3D.Is2D(&transform) && !transform.HasNonIntegerTranslation()) {
        surfaceCopyNeeded = gfxPlatform::ComponentAlphaEnabled();
        sourcePoint.x += transform.x0;
        sourcePoint.y += transform.y0;
        aContainer->mSupportsComponentAlphaChildren
          = gfxPlatform::ComponentAlphaEnabled();
      }
    }

    sourcePoint -= compositor->GetCurrentRenderTarget()->GetOrigin();
    if (surfaceCopyNeeded) {
      surface = compositor->CreateRenderTargetFromSource(surfaceRect, previousTarget, sourcePoint);
    } else {
      surface = compositor->CreateRenderTarget(surfaceRect, mode);
    }

    if (!surface) {
      return;
    }

    compositor->SetRenderTarget(surface);
  } else {
    surface = previousTarget;
    aContainer->mSupportsComponentAlphaChildren = (aContainer->GetContentFlags() & Layer::CONTENT_OPAQUE) ||
      (aContainer->GetParent() && aContainer->GetParent()->SupportsComponentAlphaChildren());
  }

  nsAutoTArray<Layer*, 12> children;
  aContainer->SortChildrenBy3DZOrder(children);

  /**
   * Render this container's contents.
   */
  for (uint32_t i = 0; i < children.Length(); i++) {
    LayerComposite* layerToRender = static_cast<LayerComposite*>(children.ElementAt(i)->ImplData());

    if (layerToRender->GetLayer()->GetEffectiveVisibleRegion().IsEmpty() &&
        !layerToRender->GetLayer()->AsContainerLayer()) {
      continue;
    }

    if (i + 1 < children.Length() &&
        layerToRender->GetLayer()->GetEffectiveTransform().IsIdentity()) {
      LayerComposite* nextLayer = static_cast<LayerComposite*>(children.ElementAt(i + 1)->ImplData());
      nsIntRect nextLayerOpaqueRect;
      if (nextLayer && nextLayer->GetLayer()) {
        nextLayerOpaqueRect = GetOpaqueRect(nextLayer->GetLayer());
      }
      if (!nextLayerOpaqueRect.IsEmpty()) {
        nsIntRegion visibleRegion;
        visibleRegion.Sub(layerToRender->GetShadowVisibleRegion(), nextLayerOpaqueRect);
        layerToRender->SetShadowVisibleRegion(visibleRegion);
        if (visibleRegion.IsEmpty()) {
          continue;
        }
      }
    }

    nsIntRect clipRect = layerToRender->GetLayer()->
        CalculateScissorRect(aClipRect, &aManager->GetWorldTransform());
    if (clipRect.IsEmpty()) {
      continue;
    }

    if (layerToRender->HasLayerBeenComposited()) {
      // Composer2D will compose this layer so skip GPU composition
      // this time & reset composition flag for next composition phase
      layerToRender->SetLayerComposited(false);
    } else {
      layerToRender->RenderLayer(clipRect);
    }
    // invariant: our GL context should be current here, I don't think we can
    // assert it though
  }

  if (needsSurface) {
    // Unbind the current surface and rebind the previous one.
#ifdef MOZ_DUMP_PAINTING
    if (gfxUtils::sDumpPainting) {
      nsRefPtr<gfxImageSurface> surf = surface->Dump(aManager->GetCompositor());
      WriteSnapshotToDumpFile(aContainer, surf);
    }
#endif

    compositor->SetRenderTarget(previousTarget);
    EffectChain effectChain;
    LayerManagerComposite::AutoAddMaskEffect autoMaskEffect(aContainer->GetMaskLayer(),
                                                            effectChain,
                                                            !aContainer->GetTransform().CanDraw2D());

    effectChain.mPrimaryEffect = new EffectRenderTarget(surface);

    gfx::Matrix4x4 transform;
    ToMatrix4x4(aContainer->GetEffectiveTransform(), transform);

    gfx::Rect rect(visibleRect.x, visibleRect.y, visibleRect.width, visibleRect.height);
    gfx::Rect clipRect(aClipRect.x, aClipRect.y, aClipRect.width, aClipRect.height);
    aManager->GetCompositor()->DrawQuad(rect, clipRect, effectChain, opacity,
                                        transform);
  }

  if (aContainer->GetFrameMetrics().IsScrollable()) {
    gfx::Matrix4x4 transform;
    ToMatrix4x4(aContainer->GetEffectiveTransform(), transform);

    const FrameMetrics& frame = aContainer->GetFrameMetrics();
    LayerRect layerBounds = ScreenRect(frame.mCompositionBounds) * ScreenToLayerScale(1.0);
    gfx::Rect rect(layerBounds.x, layerBounds.y, layerBounds.width, layerBounds.height);
    gfx::Rect clipRect(aClipRect.x, aClipRect.y, aClipRect.width, aClipRect.height);
    aManager->GetCompositor()->DrawDiagnostics(DIAGNOSTIC_CONTAINER,
                                               rect, clipRect,
                                               transform);
  }
}
Esempio n. 20
0
void R_drawWorldDebug()
{	
	glUseProgramObjectARB(NULL);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

	glDisable(GL_TEXTURE_2D);

	float x0,y0,x1,y1,w,h;

	//axis
	glLineWidth(4.0f);
	glBegin(GL_LINES);
	{

		glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
		x0 = max(-10000,camera.position.x);
		x1 = min(10000,camera.position.x+camera.size.x);
		glVertex2f(x0, 0);
		glVertex2f(x1, 0);
		glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
		y0 = max(-10000,camera.position.y);
		y1 = min(10000,camera.position.y+camera.size.y);
		glVertex2f(0, y0);
		glVertex2f(0, y1);
	}
	glEnd();

	//grid
	glLineWidth(4.0f);
	glBegin(GL_LINES);
	{
		w = tilemap_back.w_tileSize.x;
		h = tilemap_back.w_tileSize.y;
		for (int y = tilemap_back.Min.y; y < tilemap_back.Max.y; y++)
		{
			for (int x = tilemap_back.Min.x; x < tilemap_back.Max.x; x++)
			{
				x0 = tilemap_back.position.x + x * w;
				y0 = tilemap_back.position.y + y * h;

				glColor4f(0.0f, 0.0f, 0.0f, 0.75f);
				glVertex2f(x0, y0);
				glVertex2f(x0, y0 + h);
				glVertex2f(x0, y0);
				glVertex2f(x0 + w, y0);

				glColor4f(1.0f, 0.0f, 1.0f, 0.5f);
				if(y == tilemap_back.Max.y-1)
				{
					glVertex2f(x0, y0 + h);
					glVertex2f(x0 + w, y0 + h);
				}
				glColor4f(0.0f, 0.0f, 1.0f, 0.5f);
				if(x == tilemap_back.Max.x-1)
				{
					glVertex2f(x0 + w, y0);
					glVertex2f(x0 + w, y0 + h);
				}
			}
		}
	}
	glEnd();

	//highlightedTile
	if(PointinRect(Point(input.mouse.lX,input.mouse.lY),s_dstRect))
	{
		Point cursor(CLAMP(input.mouse.lX,lmenuw,client_rect.w - rmenuw),input.mouse.lY);
		Vector2 worldcursor = screenToWorld(cursor,camera,client_rect);
		highlightedTile = worldToTile(worldcursor - pselected_tilemap->position, pselected_tilemap->w_tileSize);
		highlightedTile.x = CLAMP(highlightedTile.x,0,pselected_tilemap->t_mapSize.x-1);
		highlightedTile.y = CLAMP(highlightedTile.y,0,pselected_tilemap->t_mapSize.y-1);
	}

	float lw = 2.0f;
	ScreenRect srcRect,dstRect;

	w = pselected_tilemap->w_tileSize.x;
	h = pselected_tilemap->w_tileSize.y;		
	x0 = pselected_tilemap->position.x + highlightedTile.x * w;
	y0 = pselected_tilemap->position.y + highlightedTile.y * h;

	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	srcRect = atlas_tile.sourceRectangles[selectedBrush];
	dstRect = ScreenRect(x0,y0,w,h);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, *(atlas_tile.texture));
	glBegin(GL_QUADS);
	{
		glTexCoord2d(srcRect.fLeft(), srcRect.fTop());	glVertex2f(dstRect.fLeft(), dstRect.fBottom());
		glTexCoord2d(srcRect.fRight(), srcRect.fTop());	glVertex2f(dstRect.fRight(), dstRect.fBottom());
		glTexCoord2d(srcRect.fRight(), srcRect.fBottom());	glVertex2f(dstRect.fRight(),  dstRect.fTop());
		glTexCoord2d(srcRect.fLeft(), srcRect.fBottom());	glVertex2f(dstRect.fLeft(),  dstRect.fTop());
	}
	glEnd();
	glDisable(GL_TEXTURE_2D);

	//image map
	if(blayer01loaded)
	{
		glColor4f(0.0f, 0.5f, 1.0f, 1.0f);
		x0 = pselected_tilemap->position.x + selectedTile.x * w;
		y0 = pselected_tilemap->position.y + selectedTile.y * h;

		R_DrawHorizontalLine(x0 - lw, y0, w + 2*lw, lw);
		R_DrawVerticalLine(x0, y0 , h, lw);
		R_DrawHorizontalLine(x0 - lw, y0 + h, w + 2*lw, lw);
		R_DrawVerticalLine(x0 + w, y0 + h, -h, lw);

		glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
		x0 = pselected_tilemap->position.x + highlightedTile.x * w;
		y0 = pselected_tilemap->position.y + highlightedTile.y * h;

		R_DrawHorizontalLine(x0 - lw, y0, w + 2*lw, lw);
		R_DrawVerticalLine(x0, y0 , h, lw);
		R_DrawHorizontalLine(x0 - lw, y0 + h, w + 2*lw, lw);
		R_DrawVerticalLine(x0 + w, y0 + h, -h, lw);
	}

	glEnable(GL_TEXTURE_2D);
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}
Esempio n. 21
0
void main(int argc, char *argv[])
{
	double      r, g, b;
	uint        rows, cols;
	char        fname[256];
	double      colormag;
	time_t      tstart, tend;
    int         nrgbr = 63, nrgbg = 63, nrgbb = 63;
	OctreeType  *octree;
	RGBType		color;
	FILE		*f;
	char		title[40];
	char		description[128];
    ulong       i;
    uint        j;
	int			n;
	RGBType		palette[256];
	ulong		image_start;
	union REGS	regs;
	int			resx, resy;
	int			px, py;
	int			ii;
	int			cols2, rows2;
	int			k;
	int			cli;
    int         maxr=0, maxg=0, maxb=0;

#if defined METAWINDO
	rect        screen;
#endif

	printf("Image file : ");
	scanf("%s",fname);
	if ((f = fopen(fname,"rb")) == NULL) {
        printf("%s not found.\n",fname);
		exit(1);
	}

    /*
    ** Read the image file header
    */
	fgets(title,40,f);
	fgets(description,128,f);
	fscanf(f,"%d %d",&cols,&rows);
    fscanf(f,"%lf",&colormag);
	image_start = ftell(f);

	cols2 = cols/2;
	rows2 = rows/2;
	time(&tstart);

	/*
    ** Initialize the color octree
	*/
    octree = CreateOctNode(0);

	/*
    ** Loop through the image and store each unique color.
	*/
	for (i = 0L; i < (ulong)rows*(ulong)cols; i++) {
		/*
		** Show progress...
		*/
		if ((i % (ulong)cols) == 0L) printf("%ld\r",i/cols);

        fscanf(f,"%lf %lf %lf",&r,&g,&b);
		/*
		** Convert input floating point values to bytes.  NOTE: We assume that
		** all input values are between 0..1.0
		*/
        color.r = (unsigned char)(r  * nrgbr);
        color.g = (unsigned char)(g  * nrgbg);
        color.b = (unsigned char)(b  * nrgbb);
		if (color.r > nrgbr) color.r = nrgbr;
		if (color.g > nrgbg) color.g = nrgbg;
		if (color.b > nrgbb) color.b = nrgbb;

		/*
		** Insert this color into the octree
		*/
		InsertTree(&octree, &color, 0);

		/*
		** If there are too many colors in the tree as a result of this
		** insert, reduce the octree
		*/
		while (TotalLeafNodes() > npal) {
			ReduceTree();
		}
	}

	/*
	** Make a pass through the completed octree to average down the
	** rgb components.  When done, 'n' contains the actual number of
	** colors in the palette table.
	*/
	n = 0;
	MakePaletteTable(octree, palette, &n);

	/*
	** How long did it take?
	*/
	time(&tend);
	printf("Processed %ld pixels per second\ninto %d quantized colors\n",
		   ((long)rows*(long)cols)/(tend-tstart), n);

	j = 0;
	while (j != 3) {
		printf("Output to (1)monitor or (2).PCX file or (3) quit: ");
		scanf("%s",title);
		j = atoi(title);
		if (j == 2) {
			fseek(f,image_start,0);
            SaveAsPCX(f, octree, cols, rows, nrgbr, nrgbg, nrgbb, npal, palette);
		}
		else if (j == 1) {
#if defined METAWINDO
			/*
			** NOTE: This section requires MetaWINDOW graphics lib
			**
			** Let the user choose his graphics device and resolution
			*/
			MetQuery(argc,argv);
			if (InitGraphics(GrafixCard) != 0) {
				printf("\n---Error initializing graphics device---\n");
				exit(1);
			}
			SetDisplay(GrafPg0);
			BackColor(0);
			/*
			** Set the VGA palette
			*/
			for (j = 0; j < n; j++) {
				regs.h.al = 0x10;
				regs.h.ah = 0x10;
				regs.h.bl = j;
				regs.h.bh = 0;
				regs.h.ch = (int)(palette[j].g);
				regs.h.cl = (int)(palette[j].b);
				regs.h.dh = (int)(palette[j].r);
				int86(0x10,&regs,&regs);
			}

			/*
			** Center the image on the screen
			*/
			ScreenRect(&screen);
			resx = screen.Xmax;
			resy = screen.Ymax;
			px = resx/2 - npal;

			/*
			** Display a color bar at the top of the screen
			*/
			for (ii = 0; ii < npal; ii++){
				PenColor(ii);
				SetPixel(ii*2+px,1);
				SetPixel(ii*2+px+1,1);
				SetPixel(ii*2+px,2);
				SetPixel(ii*2+px+1,2);
				SetPixel(ii*2+px,3);
				SetPixel(ii*2+px+1,3);
				SetPixel(ii*2+px,4);
				SetPixel(ii*2+px+1,4);
			}

			fseek(f,image_start,0);

			py = resy/2 - rows2 - 1;
			for (ii = 0; ii < rows ; ii++) {
				px = resx/2 - cols2;
				for (k = 0; k < cols; k++) {
					if (fscanf(f,"%f %f %f",&r,&g,&b) == EOF) {
						goto pdone;
					}
					color.r = (byte)(nrgbr * r);
					color.g = (byte)(nrgbg * g);
					color.b = (byte)(nrgbb * b);
					cli = QuantizeColor(octree, &color);
					PenColor(cli);
					SetPixel(px,py);
					px++;
				}
				py++;
			}
pdone:      getch();
			SetDisplay(TextPg0);
			StopGraphics();
#endif
		}
	}
}