Fix Keypad5 wrong on linux

This commit is contained in:
UnknownShadow200 2018-11-12 16:47:28 +11:00
parent 131e3e7613
commit 035b316d3d
5 changed files with 63 additions and 42 deletions

View File

@ -616,11 +616,12 @@ static void ErrorHandler_DumpRegisters(void* ctx) {
} }
static void ErrorHandler_DumpMemoryMap(void) { static void ErrorHandler_DumpMemoryMap(void) {
int n, fd = open("/proc/self/maps", O_RDONLY); String str; char strBuffer[STRING_SIZE * 5];
int n, fd;
fd = open("/proc/self/maps", O_RDONLY);
if (fd < 0) return; if (fd < 0) return;
String_InitArray(str, strBuffer);
char buffer[STRING_SIZE * 5];
String str = String_FromArray(buffer);
while ((n = read(fd, str.buffer, str.capacity)) > 0) { while ((n = read(fd, str.buffer, str.capacity)) > 0) {
str.length = n; str.length = n;

View File

@ -1067,14 +1067,15 @@ static void GenLevelScreen_Input(struct GenLevelScreen* s, int i, int y, bool se
static void GenLevelScreen_Label(struct GenLevelScreen* s, int i, int x, int y, const char* title) { static void GenLevelScreen_Label(struct GenLevelScreen* s, int i, int x, int y, const char* title) {
struct TextWidget* label = &s->Labels[i]; struct TextWidget* label = &s->Labels[i];
PackedCol col = PACKEDCOL_CONST(224, 224, 224, 255);
String text = String_FromReadonly(title); String text = String_FromReadonly(title);
Menu_Label(s, i + 4, label, &text, &s->TextFont, Menu_Label(s, i + 4, label, &text, &s->TextFont,
ANCHOR_CENTRE, ANCHOR_CENTRE, x, y); ANCHOR_CENTRE, ANCHOR_CENTRE, x, y);
label->Col = col;
label->XOffset = -110 - label->Width / 2; label->XOffset = -110 - label->Width / 2;
Widget_Reposition(label); Widget_Reposition(label);
PackedCol col = PACKEDCOL_CONST(224, 224, 224, 255); label->Col = col;
} }
static void GenLevelScreen_Init(void* screen) { static void GenLevelScreen_Init(void* screen) {
@ -3023,13 +3024,17 @@ static void TexIdsOverlay_Init(void* screen) {
static void TexIdsOverlay_Render(void* screen, double delta) { static void TexIdsOverlay_Render(void* screen, double delta) {
struct TexIdsOverlay* s = screen; struct TexIdsOverlay* s = screen;
int rows, origXOffset;
Menu_RenderBounds(); Menu_RenderBounds();
Gfx_SetTexturing(true); Gfx_SetTexturing(true);
Gfx_SetBatchFormat(VERTEX_FORMAT_P3FT2FC4B); Gfx_SetBatchFormat(VERTEX_FORMAT_P3FT2FC4B);
Menu_Render(s, delta); Menu_Render(s, delta);
int rows = Atlas2D_RowsCount, origXOffset = s->XOffset; rows = Atlas2D_RowsCount;
origXOffset = s->XOffset;
s->BaseTexLoc = 0; s->BaseTexLoc = 0;
while (rows > 0) { while (rows > 0) {
TexIdsOverlay_RenderTerrain(s); TexIdsOverlay_RenderTerrain(s);
TexIdsOverlay_RenderTextOverlay(s); TexIdsOverlay_RenderTextOverlay(s);
@ -3044,12 +3049,11 @@ static void TexIdsOverlay_Render(void* screen, double delta) {
} }
static bool TexIdsOverlay_KeyDown(void* screen, Key key) { static bool TexIdsOverlay_KeyDown(void* screen, Key key) {
struct TexIdsOverlay* s = screen;
if (key == KeyBind_Get(KeyBind_IDOverlay) || key == KeyBind_Get(KeyBind_PauseOrExit)) {
Gui_FreeOverlay(s); return true;
}
struct Screen* active = Gui_GetUnderlyingScreen(); struct Screen* active = Gui_GetUnderlyingScreen();
if (key == KeyBind_Get(KeyBind_IDOverlay) || key == KeyBind_Get(KeyBind_PauseOrExit)) {
Gui_FreeOverlay(screen); return true;
}
return Elem_HandlesKeyDown(active, key); return Elem_HandlesKeyDown(active, key);
} }
@ -3221,6 +3225,7 @@ static void TexPackOverlay_YesClick(void* screen, void* widget) {
static void TexPackOverlay_NoClick(void* screen, void* widget) { static void TexPackOverlay_NoClick(void* screen, void* widget) {
struct TexPackOverlay* s = screen; struct TexPackOverlay* s = screen;
struct Screen* overlay;
String url; String url;
bool isAlways; bool isAlways;
@ -3228,7 +3233,7 @@ static void TexPackOverlay_NoClick(void* screen, void* widget) {
url = String_UNSAFE_SubstringAt(&s->Identifier, 3); url = String_UNSAFE_SubstringAt(&s->Identifier, 3);
isAlways = WarningOverlay_IsAlways(s, widget); isAlways = WarningOverlay_IsAlways(s, widget);
struct Screen* overlay = ConfirmDenyOverlay_MakeInstance(&url, isAlways); overlay = ConfirmDenyOverlay_MakeInstance(&url, isAlways);
Gui_ShowOverlay(overlay, true); Gui_ShowOverlay(overlay, true);
} }

View File

@ -95,7 +95,6 @@ float Model_RenderDistance(struct Entity* entity) {
return dx * dx + dy * dy + dz * dz; return dx * dx + dy * dy + dz * dz;
} }
static struct Matrix Model_transform;
void Model_Render(struct Model* model, struct Entity* entity) { void Model_Render(struct Model* model, struct Entity* entity) {
struct Matrix m; struct Matrix m;
Vector3 pos = entity->Position; Vector3 pos = entity->Position;

View File

@ -44,7 +44,7 @@ static Key Window_MapKey(KeySym key) {
if (key >= XK_a && key <= XK_z) { return Key_A + (key - XK_a); } if (key >= XK_a && key <= XK_z) { return Key_A + (key - XK_a); }
if (key >= XK_KP_0 && key <= XK_KP_9) { if (key >= XK_KP_0 && key <= XK_KP_9) {
return Key_Keypad0 + (key - XK_KP_9); return Key_Keypad0 + (key - XK_KP_0);
} }
switch (key) { switch (key) {
@ -121,6 +121,7 @@ static Key Window_MapKey(KeySym key) {
case XK_KP_Down: return Key_Keypad2; case XK_KP_Down: return Key_Keypad2;
case XK_KP_Page_Down: return Key_Keypad3; case XK_KP_Page_Down: return Key_Keypad3;
case XK_KP_Left: return Key_Keypad4; case XK_KP_Left: return Key_Keypad4;
case XK_KP_Begin: return Key_Keypad5;
case XK_KP_Right: return Key_Keypad6; case XK_KP_Right: return Key_Keypad6;
case XK_KP_Home: return Key_Keypad7; case XK_KP_Home: return Key_Keypad7;
case XK_KP_Up: return Key_Keypad8; case XK_KP_Up: return Key_Keypad8;

View File

@ -199,11 +199,13 @@ static bool InventoryScreen_KeyDown(void* screen, Key key) {
static bool InventoryScreen_KeyPress(void* elem, char keyChar) { return true; } static bool InventoryScreen_KeyPress(void* elem, char keyChar) { return true; }
static bool InventoryScreen_KeyUp(void* screen, Key key) { static bool InventoryScreen_KeyUp(void* screen, Key key) {
struct InventoryScreen* s = screen; struct InventoryScreen* s = screen;
struct HUDScreen* hud;
if (key == KeyBind_Get(KeyBind_Inventory)) { if (key == KeyBind_Get(KeyBind_Inventory)) {
s->ReleasedInv = true; return true; s->ReleasedInv = true; return true;
} }
struct HUDScreen* hud = (struct HUDScreen*)Gui_HUD; hud = (struct HUDScreen*)Gui_HUD;
return Elem_HandlesKeyUp(&hud->Hotbar, key); return Elem_HandlesKeyUp(&hud->Hotbar, key);
} }
@ -211,11 +213,13 @@ static bool InventoryScreen_MouseDown(void* screen, int x, int y, MouseButton bt
struct InventoryScreen* s = screen; struct InventoryScreen* s = screen;
struct TableWidget* table = &s->Table; struct TableWidget* table = &s->Table;
struct HUDScreen* hud = (struct HUDScreen*)Gui_HUD; struct HUDScreen* hud = (struct HUDScreen*)Gui_HUD;
if (table->Scroll.DraggingMouse || Elem_HandlesMouseDown(&hud->Hotbar, x, y, btn)) return true; bool handled, hotbar;
if (table->Scroll.DraggingMouse || Elem_HandlesMouseDown(&hud->Hotbar, x, y, btn)) return true;
handled = Elem_HandlesMouseDown(table, x, y, btn);
bool handled = Elem_HandlesMouseDown(table, x, y, btn);
if ((!handled || table->PendingClose) && btn == MouseButton_Left) { if ((!handled || table->PendingClose) && btn == MouseButton_Left) {
bool hotbar = Key_IsControlPressed() || Key_IsShiftPressed(); hotbar = Key_IsControlPressed() || Key_IsShiftPressed();
if (!hotbar) Gui_CloseActive(); if (!hotbar) Gui_CloseActive();
} }
return true; return true;
@ -284,16 +288,21 @@ static void StatusScreen_MakeText(struct StatusScreen* s, String* status) {
static void StatusScreen_DrawPosition(struct StatusScreen* s) { static void StatusScreen_DrawPosition(struct StatusScreen* s) {
struct TextAtlas* atlas = &s->PosAtlas; struct TextAtlas* atlas = &s->PosAtlas;
struct Texture tex;
PackedCol col = PACKEDCOL_WHITE;
Vector3I pos;
VertexP3fT2fC4b vertices[4 * 64]; VertexP3fT2fC4b vertices[4 * 64];
VertexP3fT2fC4b* ptr = vertices; VertexP3fT2fC4b* ptr = vertices;
struct Texture tex = atlas->Tex; tex.X = 2; tex.Width = atlas->Offset; /* Make "Position: " prefix */
PackedCol col = PACKEDCOL_WHITE; tex = atlas->Tex;
tex.X = 2; tex.Width = atlas->Offset;
GfxCommon_Make2DQuad(&tex, col, &ptr); GfxCommon_Make2DQuad(&tex, col, &ptr);
Vector3I pos; Vector3I_Floor(&pos, &LocalPlayer_Instance.Base.Position); Vector3I_Floor(&pos, &LocalPlayer_Instance.Base.Position);
atlas->CurX = atlas->Offset + 2; atlas->CurX = atlas->Offset + 2;
/* Make (X, Y, Z) suffix */
TextAtlas_Add(atlas, 13, &ptr); TextAtlas_Add(atlas, 13, &ptr);
TextAtlas_AddInt(atlas, pos.X, &ptr); TextAtlas_AddInt(atlas, pos.X, &ptr);
TextAtlas_Add(atlas, 11, &ptr); TextAtlas_Add(atlas, 11, &ptr);
@ -561,6 +570,8 @@ static void LoadingScreen_Init(void* screen) {
#define PROG_BAR_HEIGHT 4 #define PROG_BAR_HEIGHT 4
static void LoadingScreen_Render(void* screen, double delta) { static void LoadingScreen_Render(void* screen, double delta) {
struct LoadingScreen* s = screen; struct LoadingScreen* s = screen;
PackedCol backCol = PACKEDCOL_CONST(128, 128, 128, 255);
PackedCol progCol = PACKEDCOL_CONST(128, 255, 128, 255);
int progWidth; int progWidth;
int x, y; int x, y;
@ -575,8 +586,6 @@ static void LoadingScreen_Render(void* screen, double delta) {
y = Gui_CalcPos(ANCHOR_CENTRE, 34, PROG_BAR_HEIGHT, Game_Height); y = Gui_CalcPos(ANCHOR_CENTRE, 34, PROG_BAR_HEIGHT, Game_Height);
progWidth = (int)(PROG_BAR_WIDTH * s->Progress); progWidth = (int)(PROG_BAR_WIDTH * s->Progress);
PackedCol backCol = PACKEDCOL_CONST(128, 128, 128, 255);
PackedCol progCol = PACKEDCOL_CONST(128, 255, 128, 255);
GfxCommon_Draw2DFlat(x, y, PROG_BAR_WIDTH, PROG_BAR_HEIGHT, backCol); GfxCommon_Draw2DFlat(x, y, PROG_BAR_WIDTH, PROG_BAR_HEIGHT, backCol);
GfxCommon_Draw2DFlat(x, y, progWidth, PROG_BAR_HEIGHT, progCol); GfxCommon_Draw2DFlat(x, y, progWidth, PROG_BAR_HEIGHT, progCol);
} }
@ -899,10 +908,14 @@ static void ChatScreen_ScrollHistoryBy(struct ChatScreen* s, int delta) {
} }
static bool ChatScreen_KeyDown(void* screen, Key key) { static bool ChatScreen_KeyDown(void* screen, Key key) {
static String slash = String_FromConst("/");
struct ChatScreen* s = screen; struct ChatScreen* s = screen;
s->SuppressNextPress = false; struct InputWidget* input;
int defaultIndex;
if (s->HandlesAllInput) { /* text input bar */ s->SuppressNextPress = false;
/* Handle text input bar */
if (s->HandlesAllInput) {
if (key == KeyBind_Get(KeyBind_SendChat) || key == Key_KeypadEnter || key == KeyBind_Get(KeyBind_PauseOrExit)) { if (key == KeyBind_Get(KeyBind_SendChat) || key == Key_KeypadEnter || key == KeyBind_Get(KeyBind_PauseOrExit)) {
ChatScreen_SetHandlesAllInput(s, false); ChatScreen_SetHandlesAllInput(s, false);
Key_KeyRepeat = false; Key_KeyRepeat = false;
@ -912,12 +925,12 @@ static bool ChatScreen_KeyDown(void* screen, Key key) {
} }
ChatScreen_InputStr.length = 0; ChatScreen_InputStr.length = 0;
struct InputWidget* input = &s->Input.Base; input = &s->Input.Base;
input->OnPressedEnter(input); input->OnPressedEnter(input);
SpecialInputWidget_SetActive(&s->AltText, false); SpecialInputWidget_SetActive(&s->AltText, false);
/* Reset chat when user has scrolled up in chat history */ /* Reset chat when user has scrolled up in chat history */
int defaultIndex = Chat_Log.Count - Game_ChatLines; defaultIndex = Chat_Log.Count - Game_ChatLines;
if (s->ChatIndex != defaultIndex) { if (s->ChatIndex != defaultIndex) {
s->ChatIndex = ChatScreen_ClampIndex(defaultIndex); s->ChatIndex = ChatScreen_ClampIndex(defaultIndex);
ChatScreen_ResetChat(s); ChatScreen_ResetChat(s);
@ -936,7 +949,6 @@ static bool ChatScreen_KeyDown(void* screen, Key key) {
if (key == KeyBind_Get(KeyBind_Chat)) { if (key == KeyBind_Get(KeyBind_Chat)) {
ChatScreen_OpenInput(s, &String_Empty); ChatScreen_OpenInput(s, &String_Empty);
} else if (key == Key_Slash) { } else if (key == Key_Slash) {
String slash = String_FromConst("/");
ChatScreen_OpenInput(s, &slash); ChatScreen_OpenInput(s, &slash);
} else { } else {
return false; return false;
@ -1095,14 +1107,16 @@ static void ChatScreen_OnResize(void* screen) {
static void ChatScreen_Init(void* screen) { static void ChatScreen_Init(void* screen) {
struct ChatScreen* s = screen; struct ChatScreen* s = screen;
int fontSize = (int)(8 * Game_GetChatScale()); int fontSize, largeSize;
Math_Clamp(fontSize, 8, 60);
int announceSize = (int)(16 * Game_GetChatScale());
Math_Clamp(announceSize, 8, 60);
Drawer2D_MakeFont(&s->ChatFont, fontSize, FONT_STYLE_NORMAL); fontSize = (int)(8 * Game_GetChatScale());
Drawer2D_MakeFont(&s->ChatUrlFont, fontSize, FONT_STYLE_UNDERLINE); Math_Clamp(fontSize, 8, 60);
Drawer2D_MakeFont(&s->AnnouncementFont, announceSize, FONT_STYLE_NORMAL); largeSize = (int)(16 * Game_GetChatScale());
Math_Clamp(largeSize, 8, 60);
Drawer2D_MakeFont(&s->ChatFont, fontSize, FONT_STYLE_NORMAL);
Drawer2D_MakeFont(&s->ChatUrlFont, fontSize, FONT_STYLE_UNDERLINE);
Drawer2D_MakeFont(&s->AnnouncementFont, largeSize, FONT_STYLE_NORMAL);
Screen_CommonInit(s); Screen_CommonInit(s);
Event_RegisterChat(&ChatEvents_ChatReceived, s, ChatScreen_ChatReceived); Event_RegisterChat(&ChatEvents_ChatReceived, s, ChatScreen_ChatReceived);
@ -1113,7 +1127,8 @@ static void ChatScreen_Init(void* screen) {
static void ChatScreen_Render(void* screen, double delta) { static void ChatScreen_Render(void* screen, double delta) {
struct ChatScreen* s = screen; struct ChatScreen* s = screen;
struct Texture tex; struct Texture tex;
int i, y; TimeMS now;
int i, y, logIdx;
ChatScreen_CheckOtherStatuses(s); ChatScreen_CheckOtherStatuses(s);
if (!Game_PureClassic) { Elem_Render(&s->Status, delta); } if (!Game_PureClassic) { Elem_Render(&s->Status, delta); }
@ -1129,14 +1144,14 @@ static void ChatScreen_Render(void* screen, double delta) {
Texture_Render(&tex); Texture_Render(&tex);
} }
TimeMS now = DateTime_CurrentUTC_MS(); now = DateTime_CurrentUTC_MS();
if (s->HandlesAllInput) { if (s->HandlesAllInput) {
Elem_Render(&s->Chat, delta); Elem_Render(&s->Chat, delta);
} else { } else {
/* Only render recent chat */ /* Only render recent chat */
for (i = 0; i < s->Chat.LinesCount; i++) { for (i = 0; i < s->Chat.LinesCount; i++) {
tex = s->Chat.Textures[i]; tex = s->Chat.Textures[i];
int logIdx = s->ChatIndex + i; logIdx = s->ChatIndex + i;
if (!tex.ID) continue; if (!tex.ID) continue;
if (logIdx < 0 || logIdx >= Chat_Log.Count) continue; if (logIdx < 0 || logIdx >= Chat_Log.Count) continue;
@ -1465,10 +1480,10 @@ static void DisconnectScreen_Init(void* screen) {
static void DisconnectScreen_Render(void* screen, double delta) { static void DisconnectScreen_Render(void* screen, double delta) {
struct DisconnectScreen* s = screen; struct DisconnectScreen* s = screen;
if (s->CanReconnect) { DisconnectScreen_UpdateDelayLeft(s, delta); }
PackedCol top = PACKEDCOL_CONST(64, 32, 32, 255); PackedCol top = PACKEDCOL_CONST(64, 32, 32, 255);
PackedCol bottom = PACKEDCOL_CONST(80, 16, 16, 255); PackedCol bottom = PACKEDCOL_CONST(80, 16, 16, 255);
if (s->CanReconnect) { DisconnectScreen_UpdateDelayLeft(s, delta); }
GfxCommon_Draw2DGradient(0, 0, Game_Width, Game_Height, top, bottom); GfxCommon_Draw2DGradient(0, 0, Game_Width, Game_Height, top, bottom);
Gfx_SetTexturing(true); Gfx_SetTexturing(true);