Added Scripts menu to Windows version:
- UI is Windows-specific, scripts directory scanner is cross-platform - First line of scripts is scanned for a Title: tag - celx and cel scripts added to the menuver1_5_1
parent
6cd138a92d
commit
583cb137bc
|
@ -28,6 +28,7 @@ OBJS=\
|
|||
$(INTDIR)\favorites.obj \
|
||||
$(INTDIR)\imagecapture.obj \
|
||||
$(INTDIR)\ODMenu.obj \
|
||||
$(INTDIR)\scriptmenu.obj \
|
||||
$(INTDIR)\url.obj \
|
||||
$(INTDIR)\wglext.obj \
|
||||
$(INTDIR)\wineclipses.obj \
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -209,11 +209,13 @@
|
|||
#define ID_VIEW_SINGLE 40070
|
||||
#define ID_VIEW_SHOW_FRAMES 40071
|
||||
#define ID_VIEW_SYNC_TIME 40072
|
||||
#define ID_FILE_SCRIPTS 40073
|
||||
#define ID_RENDER_STARSTYLE 40079
|
||||
#define ID_RENDER_STARSTYLE_FUZZY 40080
|
||||
#define ID_RENDER_STARSTYLE_POINTS 40081
|
||||
#define ID_RENDER_STARSTYLE_DISCS 40082
|
||||
#define ID_BOOKMARKS_FIRSTBOOKMARK 41000
|
||||
#define ID_FIRST_SCRIPT 42000
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
|
|
|
@ -0,0 +1,107 @@
|
|||
// scriptmenu.cpp
|
||||
//
|
||||
// Copyright (C) 2007, Chris Laurel <claurel@shatters.net>
|
||||
//
|
||||
// Scan a directory and build a list of Celestia script files.
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
|
||||
#include "scriptmenu.h"
|
||||
#include "celutil/directory.h"
|
||||
#include "celutil/filetype.h"
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
static const string TitleTag("Title:");
|
||||
|
||||
class ScriptScanner : public EnumFilesHandler
|
||||
{
|
||||
public:
|
||||
ScriptScanner() :
|
||||
menuItems(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
bool process(const string& filename)
|
||||
{
|
||||
if (
|
||||
#ifdef CELX
|
||||
DetermineFileType(filename) == Content_CelestiaScript ||
|
||||
#endif
|
||||
DetermineFileType(filename) == Content_CelestiaLegacyScript
|
||||
)
|
||||
{
|
||||
string filepath = getPath() + string("/") + filename;
|
||||
|
||||
// Scan the script file for metainformation. At the moment,
|
||||
// the only thing searched for is the script title, which must
|
||||
// appear on the first line after the string 'Title:'
|
||||
ifstream in(filepath.c_str());
|
||||
if (in.good())
|
||||
{
|
||||
ScriptMenuItem item;
|
||||
item.filename = filename;
|
||||
|
||||
// Read the first line, handling various newline conventions
|
||||
char firstLineBuf[512];
|
||||
int count = 0;
|
||||
while (count < sizeof(firstLineBuf) - 1 && in.good())
|
||||
{
|
||||
int c = in.get();
|
||||
if (c == '\n' || c == '\r')
|
||||
break;
|
||||
firstLineBuf[count++] = c;
|
||||
}
|
||||
|
||||
string firstLine(firstLineBuf, count);
|
||||
string::size_type titlePos = firstLine.find(TitleTag);
|
||||
|
||||
// Skip spaces after the Title: tag
|
||||
if (titlePos != string::npos)
|
||||
titlePos = firstLine.find_first_not_of(" ", titlePos + TitleTag.length());
|
||||
|
||||
if (titlePos != string::npos)
|
||||
{
|
||||
item.title = firstLine.substr(titlePos);
|
||||
}
|
||||
else
|
||||
{
|
||||
// No title tag--just use the filename
|
||||
item.title = filename;
|
||||
}
|
||||
|
||||
menuItems->push_back(item);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
vector<ScriptMenuItem>* menuItems;
|
||||
};
|
||||
|
||||
|
||||
|
||||
std::vector<ScriptMenuItem>*
|
||||
ScanScriptsDirectory(string scriptsDir, bool deep)
|
||||
{
|
||||
vector<ScriptMenuItem>* scripts = new vector<ScriptMenuItem>;
|
||||
if (scripts == NULL)
|
||||
return NULL;
|
||||
|
||||
Directory* dir = OpenDirectory(scriptsDir);
|
||||
|
||||
ScriptScanner scanner;
|
||||
scanner.menuItems = scripts;
|
||||
scanner.pushDir(scriptsDir);
|
||||
|
||||
dir->enumFiles(scanner, deep);
|
||||
|
||||
return scripts;
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
// scriptmenu.h
|
||||
//
|
||||
// Copyright (C) 2007, Chris Laurel <claurel@shatters.net>
|
||||
//
|
||||
// Scan a directory and build a list of Celestia script files.
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
struct ScriptMenuItem
|
||||
{
|
||||
std::string filename;
|
||||
std::string title;
|
||||
};
|
||||
|
||||
|
||||
std::vector<ScriptMenuItem>*
|
||||
ScanScriptsDirectory(std::string dirname, bool deep);
|
|
@ -1,6 +1,6 @@
|
|||
// winmain.cpp
|
||||
//
|
||||
// Copyright (C) 2001, Chris Laurel <claurel@shatters.net>
|
||||
// Copyright (C) 2001-2007, Chris Laurel <claurel@shatters.net>
|
||||
//
|
||||
// Windows front end for Celestia.
|
||||
//
|
||||
|
@ -53,6 +53,7 @@
|
|||
#include "wintime.h"
|
||||
#include "winsplash.h"
|
||||
#include "odmenu.h"
|
||||
#include "scriptmenu.h"
|
||||
|
||||
#include "res/resource.h"
|
||||
#include "wglext.h"
|
||||
|
@ -140,6 +141,10 @@ static const WPARAM ID_GOTO_URL = 62000;
|
|||
HWND hBookmarkTree;
|
||||
char bookmarkName[33];
|
||||
|
||||
static const string ScriptsDirectory = "scripts";
|
||||
static vector<ScriptMenuItem>* ScriptMenuItems = NULL;
|
||||
|
||||
|
||||
static LRESULT CALLBACK MainWindowProc(HWND hWnd,
|
||||
UINT uMsg,
|
||||
WPARAM wParam, LPARAM lParam);
|
||||
|
@ -167,8 +172,8 @@ struct AppPreferences
|
|||
string altSurfaceName;
|
||||
uint32 textureResolution;
|
||||
Renderer::StarStyle starStyle;
|
||||
GLContext::GLRenderPath renderPath;
|
||||
bool renderPathSet;
|
||||
GLContext::GLRenderPath renderPath;
|
||||
bool renderPathSet;
|
||||
};
|
||||
|
||||
void ChangeDisplayMode()
|
||||
|
@ -643,6 +648,16 @@ BOOL APIENTRY GLInfoProc(HWND hDlg,
|
|||
maxTextureSize);
|
||||
s += buf;
|
||||
|
||||
if (ExtensionSupported("GL_EXT_texture_cube_map"))
|
||||
{
|
||||
GLint maxCubeMapSize = 0;
|
||||
glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE_EXT, &maxCubeMapSize);
|
||||
sprintf(buf, "%s%d\r\r\n",
|
||||
UTF8ToCurrentCP(_("Max cube map size: ")).c_str(),
|
||||
maxTextureSize);
|
||||
s += buf;
|
||||
}
|
||||
|
||||
GLfloat pointSizeRange[2];
|
||||
glGetFloatv(GL_POINT_SIZE_RANGE, pointSizeRange);
|
||||
sprintf(buf, "%s%f - %f\r\r\n",
|
||||
|
@ -2118,6 +2133,45 @@ void handleKey(WPARAM key, bool down)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
static void BuildScriptsMenu(HMENU menuBar, const string& scriptsDir)
|
||||
{
|
||||
HMENU fileMenu = GetSubMenu(menuBar, 0);
|
||||
|
||||
if (ScriptMenuItems != NULL)
|
||||
delete ScriptMenuItems;
|
||||
|
||||
ScriptMenuItems = ScanScriptsDirectory(scriptsDir, false);
|
||||
if (ScriptMenuItems == NULL || ScriptMenuItems->size() == 0)
|
||||
{
|
||||
EnableMenuItem(fileMenu, ID_FILE_SCRIPTS, MF_GRAYED);
|
||||
return;
|
||||
}
|
||||
|
||||
MENUITEMINFO info;
|
||||
memset(&info, sizeof(info), 0);
|
||||
info.cbSize = sizeof(info);
|
||||
info.fMask = MIIM_SUBMENU;
|
||||
|
||||
BOOL result = GetMenuItemInfo(fileMenu, 1, TRUE, &info);
|
||||
|
||||
if (result)
|
||||
{
|
||||
HMENU scriptMenu = info.hSubMenu;
|
||||
|
||||
// Remove the old menu items
|
||||
int count = GetMenuItemCount(scriptMenu);
|
||||
while (count-- > 0)
|
||||
DeleteMenu(scriptMenu, 0, MF_BYPOSITION);
|
||||
|
||||
for (unsigned int i = 0; i < ScriptMenuItems->size(); i++)
|
||||
{
|
||||
AppendMenu(scriptMenu, MF_STRING, ID_FIRST_SCRIPT + i, (*ScriptMenuItems)[i].title.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void syncMenusWithRendererState()
|
||||
{
|
||||
int renderFlags = appCore->getRenderer()->getRenderFlags();
|
||||
|
@ -3302,6 +3356,7 @@ int APIENTRY WinMain(HINSTANCE hInstance,
|
|||
}
|
||||
|
||||
BuildFavoritesMenu(menuBar, appCore, appInstance, &odAppMenu);
|
||||
BuildScriptsMenu(menuBar, ScriptsDirectory);
|
||||
syncMenusWithRendererState();
|
||||
|
||||
appCore->setContextMenuCallback(ContextMenu);
|
||||
|
@ -4181,6 +4236,13 @@ LRESULT CALLBACK MainWindowProc(HWND hWnd,
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (LOWORD(wParam) >= ID_FIRST_SCRIPT &&
|
||||
LOWORD(wParam) < ID_FIRST_SCRIPT + ScriptMenuItems->size())
|
||||
{
|
||||
// Handle the script menu
|
||||
unsigned int scriptIndex = LOWORD(wParam) - ID_FIRST_SCRIPT;
|
||||
appCore->runScript(ScriptsDirectory + "/" + (*ScriptMenuItems)[scriptIndex].filename);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue