diff --git a/src/Camera.c b/src/Camera.c index 18b341baf..5b16daecf 100644 --- a/src/Camera.c +++ b/src/Camera.c @@ -104,7 +104,7 @@ static void PerspectiveCamera_UpdateMouseRotation(double delta) { } static void PerspectiveCamera_UpdateMouse(double delta) { - if (!Gui_GetInputGrab() && Window_Focused) Window_UpdateRawMouse(); + if (!Gui_GetInputGrab() && WindowInfo.Focused) Window_UpdateRawMouse(); PerspectiveCamera_UpdateMouseRotation(delta); cam_deltaX = 0; cam_deltaY = 0; diff --git a/src/Chat.c b/src/Chat.c index 22acab8cb..e110216ec 100644 --- a/src/Chat.c +++ b/src/Chat.c @@ -391,7 +391,7 @@ static void ResolutionCommand_Execute(const String* args, int argsCount) { int width, height; if (argsCount < 2) { Chat_Add4("&e/client: &fCurrent resolution is %i@%f2 x %i@%f2", - &Window_Width, &Display_DpiX, &Window_Height, &Display_DpiY); + &WindowInfo.Width, &Display_DpiX, &WindowInfo.Height, &Display_DpiY); } else if (!Convert_ParseInt(&args[0], &width) || !Convert_ParseInt(&args[1], &height)) { Chat_AddRaw("&e/client: &cWidth and height must be integers."); } else if (width <= 0 || height <= 0) { diff --git a/src/Game.c b/src/Game.c index 909daa28f..cf24afaff 100644 --- a/src/Game.c +++ b/src/Game.c @@ -89,7 +89,7 @@ int ScheduledTask_Add(double interval, ScheduledTaskCallback callback) { int Game_GetWindowScale(void) { - float windowScale = min(Window_Width / 640.0f, Window_Height / 480.0f); + float windowScale = min(WindowInfo.Width / 640.0f, WindowInfo.Height / 480.0f); return 1 + (int)windowScale; } @@ -253,8 +253,8 @@ cc_bool Game_ValidateBitmap(const String* file, Bitmap* bmp) { } void Game_UpdateDimensions(void) { - Game.Width = max(Window_Width, 1); - Game.Height = max(Window_Height, 1); + Game.Width = max(WindowInfo.Width, 1); + Game.Height = max(WindowInfo.Height, 1); } static void Game_OnResize(void* obj) { @@ -590,7 +590,7 @@ static void Game_RenderFrame(double delta) { Game_Vertices = 0; Camera.Active->UpdateMouse(delta); - if (!Window_Focused && !Gui_GetInputGrab()) PauseScreen_Show(); + if (!WindowInfo.Focused && !Gui_GetInputGrab()) PauseScreen_Show(); if (KeyBind_IsPressed(KEYBIND_ZOOM_SCROLL) && !Gui_GetInputGrab()) { InputHandler_SetFOV(Game_ZoomFov); @@ -642,7 +642,7 @@ void Game_Free(void* obj) { #define Game_DoFrameBody() \ Window_ProcessEvents();\ - if (!Window_Exists) return;\ + if (!WindowInfo.Exists) return;\ \ render = Stopwatch_Measure();\ time = Stopwatch_ElapsedMicroseconds(lastRender, render) / (1000.0 * 1000.0);\ diff --git a/src/Graphics.c b/src/Graphics.c index 1bcd883d2..bc643c9d9 100644 --- a/src/Graphics.c +++ b/src/Graphics.c @@ -361,7 +361,7 @@ static void D3D9_FillPresentArgs(int width, int height, D3DPRESENT_PARAMETERS* a void Gfx_Init(void) { Gfx.MinZNear = 0.05f; - HWND winHandle = (HWND)Window_Handle; + HWND winHandle = (HWND)WindowInfo.Handle; d3d = Direct3DCreate9(D3D_SDK_VERSION); D3D9_FindCompatibleFormat(); diff --git a/src/Gui.c b/src/Gui.c index 41f4f1f27..7c401c51f 100644 --- a/src/Gui.c +++ b/src/Gui.c @@ -34,8 +34,8 @@ void Widget_SetLocation(void* widget, cc_uint8 horAnchor, cc_uint8 verAnchor, in void Widget_CalcPosition(void* widget) { struct Widget* w = (struct Widget*)widget; - w->x = Gui_CalcPos(w->horAnchor, w->xOffset, w->width , Window_Width ); - w->y = Gui_CalcPos(w->verAnchor, w->yOffset, w->height, Window_Height); + w->x = Gui_CalcPos(w->horAnchor, w->xOffset, w->width , WindowInfo.Width ); + w->y = Gui_CalcPos(w->verAnchor, w->yOffset, w->height, WindowInfo.Height); } void Widget_Reset(void* widget) { diff --git a/src/Input.c b/src/Input.c index 848aad128..9f0287c29 100644 --- a/src/Input.c +++ b/src/Input.c @@ -1071,7 +1071,7 @@ static void HandleInputUp(void* obj, int key) { if (key == KeyBinds[KEYBIND_PICK_BLOCK]) MouseStateRelease(MOUSE_MIDDLE); } -static void HandleFocusChanged(void* obj) { if (!Window_Focused) Input_Clear(); } +static void HandleFocusChanged(void* obj) { if (!WindowInfo.Focused) Input_Clear(); } void InputHandler_Init(void) { Event_RegisterMove(&PointerEvents.Moved, NULL, HandlePointerMove); Event_RegisterInt(&PointerEvents.Down, NULL, HandlePointerDown); diff --git a/src/LScreens.c b/src/LScreens.c index cb2a23e98..229794735 100644 --- a/src/LScreens.c +++ b/src/LScreens.c @@ -1012,12 +1012,12 @@ static void ResourcesScreen_Draw(struct LScreen* s) { int x, y, width, height; Drawer2D_Clear(&Launcher_Framebuffer, backCol, - 0, 0, Window_Width, Window_Height); + 0, 0, WindowInfo.Width, WindowInfo.Height); width = Display_ScaleX(380); height = Display_ScaleY(140); - x = Gui_CalcPos(ANCHOR_CENTRE, 0, width, Window_Width); - y = Gui_CalcPos(ANCHOR_CENTRE, 0, height, Window_Height); + x = Gui_CalcPos(ANCHOR_CENTRE, 0, width, WindowInfo.Width); + y = Gui_CalcPos(ANCHOR_CENTRE, 0, height, WindowInfo.Height); ResourcesScreen_ResetArea(x, y, width, height); LScreen_Draw(s); @@ -1211,7 +1211,7 @@ static void ServersScreen_Init(struct LScreen* s_) { ServersScreen_ReloadServers(s); /* This is so typing on keyboard by default searchs server list */ /* But don't do that when it would cause on-screen keyboard to show */ - if (Window_SoftKeyboard) return; + if (WindowInfo.SoftKeyboard) return; LScreen_SelectWidget(s_, (struct LWidget*)&s->iptSearch, false); } @@ -1254,8 +1254,8 @@ static void ServersScreen_Layout(struct LScreen* s_) { LWidget_SetLocation(&s->btnRefresh, ANCHOR_MAX, ANCHOR_MIN, 135, 10); LWidget_SetLocation(&s->table, ANCHOR_MIN, ANCHOR_MIN, 10, 50); - s->table.width = Window_Width - s->table.x; - s->table.height = Window_Height - s->table.y * 2; + s->table.width = WindowInfo.Width - s->table.x; + s->table.height = WindowInfo.Height - s->table.y * 2; s->table.height = max(1, s->table.height); LTable_Reposition(&s->table); diff --git a/src/LWidgets.c b/src/LWidgets.c index 877aa912e..4e257435f 100644 --- a/src/LWidgets.c +++ b/src/LWidgets.c @@ -25,8 +25,8 @@ void LWidget_SetLocation(void* widget, cc_uint8 horAnchor, cc_uint8 verAnchor, i void LWidget_CalcPosition(void* widget) { struct LWidget* w = (struct LWidget*)widget; - w->x = Gui_CalcPos(w->horAnchor, Display_ScaleX(w->xOffset), w->width, Window_Width); - w->y = Gui_CalcPos(w->verAnchor, Display_ScaleY(w->yOffset), w->height, Window_Height); + w->x = Gui_CalcPos(w->horAnchor, Display_ScaleX(w->xOffset), w->width, WindowInfo.Width); + w->y = Gui_CalcPos(w->verAnchor, Display_ScaleY(w->yOffset), w->height, WindowInfo.Height); } void LWidget_Draw(void* widget) { @@ -1035,7 +1035,7 @@ static void LTable_ScrollbarClick(struct LTable* w) { static void LTable_MouseDown(void* widget, cc_bool wasSelected) { struct LTable* w = (struct LTable*)widget; - if (Mouse_X >= Window_Width - w->scrollbarWidth) { + if (Mouse_X >= WindowInfo.Width - w->scrollbarWidth) { LTable_ScrollbarClick(w); w->_lastRow = -1; } else if (Mouse_Y < w->rowsBegY) { diff --git a/src/Launcher.c b/src/Launcher.c index bc2197f37..91d1a9184 100644 --- a/src/Launcher.c +++ b/src/Launcher.c @@ -274,7 +274,7 @@ void Launcher_Run(void) { for (;;) { Window_ProcessEvents(); - if (!Window_Exists || Launcher_ShouldExit) break; + if (!WindowInfo.Exists || Launcher_ShouldExit) break; Launcher_Screen->Tick(Launcher_Screen); if (Launcher_Dirty.Width) Launcher_Display(); @@ -292,7 +292,7 @@ void Launcher_Run(void) { #ifdef CC_BUILD_ANDROID if (Launcher_ShouldExit) SwitchToGame(); #endif - if (Window_Exists) Window_Close(); + if (WindowInfo.Exists) Window_Close(); } @@ -486,20 +486,20 @@ void Launcher_ResetPixels(void) { int x; if (Launcher_Screen && Launcher_Screen->hidesTitlebar) { - Launcher_ResetArea(0, 0, Window_Width, Window_Height); + Launcher_ResetArea(0, 0, WindowInfo.Width, WindowInfo.Height); return; } if (Launcher_ClassicBackground && dirtBmp.Scan0) { - Launcher_ClearTile(0, 0, Window_Width, TILESIZE, &dirtBmp); - Launcher_ClearTile(0, TILESIZE, Window_Width, Window_Height - TILESIZE, &stoneBmp); + Launcher_ClearTile(0, 0, WindowInfo.Width, TILESIZE, &dirtBmp); + Launcher_ClearTile(0, TILESIZE, WindowInfo.Width, WindowInfo.Height - TILESIZE, &stoneBmp); } else { - Launcher_ResetArea(0, 0, Window_Width, Window_Height); + Launcher_ResetArea(0, 0, WindowInfo.Width, WindowInfo.Height); } Drawer2D_BitmappedText = (useBitmappedFont || Launcher_ClassicBackground) && fontBmp.Scan0; DrawTextArgs_Make(&args, &title_fore, &logoFont, false); - x = Window_Width / 2 - Drawer2D_TextWidth(&args) / 2; + x = WindowInfo.Width / 2 - Drawer2D_TextWidth(&args) / 2; args.text = title_back; Drawer2D_DrawText(&Launcher_Framebuffer, &args, x + 4, 4); diff --git a/src/Menus.c b/src/Menus.c index adf2f3653..12adc4b09 100644 --- a/src/Menus.c +++ b/src/Menus.c @@ -101,7 +101,7 @@ static void Menu_RenderBounds(void) { Then using wolfram alpha to solve the glblendfunc equation */ PackedCol topCol = PackedCol_Make(24, 24, 24, 105); PackedCol bottomCol = PackedCol_Make(51, 51, 98, 162); - Gfx_Draw2DGradient(0, 0, Window_Width, Window_Height, topCol, bottomCol); + Gfx_Draw2DGradient(0, 0, WindowInfo.Width, WindowInfo.Height, topCol, bottomCol); } static int Menu_DoPointerDown(void* screen, int id, int x, int y) { @@ -814,7 +814,7 @@ static void EditHotkeyScreen_Render(void* screen, double delta) { int x, y; MenuScreen_Render2(screen, delta); - x = Window_Width / 2; y = Window_Height / 2; + x = WindowInfo.Width / 2; y = WindowInfo.Height / 2; Gfx_Draw2DFlat(x - 250, y - 65, 500, 2, grey); Gfx_Draw2DFlat(x - 250, y + 45, 500, 2, grey); } @@ -1380,7 +1380,7 @@ static void SaveLevelScreen_Render(void* screen, double delta) { MenuScreen_Render2(screen, delta); #ifndef CC_BUILD_WEB - x = Window_Width / 2; y = Window_Height / 2; + x = WindowInfo.Width / 2; y = WindowInfo.Height / 2; Gfx_Draw2DFlat(x - 250, y + 90, 500, 2, grey); #endif } @@ -2005,7 +2005,7 @@ CC_NOINLINE static void MenuOptionsScreen_FreeExtHelp(struct MenuOptionsScreen* } static void MenuOptionsScreen_RepositionExtHelp(struct MenuOptionsScreen* s) { - s->extHelp.xOffset = Window_Width / 2 - s->extHelp.width / 2; + s->extHelp.xOffset = WindowInfo.Width / 2 - s->extHelp.width / 2; Widget_Layout(&s->extHelp); } @@ -3005,7 +3005,7 @@ static void TexIdsOverlay_ContextRecreated(void* screen) { struct FontDesc textFont, titleFont; int size; - size = Window_Height / ATLAS2D_TILES_PER_ROW; + size = WindowInfo.Height / ATLAS2D_TILES_PER_ROW; size = (size / 8) * 8; Math_Clamp(size, 8, 40); @@ -3015,8 +3015,8 @@ static void TexIdsOverlay_ContextRecreated(void* screen) { TextAtlas_Make(&s->idAtlas, &chars, &textFont, &prefix); Font_Free(&textFont); - s->xOffset = Gui_CalcPos(ANCHOR_CENTRE, 0, size * Atlas2D.RowsCount, Window_Width); - s->yOffset = Gui_CalcPos(ANCHOR_CENTRE, 0, size * ATLAS2D_TILES_PER_ROW, Window_Height); + s->xOffset = Gui_CalcPos(ANCHOR_CENTRE, 0, size * Atlas2D.RowsCount, WindowInfo.Width); + s->yOffset = Gui_CalcPos(ANCHOR_CENTRE, 0, size * ATLAS2D_TILES_PER_ROW, WindowInfo.Height); s->tileSize = size; s->title.yOffset = s->yOffset - 30; diff --git a/src/Screens.c b/src/Screens.c index 347b91234..78636f941 100644 --- a/src/Screens.c +++ b/src/Screens.c @@ -395,11 +395,11 @@ static void ChatScreen_UpdateChatYOffsets(struct ChatScreen* s) { y = min(s->input.base.y, Gui_HUD->hotbar.y); y -= s->input.base.yOffset; /* add some padding */ - s->altText.yOffset = Window_Height - y; + s->altText.yOffset = WindowInfo.Height - y; Widget_Layout(&s->altText); pad = s->altText.active ? 5 : 10; - s->clientStatus.yOffset = Window_Height - s->altText.y + pad; + s->clientStatus.yOffset = WindowInfo.Height - s->altText.y + pad; Widget_Layout(&s->clientStatus); s->chat.yOffset = s->clientStatus.yOffset + s->clientStatus.height; Widget_Layout(&s->chat); @@ -595,10 +595,10 @@ static void ChatScreen_DrawCrosshairs(void) { int extent; if (!Gui_IconsTex) return; - extent = (int)(CH_EXTENT * Game_Scale(Window_Height / 480.0f)); + extent = (int)(CH_EXTENT * Game_Scale(WindowInfo.Height / 480.0f)); tex.ID = Gui_IconsTex; - tex.X = (Window_Width / 2) - extent; - tex.Y = (Window_Height / 2) - extent; + tex.X = (WindowInfo.Width / 2) - extent; + tex.Y = (WindowInfo.Height / 2) - extent; tex.Width = extent * 2; tex.Height = extent * 2; @@ -827,7 +827,7 @@ static int ChatScreen_KeyUp(void* screen, int key) { #endif if (Server.SupportsFullCP437 && key == KeyBinds[KEYBIND_EXT_INPUT]) { - if (!Window_Focused) return true; + if (!WindowInfo.Focused) return true; SpecialInputWidget_SetActive(&s->altText, !s->altText.active); ChatScreen_UpdateChatYOffsets(s); } @@ -915,7 +915,7 @@ static void ChatScreen_Init(void* screen) { s->chatTextures, ChatScreen_GetChat); TextGroupWidget_Create(&s->clientStatus, CHAT_MAX_CLIENTSTATUS, s->clientStatusTextures, ChatScreen_GetClientStatus); - TextWidget_Make(&s->announcement, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -Window_Height / 4); + TextWidget_Make(&s->announcement, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -WindowInfo.Height / 4); s->status.collapsible[0] = true; /* Texture pack download status */ s->clientStatus.collapsible[0] = true; @@ -1252,11 +1252,11 @@ static void LoadingScreen_DrawBackground(void) { loc = Block_Tex(BLOCK_DIRT, FACE_YMAX); tex.ID = 0; - Tex_SetRect(tex, 0,0, Window_Width,LOADING_TILE_SIZE); + Tex_SetRect(tex, 0,0, WindowInfo.Width,LOADING_TILE_SIZE); tex.uv = Atlas1D_TexRec(loc, 1, &atlasIndex); - tex.uv.U2 = (float)Window_Width / LOADING_TILE_SIZE; + tex.uv.U2 = (float)WindowInfo.Width / LOADING_TILE_SIZE; - for (y = 0; y < Window_Height; y += LOADING_TILE_SIZE) { + for (y = 0; y < WindowInfo.Height; y += LOADING_TILE_SIZE) { tex.Y = y; Gfx_Make2DQuad(&tex, col, &ptr); count += 4; @@ -1297,8 +1297,8 @@ static void LoadingScreen_Render(void* screen, double delta) { Elem_Render(&s->message, delta); Gfx_SetTexturing(false); - x = Gui_CalcPos(ANCHOR_CENTRE, 0, PROG_BAR_WIDTH, Window_Width); - y = Gui_CalcPos(ANCHOR_CENTRE, 34, PROG_BAR_HEIGHT, Window_Height); + x = Gui_CalcPos(ANCHOR_CENTRE, 0, PROG_BAR_WIDTH, WindowInfo.Width); + y = Gui_CalcPos(ANCHOR_CENTRE, 34, PROG_BAR_HEIGHT, WindowInfo.Height); progWidth = (int)(PROG_BAR_WIDTH * s->progress); Gfx_Draw2DFlat(x, y, PROG_BAR_WIDTH, PROG_BAR_HEIGHT, backCol); @@ -1511,7 +1511,7 @@ static void DisconnectScreen_Update(void* screen, double delta) { static void DisconnectScreen_Render(void* screen, double delta) { PackedCol top = PackedCol_Make(64, 32, 32, 255); PackedCol bottom = PackedCol_Make(80, 16, 16, 255); - Gfx_Draw2DGradient(0, 0, Window_Width, Window_Height, top, bottom); + Gfx_Draw2DGradient(0, 0, WindowInfo.Width, WindowInfo.Height, top, bottom); Gfx_SetTexturing(true); Screen_Render2Widgets(screen, delta); diff --git a/src/Widgets.c b/src/Widgets.c index 2efc5dc0e..b90e07ffb 100644 --- a/src/Widgets.c +++ b/src/Widgets.c @@ -482,7 +482,7 @@ static int HotbarWidget_KeyUp(void* widget, int key) { if (w->altHandled) { w->altHandled = false; return true; } /* handled already */ /* Don't switch hotbar when alt+tab */ - if (!Window_Focused) return true; + if (!WindowInfo.Focused) return true; /* Alternate between first and second row */ index = Inventory.Offset == 0 ? 1 : 0; @@ -1600,7 +1600,7 @@ static void ChatInputWidget_Render(void* widget, double delta) { caretAtEnd = (w->caretY == i) && (w->caretX == INPUTWIDGET_LEN || w->caretPos == -1); width = w->lineWidths[i] + (caretAtEnd ? w->caretTex.Width : 0); /* Cover whole window width to match original classic behaviour */ - if (Gui_ClassicChat) { width = max(width, Window_Width - x * 4); } + if (Gui_ClassicChat) { width = max(width, WindowInfo.Width - x * 4); } Gfx_Draw2DFlat(x, y, width + w->padding * 2, w->lineHeight, backCol); y += w->lineHeight; @@ -1886,7 +1886,7 @@ static void PlayerListWidget_Reposition(void* widget) { w->width = width + LIST_BOUNDS_SIZE * 2; w->height = height + LIST_BOUNDS_SIZE * 2; - y = Window_Height / 4 - w->height / 2; + y = WindowInfo.Height / 4 - w->height / 2; w->yOffset = -max(0, y); Widget_CalcPosition(w); @@ -2194,7 +2194,7 @@ static void TextGroupWidget_Reposition(void* widget) { Widget_CalcPosition(w); for (i = 0, y = w->y; i < w->lines; i++) { - textures[i].X = Gui_CalcPos(w->horAnchor, w->xOffset, textures[i].Width, Window_Width); + textures[i].X = Gui_CalcPos(w->horAnchor, w->xOffset, textures[i].Width, WindowInfo.Width); textures[i].Y = y; y += textures[i].Height; } @@ -2463,7 +2463,7 @@ void TextGroupWidget_Redraw(struct TextGroupWidget* w, int index) { tex.Height = w->collapsible[index] ? 0 : w->defaultHeight; } - tex.X = Gui_CalcPos(w->horAnchor, w->xOffset, tex.Width, Window_Width); + tex.X = Gui_CalcPos(w->horAnchor, w->xOffset, tex.Width, WindowInfo.Width); w->textures[index] = tex; Widget_Layout(w); } diff --git a/src/Window.c b/src/Window.c index 02df5aecb..6c83f03ea 100644 --- a/src/Window.c +++ b/src/Window.c @@ -16,10 +16,7 @@ int Display_ScaleY(int y) { return (int)(y * Display_DpiY); } #define Display_CentreX(width) (Display_Bounds.X + (Display_Bounds.Width - width) / 2) #define Display_CentreY(height) (Display_Bounds.Y + (Display_Bounds.Height - height) / 2) -int Window_Width, Window_Height; -cc_bool Window_Exists, Window_Focused; -const void* Window_Handle; -cc_bool Window_SoftKeyboard; +struct _WinData WindowInfo; #ifndef CC_BUILD_WEB void Clipboard_RequestText(RequestClipboardCallback callback, void* obj) { @@ -44,13 +41,13 @@ void Cursor_SetVisible(cc_bool visible) { } static void CentreMousePosition(void) { - Cursor_SetPosition(Window_Width / 2, Window_Height / 2); + Cursor_SetPosition(WindowInfo.Width / 2, WindowInfo.Height / 2); /* Fixes issues with large DPI displays on Windows >= 8.0. */ Cursor_GetRawPos(&cursorPrevX, &cursorPrevY); } static void RegrabMouse(void) { - if (!Window_Focused || !Window_Exists) return; + if (!WindowInfo.Focused || !WindowInfo.Exists) return; CentreMousePosition(); } @@ -120,7 +117,7 @@ static void InitGraphicsMode(struct GraphicsMode* m) { static SDL_Window* win_handle; static void RefreshWindowBounds(void) { - SDL_GetWindowSize(win_handle, &Window_Width, &Window_Height); + SDL_GetWindowSize(win_handle, &WindowInfo.Width, &WindowInfo.Height); } static void Window_SDLFail(const char* place) { @@ -152,8 +149,8 @@ void Window_Create(int width, int height) { if (!win_handle) Window_SDLFail("creating window"); RefreshWindowBounds(); - Window_Exists = true; - Window_Handle = win_handle; + WindowInfo.Exists = true; + WindowInfo.Handle = win_handle; } void Window_SetTitle(const String* title) { @@ -314,11 +311,11 @@ static void OnWindowEvent(const SDL_Event* e) { Event_RaiseVoid(&WindowEvents.StateChanged); break; case SDL_WINDOWEVENT_FOCUS_GAINED: - Window_Focused = true; + WindowInfo.Focused = true; Event_RaiseVoid(&WindowEvents.FocusChanged); break; case SDL_WINDOWEVENT_FOCUS_LOST: - Window_Focused = false; + WindowInfo.Focused = false; Event_RaiseVoid(&WindowEvents.FocusChanged); break; case SDL_WINDOWEVENT_CLOSE: @@ -351,7 +348,7 @@ void Window_ProcessEvents(void) { OnWindowEvent(&e); break; case SDL_QUIT: - Window_Exists = false; + WindowInfo.Exists = false; Event_RaiseVoid(&WindowEvents.Closing); SDL_DestroyWindow(win_handle); break; @@ -500,8 +497,8 @@ static void RefreshWindowBounds(void) { win_totalHeight = Rect_Height(rect); GetClientRect(win_handle, &rect); - Window_Width = Rect_Width(rect); - Window_Height = Rect_Height(rect); + WindowInfo.Width = Rect_Width(rect); + WindowInfo.Height = Rect_Height(rect); /* GetClientRect always returns 0,0 for left,top (see MSDN) */ ClientToScreen(win_handle, &topLeft); @@ -514,7 +511,7 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara switch (message) { case WM_ACTIVATE: - Window_Focused = LOWORD(wParam) != 0; + WindowInfo.Focused = LOWORD(wParam) != 0; Event_RaiseVoid(&WindowEvents.FocusChanged); break; @@ -648,12 +645,12 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara case WM_CLOSE: Event_RaiseVoid(&WindowEvents.Closing); - if (Window_Exists) DestroyWindow(win_handle); - Window_Exists = false; + if (WindowInfo.Exists) DestroyWindow(win_handle); + WindowInfo.Exists = false; break; case WM_DESTROY: - Window_Exists = false; + WindowInfo.Exists = false; UnregisterClass(CC_WIN_CLASSNAME, win_instance); if (win_DC) ReleaseDC(win_handle, win_DC); @@ -714,8 +711,8 @@ void Window_Create(int width, int height) { win_DC = GetDC(win_handle); if (!win_DC) Logger_Abort2(GetLastError(), "Failed to get device context"); - Window_Exists = true; - Window_Handle = win_handle; + WindowInfo.Exists = true; + WindowInfo.Handle = win_handle; } void Window_SetTitle(const String* title) { @@ -865,7 +862,7 @@ void Window_ProcessEvents(void) { foreground = GetForegroundWindow(); if (foreground) { - Window_Focused = foreground == win_handle; + WindowInfo.Focused = foreground == win_handle; } } @@ -1106,9 +1103,9 @@ static void RegisterAtoms(void) { } static void RefreshWindowBounds(int width, int height) { - if (width != Window_Width || height != Window_Height) { - Window_Width = width; - Window_Height = height; + if (width != WindowInfo.Width || height != WindowInfo.Height) { + WindowInfo.Width = width; + WindowInfo.Height = height; Event_RaiseVoid(&WindowEvents.Resized); } } @@ -1183,8 +1180,8 @@ void Window_Create(int width, int height) { XkbSetDetectableAutoRepeat(win_display, true, &supported); RefreshWindowBounds(width, height); - Window_Exists = true; - Window_Handle = (void*)win_handle; + WindowInfo.Exists = true; + WindowInfo.Handle = (void*)win_handle; XClassHint hint = { 0 }; hint.res_name = GAME_APP_TITLE; @@ -1345,7 +1342,7 @@ static void HandleWMDestroy(void) { /* sync and discard all events queued */ XSync(win_display, true); XDestroyWindow(win_display, win_handle); - Window_Exists = false; + WindowInfo.Exists = false; } static void HandleWMPing(XEvent* e) { @@ -1357,7 +1354,7 @@ static void HandleGenericEvent(XEvent* e); void Window_ProcessEvents(void) { XEvent e; - while (Window_Exists) { + while (WindowInfo.Exists) { if (!XCheckIfEvent(win_display, &e, FilterEvent, (XPointer)win_handle)) break; switch (e.type) { @@ -1373,7 +1370,7 @@ void Window_ProcessEvents(void) { case DestroyNotify: Platform_LogConst("Window destroyed"); - Window_Exists = false; + WindowInfo.Exists = false; break; case ConfigureNotify: @@ -1431,10 +1428,10 @@ void Window_ProcessEvents(void) { /* Don't lose focus when another app grabs key or mouse */ if (e.xfocus.mode == NotifyGrab || e.xfocus.mode == NotifyUngrab) break; - Window_Focused = e.type == FocusIn; + WindowInfo.Focused = e.type == FocusIn; Event_RaiseVoid(&WindowEvents.FocusChanged); /* TODO: Keep track of keyboard when focus is lost */ - if (!Window_Focused) Input_Clear(); + if (!WindowInfo.Focused) Input_Clear(); break; case MappingNotify: @@ -1900,7 +1897,7 @@ static pascal OSErr HandleQuitMessage(const AppleEvent* ev, AppleEvent* reply, l } static void Window_CommonCreate(void) { - Window_Exists = true; + WindowInfo.Exists = true; /* for quit buttons in dock and menubar */ AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP(HandleQuitMessage), 0, false); @@ -2041,8 +2038,8 @@ static void RefreshWindowBounds(void) { /* TODO: kWindowContentRgn ??? */ GetWindowBounds(win_handle, kWindowGlobalPortRgn, &r); - windowX = r.left; Window_Width = r.right - r.left; - windowY = r.top; Window_Height = r.bottom - r.top; + windowX = r.left; WindowInfo.Width = r.right - r.left; + windowY = r.top; WindowInfo.Height = r.bottom - r.top; } static OSStatus Window_ProcessKeyboardEvent(EventRef inEvent) { @@ -2087,30 +2084,30 @@ static OSStatus Window_ProcessWindowEvent(EventRef inEvent) { switch (GetEventKind(inEvent)) { case kEventWindowClose: - Window_Exists = false; + WindowInfo.Exists = false; Event_RaiseVoid(&WindowEvents.Closing); return eventNotHandledErr; case kEventWindowClosed: - Window_Exists = false; + WindowInfo.Exists = false; return 0; case kEventWindowBoundsChanged: - oldWidth = Window_Width; oldHeight = Window_Height; + oldWidth = WindowInfo.Width; oldHeight = WindowInfo.Height; RefreshWindowBounds(); - if (oldWidth != Window_Width || oldHeight != Window_Height) { + if (oldWidth != WindowInfo.Width || oldHeight != WindowInfo.Height) { Event_RaiseVoid(&WindowEvents.Resized); } return eventNotHandledErr; case kEventWindowActivated: - Window_Focused = true; + WindowInfo.Focused = true; Event_RaiseVoid(&WindowEvents.FocusChanged); return eventNotHandledErr; case kEventWindowDeactivated: - Window_Focused = false; + WindowInfo.Focused = false; Event_RaiseVoid(&WindowEvents.FocusChanged); return eventNotHandledErr; @@ -2152,8 +2149,8 @@ static OSStatus Window_ProcessMouseEvent(EventRef inEvent) { if (!win_fullscreen) { mouseX -= windowX; mouseY -= windowY; - if (mouseX < 0 || mouseX >= Window_Width) return eventNotHandledErr; - if (mouseY < 0 || mouseY >= Window_Height) return eventNotHandledErr; + if (mouseX < 0 || mouseX >= WindowInfo.Width) return eventNotHandledErr; + if (mouseY < 0 || mouseY >= WindowInfo.Height) return eventNotHandledErr; } kind = GetEventKind(inEvent); @@ -2385,8 +2382,8 @@ void Window_SetSize(int width, int height) { void Window_Close(void) { /* DisposeWindow only sends a kEventWindowClosed */ Event_RaiseVoid(&WindowEvents.Closing); - if (Window_Exists) DisposeWindow(win_handle); - Window_Exists = false; + if (WindowInfo.Exists) DisposeWindow(win_handle); + WindowInfo.Exists = false; } void Window_ProcessEvents(void) { @@ -2454,8 +2451,8 @@ void Window_DrawFramebuffer(Rect2D r) { /* TODO: Only update changed bit.. */ rect.origin.x = 0; rect.origin.y = 0; - rect.size.width = Window_Width; - rect.size.height = Window_Height; + rect.size.width = WindowInfo.Width; + rect.size.height = WindowInfo.Height; err = QDBeginCGContext(fb_port, &context); if (err) Logger_Abort2(err, "Begin draw"); @@ -2562,8 +2559,8 @@ static void RefreshWindowBounds(void) { windowX = (int)win.origin.x + (int)view.origin.x; windowY = Display_Bounds.Height - ((int)win.origin.y + (int)win.size.height) + viewY; - Window_Width = (int)view.size.width; - Window_Height = (int)view.size.height; + WindowInfo.Width = (int)view.size.width; + WindowInfo.Height = (int)view.size.height; } static void OnDidResize(id self, SEL cmd, id notification) { @@ -2577,12 +2574,12 @@ static void OnDidMove(id self, SEL cmd, id notification) { } static void OnDidBecomeKey(id self, SEL cmd, id notification) { - Window_Focused = true; + WindowInfo.Focused = true; Event_RaiseVoid(&WindowEvents.FocusChanged); } static void OnDidResignKey(id self, SEL cmd, id notification) { - Window_Focused = false; + WindowInfo.Focused = false; Event_RaiseVoid(&WindowEvents.FocusChanged); } @@ -2595,7 +2592,7 @@ static void OnDidDeminiaturize(id self, SEL cmd, id notification) { } static void OnWillClose(id self, SEL cmd, id notification) { - Window_Exists = false; + WindowInfo.Exists = false; Event_RaiseVoid(&WindowEvents.Closing); } @@ -2715,9 +2712,9 @@ void Window_SetSize(int width, int height) { /* Can't use setContentSize:, because that resizes from the bottom left corner. */ CGRect rect = ((CGRect(*)(id, SEL))(void *)objc_msgSend_stret)(winHandle, selFrame); - rect.origin.y += Window_Height - height; - rect.size.width += width - Window_Width; - rect.size.height += height - Window_Height; + rect.origin.y += WindowInfo.Height - height; + rect.size.width += width - WindowInfo.Width; + rect.size.height += height - WindowInfo.Height; objc_msgSend(winHandle, sel_registerName("setFrame:display:"), rect, true); } @@ -2755,7 +2752,7 @@ static cc_bool GetMouseCoords(int* x, int* y) { *x = (int)loc.x - windowX; *y = (Display_Bounds.Height - (int)loc.y) - windowY; // TODO: this seems to be off by 1 - return *x >= 0 && *y >= 0 && *x < Window_Width && *y < Window_Height; + return *x >= 0 && *y >= 0 && *x < WindowInfo.Width && *y < WindowInfo.Height; } void Window_ProcessEvents(void) { @@ -2880,8 +2877,8 @@ static void View_DrawRect(id self, SEL cmd, CGRect r_) { /* TODO: Only update changed bit.. */ rect.origin.x = 0; rect.origin.y = 0; - rect.size.width = Window_Width; - rect.size.height = Window_Height; + rect.size.width = WindowInfo.Width; + rect.size.height = WindowInfo.Height; /* TODO: REPLACE THIS AWFUL HACK */ provider = CGDataProviderCreateWithData(NULL, fb_bmp.Scan0, @@ -2900,7 +2897,7 @@ static void View_DrawRect(id self, SEL cmd, CGRect r_) { void Window_DrawFramebuffer(Rect2D r) { CGRect rect; rect.origin.x = r.X; - rect.origin.y = Window_Height - r.Y - r.Height; + rect.origin.y = WindowInfo.Height - r.Y - r.Height; rect.size.width = r.Width; rect.size.height = r.Height; @@ -2924,7 +2921,7 @@ void Window_FreeFramebuffer(Bitmap* bmp) { static cc_bool keyboardOpen; static void RefreshWindowBounds(void) { - emscripten_get_canvas_element_size(NULL, &Window_Width, &Window_Height); + emscripten_get_canvas_element_size(NULL, &WindowInfo.Width, &WindowInfo.Height); } static void CorrectPointerFocus(void) { @@ -2960,8 +2957,8 @@ static void RescaleXY(int srcX, int srcY, int* dstX, int* dstY) { double css_width, css_height; emscripten_get_element_css_size(NULL, &css_width, &css_height); - *dstX = (int)(srcX * Window_Width / css_width); - *dstY = (int)(srcY * Window_Height / css_height); + *dstX = (int)(srcX * WindowInfo.Width / css_width); + *dstY = (int)(srcY * WindowInfo.Height / css_height); } static EM_BOOL OnMouseMove(int type, const EmscriptenMouseEvent* ev, void* data) { @@ -3017,7 +3014,7 @@ static EM_BOOL OnTouchEnd(int type, const EmscriptenTouchEvent* ev, void* data) } static EM_BOOL OnFocus(int type, const EmscriptenFocusEvent* ev, void* data) { - Window_Focused = type == EMSCRIPTEN_EVENT_FOCUS; + WindowInfo.Focused = type == EMSCRIPTEN_EVENT_FOCUS; Event_RaiseVoid(&WindowEvents.FocusChanged); return true; } @@ -3231,8 +3228,8 @@ void Window_Init(void) { } void Window_Create(int width, int height) { - Window_Exists = true; - Window_Focused = true; + WindowInfo.Exists = true; + WindowInfo.Focused = true; HookEvents(); /* let the webpage decide on bounds */ RefreshWindowBounds(); @@ -3297,7 +3294,7 @@ void Window_SetSize(int width, int height) { } void Window_Close(void) { - Window_Exists = false; + WindowInfo.Exists = false; Event_RaiseVoid(&WindowEvents.Closing); /* Don't want cursor stuck on the dead 0,0 canvas */ Window_DisableRawMouse(); @@ -3412,9 +3409,9 @@ void Window_DisableRawMouse(void) { static ANativeWindow* win_handle; static void RefreshWindowBounds(void) { - Window_Width = ANativeWindow_getWidth(win_handle); - Window_Height = ANativeWindow_getHeight(win_handle); - Platform_Log2("SCREEN BOUNDS: %i,%i", &Window_Width, &Window_Height); + WindowInfo.Width = ANativeWindow_getWidth(win_handle); + WindowInfo.Height = ANativeWindow_getHeight(win_handle); + Platform_Log2("SCREEN BOUNDS: %i,%i", &WindowInfo.Width, &WindowInfo.Height); Event_RaiseVoid(&WindowEvents.Resized); } @@ -3562,20 +3559,20 @@ static void JNICALL java_onPause(JNIEnv* env, jobject o) { static void JNICALL java_onDestroy(JNIEnv* env, jobject o) { Platform_LogConst("APP - ON DESTROY"); - if (Window_Exists) Window_Close(); + if (WindowInfo.Exists) Window_Close(); /* TODO: signal to java code we're done */ JavaCallVoid(env, "processedDestroyed", "()V", NULL); } static void JNICALL java_onGotFocus(JNIEnv* env, jobject o) { Platform_LogConst("APP - GOT FOCUS"); - Window_Focused = true; + WindowInfo.Focused = true; Event_RaiseVoid(&WindowEvents.FocusChanged); } static void JNICALL java_onLostFocus(JNIEnv* env, jobject o) { Platform_LogConst("APP - LOST FOCUS"); - Window_Focused = false; + WindowInfo.Focused = false; Event_RaiseVoid(&WindowEvents.FocusChanged); /* TODO: Disable rendering? */ } @@ -3616,15 +3613,15 @@ void Window_Init(void) { JavaGetCurrentEnv(env); JavaRegisterNatives(env, methods); - Window_SoftKeyboard = true; - Input_TouchMode = true; + WindowInfo.SoftKeyboard = true; + Input_TouchMode = true; Display_BitsPerPixel = 32; Display_DpiX = JavaCallFloat(env, "getDpiX", "()F", NULL); Display_DpiY = JavaCallFloat(env, "getDpiY", "()F", NULL); } void Window_Create(int width, int height) { - Window_Exists = true; + WindowInfo.Exists = true; /* actual window creation is done when processSurfaceCreated is received */ } @@ -3649,7 +3646,7 @@ cc_result Window_ExitFullscreen(void) { return 0; } void Window_SetSize(int width, int height) { } void Window_Close(void) { - Window_Exists = false; + WindowInfo.Exists = false; Event_RaiseVoid(&WindowEvents.Closing); /* TODO: Do we need to call finish here */ /* ANativeActivity_finish(app->activity); */ @@ -4206,11 +4203,11 @@ static cc_result GLContext_SetFullscreen(void) { } win_fullscreen = true; - ctx_windowWidth = Window_Width; - ctx_windowHeight = Window_Height; + ctx_windowWidth = WindowInfo.Width; + ctx_windowHeight = WindowInfo.Height; - windowX = Display_Bounds.X; Window_Width = Display_Bounds.Width; - windowY = Display_Bounds.Y; Window_Height = Display_Bounds.Height; + windowX = Display_Bounds.X; WindowInfo.Width = Display_Bounds.Width; + windowY = Display_Bounds.Y; WindowInfo.Height = Display_Bounds.Height; return 0; } diff --git a/src/Window.h b/src/Window.h index 35a48fd62..912e2d83d 100644 --- a/src/Window.h +++ b/src/Window.h @@ -51,17 +51,20 @@ int Display_ScaleX(int x); /* Scales the given Y coordinate from 96 dpi to current display dpi. */ int Display_ScaleY(int y); -/* Size of the content area of the window. (i.e. area that can draw to) */ -/* This area does NOT include borders and titlebar surrounding the window. */ -extern int Window_Width, Window_Height; -/* Whether the window is actually valid (i.e. not destroyed). */ -extern cc_bool Window_Exists; -/* Whether the user is interacting with the window. */ -extern cc_bool Window_Focused; -/* Readonly platform-specific handle to the window. */ -extern const void* Window_Handle; -/* Whether the platform only supports on-screen keyboard. */ -extern cc_bool Window_SoftKeyboard; +/* Data for the window. */ +CC_VAR extern struct _WinData { + /* Readonly platform-specific handle to the window. */ + void* Handle; + /* Size of the content area of the window. (i.e. area that can draw to) */ + /* This area does NOT include borders and titlebar surrounding the window. */ + int Width, Height; + /* Whether the window is actually valid (i.e. not destroyed). */ + cc_bool Exists; + /* Whether the user is interacting with the window. */ + cc_bool Focused; + /* Whether the platform only supports on-screen keyboard. */ + cc_bool SoftKeyboard; +} WindowInfo; /* Initalises state for window. Also sets Display_ members. */ void Window_Init(void);