Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BufferView] + add option to colorize main window when it's not in focus #337

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion GViewCore/src/App/GViewApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ bool GView::App::ResetConfiguration()
ini["GView"]["Key.SwitchToView"] = Key::Alt | Key::F;
ini["GView"]["Key.GoTo"] = Key::F5;
ini["GView"]["Key.Find"] = Key::Alt | Key::F7;
ini["GView"]["Key.ChoseType"] = Key::Alt | Key::F1;
ini["GView"]["Key.ChooseType"] = Key::Alt | Key::F1;

// all good (save config)
return ini.Save(AppCUI::Application::GetAppSettingsFile());
Expand Down
14 changes: 14 additions & 0 deletions GViewCore/src/View/BufferViewer/BufferViewer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ struct Config {
AppCUI::Input::Key FindPrevious;
AppCUI::Input::Key Copy;
AppCUI::Input::Key DissasmDialog;
AppCUI::Input::Key ShowColorNotFocused;
} Keys;
bool Loaded;

Expand Down Expand Up @@ -144,6 +145,17 @@ namespace Commands
constexpr int BUFFERVIEW_CMD_FINDNEXT = 0xBF07;
constexpr int BUFFERVIEW_CMD_FINDPREVIOUS = 0xBF08;
constexpr int BUFFERVIEW_CMD_DISSASM_DIALOG = 0xBF09;
/*
constexpr int32 VIEW_COMMAND_ACTIVATE_COMPARE{ 0xBF10 };
constexpr int32 VIEW_COMMAND_DEACTIVATE_COMPARE{ 0xBF11 };
constexpr int32 VIEW_COMMAND_ACTIVATE_SYNC{ 0xBF12 };
constexpr int32 VIEW_COMMAND_DEACTIVATE_SYNC{ 0xBF13 };
constexpr int32 VIEW_COMMAND_ACTIVATE_CODE_EXECUTION{ 0xBF14 };
constexpr int32 VIEW_COMMAND_DEACTIVATE_CODE_EXECUTION{ 0xBF15 };
constexpr int32 VIEW_COMMAND_ACTIVATE_OBJECT_HIGHLIGHTING{ 0xBF16 };
constexpr int32 VIEW_COMMAND_DEACTIVATE_OBJECT_HIGHLIGHTING{ 0xBF17 };
*/
constexpr int BUFFERVIEW_CMD_SHOW_COLOR = 0xBF18;

//TODO: fully integrate these commands
static KeyboardControl ChangeColumnsCount = { Input::Key::F6, "ChangeColumnsCount", "Change the columns number", BUFFERVIEW_CMD_CHANGECOL };
Expand All @@ -157,6 +169,7 @@ namespace Commands
static KeyboardControl FindNext = { Input::Key::Ctrl | Input::Key::F7, "FindNext", "Find the next sequence", BUFFERVIEW_CMD_FINDNEXT };
static KeyboardControl FindPrevious = { Input::Key::Ctrl | Input::Key::Shift | Input::Key::F7, "FindPrevious", "Find previous sequence", BUFFERVIEW_CMD_FINDPREVIOUS };
static KeyboardControl DissasmDialogCmd = { Input::Key::Ctrl | Input::Key::D, "DissasmDialog", "Open dissasm dialog", BUFFERVIEW_CMD_DISSASM_DIALOG };
static KeyboardControl ShowColorNotFocused = { Input::Key::Ctrl | Input::Key::Alt | Input::Key::C, "ShowColor", "Show color when main windows is not in focus", BUFFERVIEW_CMD_SHOW_COLOR };
}

class Instance : public View::ViewControl, public GView::Utils::SelectionZoneInterface, public GView::Utils::ObjectHighlightingZonesInterface
Expand Down Expand Up @@ -270,6 +283,7 @@ class Instance : public View::ViewControl, public GView::Utils::SelectionZoneInt
uint32 currentAdrressMode{ 0 };
String addressModesList;
BufferColor bufColor;
bool showColorNotFocused{ true };

static Config config;

Expand Down
43 changes: 24 additions & 19 deletions GViewCore/src/View/BufferViewer/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,28 @@ using namespace AppCUI::Input;

constexpr auto SECTION_NAME_VIEW_BUFFER = "View.Buffer";

constexpr auto KEY_NAME_CHANGE_COLUMNS_COUNT = "Key.ChangeColumnsCount";
constexpr auto KEY_NAME_CHANGE_VALUE_FORMAT_OR_CP = "Key.ChangeValueFormatOrCP";
constexpr auto KEY_NAME_CHANGE_ADDRESS_MODE = "Key.ChangeAddressMode";
constexpr auto KEY_NAME_GO_TO_ENTRY_POINT = "Key.GoToEntryPoint";
constexpr auto KEY_NAME_CHANGE_SELECTION_TYPE = "Key.ChangeSelectionType";
constexpr auto KEY_NAME_SHOW_HIDE_STRINGS = "Key.ShowHideStrings";
constexpr auto KEY_NAME_FIND_NEXT = "Key.FindNext";
constexpr auto KEY_NAME_FIND_PREVIOUS = "Key.FindPrevious";
constexpr auto KEY_NAME_COPY = "Key.Copy";
constexpr auto KEY_NAME_DISSASM = "Key.DissasmDialog";
constexpr auto KEY_NAME_CHANGE_COLUMNS_COUNT = "Key.ChangeColumnsCount";
constexpr auto KEY_NAME_CHANGE_VALUE_FORMAT_OR_CP = "Key.ChangeValueFormatOrCP";
constexpr auto KEY_NAME_CHANGE_ADDRESS_MODE = "Key.ChangeAddressMode";
constexpr auto KEY_NAME_GO_TO_ENTRY_POINT = "Key.GoToEntryPoint";
constexpr auto KEY_NAME_CHANGE_SELECTION_TYPE = "Key.ChangeSelectionType";
constexpr auto KEY_NAME_SHOW_HIDE_STRINGS = "Key.ShowHideStrings";
constexpr auto KEY_NAME_FIND_NEXT = "Key.FindNext";
constexpr auto KEY_NAME_FIND_PREVIOUS = "Key.FindPrevious";
constexpr auto KEY_NAME_COPY = "Key.Copy";
constexpr auto KEY_NAME_DISSASM = "Key.DissasmDialog";
constexpr auto KEY_NAME_SHOW_COLOR_WHEN_NOT_FOCUSED = "Key.ShowColorNotFocused";

constexpr auto KEY_CHANGE_COLUMNS_COUNT = Key::F6;
constexpr auto KEY_CHANGE_VALUE_FORMAT_OR_CP = Key::F2;
constexpr auto KEY_CHANGE_ADDRESS_MODE = Key::F3;
constexpr auto KEY_GO_TO_ENTRY_POINT = Key::F7;
constexpr auto KEY_CHANGE_SELECTION_TYPE = Key::F9;
constexpr auto KEY_SHOW_HIDE_STRINGS = Key::Alt | Key::F3;
constexpr auto KEY_FIND_NEXT = Key::Ctrl | Key::F7;
constexpr auto KEY_FIND_PREVIOUS = Key::Ctrl | Key::Shift | Key::F7;
constexpr auto KEY_DISSASM = Key::Ctrl | Key::D;
constexpr auto KEY_CHANGE_COLUMNS_COUNT = Key::F6;
constexpr auto KEY_CHANGE_VALUE_FORMAT_OR_CP = Key::F2;
constexpr auto KEY_CHANGE_ADDRESS_MODE = Key::F3;
constexpr auto KEY_GO_TO_ENTRY_POINT = Key::F7;
constexpr auto KEY_CHANGE_SELECTION_TYPE = Key::F9;
constexpr auto KEY_SHOW_HIDE_STRINGS = Key::Alt | Key::F3;
constexpr auto KEY_FIND_NEXT = Key::Ctrl | Key::F7;
constexpr auto KEY_FIND_PREVIOUS = Key::Ctrl | Key::Shift | Key::F7;
constexpr auto KEY_DISSASM = Key::Ctrl | Key::D;
constexpr auto KEY_SHOW_COLOR_WHEN_NOT_FOCUSED = Key::Ctrl | Key::Alt | Key::C;

void Config::Update(IniSection sect)
{
Expand All @@ -37,6 +39,7 @@ void Config::Update(IniSection sect)
sect.UpdateValue(KEY_NAME_FIND_NEXT, KEY_FIND_NEXT, true);
sect.UpdateValue(KEY_NAME_FIND_PREVIOUS, KEY_FIND_PREVIOUS, true);
sect.UpdateValue(KEY_NAME_DISSASM, KEY_DISSASM, true);
sect.UpdateValue(KEY_NAME_SHOW_COLOR_WHEN_NOT_FOCUSED, KEY_SHOW_COLOR_WHEN_NOT_FOCUSED, true);
}

void Config::Initialize()
Expand All @@ -57,6 +60,7 @@ void Config::Initialize()
this->Keys.FindNext = sect.GetValue(KEY_NAME_FIND_NEXT).ToKey(KEY_FIND_NEXT);
this->Keys.FindPrevious = sect.GetValue(KEY_NAME_FIND_PREVIOUS).ToKey(KEY_FIND_PREVIOUS);
this->Keys.DissasmDialog = sect.GetValue(KEY_NAME_DISSASM).ToKey(KEY_DISSASM);
this->Keys.ShowColorNotFocused = sect.GetValue(KEY_NAME_SHOW_COLOR_WHEN_NOT_FOCUSED).ToKey(KEY_SHOW_COLOR_WHEN_NOT_FOCUSED);
}
else
{
Expand All @@ -69,6 +73,7 @@ void Config::Initialize()
this->Keys.FindNext = KEY_FIND_NEXT;
this->Keys.FindPrevious = KEY_FIND_PREVIOUS;
this->Keys.DissasmDialog = KEY_DISSASM;
this->Keys.ShowColorNotFocused = KEY_SHOW_COLOR_WHEN_NOT_FOCUSED;
}

this->Loaded = true;
Expand Down
43 changes: 32 additions & 11 deletions GViewCore/src/View/BufferViewer/Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,6 @@ bool Instance::ShowCopyDialog()

return true;
}

bool Instance::ShowDissasmDialog()
{
DissasmDialog dlg(this);
Expand Down Expand Up @@ -694,7 +693,7 @@ void Instance::WriteHeaders(Renderer& renderer)
WriteTextParams params(WriteTextFlags::OverwriteColors | WriteTextFlags::SingleLine | WriteTextFlags::ClipToWidth);
params.Align = TextAlignament::Left;
params.Y = 0;
params.Color = this->HasFocus() ? Cfg.Header.Text.Focused : Cfg.Header.Text.Normal;
params.Color = (this->showColorNotFocused || this->HasFocus()) ? Cfg.Header.Text.Focused : Cfg.Header.Text.Normal;

renderer.FillHorizontalLine(0, 0, this->GetWidth(), ' ', params.Color);

Expand Down Expand Up @@ -739,7 +738,7 @@ void Instance::WriteLineAddress(DrawLineInfo& dli)
auto c = Cfg.Text.Inactive;
auto n = dli.chNameAndSize;

if (HasFocus()) {
if (this->showColorNotFocused || this->HasFocus()) {
c = OffsetToColorZone(dli.offset);
}

Expand Down Expand Up @@ -817,10 +816,10 @@ void Instance::WriteLineAddress(DrawLineInfo& dli)
}
void Instance::WriteLineTextToChars(DrawLineInfo& dli)
{
auto cp = Cfg.Text.Inactive;
bool activ = this->HasFocus();
auto cp = Cfg.Text.Inactive;
bool active = this->showColorNotFocused || this->HasFocus();

if (activ) {
if (active) {
const auto startCh = dli.chText;
const auto ofsStart = dli.offset;
while (dli.start < dli.end) {
Expand Down Expand Up @@ -857,14 +856,14 @@ void Instance::WriteLineNumbersToChars(DrawLineInfo& dli)
{
auto c = dli.chNumbers;
auto cp = Cfg.Text.Inactive;
bool activ = this->HasFocus();
bool active = this->showColorNotFocused || this->HasFocus();
auto ut = (uint8) 0;
auto sps = dli.chText;
auto start = dli.offset;
auto end = start + (dli.end - dli.start);

while (dli.start < dli.end) {
if (activ) {
if (active) {
cp = OffsetToColor(dli.offset);

if (selection.Contains(dli.offset)) {
Expand Down Expand Up @@ -987,7 +986,7 @@ void Instance::WriteLineNumbersToChars(DrawLineInfo& dli)
c->Color = cp;
c++;

if (activ) {
if (active) {
if (StringInfo.type == StringType::Unicode) {
if (dli.offset > StringInfo.middle)
dli.chText->Code = ' ';
Expand All @@ -1011,7 +1010,7 @@ void Instance::WriteLineNumbersToChars(DrawLineInfo& dli)
c->Color = Cfg.Text.Inactive;
c++;
}
if ((activ) && (this->cursor.GetCurrentPosition() >= start) && (this->cursor.GetCurrentPosition() < end)) {
if ((active) && (this->cursor.GetCurrentPosition() >= start) && (this->cursor.GetCurrentPosition() < end)) {
const auto reprsz = characterFormatModeSize[static_cast<uint32>(this->Layout.charFormatMode)] + 1;
c = dli.chNumbers + (this->cursor.GetCurrentPosition() - start) * reprsz;
const auto st = this->chars.GetBuffer();
Expand Down Expand Up @@ -1137,6 +1136,12 @@ bool Instance::OnUpdateCommandBar(AppCUI::Application::CommandBar& commandBar)

commandBar.SetCommand(config.Keys.DissasmDialog, "Dissasm", BUFFERVIEW_CMD_DISSASM_DIALOG);

if (this->showColorNotFocused) {
commandBar.SetCommand(config.Keys.ShowColorNotFocused, "ShowColorWhenNotFocused:ON", BUFFERVIEW_CMD_SHOW_COLOR);
} else {
commandBar.SetCommand(config.Keys.ShowColorNotFocused, "ShowColorWhenNotFocused:OFF", BUFFERVIEW_CMD_SHOW_COLOR);
}

return false;
}
bool Instance::OnKeyEvent(AppCUI::Input::Key keyCode, char16 charCode)
Expand Down Expand Up @@ -1447,6 +1452,11 @@ bool Instance::OnEvent(Reference<Control>, Event eventType, int ID)
case VIEW_COMMAND_DEACTIVATE_OBJECT_HIGHLIGHTING:
showObjectsHighlighting = false;
return true;

case BUFFERVIEW_CMD_SHOW_COLOR:
this->showColorNotFocused = !this->showColorNotFocused;
UpdateViewSizes();
return true;
}
return false;
}
Expand All @@ -1470,6 +1480,7 @@ bool Instance::UpdateKeys(KeyboardControlsInterface* interface)
interface->RegisterKey(&FindNext);
interface->RegisterKey(&FindPrevious);
interface->RegisterKey(&DissasmDialogCmd);
interface->RegisterKey(&ShowColorNotFocused);
return true;
}

Expand Down Expand Up @@ -1595,7 +1606,6 @@ int Instance::Print8bitValue(int x, int height, AppCUI::Utils::BufferView buffer
}
return x;
}

int Instance::Print16bitValue(int x, int height, AppCUI::Utils::BufferView buffer, Renderer& r)
{
if (buffer.GetLength() < 2)
Expand Down Expand Up @@ -1922,6 +1932,8 @@ enum class PropertyID : uint32 {
ChangeSelectionType,
ShowHideStrings,
Dissasm,
// color behavior
ShowColorNotFocused
};
#define BT(t) static_cast<uint32>(t)

Expand Down Expand Up @@ -2012,6 +2024,9 @@ bool Instance::GetPropertyValue(uint32 id, PropertyValue& value)
case PropertyID::Dissasm:
value = config.Keys.DissasmDialog;
return true;
case PropertyID::ShowColorNotFocused:
value = config.Keys.ShowColorNotFocused;
return true;
}
return false;
}
Expand Down Expand Up @@ -2115,6 +2130,9 @@ bool Instance::SetPropertyValue(uint32 id, const PropertyValue& value, String& e
case PropertyID::AddressType:
this->currentAdrressMode = (uint32) std::get<uint64>(value);
return true;
case PropertyID::ShowColorNotFocused:
this->showColorNotFocused = (bool) std::get<bool>(value);
return true;
}
error.SetFormat("Unknown internat ID: %u", id);
return false;
Expand Down Expand Up @@ -2194,6 +2212,9 @@ const vector<Property> Instance::GetPropertiesList()

// dissasm
{ BT(PropertyID::Dissasm), "Shortcuts", "Dissasm", PropertyType::Key },

// coloring
{ BT(PropertyID::ShowColorNotFocused), "Coloring", "Show color when main window is not in focus", PropertyType::Boolean },
};
}
#undef BT
2 changes: 1 addition & 1 deletion GViewCore/src/include/Internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ namespace App
static GView::KeyboardControl FILE_WINDOW_COMMAND_INSERT = { Input::Key::Ctrl | Input::Key::Insert, "CopyDialog", "Open the CopyPaste dialog", CMD_COPY_DIALOG };
static GView::KeyboardControl INSTANCE_CHANGE_VIEW = { Input::Key::F4, "ChangeView", "Change the current viewer", CMD_NEXT_VIEW };
static GView::KeyboardControl INSTANCE_SWITCH_TO = { Input::Key::Alt | Input::Key::F, "SwitchToView", "Set focus on viewer", CMD_SWITCH_TO_VIEW };
static GView::KeyboardControl INSTANCE_NEW_TYPE = { Input::Key::Alt | Input::Key::F1, "ChoseType", "Choose a new plugin type", CMD_SWITCH_TO_VIEW };
static GView::KeyboardControl INSTANCE_NEW_TYPE = { Input::Key::Alt | Input::Key::F1, "ChooseType", "Choose a new plugin type", CMD_SWITCH_TO_VIEW };
static GView::KeyboardControl INSTANCE_KEY_CONFIGURATOR = { Input::Key::F1, "ShowKeys", "Show available keys", CMD_SHOW_KEY_CONFIGURATOR };
}

Expand Down
Loading