2006-04-12 01:59:08 +02:00
|
|
|
/**
|
|
|
|
* =========================================================================
|
|
|
|
* File : sysdep.h
|
|
|
|
* Project : 0 A.D.
|
|
|
|
* Description : various system-specific function implementations
|
|
|
|
*
|
|
|
|
* @author Jan.Wassenberg@stud.uni-karlsruhe.de
|
|
|
|
* =========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2007-04-30 16:35:19 +02:00
|
|
|
* Copyright (c) 2003-2007 Jan Wassenberg
|
2006-04-12 01:59:08 +02:00
|
|
|
*
|
|
|
|
* Redistribution and/or modification are also permitted under the
|
|
|
|
* terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation (version 2 or later, at your option).
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*/
|
|
|
|
|
2007-04-30 16:35:19 +02:00
|
|
|
#ifndef INCLUDED_SYSDEP
|
|
|
|
#define INCLUDED_SYSDEP
|
2004-03-03 00:56:51 +01:00
|
|
|
|
2006-06-22 20:26:08 +02:00
|
|
|
#include "lib/debug.h" // ErrorReaction
|
2006-09-04 22:59:21 +02:00
|
|
|
|
2007-04-30 21:58:04 +02:00
|
|
|
#include <cstdarg> // needed for sys_vsnprintf
|
2004-07-13 00:05:49 +02:00
|
|
|
|
2006-08-04 11:30:43 +02:00
|
|
|
|
2005-08-09 18:23:19 +02:00
|
|
|
//
|
|
|
|
// output
|
|
|
|
//
|
2004-03-03 00:56:51 +01:00
|
|
|
|
2005-12-10 08:04:31 +01:00
|
|
|
// raise a message box with the given text or (depending on platform)
|
|
|
|
// otherwise inform the user.
|
2005-12-12 20:19:30 +01:00
|
|
|
// called from debug_display_msgw.
|
2005-12-07 04:38:39 +01:00
|
|
|
extern void sys_display_msg(const char* caption, const char* msg);
|
|
|
|
extern void sys_display_msgw(const wchar_t* caption, const wchar_t* msg);
|
2005-12-12 20:19:30 +01:00
|
|
|
|
2006-06-22 20:26:08 +02:00
|
|
|
// show the error dialog. flags: see DebugDisplayErrorFlags.
|
2005-12-12 20:19:30 +01:00
|
|
|
// called from debug_display_error.
|
2006-06-22 20:26:08 +02:00
|
|
|
// can be overridden by means of ah_display_error.
|
|
|
|
extern ErrorReaction sys_display_error(const wchar_t* text, uint flags);
|
2004-03-03 00:56:51 +01:00
|
|
|
|
2004-03-03 01:37:41 +01:00
|
|
|
|
2005-08-09 18:23:19 +02:00
|
|
|
//
|
|
|
|
// clipboard
|
|
|
|
//
|
|
|
|
|
2005-12-07 04:38:39 +01:00
|
|
|
// "copy" text into the clipboard. replaces previous contents.
|
2005-12-11 23:23:55 +01:00
|
|
|
extern LibError sys_clipboard_set(const wchar_t* text);
|
2005-12-07 04:38:39 +01:00
|
|
|
|
|
|
|
// allow "pasting" from clipboard. returns the current contents if they
|
|
|
|
// can be represented as text, otherwise 0.
|
|
|
|
// when it is no longer needed, the returned pointer must be freed via
|
|
|
|
// sys_clipboard_free. (NB: not necessary if zero, but doesn't hurt)
|
|
|
|
extern wchar_t* sys_clipboard_get(void);
|
|
|
|
|
|
|
|
// frees memory used by <copy>, which must have been returned by
|
|
|
|
// sys_clipboard_get. see note above.
|
2005-12-11 23:23:55 +01:00
|
|
|
extern LibError sys_clipboard_free(wchar_t* copy);
|
2004-07-13 23:17:26 +02:00
|
|
|
|
|
|
|
|
2005-08-09 18:23:19 +02:00
|
|
|
//
|
|
|
|
// mouse cursor
|
|
|
|
//
|
|
|
|
|
2005-08-10 02:27:56 +02:00
|
|
|
// note: these do not warn on error; that is left to the caller.
|
|
|
|
|
2005-12-07 04:38:39 +01:00
|
|
|
// creates a cursor from the given image.
|
|
|
|
// w, h specify image dimensions [pixels]. limit is implementation-
|
|
|
|
// dependent; 32x32 is typical and safe.
|
|
|
|
// bgra_img is the cursor image (BGRA format, bottom-up).
|
|
|
|
// it is no longer needed and can be freed after this call returns.
|
2005-09-29 07:00:20 +02:00
|
|
|
// hotspot (hx,hy) is the offset from its upper-left corner to the
|
2005-12-07 04:38:39 +01:00
|
|
|
// position where mouse clicks are registered.
|
2006-09-22 15:19:40 +02:00
|
|
|
// cursor is only valid when INFO::OK is returned; in that case, it must be
|
2006-04-24 07:20:14 +02:00
|
|
|
// sys_cursor_free-ed when no longer needed.
|
2005-12-11 23:23:55 +01:00
|
|
|
extern LibError sys_cursor_create(uint w, uint h, void* bgra_img,
|
2005-09-29 07:00:20 +02:00
|
|
|
uint hx, uint hy, void** cursor);
|
2005-08-09 18:23:19 +02:00
|
|
|
|
2006-03-06 04:46:12 +01:00
|
|
|
// create a fully transparent cursor (i.e. one that when passed to set hides
|
|
|
|
// the system cursor)
|
|
|
|
extern LibError sys_cursor_create_empty(void **cursor);
|
|
|
|
|
2005-08-09 18:23:19 +02:00
|
|
|
// replaces the current system cursor with the one indicated. need only be
|
|
|
|
// called once per cursor; pass 0 to restore the default.
|
2005-12-11 23:23:55 +01:00
|
|
|
extern LibError sys_cursor_set(void* cursor);
|
2005-08-09 18:23:19 +02:00
|
|
|
|
|
|
|
// destroys the indicated cursor and frees its resources. if it is
|
|
|
|
// currently the system cursor, the default cursor is restored first.
|
2005-12-11 23:23:55 +01:00
|
|
|
extern LibError sys_cursor_free(void* cursor);
|
2005-08-09 18:23:19 +02:00
|
|
|
|
|
|
|
|
2005-12-07 04:38:39 +01:00
|
|
|
//
|
|
|
|
// misc
|
|
|
|
//
|
2005-09-14 18:58:10 +02:00
|
|
|
|
2007-04-30 21:58:04 +02:00
|
|
|
// sys_vsnprintf: doesn't quite follow the standard for vsnprintf, but works
|
|
|
|
// better across compilers:
|
|
|
|
// - handles positional parameters and %lld
|
|
|
|
// - always null-terminates the buffer
|
|
|
|
// - returns -1 on overflow (if the output string (including null) does not fit in the buffer)
|
|
|
|
extern int sys_vsnprintf(char* buffer, size_t count, const char* format, va_list argptr);
|
|
|
|
|
|
|
|
|
2006-06-23 19:41:55 +02:00
|
|
|
// describe the current OS error state.
|
|
|
|
//
|
|
|
|
// err: if not 0, use that as the error code to translate; otherwise,
|
|
|
|
// uses GetLastError or similar.
|
|
|
|
// rationale: it is expected to be rare that OS return/error codes are
|
|
|
|
// actually seen by user code, but we leave the possibility open.
|
2005-12-11 23:23:55 +01:00
|
|
|
extern LibError sys_error_description_r(int err, char* buf, size_t max_chars);
|
2005-11-19 19:12:16 +01:00
|
|
|
|
2005-12-07 04:38:39 +01:00
|
|
|
// determine filename of the module to whom the given address belongs.
|
|
|
|
// useful for handling exceptions in other modules.
|
|
|
|
// <path> receives full path to module; it must hold at least MAX_PATH chars.
|
|
|
|
// on error, it is set to L"".
|
|
|
|
// return path for convenience.
|
|
|
|
wchar_t* sys_get_module_filename(void* addr, wchar_t* path);
|
|
|
|
|
|
|
|
// store full path to the current executable.
|
|
|
|
// useful for determining installation directory, e.g. for VFS.
|
2005-12-11 23:23:55 +01:00
|
|
|
extern LibError sys_get_executable_name(char* n_path, size_t buf_size);
|
2005-12-07 04:38:39 +01:00
|
|
|
|
|
|
|
// have the user specify a directory via OS dialog.
|
|
|
|
// stores its full path in the given buffer, which must hold at least
|
|
|
|
// PATH_MAX chars.
|
2005-12-11 23:23:55 +01:00
|
|
|
extern LibError sys_pick_directory(char* n_path, size_t buf_size);
|
2005-12-07 04:38:39 +01:00
|
|
|
|
2004-06-03 03:43:33 +02:00
|
|
|
|
|
|
|
|
2004-08-18 04:13:53 +02:00
|
|
|
|
2006-04-03 03:00:45 +02:00
|
|
|
// return the largest sector size [bytes] of any storage medium
|
|
|
|
// (HD, optical, etc.) in the system.
|
|
|
|
//
|
|
|
|
// this may be a bit slow to determine (iterates over all drives),
|
|
|
|
// but caches the result so subsequent calls are free.
|
|
|
|
// (caveat: device changes won't be noticed during this program run)
|
|
|
|
//
|
|
|
|
// sector size is relevant because Windows aio requires all IO
|
|
|
|
// buffers, offsets and lengths to be a multiple of it. this requirement
|
|
|
|
// is also carried over into the vfs / file.cpp interfaces for efficiency
|
|
|
|
// (avoids the need for copying to/from align buffers).
|
|
|
|
//
|
|
|
|
// waio uses the sector size to (in some cases) align IOs if
|
|
|
|
// they aren't already, but it's also needed by user code when
|
|
|
|
// aligning their buffers to meet the requirements.
|
|
|
|
//
|
|
|
|
// the largest size is used so that we can read from any drive. while this
|
|
|
|
// is a bit wasteful (more padding) and requires iterating over all drives,
|
|
|
|
// it is the only safe way: this may be called before we know which
|
|
|
|
// drives will be needed, and hardlinks may confuse things.
|
|
|
|
extern size_t sys_max_sector_size();
|
|
|
|
|
2006-03-15 06:18:32 +01:00
|
|
|
#if OS_WIN
|
2006-11-18 18:48:49 +01:00
|
|
|
# define SYS_DIR_SEP '\\'
|
2006-03-15 06:18:32 +01:00
|
|
|
#else
|
2006-11-18 18:48:49 +01:00
|
|
|
# define SYS_DIR_SEP '/'
|
2006-03-15 06:18:32 +01:00
|
|
|
#endif
|
|
|
|
|
2007-04-30 16:35:19 +02:00
|
|
|
#endif // #ifndef INCLUDED_SYSDEP
|