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

[glass] Add "About" popup with version number #3031

Merged
merged 1 commit into from
Jan 1, 2021
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
3 changes: 2 additions & 1 deletion glass/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ install(DIRECTORY src/libnt/native/include/ DESTINATION "${include_dest}/glass")
# glass application
#

configure_file(src/app/generate/WPILibVersion.cpp.in WPILibVersion.cpp)
GENERATE_RESOURCES(src/app/native/resources generated/app/cpp GLASS glass glass_resources_src)

file(GLOB glass_src src/app/native/cpp/*.cpp)
file(GLOB glass_src src/app/native/cpp/*.cpp ${CMAKE_CURRENT_BINARY_DIR}/WPILibVersion.cpp)

if (WIN32)
set(glass_rc src/app/native/win/glass.rc)
Expand Down
39 changes: 39 additions & 0 deletions glass/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,50 @@ if (!project.hasProperty('onlylinuxathena') && !project.hasProperty('onlylinuxra
apply from: "${rootDir}/shared/resources.gradle"
apply from: "${rootDir}/shared/config.gradle"

def wpilibVersionFileInput = file("src/app/generate/WPILibVersion.cpp.in")
def wpilibVersionFileOutput = file("$buildDir/generated/app/cpp/WPILibVersion.cpp")

task generateCppVersion() {
description = 'Generates the wpilib version class'
group = 'WPILib'

outputs.file wpilibVersionFileOutput
inputs.file wpilibVersionFileInput

if (wpilibVersioning.releaseMode) {
outputs.upToDateWhen { false }
}

// We follow a simple set of checks to determine whether we should generate a new version file:
// 1. If the release type is not development, we generate a new version file
// 2. If there is no generated version number, we generate a new version file
// 3. If there is a generated build number, and the release type is development, then we will
// only generate if the publish task is run.
doLast {
def version = wpilibVersioning.version.get()
println "Writing version ${version} to $wpilibVersionFileOutput"

if (wpilibVersionFileOutput.exists()) {
wpilibVersionFileOutput.delete()
}
def read = wpilibVersionFileInput.text.replace('${wpilib_version}', version)
wpilibVersionFileOutput.write(read)
}
}

gradle.taskGraph.addTaskExecutionGraphListener { graph ->
def willPublish = graph.hasTask(publish)
if (willPublish) {
generateCppVersion.outputs.upToDateWhen { false }
}
}

def generateTask = createGenerateResourcesTask('app', 'GLASS', 'glass', project)

project(':').libraryBuild.dependsOn build
tasks.withType(CppCompile) {
dependsOn generateTask
dependsOn generateCppVersion
}

nativeUtils.exportsConfigs {
Expand Down
7 changes: 7 additions & 0 deletions glass/src/app/generate/WPILibVersion.cpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Autogenerated file! Do not manually edit this file. This version is regenerated
* any time the publish task is run, or when this file is deleted.
*/
const char* GetWPILibVersion() {
return "${wpilib_version}";
}
24 changes: 24 additions & 0 deletions glass/src/app/native/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

namespace gui = wpi::gui;

const char* GetWPILibVersion();

namespace glass {
wpi::StringRef GetResource_glass_16_png();
wpi::StringRef GetResource_glass_32_png();
Expand Down Expand Up @@ -181,7 +183,29 @@ int main() {
gPlotProvider->DisplayMenu();
ImGui::EndMenu();
}

bool about = false;
if (ImGui::BeginMenu("Info")) {
if (ImGui::MenuItem("About")) {
about = true;
}
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();

if (about) {
ImGui::OpenPopup("About");
about = false;
PeterJohnson marked this conversation as resolved.
Show resolved Hide resolved
}
if (ImGui::BeginPopupModal("About")) {
ImGui::Text("Glass: A different kind of dashboard");
ImGui::Separator();
ImGui::Text("v%s", GetWPILibVersion());
if (ImGui::Button("Close")) {
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
});

gui::Initialize("Glass - DISCONNECTED", 1024, 768);
Expand Down