<commit_before>//
// Name:	 canvas.cpp
// Purpose: Implements the canvas class for the Enviro wxWidgets application.
//
// Copyright (c) 2001-2005 Virtual Terrain Project
// Free for all uses, see license.txt for details.
//

// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

#include "vtlib/vtlib.h"
#include "vtlib/core/TerrainScene.h"
#include "vtlib/core/Event.h"
#include "vtui/wxString2.h"
#include "vtdata/vtLog.h"
#include "EnviroGUI.h"			// for g_App, GetTerrainScene
#include "canvas.h"
#include "EnviroFrame.h"		// for UpdateStatus and OnChar
#include "EnviroApp.h"

DECLARE_APP(EnviroApp)

/*
 * vtGLCanvas implementation
 */
BEGIN_EVENT_TABLE(vtGLCanvas, wxGLCanvas)
EVT_CLOSE(vtGLCanvas::OnClose)
EVT_SIZE(vtGLCanvas::OnSize)
EVT_PAINT(vtGLCanvas::OnPaint)
EVT_CHAR(vtGLCanvas::OnChar)
EVT_KEY_DOWN(vtGLCanvas::OnKeyDown)
EVT_KEY_UP(vtGLCanvas::OnKeyUp)
EVT_MOUSE_EVENTS(vtGLCanvas::OnMouseEvent)
EVT_ERASE_BACKGROUND(vtGLCanvas::OnEraseBackground)
EVT_IDLE(vtGLCanvas::OnIdle)
END_EVENT_TABLE()

static vtGLCanvas *s_canvas = NULL;

vtGLCanvas::vtGLCanvas(wxWindow *parent, wxWindowID id,
	const wxPoint& pos, const wxSize& size, long style, const wxString& name, int* gl_attrib):
		wxGLCanvas(parent, id, pos, size, style, name, gl_attrib)
{
	VTLOG1("vtGLCanvas constructor\n");

	VTLOG1("vtGLCanvas: calling Show on parent\n");
	parent->Show();

	// Documentation says about SetCurrent:
	// "Note that this function may only be called after the window has been shown."
	VTLOG1("vtGLCanvas: calling SetCurrent\n");
	SetCurrent();

	wxGLContext *context = GetContext();
	if (context)
		VTLOG("OpenGL context: %lx\n", context);
	else
	{
		VTLOG1("No OpenGL context, quitting app.\n");
	    exit(0);
	}

	VTLOG1("OpenGL version: ");
	VTLOG1((const char *) glGetString(GL_VERSION));
	VTLOG1("\n");

	m_bPainting = false;
	m_bRunning = true;
	m_bShowFrameRateChart = false;

	for (int i = 0; i < 512; i++)
		m_pbKeyState[i] = false;
	vtGetScene()->SetKeyStates(m_pbKeyState);
	m_iConsecutiveMousemoves = 0;

	s_canvas = this;
	VTLOG1("vtGLCanvas, leaving constructor\n");
}

vtGLCanvas::~vtGLCanvas(void)
{
	VTLOG1("Deleting Canvas\n");
}


void EnableContinuousRendering(bool bTrue)
{
	VTLOG("EnableContinuousRendering %d\n", bTrue);
	if (!s_canvas)
		return;

	bool bNeedRefresh = (s_canvas->m_bRunning == false && bTrue == true);
	s_canvas->m_bRunning = bTrue;
	if (bNeedRefresh)
		s_canvas->Refresh(FALSE);

	vtGetScene()->TimerRunning(bTrue);
}

void vtGLCanvas::OnPaint( wxPaintEvent& event )
{
	static bool bFirstPaint = true;
	if (bFirstPaint) VTLOG1("vtGLCanvas: first OnPaint\n");

	// place the dc inside a scope, to delete it before the end of function
	if (1)
	{
		// This is a dummy, to avoid an endless succession of paint messages.
		// OnPaint handlers must always create a wxPaintDC.
		if (bFirstPaint) VTLOG1("vtGLCanvas: creating a wxPaintDC on the stack\n");
		wxPaintDC dc(this);

		// Safety checks
		if (!s_canvas)
		{
			VTLOG1("OnPaint: Canvas not yet constructed, returning\n");
			return;
		}
		if (!GetContext())
		{
			VTLOG1("OnPaint: No context yet, returning\n");
			return;
		}

		// Avoid reentrance
		if (m_bPainting) return;

		m_bPainting = true;

		// Render the Scene Graph
		if (bFirstPaint) VTLOG1("vtGLCanvas: DoUpdate\n");
		vtGetScene()->DoUpdate();

		if (m_bShowFrameRateChart)
			vtGetScene()->DrawFrameRateChart();

		if (bFirstPaint) VTLOG1("vtGLCanvas: SwapBuffers\n");
		SwapBuffers();

		if (bFirstPaint) VTLOG1("vtGLCanvas: update status bar\n");
		EnviroFrame *frame = (EnviroFrame*) GetParent();

		// update the status bar every 1/10 of a second
		static float last_stat = 0.0f;
		static vtString last_msg;
		float cur = vtGetTime();
		if (cur - last_stat > 0.1f || g_App.GetMessage() != last_msg)
		{
			last_msg = g_App.GetMessage();
			last_stat = cur;
			frame->UpdateStatus();
		}

		frame->UpdateLODInfo();

		m_bPainting = false;
	}

	// Reset the number of mousemoves we've gotten since last redraw
	m_iConsecutiveMousemoves = 0;

	if (bFirstPaint)
		bFirstPaint = false;
}

void vtGLCanvas::OnClose(wxCloseEvent& event)
{
	m_bRunning = false;
}

void vtGLCanvas::OnSize(wxSizeEvent& event)
{
  // Presumably this is a wxMSWism.<commit_msg>more OnSize logging<commit_after>//
// Name:	 canvas.cpp
// Purpose: Implements the canvas class for the Enviro wxWidgets application.
//
// Copyright (c) 2001-2005 Virtual Terrain Project
// Free for all uses, see license.txt for details.
//

// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

#include "vtlib/vtlib.h"
#include "vtlib/core/TerrainScene.h"
#include "vtlib/core/Event.h"
#include "vtui/wxString2.h"
#include "vtdata/vtLog.h"
#include "EnviroGUI.h"			// for g_App, GetTerrainScene
#include "canvas.h"
#include "EnviroFrame.h"		// for UpdateStatus and OnChar
#include "EnviroApp.h"

DECLARE_APP(EnviroApp)

/*
 * vtGLCanvas implementation
 */
BEGIN_EVENT_TABLE(vtGLCanvas, wxGLCanvas)
EVT_CLOSE(vtGLCanvas::OnClose)
EVT_SIZE(vtGLCanvas::OnSize)
EVT_PAINT(vtGLCanvas::OnPaint)
EVT_CHAR(vtGLCanvas::OnChar)
EVT_KEY_DOWN(vtGLCanvas::OnKeyDown)
EVT_KEY_UP(vtGLCanvas::OnKeyUp)
EVT_MOUSE_EVENTS(vtGLCanvas::OnMouseEvent)
EVT_ERASE_BACKGROUND(vtGLCanvas::OnEraseBackground)
EVT_IDLE(vtGLCanvas::OnIdle)
END_EVENT_TABLE()

static vtGLCanvas *s_canvas = NULL;

vtGLCanvas::vtGLCanvas(wxWindow *parent, wxWindowID id,
	const wxPoint& pos, const wxSize& size, long style, const wxString& name, int* gl_attrib):
		wxGLCanvas(parent, id, pos, size, style, name, gl_attrib)
{
	VTLOG1("vtGLCanvas constructor\n");

	VTLOG1("vtGLCanvas: calling Show on parent\n");
	parent->Show();

	// Documentation says about SetCurrent:
	// "Note that this function may only be called after the window has been shown."
	VTLOG1("vtGLCanvas: calling SetCurrent\n");
	SetCurrent();

	wxGLContext *context = GetContext();
	if (context)
		VTLOG("OpenGL context: %lx\n", context);
	else
	{
		VTLOG1("No OpenGL context, quitting app.\n");
	    exit(0);
	}

	VTLOG1("OpenGL version: ");
	VTLOG1((const char *) glGetString(GL_VERSION));
	VTLOG1("\n");

	m_bPainting = false;
	m_bRunning = true;
	m_bShowFrameRateChart = false;

	for (int i = 0; i < 512; i++)
		m_pbKeyState[i] = false;
	vtGetScene()->SetKeyStates(m_pbKeyState);
	m_iConsecutiveMousemoves = 0;

	s_canvas = this;
	VTLOG1("vtGLCanvas, leaving constructor\n");
}

vtGLCanvas::~vtGLCanvas(void)
{
	VTLOG1("Deleting Canvas\n");
}


void EnableContinuousRendering(bool bTrue)
{
	VTLOG("EnableContinuousRendering %d\n", bTrue);
	if (!s_canvas)
		return;

	bool bNeedRefresh = (s_canvas->m_bRunning == false && bTrue == true);
	s_canvas->m_bRunning = bTrue;
	if (bNeedRefresh)
		s_canvas->Refresh(FALSE);

	vtGetScene()->TimerRunning(bTrue);
}

void vtGLCanvas::OnPaint( wxPaintEvent& event )
{
	static bool bFirstPaint = true;
	if (bFirstPaint) VTLOG1("vtGLCanvas: first OnPaint\n");

	// place the dc inside a scope, to delete it before the end of function
	if (1)
	{
		// This is a dummy, to avoid an endless succession of paint messages.
		// OnPaint handlers must always create a wxPaintDC.
		if (bFirstPaint) VTLOG1("vtGLCanvas: creating a wxPaintDC on the stack\n");
		wxPaintDC dc(this);

		// Safety checks
		if (!s_canvas)
		{
			VTLOG1("OnPaint: Canvas not yet constructed, returning\n");
			return;
		}
		if (!GetContext())
		{
			VTLOG1("OnPaint: No context yet, returning\n");
			return;
		}

		// Avoid reentrance
		if (m_bPainting) return;

		m_bPainting = true;

		// Render the Scene Graph
		if (bFirstPaint) VTLOG1("vtGLCanvas: DoUpdate\n");
		vtGetScene()->DoUpdate();

		if (m_bShowFrameRateChart)
			vtGetScene()->DrawFrameRateChart();

		if (bFirstPaint) VTLOG1("vtGLCanvas: SwapBuffers\n");
		SwapBuffers();

		if (bFirstPaint) VTLOG1("vtGLCanvas: update status bar\n");
		EnviroFrame *frame = (EnviroFrame*) GetParent();

		// update the status bar every 1/10 of a second
		static float last_stat = 0.0f;
		static vtString last_msg;
		float cur = vtGetTime();
		if (cur - last_stat > 0.1f || g_App.GetMessage() != last_msg)
		{
			last_msg = g_App.GetMessage();
			last_stat = cur;
			frame->UpdateStatus();
		}

		frame->UpdateLODInfo();

		m_bPainting = false;
	}

	// Reset the number of mousemoves we've gotten since last redraw
	m_iConsecutiveMousemoves = 0;

	if (bFirstPaint)
		bFirstPaint = false;
}

void vtGLCanvas::OnClose(wxCloseEvent& event)
{
	m_bRunning = false;
}

void vtGLCanvas::OnSize(wxSizeEvent& event)
{
	static bool count = 0;
	if (count < 3)
	{
		VTLOG("Canvas  OnSize: %d %d\n", event.GetSize().x, event.GetSize().y);
		count++;
	}
  // Presumably this is a wxMSWism.
{'fraction_non_alphanumeric': 0.13176874642243847, 'fraction_numerical': 0.009387521465369204, 'mean_word_length': 4.654368932038835, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4017891', 'n_tokens_mistral': 3438, 'n_tokens_neox': 3235, 'n_words': 779}