Commit graph

23 commits

Author SHA1 Message Date
Daniel Gibson
c41ac185cc Rename variables and Named Event for GUI scripts, add more such vars
"gui::horPad" is now called "gui::cstHorPad", "gui::vertPad" is now
called "gui::cstVertPad", so it's clearer that they belong to the
CST anchor system.

I also added "gui::cstAspectRatio", the aspect ratio of screen or Doom3's
window resolution (when using windowed mode).
Furthermore "gui::cstWidth" and "gui::cstHeigh" with the screen
(or Doom3 window) resolution in *virtual* pixels, based on that GUI
640x480 coordinate system.
For widescreen resolutions, "gui::cstHeight" is always 480 and
"gui::cstWidth" is scaled according to the aspect ratio (>640).
For tall resolutions, "gui::cstWidth" is always 640 and "gui::cstHeight"
is scaled according to the aspect ratio (> 480).
2025-02-23 06:33:27 +01:00
Daniel Gibson
60e670f12a Provide variables "gui::horPad" and "gui::vertPad" to GUI scripts
they are set before onActivate and also whenever the (Doom3 SDL) window
size changes, in that case additionally the "UpdateWindowSize" Named
Event is called in the script, in case you wanna do anything special
in that case:

  onNamedEvent UpdateWindowSize {
    set "print" "UpdateWindowSize - horPad:" "gui::horPad"
          "vertPad:" "gui::vertPad";
  }

horPad is the width of the padding border (empty space) between the
  left/right border of Doom3's SDL window and a centered
  (cstAnchor CST_ANCHOR_CENTER_CENTER) full-sized windowDef in virtual
  pixels (in the Doom3 GUI coordinate system, which usually is 640x480).
vertPad is the same for the padding border between the top/bottom border
  and a centered full-sized windowDef

One of those values will always be 0.

So for example if you play Doom3 at 1600x1200 (a 4:3 resolution like
640x480) both horPad and vertPad are 0.
If you play at 1680x1050 (16:10 resolution) and your windowDef Desktop
is 640x480 (the default), horPad is 64 (and vertPad is  0), because
there are 64 virtual pixels between the left window border and a
centered 640x480 windowDef (and also between the centered windowDef
and the right window border.

gui::horPad and gui::vertPad are useful for filling those otherwise
empty padding areas with windowDefs that you anchor to the corresponding
points of the window (like CST_ANCHOR_LEFT and CST_ANCHOR_RIGHT when
there's horizontal padding) that have just the right size.

Example of a green rectangle filling parts of the left padding area,
but not touching the center area (10 virtual pixels distance):

  windowDef leftPadFiller {
    cstAnchor  CST_ANCHOR_LEFT
    rect   0, 200, "gui::horPad" - 10, 40
    backColor 0, 1, 0, 1
  }
2025-02-20 03:44:18 +01:00
Daniel Gibson
4aef5c1dd4 Fix mousecursor handling for menus using "scaleto43 0"
especially useful when using cstAnchor

also providing an easy generic way to figure out if the window of an
idUserInterface is scaled to 4:3 aspect ratio or not, depending on
r_scaleMenusTo43 and the WIN_SCALETO43/WIN_NO_SCALETO43 window flags,
that come from "scaleto43 1" (or 0) set in the GUIs Desktop windowDef
2025-02-19 22:38:29 +01:00
Daniel Gibson
c30bff8c67 Support "scaleto43 0" in Desktop windowDefs to explicitly stretch them
even if r_scaleMenusTo43 1 and they'd usually be scaled to 4:3.
Useful when using anchors in fullscreen menus (like the PDA)

This is analogous to "scaleto43 1" in windowDefs which allows scaling
to 4:3 (with black/empty bars) even if by default it would *not* be
scaled.
2025-02-17 03:42:50 +01:00
Daniel Gibson
5376c6d74c HighDPI support, hopefully 2024-06-03 14:49:23 +02:00
Daniel Gibson
6310f699e1 Fix cursor focus for gamepads, once again, #566
hopefully it works now...
2024-03-20 18:31:28 +01:00
Daniel Gibson
9e8d399257 Further gamepad improvements
- the gamepad button (or trigger) bound to attack (fire) now always
  acts like the left mouse button in menus
- Display correct button name for "Back" button on Playstation-like
  gamepads, even depending on whether it's PS3-like ("Select") or
  PS4/5-like ("Share")
- Log some more information about detected gamepads
2024-01-18 19:53:45 +01:00
Daniel Gibson
cf5d10f4e6 Fix gamepad pseudo-mouse input for UIs in multiplayer mode
also, only generate pseudo-mouse-move events for gamecode
(by modifying idUsercmdGenLocal::continuousMouseX/Y) when an
interactive ingame UI is active
2024-01-17 17:45:43 +01:00
Daniel Gibson
03ec74fd6f Make PDA work with gamepad, incl. making Pad A emulate leftclick
this is a bit hacky and ugly, and doesn't work properly in multiplayer
mode yet, see FIXME in idUserInterfaceLocal::Activate()
2024-01-17 07:06:52 +01:00
Daniel Gibson
e0bb01ef52 Gamepad cursor control improvements
- make moving the cursor more precise by using an exponential curve
  for axis value => cursor speed
- emulate cursor keys with DPad and Enter with left trigger
- also use right trigger for leftclick, as it's usually used for firing
  a weapon and thus used for "clicking" ingame UIs
- fix hovering/highlighting menu elements when moving cursor
  with gamepad
2024-01-16 19:18:54 +01:00
Daniel Gibson
6eac0540bf Various gamepad improvements
- treat DPad as 4 regular buttons (was already the case mostly, but now
  the code is simpler)
- rename in_invertLook to joy_invertLook and in_useJoystick to
  in_useGamepad and remove unused CVars
- make controller Start button generate K_ESCAPE events, so it can
  always be used to open/close the menu (similar to D3BFG)
- move mousecursor with sticks, A button (south) for left-click,
  B button (east) for right-click (doesn't work in PDA yet)
- removed special handling of K_JOY_BTN_* in idWindow::HandleEvent()
  by generating fake mouse button events for gamepad A/B
  in idUserInterfaceLocal::HandleEvent()
2024-01-16 17:29:30 +01:00
Daniel Gibson
ae63021d00 Add absolute mouse mode and refactor mouse grabbing code
There were lots of places in the code that called Sys_GrabInput(),
some of them each frame.
Most of this is unified in events.cpp now, in handleMouseGrab() which
is called once per frame by Sys_GenerateEvents() - this makes reasoning
about when the mouse is grabbed and when not a lot easier.
Sys_GrabInput(false) still is called in a few places, before operations
that tend to take long (like loading a map or vid_restart), but
(hopefully) not regularly anymore.

The other big change is that the game now uses SDLs absolute mouse mode
for fullscreen menus (except the PDA which is an ugly hack), so the
ingame cursor is at the same position as the system cursor, which
especially helps when debugging with `in_nograb 1` and should also help
if someone wants to integrate an additional GUI toolkit like Dear ImGui.
2022-01-10 00:46:32 +01:00
gab
7d9d8680e1 Additional fix 2019-01-07 15:06:59 +01:00
Daniel Gibson
cd0a11f974 Allow scaling non-menu WIN_DESKTOP GUIs to 4:3
WIN_DESKTOP means that this can currently only be set for the top-level
window in a .gui (all its subwindows/widgets will be scaled implicitly)

There are two ways to make a GUI use this:
1. in the .gui add a window variable "scaleto43 1", like
    windowDef Desktop {
	rect	0 ,0 ,640 ,480
	nocursor	1
	float	talk 	0

	scaleto43 1

	// .. etc rest of windowDef

2. When creating the GUI from C++ code, you can afterwards make the
   UserInterface scale to 4:3 like this:
    idUserInterface* ui = Whatever(); // create it
    ui->SetStateBool("scaleto43", true);
    ui->StateChanged(gameLocal.time);
   Both lines are important!

As you can see in my changes to Player.cpp, my primary usecase for this
is the cursor/crosshair GUI.
2018-11-05 04:33:57 +01:00
Daniel Gibson
e41bf2b147 Scale "Menu" GUIs (incl. PDA + fullscreen vids) to 4:3
So stuff doesn't look so distorted in widescreen resolutions.
Implies that there are black bars on the left/right then..

Can be disabled with "r_scaleMenusTo43 0"

Does *not* affect the HUD (incl. crosshair) - scaling it automagically
would be very hard (or impossible), because it doesn't only render
the crosshair, healthpoints etc, but also fullscreen effects like the
screen turning red when the player is hit - and fullscreen effects
would look very shitty if they didn't cover the whole screen but had
"empty" bars on left/right.

(Mostly) fixes #188 and #189
2018-10-28 05:29:11 +01:00
Daniel Gibson
dad0eda29e Release Candiate 1 preparations, other small fixes 2015-10-03 19:14:22 +02:00
Daniel Gibson
61d3efec98 Fix mouse cursor moving to fast in fullscreen GUIs (main menu, PDA)
The fullscreen guis pretend to be 640x480 internally, also for the mouse
cursor position. So adding the actually moved pixels (when playing the
game at a higher resolution) to the GUIs cursor position makes it move
too fast.
To fix that I detect (hopefully that check is reliable!) if the
idUserInterfaceLocal instance is a fullscreen GUI and if so scale the
reported mouse moved pixels with 640/actual_window_width and
480/actual_window_height.
2015-09-30 18:38:27 +02:00
dhewg
736ec20d4d Untangle the epic precompiled.h mess
Don't include the lazy precompiled.h everywhere, only what's
required for the compilation unit.
platform.h needs to be included instead to provide all essential
defines and types.
All includes use the relative path to the neo or the game
specific root.
Move all idlib related includes from idlib/Lib.h to precompiled.h.
precompiled.h still exists for the MFC stuff in tools/.
Add some missing header guards.
2011-12-19 23:21:47 +01:00
dhewg
3f5c14ef5f Fix -Wunused-but-set-variable warnings
variable set but not used

Removes some CollisionModel code under _DEBUG which was probably a
leftover, since it was completely useless (its done later anyways).
2011-12-10 15:36:04 +01:00
dhewg
e4771f3a5f Fix -Wunused-variable warnings
unused variable
2011-12-10 15:36:03 +01:00
dhewg
79ad905e05 Fix all whitespace errors
Excluding 3rd party files.
2011-12-10 15:35:54 +01:00
dhewg
ff493f6847 Fix quoting in GPL headers 2011-12-10 15:34:48 +01:00
Timothee 'TTimo' Besset
fb1609f554 hello world 2011-11-22 15:28:15 -06:00