Skip to content

Commit

Permalink
Draw a crosshair on current pointer coordinates (#510)
Browse files Browse the repository at this point in the history
  • Loading branch information
clementgallet committed Dec 30, 2022
1 parent 46f72e6 commit 44dc7d3
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

* Add a "Save as default" button for the Encode window (#507)
* Revamp settings
* Draw a crosshair on current pointer coordinates (#510)

### Changed

Expand All @@ -14,6 +15,7 @@
* Fix OSD SDL2 renderer memory leak
* Fix SDL_GameController functions as they raised the maximum number of buttons
* Get game window size from SDL2 when possible (#513)
* Set pixel buffer and pack row before reading pixels (#505)

## [1.4.4] - 2022-10-25
### Added
Expand Down
33 changes: 22 additions & 11 deletions src/library/renderhud/RenderHUD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ void RenderHUD::resetOffsets()

void RenderHUD::drawFrame(uint64_t framecount)
{
Color fg_color = {255, 255, 255, 0};
Color bg_color = {0, 0, 0, 0};
Color fg_color = {255, 255, 255, 255};
Color bg_color = {0, 0, 0, 255};
std::string framestr = std::to_string(framecount);
switch (shared_config.recording) {
case SharedConfig::RECORDING_READ:
Expand All @@ -122,8 +122,8 @@ void RenderHUD::drawFrame(uint64_t framecount)

void RenderHUD::drawNonDrawFrame(uint64_t nondraw_framecount)
{
Color red_color = {255, 0, 0, 0};
Color bg_color = {0, 0, 0, 0};
Color red_color = {255, 0, 0, 255};
Color bg_color = {0, 0, 0, 255};
std::string nondraw_framestr = std::to_string(nondraw_framecount);

int x, y;
Expand Down Expand Up @@ -196,7 +196,7 @@ void RenderHUD::drawInputs(const AllInputs& ai, Color fg_color)
}

/* Render */
Color bg_color = {0, 0, 0, 0};
Color bg_color = {0, 0, 0, 255};
std::string text = oss.str();
if (!text.empty()) {
int x, y;
Expand All @@ -216,8 +216,8 @@ void RenderHUD::insertMessage(const char* message)

void RenderHUD::drawMessages()
{
Color fg_color = {255, 255, 255, 0};
Color bg_color = {0, 0, 0, 0};
Color fg_color = {255, 255, 255, 255};
Color bg_color = {0, 0, 0, 255};

TimeHolder message_timeout;
message_timeout = {2, 0};
Expand Down Expand Up @@ -254,8 +254,8 @@ void RenderHUD::resetWatches()

void RenderHUD::drawWatches()
{
Color fg_color = {255, 255, 255, 0};
Color bg_color = {0, 0, 0, 0};
Color fg_color = {255, 255, 255, 255};
Color bg_color = {0, 0, 0, 255};

for (auto iter = watches.begin(); iter != watches.end(); iter++) {
int x, y;
Expand Down Expand Up @@ -283,6 +283,15 @@ void RenderHUD::drawLua()
}
}

void RenderHUD::drawCrosshair(const AllInputs& ai)
{
int size = 5;
renderRect(ai.pointer_x-1, ai.pointer_y-size-1, 3, 2*size+3, 0, {0, 0, 0, 255}, {0, 0, 0, 255});
renderRect(ai.pointer_x-size-1, ai.pointer_y-1, 2*size+3, 3, 0, {0, 0, 0, 255}, {0, 0, 0, 255});
renderLine(ai.pointer_x, ai.pointer_y-size, ai.pointer_x, ai.pointer_y+size, {255, 255, 255, 255});
renderLine(ai.pointer_x-size, ai.pointer_y, ai.pointer_x+size, ai.pointer_y, {255, 255, 255, 255});
}

void RenderHUD::insertLuaText(int x, int y, std::string text, uint32_t fg_color, uint32_t bg_color)
{
LuaText lt;
Expand Down Expand Up @@ -376,8 +385,8 @@ void RenderHUD::drawAll(uint64_t framecount, uint64_t nondraw_framecount, const
// hud.drawNonDrawFrame(nondraw_framecount);
}
if (shared_config.osd & SharedConfig::OSD_INPUTS) {
drawInputs(ai, {255, 255, 255, 0});
drawInputs(preview_ai, {160, 160, 160, 0});
drawInputs(ai, {255, 255, 255, 255});
drawInputs(preview_ai, {160, 160, 160, 255});
}

if (shared_config.osd & SharedConfig::OSD_MESSAGES)
Expand All @@ -389,6 +398,8 @@ void RenderHUD::drawAll(uint64_t framecount, uint64_t nondraw_framecount, const
if (shared_config.osd & SharedConfig::OSD_LUA)
drawLua();

if (shared_config.osd & SharedConfig::OSD_CROSSHAIR)
drawCrosshair(ai);
}

}
Expand Down
3 changes: 3 additions & 0 deletions src/library/renderhud/RenderHUD.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ class RenderHUD
/* Display lua drawings */
void drawLua();

/* Display crosshair on current pointer position */
void drawCrosshair(const AllInputs& ai);

/* Location offsets when displaying multiple texts on the same location */
int offsets[9];

Expand Down
8 changes: 7 additions & 1 deletion src/program/ui/settings/VideoPane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ void VideoPane::initLayout()
watchesVertChoice->addItem("Bottom", SharedConfig::OSD_BOTTOM);

osdLuaBox = new QCheckBox(tr("Lua"));
osdCrosshairBox = new QCheckBox(tr("Crosshair"));

osdEncodeBox = new QCheckBox(tr("OSD on video encode"));

Expand All @@ -153,7 +154,8 @@ void VideoPane::initLayout()
osdLayout->addWidget(watchesHorChoice, 3, 1);
osdLayout->addWidget(watchesVertChoice, 3, 2);
osdLayout->addWidget(osdLuaBox, 4, 0);
osdLayout->addWidget(osdEncodeBox, 5, 0, 1, 3);
osdLayout->addWidget(osdCrosshairBox, 5, 0);
osdLayout->addWidget(osdEncodeBox, 6, 0, 1, 3);

renderingBox = new QGroupBox(tr("Rendering"));
QVBoxLayout* renderingLayout = new QVBoxLayout;
Expand Down Expand Up @@ -197,6 +199,7 @@ void VideoPane::initSignals()
connect(watchesHorChoice, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &VideoPane::saveConfig);
connect(watchesVertChoice, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &VideoPane::saveConfig);
connect(osdLuaBox, &QAbstractButton::clicked, this, &VideoPane::saveConfig);
connect(osdCrosshairBox, &QAbstractButton::clicked, this, &VideoPane::saveConfig);
connect(osdEncodeBox, &QAbstractButton::clicked, this, &VideoPane::saveConfig);

connect(rendSoftBox, &QAbstractButton::clicked, this, &VideoPane::saveConfig);
Expand Down Expand Up @@ -249,6 +252,7 @@ void VideoPane::loadConfig()
osdMessagesBox->setChecked(context->config.sc.osd & SharedConfig::OSD_MESSAGES);
osdRamBox->setChecked(context->config.sc.osd & SharedConfig::OSD_RAMWATCHES);
osdLuaBox->setChecked(context->config.sc.osd & SharedConfig::OSD_LUA);
osdCrosshairBox->setChecked(context->config.sc.osd & SharedConfig::OSD_CROSSHAIR);
osdEncodeBox->setChecked(context->config.sc.osd_encode);

int index;
Expand Down Expand Up @@ -318,6 +322,8 @@ void VideoPane::saveConfig()
context->config.sc.osd |= SharedConfig::OSD_RAMWATCHES;
if (osdLuaBox->isChecked())
context->config.sc.osd |= SharedConfig::OSD_LUA;
if (osdCrosshairBox->isChecked())
context->config.sc.osd |= SharedConfig::OSD_CROSSHAIR;

context->config.sc.osd_encode = osdEncodeBox->isChecked();

Expand Down
1 change: 1 addition & 0 deletions src/program/ui/settings/VideoPane.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class VideoPane : public QWidget {
QCheckBox* osdMessagesBox;
QCheckBox* osdRamBox;
QCheckBox* osdLuaBox;
QCheckBox* osdCrosshairBox;
QCheckBox* osdEncodeBox;

QComboBox *frameHorChoice;
Expand Down
5 changes: 3 additions & 2 deletions src/shared/SharedConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ struct __attribute__((packed, aligned(8))) SharedConfig {
OSD_INPUTS = 0x02,
OSD_MESSAGES = 0x04,
OSD_RAMWATCHES = 0x08,
OSD_LUA = 0x10
OSD_LUA = 0x10,
OSD_CROSSHAIR = 0x20,
};

/* Elements to be displayed on the OSD */
int osd = OSD_FRAMECOUNT | OSD_INPUTS | OSD_MESSAGES | OSD_RAMWATCHES | OSD_LUA;
int osd = OSD_FRAMECOUNT | OSD_INPUTS | OSD_MESSAGES | OSD_RAMWATCHES | OSD_LUA | OSD_CROSSHAIR;

/* OSD text location */
enum OSDLocation {
Expand Down

0 comments on commit 44dc7d3

Please sign in to comment.