5 // Key to character mapping
6 static byte characters[2][128] =
9 128,128,'1','2','3','4','5','6','7','8','9','0','-','=',128,128,
10 'q','w','e','r','t','y','u','i','o','p','[',']',128,128,'a','s',
11 'd','f','g','h','j','k','l',';','\'','`',128,'\\','z','x','c','v',
12 'b','n','m',',','.','/',128,'*',128,' ',128,128,128,128,128,128,
13 128,128,128,128,128,128,128,'7','8','9','-','4','5','6','+','1',
14 '2','3','0',128,128,128,128,128,128,128,128,128,128,128,128,128,
15 128,128,'/',128,128,128,128,128,128,128,128,128,128,128,128,128,
16 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128
19 128,128,'!','@','#','$','%','^','&','*','(',')','_','+',128,128,
20 'Q','W','E','R','T','Y','U','I','O','P','{','}',128,128,'A','S',
21 'D','F','G','H','J','K','L',':','"','~',128,'|','Z','X','C','V',
22 'B','N','M','<','>','?',128,'*',128,' ',128,128,128,128,128,128,
23 128,128,128,128,128,128,128,'7','8','9','-','4','5','6','+','1',
24 '2','3','0',128,128,128,128,128,128,128,128,128,128,128,128,128,
25 128,128,'/',128,128,128,128,128,128,128,128,128,128,128,128,128,
26 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128
30 public struct Joystick
39 public class Interface
42 class_data const char * name;
44 class_property const char * name
46 set { class_data(name) = value; }
47 get { return class_data(name); }
50 // --- User Interface System ---
51 virtual bool ::Initialize();
52 virtual void ::Terminate();
53 virtual bool ::ProcessInput(bool processAll);
54 virtual void ::Wait();
55 virtual void ::Lock(Window window);
56 virtual void ::Unlock(Window window);
57 virtual void ::SetTimerResolution(uint hertz);
59 virtual const char ** ::GraphicsDrivers(int * numDrivers);
60 virtual void ::EnsureFullScreen(bool * fullScreen);
61 virtual void ::GetCurrentMode(bool * fullScreen, Resolution * resolution, PixelFormat * colorDepth, int * refreshRate);
62 virtual bool ::ScreenMode(bool fullScreen, Resolution resolution, PixelFormat colorDepth, int refreshRate, bool * textMode);
64 // --- Window Creation ---
65 virtual void * ::CreateRootWindow(Window window);
66 virtual void ::DestroyRootWindow(Window window);
68 // --- Window manipulation ---
69 virtual void ::SetRootWindowCaption(Window window, const char * name);
70 virtual void ::PositionRootWindow(Window window, int x, int y, int w, int h, bool move, bool resize);
71 virtual void ::OffsetWindow(Window window, int * x, int * y);
72 virtual void ::UpdateRootWindow(Window window);
73 virtual void ::SetRootWindowState(Window window, WindowState state, bool visible);
74 virtual void ::ActivateRootWindow(Window window);
75 virtual void ::OrderRootWindow(Window window, bool topMost);
76 virtual void ::SetRootWindowColor(Window window);
77 virtual void ::FlashRootWindow(Window window);
79 // --- Mouse-based window movement ---
80 virtual void ::StartMoving(Window window, int x, int y, bool fromKeyBoard);
81 virtual void ::StopMoving(Window window);
83 // --- Mouse manipulation ---
84 virtual void ::GetMousePosition(int *x, int *y);
85 virtual void ::SetMousePosition(int x, int y);
86 virtual void ::SetMouseRange(Window window, Box box);
87 virtual void ::SetMouseCapture(Window window);
89 // --- Mouse cursor ---
90 virtual void ::SetMouseCursor(Window window, SystemCursor cursor);
92 // --- Caret manipulation ---
93 virtual void ::SetCaret(int caretX, int caretY, int size);
95 // --- Clipboard manipulation ---
96 virtual void ::ClearClipboard();
97 virtual bool ::AllocateClipboard(ClipBoard clipBoard, uint size);
98 virtual bool ::SaveClipboard(ClipBoard clipBoard);
99 virtual bool ::LoadClipboard(ClipBoard clipBoard);
100 virtual void ::UnloadClipboard(ClipBoard clipBoard);
102 // --- State based input ---
103 virtual bool ::AcquireInput(Window window, bool state);
104 virtual bool ::GetMouseState(MouseButtons * buttons, int * x, int * y);
105 virtual bool ::GetJoystickState(int device, Joystick joystick);
106 virtual bool ::GetKeyState(Key key);
108 virtual bool ::SetIcon(Window window, BitmapResource icon);
109 virtual void ::GetScreenArea(Window window, Box box);
111 Key ::GetExtendedKey(Key key)
115 case keyPadHome: return home;
116 case keyPadUp: return up;
117 case keyPadPageUp: return pageUp;
118 case keyPadLeft: return left;
119 case keyPadRight: return right;
120 case keyPadEnd: return end;
121 case keyPadDown: return down;
122 case keyPadPageDown: return pageDown;
123 case keyPadInsert: return insert;
124 case keyPadDelete: return del;
125 case enter: return keyPadEnter;
126 case leftControl: return rightControl;
127 case leftAlt: return rightAlt;
128 case slash: return keyPadSlash;
129 case numLock: return numLock;
130 case scrollLock: return pauseBreak;
135 void ::WriteKeyedTextDisabled(Surface surface, int x, int y, const char *text, Key hotKey, bool disabled)
139 char * tab = strstr(text, "\t");
140 bool opacity = surface.textOpacity;
144 surface.SetForeground(guiApp.currentSkin.disabledFrontColor);
148 int len = strlen(tab+1),tw;
149 surface.TextExtent(tab+1, strlen(tab + 1), &tw, null);
153 surface.SetForeground(guiApp.currentSkin.disabledBackColor);
154 surface.WriteText(x+1,y+1, text,tab-text);
155 surface.WriteText(surface.width - 3 - tw - 12 + 1, y + 1,tab+1,len);
156 surface.SetForeground(guiApp.currentSkin.disabledFrontColor );
158 surface.TextOpacity(false);
160 surface.TextOpacity(false);
161 surface.WriteText(x,y, text,tab-text);
162 surface.WriteText(surface.width - 3 - tw - 12, y,tab+1,len);
163 surface.TextOpacity(opacity);
169 surface.SetForeground(guiApp.currentSkin.disabledBackColor);
170 surface.WriteText(x+1,y+1, text,strlen(text));
171 surface.SetForeground(guiApp.currentSkin.disabledFrontColor);
172 surface.TextOpacity(false);
174 surface.WriteText(x,y, text, strlen(text));
175 surface.TextOpacity(opacity);
182 char * tab = strchr(text, '\t');
184 // Look for an uppercase letter starting a word
186 ch = isalpha(characters[1][hotKey.code]) ? characters[1][hotKey.code] : characters[0][hotKey.code];
187 for(c = 0; text[c] && text[c] != '\t'; c++)
189 if(toupper(text[c]) == ch && firstLetter)
191 else if(text[c] == ' ')
197 // Look for an uppercase letter anywhere
198 if(!text[c] || text[c] == '\t')
200 char * string = strchr(text, ch);
201 if(string && (!tab || string < tab)) c = string - text;
204 // Look for a lowercase letter starting a word
205 if(!text[c] || text[c] == '\t')
208 ch = characters[0][hotKey.code];
209 for(c = 0; text[c] && text[c] != '\t'; c++)
211 if(tolower(text[c]) == ch && firstLetter)
213 else if(text[c] == ' ')
220 // Look for a lowercase letter anywhere
221 if(!text[c] || text[c] == '\t')
223 char * string = strchr(text, characters[0][hotKey.code]);
224 if(string && (!tab || string < tab)) c = string - text;
227 if(text[c] && text[c] != '\t')
230 surface.TextExtent(text, (int)c, &tw, null);
231 surface.TextExtent(text + c, 1, &cw, &ch);
236 surface.SetForeground(guiApp.currentSkin.disabledBackColor);
237 surface.HLine(x + tw + 1, x + tw + cw-1 + 1, y + ch-1 + 1);
238 surface.SetForeground(guiApp.currentSkin.disabledFrontColor);
240 surface.HLine(x + tw, x + tw + cw-1, y + ch-1);
244 surface.SetForeground(Color { 255,255,85 });
245 surface.WriteText(x + c * textCellW, y, text + c, 1);
252 void ::WriteKeyedText(Surface surface, int x, int y, const char *text, Key hotKey)
254 WriteKeyedTextDisabled(surface, x, y, text, hotKey, false);
257 char ::TranslateKey(Key key, bool shift)
259 int code = (int)key.code;
260 return (code <= 127) ? characters[shift][code] : 0;