Skip to content

Commit

Permalink
Init UI
Browse files Browse the repository at this point in the history
  • Loading branch information
vietanhdev committed Jul 25, 2023
1 parent dce641d commit b3b2994
Show file tree
Hide file tree
Showing 25 changed files with 57,907 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

Your customized AI characters on commodity hardware. This project aims to be a framework to enable the creation of AI characters that can be used in games, simulations, virtual assistants, and other applications without depending on specific platforms, cloud services, or specialized hardware.

**Some of the applications you can build with CustomChar:**
![](docs/customchar.png)

**Some of applications you can build with CustomChar:**

- Game characters that can talk to you and interact with you.
- Your customized virtual assistant. Think about a [JARVIS](https://en.wikipedia.org/wiki/J.A.R.V.I.S.) version on your computer.
Expand Down
6 changes: 6 additions & 0 deletions customchar-ui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
build
.DS_Store
.vscode
.idea
imgui.ini
*.o
107 changes: 107 additions & 0 deletions customchar-ui/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#
# Cross Platform Makefile
# Compatible with MSYS2/MINGW, Ubuntu 14.04.1 and Mac OS X
#
# You will need GLFW (http://www.glfw.org):
# Linux:
# apt-get install libglfw-dev
# Mac OS X:
# brew install glfw
# MSYS2:
# pacman -S --noconfirm --needed mingw-w64-x86_64-toolchain mingw-w64-x86_64-glfw
#

# CXX = g++
#CXX = clang++

EXE_BASE = customchar-ui
IMGUI_DIR = ./libs/imgui
SOURCES = main.cpp
SOURCES += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_draw.cpp $(IMGUI_DIR)/imgui_tables.cpp $(IMGUI_DIR)/imgui_widgets.cpp
SOURCES += $(IMGUI_DIR)/backends/imgui_impl_glfw.cpp $(IMGUI_DIR)/backends/imgui_impl_opengl3.cpp
SOURCES += chat_message.cpp chat_history.cpp
OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES))))
UNAME_S := $(shell uname -s)
LINUX_GL_LIBS = -lGL

CXXFLAGS = -std=c++2a -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends -I./libs/imgui/include -pthread
CXXFLAGS += -g -Wall -Wformat
LIBS =

##---------------------------------------------------------------------
## OPENGL ES
##---------------------------------------------------------------------

## This assumes a GL ES library available in the system, e.g. libGLESv2.so
# CXXFLAGS += -DIMGUI_IMPL_OPENGL_ES2
# LINUX_GL_LIBS = -lGLESv2

##---------------------------------------------------------------------
## BUILD FLAGS PER PLATFORM
##---------------------------------------------------------------------

ifeq ($(UNAME_S), Linux) #LINUX
CXX = g++-11
ECHO_MESSAGE = "Linux"
LIBS += $(LINUX_GL_LIBS) `pkg-config --static --libs glfw3`

CXXFLAGS += `pkg-config --cflags glfw3`
CFLAGS = $(CXXFLAGS)

EXE = $(EXE_BASE)
endif

ifeq ($(UNAME_S), Darwin) #APPLE
ECHO_MESSAGE = "Mac OS X"
LIBS += -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo
LIBS += -L/usr/local/lib -L/opt/local/lib -L/opt/homebrew/lib
#LIBS += -lglfw3
LIBS += -lglfw

CXXFLAGS += -I/usr/local/include -I/opt/local/include -I/opt/homebrew/include
CFLAGS = $(CXXFLAGS)

EXE = $(EXE_BASE).app
endif

ifeq ($(OS), Windows_NT)
ECHO_MESSAGE = "MinGW"
LIBS += -lglfw3 -lgdi32 -lopengl32 -limm32

CXXFLAGS += `pkg-config --cflags glfw3`
CFLAGS = $(CXXFLAGS)

EXE = $(EXE_BASE).exe
endif

##---------------------------------------------------------------------
## BUILD RULES
##---------------------------------------------------------------------

%.o:%.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<

%.o:src/%.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<

%.o:$(IMGUI_DIR)/%.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<

%.o:$(IMGUI_DIR)/backends/%.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<

all: $(EXE)
# Probably a better way to do this, but this works for now
rm -rf build
mkdir -p build
find . -name "*.o" -exec mv {} ./build \;
mv $(EXE) ./build
# Success message
@echo Build complete for $(ECHO_MESSAGE)

$(EXE): $(OBJS)
$(CXX) -o $@ $^ $(CXXFLAGS) $(LIBS)

clean:
rm -f $(EXE) $(OBJS)
rm -rf build
10 changes: 10 additions & 0 deletions customchar-ui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# CustomChar UI

C++ UI for CustomChar using Dear ImGui.

- [ ] Basic chat window.
- [ ] Format messages.
- [ ] Animation when talking.
- [ ] Tranparent window.
- [ ] Custom font.
- [ ] Dynamic window size.
23 changes: 23 additions & 0 deletions customchar-ui/chat_history.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "chat_history.h"

ChatHistory::ChatHistory() { old_size = 0; }

ChatHistory::~ChatHistory() {}

void ChatHistory::add_message(std::string message, std::string sender) {
ChatMessage new_message;
new_message.set_time();
new_message.set_message(message, sender);
hist_vec.push_back(new_message);
}

std::vector<ChatMessage> ChatHistory::get_char_history() { return hist_vec; }

bool ChatHistory::has_new_message() {
if (old_size != hist_vec.size()) {
old_size = hist_vec.size();
return true;
}

return false;
}
20 changes: 20 additions & 0 deletions customchar-ui/chat_history.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <string>
#include <vector>

#include "chat_message.h"

class ChatHistory {
public:
ChatHistory();
~ChatHistory();

void add_message(std::string, std::string);
std::vector<ChatMessage> get_char_history();
bool has_new_message();

private:
std::vector<ChatMessage> hist_vec;
std::vector<ChatMessage>::size_type old_size;
};
35 changes: 35 additions & 0 deletions customchar-ui/chat_message.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "chat_message.h"

#include <ctime>

ChatMessage::ChatMessage() {
message = "";
sender = "Unknown";
}

ChatMessage::ChatMessage(std::string in_message, std::string in_sender) {
set_message(in_message, in_sender);
}

ChatMessage::~ChatMessage() {}

void ChatMessage::set_message(std::string input) { message = input; }

void ChatMessage::set_message(std::string in_message, std::string in_sender) {
message = in_message;
sender = in_sender;
}

void ChatMessage::set_sender(std::string input) { sender = input; }

void ChatMessage::set_time() {
time_t time_now = time(NULL);
char* ct = ctime(&time_now);
timestamp = ct;
}

std::string ChatMessage::get_message() { return message; }

std::string ChatMessage::get_sender() { return sender; }

std::string ChatMessage::get_time() { return timestamp; }
25 changes: 25 additions & 0 deletions customchar-ui/chat_message.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include <ctime>
#include <string>

class ChatMessage {
public:
ChatMessage();
ChatMessage(std::string, std::string);
~ChatMessage();

void set_message(std::string);
void set_message(std::string, std::string);
void set_sender(std::string);
void set_time();

std::string get_message();
std::string get_sender();
std::string get_time();

private:
std::string message;
std::string sender;
std::string timestamp;
};
Loading

0 comments on commit b3b2994

Please sign in to comment.