<commit_before>//
// Name:	 canvas.cpp
// Purpose:	 Implements the canvas class for the wxWindows application.
//
// Copyright (c) 2001-2003 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/NavEngines.h"
#include "vtdata/vtLog.h"
#include "canvas.h"
#include "frame.h"
#include "app.h"

#ifndef WIN32
#define Sleep sleep
#endif

DECLARE_APP(vtApp)

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

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)
{
	VTLOG(" constructing Canvas\n");
	parent->Show(true);
	SetCurrent();

	wxGLContext *context = GetContext();
	if (context)
		VTLOG("OpenGL context: %lx\n", context);
	else
	{
		VTLOG("No OpenGL context.\n");
		return;
	}
	VTLOG("OpenGL version: %s\n", (const char *) glGetString(GL_VERSION));

	m_bPainting = false;
	m_bRunning = true;
}


vtGLCanvas::~vtGLCanvas(void)
{
	VTLOG(" destructing Canvas\n");
}

void vtGLCanvas::UpdateStatusText()
{
	vtFrame *frame = GetMainFrame();
	if (!frame || !frame->GetStatusBar()) return;

	vtScene *scene = vtGetScene();
	if (!scene) return;

	// get framerate
	float fps = scene->GetFrameRate();

	// get camera distance
	float dist = wxGetApp().m_pTrackball->GetRadius();

	wxString str;
	str.Printf(_T("fps %.3g, camera distance %.2f meters"), fps, dist);

	frame->SetStatusText(str);
}

void vtGLCanvas::OnPaint( wxPaintEvent& event )
{
	static bool bFirst = true;

	if (bFirst)
	{
		VTLOG("first OnPaint\n");
		bFirst = false;
	}
	// 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.
		wxPaintDC dc(this);
#ifndef __WXMOTIF__
		if (!GetContext()) return;<commit_msg>Prevent crash in UpdateStatusText<commit_after>//
// Name:	 canvas.cpp
// Purpose:	 Implements the canvas class for the wxWindows application.
//
// Copyright (c) 2001-2003 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/NavEngines.h"
#include "vtdata/vtLog.h"
#include "canvas.h"
#include "frame.h"
#include "app.h"

#ifndef WIN32
#define Sleep sleep
#endif

DECLARE_APP(vtApp)

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

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)
{
	VTLOG(" constructing Canvas\n");
	parent->Show(true);
	SetCurrent();

	wxGLContext *context = GetContext();
	if (context)
		VTLOG("OpenGL context: %lx\n", context);
	else
	{
		VTLOG("No OpenGL context.\n");
		return;
	}
	VTLOG("OpenGL version: %s\n", (const char *) glGetString(GL_VERSION));

	m_bPainting = false;
	m_bRunning = true;
}


vtGLCanvas::~vtGLCanvas(void)
{
	VTLOG(" destructing Canvas\n");
}

void vtGLCanvas::UpdateStatusText()
{
	vtFrame *frame = GetMainFrame();
	if (!frame || !frame->GetStatusBar()) return;

	vtScene *scene = vtGetScene();
	if (!scene) return;

	// get framerate
	float fps = scene->GetFrameRate();

	// get camera distance
	float dist = 0;
	if (NULL != wxGetApp().m_pTrackball)
        dist = wxGetApp().m_pTrackball->GetRadius();

	wxString str;
	str.Printf(_T("fps %.3g, camera distance %.2f meters"), fps, dist);

	frame->SetStatusText(str);
}

void vtGLCanvas::OnPaint( wxPaintEvent& event )
{
	static bool bFirst = true;

	if (bFirst)
	{
		VTLOG("first OnPaint\n");
		bFirst = false;
	}
	// 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.
		wxPaintDC dc(this);
#ifndef __WXMOTIF__
		if (!GetContext()) return;
{'fraction_non_alphanumeric': 0.13733994217265594, 'fraction_numerical': 0.0055762081784386614, 'mean_word_length': 4.786140979689367, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '3927668', 'n_tokens_mistral': 1846, 'n_tokens_neox': 1777, 'n_words': 449}