mainmenu.cpp
来自「一个由Mike Gashler完成的机器学习方面的includes neural」· C++ 代码 · 共 302 行
CPP
302 行
// --------------------------------------------------------
// This demo file is dedicated to the Public Domain. See:
// http://creativecommons.org/licenses/publicdomain
// --------------------------------------------------------
#include "MainMenu.h"
#ifdef WIN32
#include <direct.h>
#else // WIN32
#include <unistd.h>
#endif // !WIN32
#include "../GClasses/GTime.h"
#include "../GClasses/GThread.h"
#include "../GClasses/GMacros.h"
#include "../GClasses/GFile.h"
#include "PredAcc.h"
#include "Interpolate.h"
#include "Manifold.h"
#include "Test.h"
#include "RayTrace.h"
#include "Chart.h"
#include "Paint.h"
#include "Rank.h"
#include "Agents.h"
#include "Video.h"
class MainMenuDialog : public GWidgetDialog
{
protected:
MainMenuController* m_pController;
GWidgetImageButton* m_pButtonManual;
GWidgetTextButton* m_pButtonDocs;
GWidgetTextButton* m_pButtonTests;
GWidgetTextButton* m_pButtonPredAcc;
GWidgetTextButton* m_pButtonChart;
GWidgetTextButton* m_pButtonInterpolate;
GWidgetTextButton* m_pButtonManifold;
GWidgetTextButton* m_pButtonRayTrace;
GWidgetTextButton* m_pButtonPaint;
GWidgetTextButton* m_pButtonRank;
GWidgetTextButton* m_pButtonAgents;
GWidgetTextButton* m_pButtonVideo;
public:
MainMenuDialog(MainMenuController* pController, int w, int h);
virtual ~MainMenuDialog();
virtual void OnChangeListSelection(GWidgetListBox* pListBox);
virtual void OnReleaseImageButton(GWidgetImageButton* pButton);
virtual void OnReleaseTextButton(GWidgetTextButton* pButton);
};
// ------------------------
#define BACKGROUND_COLOR 0xffeeeecc
MainMenuDialog::MainMenuDialog(MainMenuController* pController, int w, int h)
: GWidgetDialog(w, h, BACKGROUND_COLOR)
{
m_pController = pController;
// Make the manual button
GImage* pManualImage = ControllerBase::GetManualImage();
m_pButtonManual = new GWidgetImageButton(this, w - pManualImage->GetWidth() / 2 - 5, 5, pManualImage);
// Make the main title
new GWidgetTextLabel(this, 30, 5, 250, 40, "Wa f f l e s", 0xff442266);
#ifdef _DEBUG
new GWidgetTextLabel(this, 300, 20, 650, 16,
# ifdef WIN32
"(You are in debug mode. It will run faster if you build in retail mode)",
# else // WIN32
"(You are in debug mode. It will run faster if you build with \"make opt\" instead of just \"make\")",
# endif // !WIN32
0xff880000);
#endif // _DEBUG
new GWidgetTextLabel(this, 30, 50, 400, 16, "A pile of cross-platform C++ tools to assist research in:", 0xff442266);
new GWidgetTextLabel(this, 250, 65, 200, 16, "Machine Learning", 0xff442266);
new GWidgetTextLabel(this, 250, 80, 200, 16, "Artificial Intelligence", 0xff442266);
new GWidgetTextLabel(this, 250, 95, 200, 16, "Data Mining", 0xff442266);
new GWidgetTextLabel(this, 250, 110, 200, 16, "Vision/Image Processing", 0xff442266);
new GWidgetTextLabel(this, 25, 220, 300, 26, "ML / AI", 0xff442266);
m_pButtonPredAcc = new GWidgetTextButton(this, 25, 250, 300, 24, "Test Predicitive Accuracy with an ARFF file");
m_pButtonChart = new GWidgetTextButton(this, 25, 300, 300, 24, "Chart an ARFF file");
m_pButtonInterpolate = new GWidgetTextButton(this, 25, 350, 300, 24, "Interpolate an Image With ML");
m_pButtonManifold = new GWidgetTextButton(this, 25, 400, 300, 24, "The Manifold Sculpting Algorithm");
m_pButtonRank = new GWidgetTextButton(this, 25, 450, 300, 24, "Rank Learners");
//m_pButtonAgents = new GWidgetTextButton(this, 25, 500, 300, 24, "Agents");
new GWidgetTextLabel(this, 350, 220, 300, 26, "Images", 0xff442266);
m_pButtonRayTrace = new GWidgetTextButton(this, 350, 250, 300, 24, "Ray trace some scenes");
m_pButtonPaint = new GWidgetTextButton(this, 350, 300, 300, 24, "Image Processing Tools");
//m_pButtonVideo = new GWidgetTextButton(this, 350, 350, 300, 24, "Video Morph Tool");
new GWidgetTextLabel(this, 675, 220, 300, 26, "Misc", 0xff442266);
m_pButtonDocs = new GWidgetTextButton(this, 675, 250, 300, 24, "View Library API Documentation");
m_pButtonTests = new GWidgetTextButton(this, 675, 300, 300, 24, "Run Automated Tests");
}
/*virtual*/ MainMenuDialog::~MainMenuDialog()
{
}
/*virtual*/ void MainMenuDialog::OnChangeListSelection(GWidgetListBox* pListBox)
{
}
/*virtual*/ void MainMenuDialog::OnReleaseImageButton(GWidgetImageButton* pButton)
{
if(pButton == m_pButtonManual)
OpenAppFile("../doc/Waffles/MainMenu.html");
else
GAssert(false, "unrecognized image button");
}
void ChangeAppDir(const char* szDir)
{
const char* szAppPath = ControllerBase::GetAppPath();
GTEMPBUF(char, szNewDir, strlen(szAppPath) + strlen(szDir) + 2);
strcpy(szNewDir, szAppPath);
strcat(szNewDir, szDir);
chdir(szNewDir);
}
/*virtual*/ void MainMenuDialog::OnReleaseTextButton(GWidgetTextButton* pButton)
{
if(pButton == m_pButtonDocs)
OpenAppFile("../doc/GClasses/index.html");
else if(pButton == m_pButtonTests)
{
TestController c;
c.RunModal();
}
else if(pButton == m_pButtonPredAcc)
{
ChangeAppDir("arff");
PredAccController c;
c.RunModal();
ChangeAppDir("");
}
else if(pButton == m_pButtonInterpolate)
{
InterpolateController c;
c.RunModal();
}
else if(pButton == m_pButtonManifold)
{
ManifoldMenuController c;
c.RunModal();
}
else if(pButton == m_pButtonRayTrace)
{
ChangeAppDir("rib");
RayTraceController c;
c.RunModal();
ChangeAppDir("");
}
else if(pButton == m_pButtonChart)
{
ChangeAppDir("arff");
ChartController c;
c.RunModal();
ChangeAppDir("");
}
else if(pButton == m_pButtonPaint)
{
ChangeAppDir("images");
PaintController c;
c.RunModal();
ChangeAppDir("");
}
else if(pButton == m_pButtonRank)
{
RankController c;
c.RunModal();
}
else if(pButton == m_pButtonAgents)
{
AgentsMenuController c;
c.RunModal();
}
else if(pButton == m_pButtonVideo)
{
VideoController c;
c.RunModal();
}
else
GAssert(false, "unrecognized text button");
}
// -------------------------------------------------------------------------------
class MainMenuView : public ViewBase
{
protected:
MainMenuDialog* m_pDialog;
public:
MainMenuView(MainMenuController* pController);
virtual ~MainMenuView();
virtual void OnChar(char c);
virtual void OnMouseDown(int nButton, int x, int y);
virtual void OnMouseUp(int nButton, int x, int y);
virtual bool OnMousePos(int x, int y);
protected:
virtual void Draw(SDL_Surface *pScreen);
};
MainMenuView::MainMenuView(MainMenuController* pController)
: ViewBase()
{
m_pDialog = new MainMenuDialog(pController, m_screenRect.w, m_screenRect.h);
}
MainMenuView::~MainMenuView()
{
delete(m_pDialog);
}
/*virtual*/ void MainMenuView::Draw(SDL_Surface *pScreen)
{
// Clear the screen
SDL_FillRect(pScreen, NULL/*&r*/, 0x000000);
// Draw the dialog
BlitImage(pScreen, m_screenRect.x, m_screenRect.y, m_pDialog->GetImage());
}
void MainMenuView::OnChar(char c)
{
m_pDialog->HandleChar(c);
}
void MainMenuView::OnMouseDown(int nButton, int x, int y)
{
x -= m_screenRect.x;
y -= m_screenRect.y;
GWidgetAtomic* pNewWidget = m_pDialog->FindAtomicWidget(x, y);
m_pDialog->GrabWidget(pNewWidget, nButton, x, y);
}
void MainMenuView::OnMouseUp(int nButton, int x, int y)
{
m_pDialog->ReleaseWidget(nButton);
}
bool MainMenuView::OnMousePos(int x, int y)
{
return m_pDialog->HandleMousePos(x - m_screenRect.x, y - m_screenRect.y);
}
// -------------------------------------------------------------------------------
MainMenuController::MainMenuController()
: ControllerBase()
{
m_pView = new MainMenuView(this);
}
MainMenuController::~MainMenuController()
{
delete(m_pView);
}
void MainMenuController::RunModal()
{
double timeOld = GTime::GetTime();
double time;
m_pView->Update();
while(m_bKeepRunning)
{
time = GTime::GetTime();
if(HandleEvents(time - timeOld)) // HandleEvents returns true if it thinks the view needs to be updated
{
m_pView->Update();
}
else
GThread::sleep(10);
timeOld = time;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?