Skip to content

Commit

Permalink
- Working on tab window UI 5/n
Browse files Browse the repository at this point in the history
- Working on input bar 2/n
- Added Splash screen.
- Added App icon.
  • Loading branch information
casdata committed Apr 30, 2023
1 parent b4ccee1 commit dc94e8c
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 23 deletions.
Binary file added Assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set(serial_PATH ${serial_PATH} ${CMAKE_SOURCE_DIR}/Serial)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
set(SDL2_PATH "SDL2")
set(SDL2_IMAGE_PATH "SDL2")
set(APP_ICON_RESOURCE_WINDOWS "${CMAKE_CURRENT_SOURCE_DIR}/appicon.rc")

find_package(OpenGL REQUIRED)
find_package(SDL2 REQUIRED)
Expand Down Expand Up @@ -70,7 +71,8 @@ add_executable(FruitySerial main.cpp
Tools/ClockTime.cpp
Tools/ClockTime.h
Tools/UndoRedo.cpp
Tools/UndoRedo.h)
Tools/UndoRedo.h
${APP_ICON_RESOURCE_WINDOWS})


target_include_directories(${PROJECT_NAME} PUBLIC ${imgui_SOURCE_DIR} ${imgui_SOURCE_DIR}/backends)
Expand Down
9 changes: 9 additions & 0 deletions Data/DTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,15 @@ static const char* BYTE_SIZE_ITEMS[] = {"5", "6", "7", "8"};
static const char* PARITY_ITEMS[] = {"none", "odd", "even"};
static const char* STOP_BITS_ITEMS[] = {"1", "1.5", "2"};
static const char* FLOW_CONTROL_ITEMS[] = {"none", "software", "hardware"};

static const char* EOL_ITEMS[] = {"no line", "new line", "carriage return", "cr & lf"};

/*
* noLine,
newLine,
carrieReturn,
crAndLf
*/
/*
* RAW_DEC = 0,
RAW_HEX,
Expand Down
53 changes: 51 additions & 2 deletions UIDisplays/Hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Hud::Hud() {
ret = FunctionTools::loadTextureFromFile("../Assets/menuDarkUp.png", &menuDarkTexture, &imageWidth, &imageHeight);
IM_ASSERT(ret);

ret = FunctionTools::loadTextureFromFile("../Assets/icon.png", &iconTexture, &imageWidth, &imageHeight);
IM_ASSERT(ret);

ret = FunctionTools::loadTextureFromFile("../Assets/newBtn.png", &newBtnTexture, &imageWidth, &imageHeight);
IM_ASSERT(ret);

Expand Down Expand Up @@ -95,18 +98,64 @@ void Hud::menuBar(MenuData &menuData, AppData &appData, const IOData &ioData) {
else
texture = menuLightTexture;

//if(menuData.titleBar != TB_ENABLE)
//texture = iconTexture;

float iconSize = FunctionTools::norm2Height(static_cast<int>(menuBarIconSize->y));
int imagePadding = FunctionTools::norm2Height(4);


if(menuData.titleBar != TB_ENABLE) {
ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetColorU32(ImGuiCol_MenuBarBg));

ImVec2 tempCursor0 = ImGui::GetCursorScreenPos();

if(ImGui::ImageButton((void*)(intptr_t)iconTexture, ImVec2(iconSize,iconSize), ImVec2(0,0), ImVec2(1,1),imagePadding)){
ImGui::OpenPopup("iconMenu");
}

ImGui::PopStyleColor();

ImGui::SetNextWindowPos(ImVec2(tempCursor0.x + FunctionTools::norm2Height(4), ImGui::GetWindowViewport()->Pos.y + FunctionTools::norm2Height(31)));
if(ImGui::BeginPopup("iconMenu")){
if(ImGui::MenuItem("Restore")){

}
ImGui::Spacing();

if(ImGui::MenuItem("Minimize")){

}
ImGui::Spacing();

if(ImGui::MenuItem("Maximize")){

}
ImGui::Separator();

if(ImGui::MenuItem("Close")){

}

ImGui::EndPopup();
}

ImGui::Spacing();

}


ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetColorU32(ImGuiCol_MenuBarBg));

ImVec2 tempCursor = ImGui::GetCursorScreenPos();

if(ImGui::ImageButton((void*)(intptr_t)texture, ImVec2(iconSize,iconSize), ImVec2(0,0), ImVec2(1,1), imagePadding)) {
ImGui::OpenPopup("menuPopup");
}

ImGui::PopStyleColor();


ImGui::SetNextWindowPos(ImVec2(ImGui::GetWindowViewport()->Pos.x + FunctionTools::norm2Height(8),ImGui::GetWindowViewport()->Pos.y + FunctionTools::norm2Height(31)));
ImGui::SetNextWindowPos(ImVec2(tempCursor.x, ImGui::GetWindowViewport()->Pos.y + FunctionTools::norm2Height(31)));

if(ImGui::BeginPopup("menuPopup")){

Expand Down
1 change: 1 addition & 0 deletions UIDisplays/Hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Hud {
GLuint maximizeTexture = 0;
GLuint maximize2Texture = 0;
GLuint closeTexture = 0;
GLuint iconTexture = 0;

GLuint uNewBtnTexture = 0;
GLuint uOpenBtnTexture = 0;
Expand Down
31 changes: 12 additions & 19 deletions UIDisplays/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,18 +518,6 @@ void MainWindow::updateAndPrintInputBar(const double &dt, const AppData &appData




/*
if (appData.uiTheme == DARK)
tColor = IM_COL32_WHITE;
else
tColor = IM_COL32_BLACK;
draw_list->AddText(textPos, tColor, inputTextBarBuffer.c_str());
*/



if (onInputTextBar) {
caretCurrentTime += dt;
if (caretCurrentTime > 700) {
Expand Down Expand Up @@ -558,15 +546,12 @@ void MainWindow::updateAndPrintInputBar(const double &dt, const AppData &appData

ImGui::PopFont();


ImGui::SameLine();

static char buf[12] = "";
ImGui::SetNextItemWidth(120);
ImGui::InputText("##inputBar", buf, sizeof(buf));
static int eolOp = 0;
//ImGui::Combo("##eolOption", &eolOp)

ImGui::SameLine();

ImGui::Button("Send");


Expand Down Expand Up @@ -980,8 +965,12 @@ void MainWindow::checkInputTextBarIO(const double &dt, AppData &appdata, const I



for (size_t i = 0; i < ioData.charBuffer.size(); i++, iTextBarBufferPC++)
inputTextBarBuffer.insert(inputTextBarBuffer.begin() + iTextBarBufferPC, ioData.charBuffer.at(i));
for (size_t i = 0; i < ioData.charBuffer.size(); i++, iTextBarBufferPC++) {
if(ioData.charBuffer.at(i) == 0xD || ioData.charBuffer.at(i) == 0xA) //carriage or new line char
inputTextBarBuffer.insert(inputTextBarBuffer.begin() + iTextBarBufferPC, 0x20); //space char
else
inputTextBarBuffer.insert(inputTextBarBuffer.begin() + iTextBarBufferPC, ioData.charBuffer.at(i));
}



Expand Down Expand Up @@ -1036,6 +1025,8 @@ void MainWindow::checkInputTextBarIO(const double &dt, AppData &appdata, const I
}

if(ioData.keyLeft == DOWN){
ImGui::SetKeyboardFocusHere();

caretCurrentTime = 0;
showInputBarCaret = true;

Expand Down Expand Up @@ -1095,6 +1086,8 @@ void MainWindow::checkInputTextBarIO(const double &dt, AppData &appdata, const I
}

if(ioData.keyRight == DOWN){
ImGui::SetKeyboardFocusHere();

caretCurrentTime = 0;
showInputBarCaret = true;

Expand Down
Binary file added appicon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions appicon.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IDI_ICON1 ICON DISCARDABLE "appicon.ico"
91 changes: 90 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <iostream>
#include <string>
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_thread.h>


Expand All @@ -30,10 +31,19 @@
#include "serial/serial.h"
#include "SerialManager.h"
#include "ClockTime.h"
//#include "SDL_syswm.h"

SDL_Window* gSplashWindow;
SDL_Window* gWindow;
SDL_GLContext gl_context;

SDL_Surface* iconSurface = nullptr;
SDL_Surface* gSplashSurface = nullptr;
SDL_Surface* pngSplashSurface = nullptr;

bool splashEnable = true;
double splashCurrentTime = 0;

Hud *hud;
SerialManager *serialManager;
ClockTime *clockTime;
Expand Down Expand Up @@ -456,6 +466,24 @@ int main(int, char**)
ImGui::End();


if(splashEnable){
splashCurrentTime += deltaTime;
if(splashCurrentTime > 1600 ){
splashEnable = false;

SDL_ShowWindow(gWindow);

SDL_FreeSurface(pngSplashSurface);
pngSplashSurface = nullptr;

SDL_DestroyWindow(gSplashWindow);
gSplashWindow = nullptr;

IMG_Quit();

}
}


hud->drawMainWin(deltaTime, appData, serialManager);

Expand Down Expand Up @@ -508,6 +536,9 @@ int main(int, char**)
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
SDL_GL_MakeCurrent(backup_current_window, backup_current_context);

if(splashEnable)
SDL_UpdateWindowSurface(gSplashWindow);
}

SDL_GL_SwapWindow(gWindow);
Expand All @@ -525,6 +556,8 @@ int main(int, char**)

SDL_GL_DeleteContext(gl_context);
SDL_DestroyWindow(gWindow);
SDL_FreeSurface(iconSurface);

SDL_Quit();

return 0;
Expand Down Expand Up @@ -562,12 +595,68 @@ bool initSDL(){
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);


SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);// | SDL_WINDOW_BORDERLESS);
gWindow = SDL_CreateWindow("Fruity Serial Terminal", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1024, 768, window_flags); //1280, 980,

gSplashWindow = SDL_CreateWindow("Loading", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 470, 626, window_flags | SDL_WINDOW_BORDERLESS);
gl_context = SDL_GL_CreateContext(gSplashWindow);

//SDL_SetWindowOpacity(gSplashWindow, 0.9f);
/*
SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version);
SDL_GetWindowWMInfo(gSplashWindow, &wmInfo);
HWND hWnd = wmInfo.info.win.window;
SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE | WS_EX_LAYERED));
SetLayeredWindowAttributes(hWnd,RGB(255, 255, 255),0, LWA_COLORKEY );
*/

gWindow = SDL_CreateWindow("Fruity Serial Terminal", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1024, 768, window_flags | SDL_WINDOW_HIDDEN ); //1280, 980,
gl_context = SDL_GL_CreateContext(gWindow);
SDL_GL_MakeCurrent(gWindow, gl_context);
SDL_GL_SetSwapInterval(1); // Enable vsync

int imgFlags = IMG_INIT_PNG;

SDL_Surface* loadedSurface = IMG_Load("../Assets/icon.png");
if(loadedSurface != nullptr){
iconSurface = SDL_ConvertSurface(loadedSurface, loadedSurface->format, 0);

if(iconSurface == nullptr)
std::cout << "ERROR: can't create png icon" << std::endl;
else
SDL_SetWindowIcon(gWindow, loadedSurface);



SDL_FreeSurface(loadedSurface);
}

loadedSurface = IMG_Load("../Assets/splash.png");
if(loadedSurface != nullptr){
pngSplashSurface = SDL_ConvertSurface(loadedSurface, loadedSurface->format, 0);

if(pngSplashSurface == nullptr)
std::cout << "ERROR: can't create png splash" << std::endl;
else{

if(!(IMG_Init(imgFlags) & imgFlags))
std::cout<<"SDL_image could not initialize!"<<std::endl;
else{
gSplashSurface = SDL_GetWindowSurface(gSplashWindow);
SDL_BlitSurface(pngSplashSurface, nullptr, gSplashSurface, nullptr);
}

}


SDL_FreeSurface(loadedSurface);
}


SDL_DisplayMode dm;
SDL_GetCurrentDisplayMode(0, &dm);
std::cout<<"DisplayMode: "<<dm.w<<" "<<dm.h<<std::endl;
Expand Down

0 comments on commit dc94e8c

Please sign in to comment.