1 /*
2  * definitions for the system dependent part of simutrans
3  *
4  * This file is part of the Simutrans project under the artistic license.
5  */
6 
7 #ifndef simsys_h
8 #define simsys_h
9 
10 #include <stddef.h>
11 #include "simtypes.h"
12 #include <zlib.h>
13 
14 // Provide chdir().
15 #if defined(_WIN32) && !defined(__CYGWIN__)
16 #	include <direct.h>
17 #else
18 #	include <unistd.h>
19 #endif
20 
21 /* Variable for message processing */
22 
23 /* Classes */
24 
25 #define SIM_NOEVENT         0
26 #define SIM_MOUSE_BUTTONS   1
27 #define SIM_KEYBOARD        2
28 #define SIM_MOUSE_MOVE      3
29 #define SIM_STRING          4
30 #define SIM_SYSTEM          254
31 #define SIM_IGNORE_EVENT    255
32 
33 /* Actions */ /* added RIGHTUP and MIDUP */
34 #define SIM_MOUSE_LEFTUP            1
35 #define SIM_MOUSE_RIGHTUP           2
36 #define SIM_MOUSE_MIDUP             3
37 #define SIM_MOUSE_LEFTBUTTON        4
38 #define SIM_MOUSE_RIGHTBUTTON       5
39 #define SIM_MOUSE_MIDBUTTON         6
40 #define SIM_MOUSE_MOVED             7
41 #define SIM_MOUSE_WHEELUP           8 //2003-11-04 hsiegeln added
42 #define SIM_MOUSE_WHEELDOWN         9 //2003-11-04 hsiegeln added
43 
44 /* Global Variable for message processing */
45 
46 struct sys_event
47 {
48 	unsigned long type;
49 	union {
50 		unsigned long code;
51 		void *ptr;
52 	};
53 	int mx;                  /* es sind negative Koodinaten mgl */
54 	int my;
55 	int mb;
56 	/**
57 	 * new window size for SYSTEM_RESIZE
58 	 */
59 	int size_x, size_y;
60 	unsigned int key_mod; /* key mod, like ALT, STRG, SHIFT */
61 };
62 
63 extern struct sys_event sys_event;
64 
65 extern char const PATH_SEPARATOR[];
66 
67 // scale according to dpi setting
68 bool dr_auto_scale(bool);
69 
70 bool dr_os_init(int const* parameter);
71 
72 /* maximum size possible (if there) */
73 struct resolution
74 {
75 	int w;
76 	int h;
77 };
78 resolution dr_query_screen_resolution();
79 
80 int dr_os_open(int w, int h, int fullscreen);
81 void dr_os_close();
82 
83 // returns the locale; NULL if unknown
84 const char *dr_get_locale_string();
85 
86 // Functions the same as normal mkdir except path must be UTF-8 encoded and a default mode of 0777 is assumed.
87 int dr_mkdir(char const* path);
88 
89 /**
90  * Moves the specified file to the system's trash bin.
91  * If trash is not available on the platform, removes file.
92  * @param path UTF-8 path to the file to delete.
93  * @return False on success.
94  */
95 bool dr_movetotrash(const char *path);
96 
97 /**
98  * Returns true if platform supports recycle bin, otherwise false.
99  * Used to control which UI tooltip is shown for deletion.
100  */
101 bool dr_cantrash();
102 
103 // Functions the same as cstdio remove except path must be UTF-8 encoded.
104 int dr_remove(const char *path);
105 
106 // rename a file and delete eventually existing file new_utf8
107 int dr_rename( const char *existing_utf8, const char *new_utf8 );
108 
109 // Functions the same as chdir except path must be UTF-8 encoded.
110 int dr_chdir(const char *path);
111 
112 // Functions the same as getcwd except path must be UTF-8 encoded.
113 char *dr_getcwd(char *buf, size_t size);
114 
115 // Functions the same as fopen except filename must be UTF-8 encoded.
116 FILE *dr_fopen(const char *filename, const char *mode);
117 
118 // Functions the same as gzopen except path must be UTF-8 encoded.
119 gzFile dr_gzopen(const char *path, const char *mode);
120 
121 // Functions the same as stat except path must be UTF-8 encoded.
122 int dr_stat(const char *path, struct stat *buf);
123 
124 /* query home directory */
125 char const* dr_query_homedir();
126 
127 unsigned short* dr_textur_init();
128 
129 // returns the file path to a font file (or more than one, if used with number higher than zero)
130 const char *dr_query_fontpath( int );
131 
132 void dr_textur(int xp, int yp, int w, int h);
133 
134 /* returns the actual width (might be larger than requested! */
135 int dr_textur_resize(unsigned short** textur, int w, int h);
136 
137 // needed for screen update
138 void dr_prepare_flush();	// waits, if previous update not yet finished
139 void dr_flush();	// copy to screen (eventually multithreaded)
140 
141 /**
142  * Transform a 24 bit RGB color into the system format.
143  * @return converted color value
144  * @author Hj. Malthaner
145  */
146 unsigned int get_system_color(unsigned int r, unsigned int g, unsigned int b);
147 
148 void show_pointer(int yesno);
149 
150 void set_pointer(int loading);
151 
152 void move_pointer(int x, int y);
153 
154 int get_mouse_x();
155 int get_mouse_y();
156 
157 void ex_ord_update_mx_my();
158 
159 void GetEvents();
160 void GetEventsNoWait();
161 
162 uint32 dr_time();
163 void dr_sleep(uint32 millisec);
164 
165 // error message in case of fatal events
166 void dr_fatal_notify(char const* msg);
167 
168 /**
169  * Some wrappers can save screenshots.
170  * @return 1 on success, 0 if not implemented for a particular wrapper and -1
171  *         in case of error.
172  * @author Hj. Malthaner
173  */
174 int dr_screenshot(const char *filename, int x, int y, int w, int h);
175 
176 /**
177  * Copy text to the clipboard
178  * @param source : pointer to the start of the source text
179  * @param length : number of character bytes to copy
180  * @author Knightly
181  */
182 void dr_copy(const char *source, size_t length);
183 
184 /**
185  * Paste text from the clipboard
186  * @param target : pointer to the insertion position in the target text
187  * @param max_length : maximum number of character bytes which could be inserted
188  * @return number of character bytes actually inserted -> for cursor advancing
189  * @author Knightly
190  */
191 size_t dr_paste(char *target, size_t max_length);
192 
193 /**
194  * Open a program/starts a script to download pak sets from sourceforge
195  * @param path_to_program : actual simutrans pakfile directory
196  * @param portabel : true if local files to be save in simutransdir
197  * @return false, if nothing was downloaded
198  */
199 bool dr_download_pakset( const char *path_to_program, bool portable );
200 
201 /**
202  * Shows the touch keyboard when using systems without a hardware keyboard.
203  * Will be ignored if there is an hardware keyboard available.
204  */
205 void dr_start_textinput();
206 
207 /**
208  * Hides the touch keyboard when using systems without a hardware keyboard.
209  * Will be ignored it there is no on-display keyboard shown.
210  */
211 void dr_stop_textinput();
212 
213 /**
214  * Inform the IME of a ideal place to open its popup.
215  */
216 void dr_notify_input_pos(int x, int y);
217 
218 int sysmain(int argc, char** argv);
219 
220 #endif
221