| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326 |
- /*
- Copyright (C) 2011 by Ivan Safrin
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- */
- #pragma once
- #include "PolyGlobals.h"
- #include "PolyString.h"
- #include "PolyRectangle.h"
- #include "PolyVector2.h"
- #include "PolyEventDispatcher.h"
- #include "PolyCoreInput.h"
- #include "PolyCoreServices.h"
- #include "PolyThreaded.h"
- #define CURSOR_ARROW 0
- #define CURSOR_TEXT 1
- #define CURSOR_POINTER 2
- #define CURSOR_CROSSHAIR 3
- #define CURSOR_RESIZE_LEFT_RIGHT 4
- #define CURSOR_RESIZE_UP_DOWN 5
- long getThreadID();
- namespace Polycode {
- class Renderer;
- class _PolyExport CoreMutex {
- public:
- int mutexID;
- };
-
- class _PolyExport CoreFileExtension {
- public:
- String extension;
- String description;
- };
-
- class _PolyExport PolycodeViewBase {
- public:
- PolycodeViewBase() { windowData = NULL; }
- virtual ~PolycodeViewBase(){}
- void *windowData;
- };
- /**
- * The main core of the framework. The core deals with system-level functions, such as window initialization and OS interaction. Each platform has its own implementation of this base class. NOTE: SOME OF THE FUNCTIONALITY IN THE CORE IS NOT FULLY IMPLEMENTED!!
- */
- class _PolyExport Core : public EventDispatcher {
- public:
-
- /**
- * Constructor.
- * @param xRes Inital horizontal resolution of the renderer.
- * @param yRes Inital vertical resolution of the renderer.
- * @param fullScreen True to launch in fullscreen, false to launch in window.
- * @param aaLevel Level of anti-aliasing. Possible values are 2,4 and 6.
- * @param frameRate Frame rate that the core will update and render at.
- * @param monitorIndex If fullScreen is true, the monitor index to fullscreen to. Pass -1 to use primary monitor.
- */
- Core(int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel, int frameRate, int monitorIndex);
- virtual ~Core();
-
- virtual bool Update() = 0;
-
- /**
- * Show or hide cursor.
- * @param newval True to show mouse, false to hide it.
- */
- virtual void enableMouse(bool newval);
-
- /**
- * Sets the cursor the application is using.
- * @param cursorType Type of cursor to use. Possible values are CURSOR_ARROW, CURSOR_TEXT, CURSOR_POINTER, CURSOR_CROSSHAIR, CURSOR_RESIZE_LEFT_RIGHT, CURSOR_RESIZE_UP_DOWN
- */
- virtual void setCursor(int cursorType) = 0;
-
- /**
- * Launches a Threaded class into its own thread. See the documentation for Threaded for information on how to crated threaded classes.
- * @param target Target threaded class.
- * @see Threaded
- */
- virtual void createThread(Threaded *target) = 0;
- /**
- * Locks a mutex.
- * @param mutex Mutex to lock.
- */
- virtual void lockMutex(CoreMutex *mutex) = 0;
-
- /**
- * Unlocks a mutex.
- * @param mutex Mutex to lock.
- */
- virtual void unlockMutex(CoreMutex *mutex) = 0;
-
- /**
- * Creates a mutex
- * @return Newly created mutex.
- */
- virtual CoreMutex *createMutex() = 0;
-
- /**
- * Copies the specified string to system clipboard.
- * @param str String to copy to clipboard.
- */
- virtual void copyStringToClipboard(const String& str) = 0;
-
- /**
- * Returns the system clipboard as a string.
- * @return String from clipboard.
- */
- virtual String getClipboardString() = 0;
-
- /**
- * Returns the core services. See CoreServices for a detailed explanation of services.
- * @return Core services.
- @see CoreServices
- */
- CoreServices *getServices();
-
- /**
- * Returns the current average frames per second.
- * @return Current average frames per second.
- */
- Number getFPS();
-
- /**
- * Shuts down the core and quits the application.
- */
- void Shutdown();
- /**
- * Checks if core is in fullscreen mode.
- * @return True if in full screen, false if otherwise.
- */
- bool isFullscreen(){ return fullScreen; }
-
- /**
- * Returns the current anti-aliasing level.
- * @return Current anti-aliasing level.
- */
- int getAALevel() { return aaLevel; }
- /**
- * Returns the input class. See CoreInput for details in input.
- * @return Input class.
- * @see CoreInput
- */
- CoreInput *getInput();
-
- /**
- * Returns current horizontal resolution.
- * @return Current horizontal resolution.
- */
- Number getXRes();
-
- /**
- * Returns current vertical resolution.
- * @return Current vertical resolution.
- */
- Number getYRes();
-
- // deprecated
- int getNumVideoModes();
-
- /**
- * Returns the available system video modes.
- * @return An STL vector of video modes.
- */
- virtual std::vector<Rectangle> getVideoModes() = 0;
-
- /**
- * Creates a folder on disk with the specified path.
- * @param folderPath Path to create the folder in.
- */
- virtual void createFolder(const String& folderPath) = 0;
-
- /**
- * Copies a disk item from one path to another
- * @param itemPath Path to the item to copy.
- * @param destItemPath Destination path to copy to.
- */
- virtual void copyDiskItem(const String& itemPath, const String& destItemPath) = 0;
-
- /**
- * Moves a disk item from one path to another
- * @param itemPath Path to the item to move.
- * @param destItemPath Destination path to move to.
- */
- virtual void moveDiskItem(const String& itemPath, const String& destItemPath) = 0;
-
- /**
- * Removes a disk item.
- * @param itemPath Path to the item to remove.
- */
- virtual void removeDiskItem(const String& itemPath) = 0;
- /**
- * Opens a system folder picker and suspends operation.
- * @return The selected path returned from the picker.
- */
- virtual String openFolderPicker() = 0;
-
- /**
- * Opens a system file picker for the specified extensions.
- * @param extensions An STL vector containing the allowed file extensions that can be selected.
- * @param allowMultiple If set to true, the picker can select multiple files.
- * @return An STL vector of the selected file paths.
- */
- virtual std::vector<String> openFilePicker(std::vector<CoreFileExtension> extensions, bool allowMultiple) = 0;
-
- void setVideoModeIndex(int index, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel);
-
- /**
- * Sets a new video mode.
- * @param xRes New horizontal resolution of the renderer.
- * @param yRes New vertical resolution of the renderer.
- * @param fullScreen True to launch in fullscreen, false to launch in window.
- * @param aaLevel Level of anti-aliasing. Possible values are 2,4 and 6.
- */
- virtual void setVideoMode(int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel) = 0;
-
- /**
- * Resizes the renderer.
- * @param xRes New horizontal resolution of the renderer.
- * @param yRes New vertical resolution of the renderer.
- */
- virtual void resizeTo(int xRes, int yRes) = 0;
-
- void doSleep();
-
- /**
- * Returns the time elapsed since last frame.
- * @return Time elapsed since last frame in floating point microseconds.
- */
- Number getElapsed();
-
- /**
- * Returns the total ticks elapsed since launch.
- * @return Time elapsed since launch in milliseconds
- */
- virtual unsigned int getTicks() = 0;
-
- /**
- * Returns the total ticks elapsed since launch.
- * @return Time elapsed since launch in floating point microseconds.
- */
- Number getTicksFloat();
-
- void setUserPointer(void *ptr) { userPointer = ptr; }
- void *getUserPointer() { return userPointer; }
-
- static const int EVENT_CORE_RESIZE = 0;
-
- /**
- * Returns the default working path of the application.
- */
- String getDefaultWorkingDirectory();
-
- /**
- * Returns the default working path of the application.
- */
- String getUserHomeDirectory();
-
- protected:
-
- String userHomeDirectory;
- String defaultWorkingDirectory;
-
- void *userPointer;
-
- long refreshInterval;
-
- bool fullScreen;
- int aaLevel;
-
- std::vector<Vector2> videoModes;
- void updateCore();
- int numVideoModes;
-
- bool running;
- Number fps;
- unsigned int frameTicks;
- unsigned int lastFrameTicks;
- unsigned int lastFPSTicks;
- unsigned int elapsed;
-
- bool mouseEnabled;
-
- unsigned int lastSleepFrameTicks;
-
- int xRes;
- int yRes;
-
- int monitorIndex;
-
- int frames;
-
- CoreInput *input;
- Renderer *renderer;
- CoreServices *services;
- };
-
- }
|