Added for reference
This commit is contained in:
parent
13e023f856
commit
e44fe9f8ab
45 changed files with 31896 additions and 0 deletions
106
src/page/PageComponent.h
Normal file
106
src/page/PageComponent.h
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
#ifndef _PAGE_COMPONENT_H
|
||||
#define _PAGE_COMPONENT_H
|
||||
|
||||
#include "imgui.h"
|
||||
#include "PageFont.h"
|
||||
#include "PageDraw.h"
|
||||
#include "PageWindow.h"
|
||||
|
||||
class PageText: public PageDrawComponent {
|
||||
private:
|
||||
const char* text;
|
||||
PageFontType font = NORMAL;
|
||||
bool bullet = false;
|
||||
ImVec4 color;
|
||||
bool colorFlag = false;
|
||||
bool multiLine = false;
|
||||
bool multiLineReadOnly = true;
|
||||
public:
|
||||
PageText(const char* text) {
|
||||
this->text = text;
|
||||
}
|
||||
void drawComponent(void) {
|
||||
PAGE_FONT.pushFont(font);
|
||||
if (colorFlag) {
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, color);
|
||||
}
|
||||
if (bullet) {
|
||||
ImGui::Bullet();
|
||||
}
|
||||
if (multiLine) {
|
||||
char* textLine = (char*)text;
|
||||
ImGui::InputTextMultiline("##source", textLine, strlen(textLine), ImVec2(-1.0f, ImGui::GetTextLineHeight() * 16), ImGuiInputTextFlags_AllowTabInput | (multiLineReadOnly ? ImGuiInputTextFlags_ReadOnly : 0));
|
||||
} else {
|
||||
ImGui::Text(text);
|
||||
}
|
||||
if (colorFlag) {
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
PAGE_FONT.popFont(font);
|
||||
}
|
||||
PageText* setFont(PageFontType font) {
|
||||
this->font = font;
|
||||
return this;
|
||||
}
|
||||
PageText* setBullet() {
|
||||
bullet = true;
|
||||
return this;
|
||||
}
|
||||
PageText* setColor(ImVec4 color) {
|
||||
this->color = color;
|
||||
colorFlag = true;
|
||||
return this;
|
||||
}
|
||||
PageText* setMultiLine() {
|
||||
multiLine = true;
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
class PageImage: public PageDrawComponent {
|
||||
private:
|
||||
void* image;
|
||||
ImVec2 size = ImVec2(100,100);
|
||||
ImColor tintColor = ImColor(255,255,255,255);
|
||||
ImColor borderColor = ImColor(255,255,255,128);
|
||||
public:
|
||||
PageImage(void* image) {
|
||||
this->image = image;
|
||||
}
|
||||
void drawComponent(void) {
|
||||
ImGui::Image((void *)this->image, this->size, ImVec2(0,0), ImVec2(1,1), this->tintColor , this->borderColor);
|
||||
}
|
||||
PageImage* setSize(ImVec2 size) {
|
||||
this->size = size;
|
||||
return this;
|
||||
}
|
||||
PageImage* setSize(float x, float y) {
|
||||
return this->setSize(ImVec2(x,y));
|
||||
}
|
||||
};
|
||||
class PageLink: public PageDrawComponent {
|
||||
private:
|
||||
const char* text;
|
||||
PageFontType font = NORMAL;
|
||||
bool clicked = false;
|
||||
public:
|
||||
PageLink(const char* text) {
|
||||
this->text = text;
|
||||
}
|
||||
void drawComponent(void) {
|
||||
PAGE_FONT.pushFont(font);
|
||||
if (ImGui::Selectable(text, &clicked)) {
|
||||
if (PAGE_WINDOW.platformOpenUrl != NULL) {
|
||||
PAGE_WINDOW.platformOpenUrl(text);
|
||||
}
|
||||
}
|
||||
//ImGui::SameLine();
|
||||
PAGE_FONT.popFont(font);
|
||||
}
|
||||
PageLink* setFont(PageFontType font) {
|
||||
this->font = font;
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
76
src/page/PageController.cpp
Normal file
76
src/page/PageController.cpp
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
#include "PageController.h"
|
||||
|
||||
PageController::PageController(const char* id, const char* title) {
|
||||
this->id = id;
|
||||
this->title = title;
|
||||
this->buildText(this->getTitle())->setFont(HEADER_MAIN);
|
||||
}
|
||||
|
||||
const char* PageController::getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
const char* PageController::getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
void PageController::loadImage(const char* filename) {
|
||||
printf("loadImage: %s\n",filename);
|
||||
void* imageId = (void*)SOIL_load_OGL_texture(filename, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS);
|
||||
if(imageId == NULL) {
|
||||
printf("Failed to load texture\n");
|
||||
return;
|
||||
}
|
||||
this->images.insert(std::pair<const char*,void*>(filename,imageId));
|
||||
}
|
||||
|
||||
int PageController::getImageCount() {
|
||||
return this->images.size();
|
||||
}
|
||||
|
||||
int PageController::getDrawCount() {
|
||||
return this->components.size();
|
||||
}
|
||||
|
||||
void PageController::drawLayer() {
|
||||
for (auto comp : this->components) {
|
||||
comp->drawComponent();
|
||||
}
|
||||
}
|
||||
|
||||
void PageController::addComponent(PageDrawComponent* component) {
|
||||
this->components.push_back(component);
|
||||
}
|
||||
|
||||
void PageController::setMenu(bool menu) {
|
||||
this->menu = menu;
|
||||
}
|
||||
|
||||
bool PageController::getMenu() {
|
||||
return this->menu;
|
||||
}
|
||||
|
||||
PageText* PageController::buildText(const char* text) {
|
||||
PageText* result = new PageText(text);
|
||||
addComponent(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
PageLink* PageController::buildLink(const char* url) {
|
||||
PageLink* result = new PageLink(url);
|
||||
addComponent(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
PageImage* PageController::buildImage(void* imageRef) {
|
||||
PageImage* result = new PageImage(imageRef);
|
||||
addComponent(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
PageImage* PageController::buildImage(const char* filename) {
|
||||
if (images.find(filename) == images.end()) {
|
||||
loadImage(filename);
|
||||
}
|
||||
return buildImage(images.at(filename));
|
||||
}
|
||||
45
src/page/PageController.h
Normal file
45
src/page/PageController.h
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#ifndef _PAGE_CONTROLLER_H
|
||||
#define _PAGE_CONTROLLER_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "PageComponent.h"
|
||||
#include "PageDraw.h"
|
||||
// TODO: goto SDL_Image ?
|
||||
#include "SOIL.h"
|
||||
|
||||
|
||||
class PageController: public PageDrawLayer {
|
||||
private:
|
||||
const char* id;
|
||||
const char* title;
|
||||
bool menu = true;
|
||||
std::map <const char* , void*> images;
|
||||
std::vector<PageDrawComponent*> components;
|
||||
|
||||
void loadImage(const char* filename);
|
||||
PageImage* buildImage(void* imageRef);
|
||||
public:
|
||||
PageController(const char* id, const char* title);
|
||||
|
||||
const char* getId();
|
||||
const char* getTitle();
|
||||
|
||||
int getImageCount();
|
||||
|
||||
int getDrawCount();
|
||||
void drawLayer(); // from super
|
||||
|
||||
void addComponent(PageDrawComponent* component);
|
||||
void setMenu(bool menu);
|
||||
bool getMenu();
|
||||
|
||||
PageText* buildText(const char* text);
|
||||
PageLink* buildLink(const char* url);
|
||||
PageImage* buildImage(const char* filename);
|
||||
};
|
||||
|
||||
#endif
|
||||
15
src/page/PageDraw.h
Normal file
15
src/page/PageDraw.h
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#ifndef _PAGE_DRAW_H
|
||||
#define _PAGE_DRAW_H
|
||||
|
||||
class PageDrawLayer {
|
||||
public:
|
||||
virtual void drawLayer(void) = 0;
|
||||
};
|
||||
|
||||
class PageDrawComponent {
|
||||
public:
|
||||
virtual void drawComponent(void) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
69
src/page/PageFont.cpp
Normal file
69
src/page/PageFont.cpp
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
#include "PageFont.h"
|
||||
|
||||
PageFont::PageFont() {
|
||||
}
|
||||
|
||||
void PageFont::loadFonts() {
|
||||
printf("fonts loadings\n");
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
// NOTE: Load fonts from large to small else scaling doesn't work
|
||||
|
||||
ImFontConfig fontConfigHeaderMain;
|
||||
fontConfigHeaderMain.MergeMode = false;
|
||||
fontConfigHeaderMain.PixelSnapH = true;
|
||||
ImFont* fontHeaderMain = io.Fonts->AddFontFromFileTTF("data/font/roboto-bold.ttf", 24.0f, &fontConfigHeaderMain);
|
||||
|
||||
ImFontConfig fontConfigHeaderSub;
|
||||
fontConfigHeaderSub.MergeMode = false;
|
||||
fontConfigHeaderSub.PixelSnapH = true;
|
||||
ImFont* fontHeaderSub = io.Fonts->AddFontFromFileTTF("data/font/roboto-bold.ttf", 20.0f, &fontConfigHeaderSub);
|
||||
|
||||
ImFontConfig fontConfigNormal;
|
||||
fontConfigNormal.MergeMode = false;
|
||||
fontConfigNormal.PixelSnapH = true;
|
||||
io.Fonts->AddFontFromFileTTF("data/font/lato-blackitalic-webfont.ttf", 16.0f, &fontConfigNormal);
|
||||
static ImWchar iconRange[] = { 0xf000, 0xf3ff, 0 };
|
||||
ImFontConfig fontConfigNormalIcon;
|
||||
fontConfigNormalIcon.MergeMode = true;
|
||||
fontConfigNormalIcon.PixelSnapH = true;
|
||||
io.Fonts->AddFontFromFileTTF("data/font/fontawesome-webfont.ttf", 16.0f, &fontConfigNormalIcon, iconRange);
|
||||
|
||||
ImFontConfig fontConfigSmall;
|
||||
fontConfigSmall.MergeMode = false;
|
||||
fontConfigSmall.PixelSnapH = true;
|
||||
ImFont* fontSmall = io.Fonts->AddFontFromFileTTF("data/font/lato-blackitalic-webfont.ttf", 12.0f, &fontConfigSmall);
|
||||
|
||||
this->fonts.insert(std::pair<PageFontType,ImFont*>(HEADER_MAIN, fontHeaderMain));
|
||||
this->fonts.insert(std::pair<PageFontType,ImFont*>(HEADER_SUB, fontHeaderSub));
|
||||
this->fonts.insert(std::pair<PageFontType,ImFont*>(SMALL, fontSmall));
|
||||
|
||||
// swap ImGui main font to normal
|
||||
ImFont* font0 = io.Fonts->Fonts.Data[0];
|
||||
ImFont* font2 = io.Fonts->Fonts.Data[2];
|
||||
io.Fonts->Fonts.Data[0] = font2;
|
||||
io.Fonts->Fonts.Data[2] = font0;
|
||||
|
||||
printf("fonts initialized\n");
|
||||
}
|
||||
|
||||
void PageFont::pushFont(PageFontType type) {
|
||||
if (NORMAL == type) {
|
||||
return;
|
||||
}
|
||||
if (this->fonts.find(type) == this->fonts.end()) {
|
||||
printf("ERR: unknown font: %i\n",type);
|
||||
ImGui::PushFont(this->fonts.at(SMALL)); // else pop will error
|
||||
} else {
|
||||
ImGui::PushFont(this->fonts.at(type));
|
||||
}
|
||||
}
|
||||
|
||||
void PageFont::popFont(PageFontType type) {
|
||||
if (NORMAL == type) {
|
||||
return;
|
||||
}
|
||||
ImGui::PopFont();
|
||||
}
|
||||
|
||||
PageFont PAGE_FONT;
|
||||
|
||||
27
src/page/PageFont.h
Normal file
27
src/page/PageFont.h
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#ifndef _PAGE_FONT_H
|
||||
#define _PAGE_FONT_H
|
||||
|
||||
#include "imgui.h"
|
||||
#include <stdio.h>
|
||||
#include <map>
|
||||
|
||||
enum PageFontType {
|
||||
HEADER_MAIN,
|
||||
HEADER_SUB,
|
||||
NORMAL,
|
||||
SMALL,
|
||||
};
|
||||
|
||||
class PageFont {
|
||||
private:
|
||||
std::map <PageFontType, ImFont*> fonts;
|
||||
public:
|
||||
PageFont();
|
||||
void loadFonts();
|
||||
void pushFont(PageFontType font);
|
||||
void popFont(PageFontType font);
|
||||
};
|
||||
|
||||
extern PageFont PAGE_FONT;
|
||||
|
||||
#endif
|
||||
130
src/page/PageWindow.cpp
Normal file
130
src/page/PageWindow.cpp
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
#include "PageWindow.h"
|
||||
|
||||
ImGuiWindowFlags WINDOW_PANE_FLAGS = ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_NoFocusOnAppearing|ImGuiWindowFlags_NoBringToFrontOnFocus;
|
||||
ImGuiWindowFlags WINDOW_BACKGROUND_FLAGS = WINDOW_PANE_FLAGS|ImGuiWindowFlags_NoScrollbar|ImGuiWindowFlags_NoInputs;
|
||||
|
||||
PageWindow::PageWindow() {
|
||||
}
|
||||
|
||||
void PageWindow::renderMenu() {
|
||||
ImGui::SetNextWindowPos(ImVec2(ImGui::GetIO().DisplaySize.x * layoutMarginX, ImGui::GetIO().DisplaySize.y * layoutMarginY), ImGuiSetCond_Always);
|
||||
ImGui::SetNextWindowSize(ImVec2((ImGui::GetIO().DisplaySize.x * (1.0f - layoutMarginX)) - (ImGui::GetIO().DisplaySize.x * layoutMarginX), menuHeight), ImGuiSetCond_Always);
|
||||
ImGui::Begin("Menu###menu", &menuRender , ImVec2(300, 200), 0.5f, WINDOW_PANE_FLAGS);
|
||||
PAGE_FONT.pushFont(HEADER_MAIN);
|
||||
bool first = true;
|
||||
for (auto page : pages) {
|
||||
if (!page.second->getMenu()) {
|
||||
continue;
|
||||
}
|
||||
if (!first) {
|
||||
ImGui::SameLine();
|
||||
}
|
||||
first = false;
|
||||
if (ImGui::Button(page.second->getTitle())) {
|
||||
this->setPageCurrent(page.second);
|
||||
}
|
||||
}
|
||||
PAGE_FONT.popFont(HEADER_MAIN);
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void PageWindow::renderPage(void) {
|
||||
int preHeight = this->menuHeight;
|
||||
if (!menuRender) {
|
||||
preHeight = 0;
|
||||
}
|
||||
int postHeight = this->footerHeight;
|
||||
if (!footerRender) {
|
||||
postHeight = 0;
|
||||
}
|
||||
ImGui::SetNextWindowPos(ImVec2(ImGui::GetIO().DisplaySize.x * layoutMarginX, (ImGui::GetIO().DisplaySize.y * layoutMarginY)*2 + preHeight), ImGuiSetCond_Always);
|
||||
ImGui::SetNextWindowSize(ImVec2((ImGui::GetIO().DisplaySize.x * (1.0f - layoutMarginX)) - (ImGui::GetIO().DisplaySize.x * layoutMarginX), ImGui::GetIO().DisplaySize.y - preHeight - postHeight - (ImGui::GetIO().DisplaySize.y * layoutMarginY)*4 ), ImGuiSetCond_Always);
|
||||
ImGui::Begin("Home###content", &pageRender , ImVec2(300, 200), 0.5f, WINDOW_PANE_FLAGS);
|
||||
|
||||
if (pageCurrent == NULL) {
|
||||
ImGui::Text("NULL");
|
||||
} else {
|
||||
pageCurrent->drawLayer();
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void PageWindow::renderFooter(void) {
|
||||
ImGui::SetNextWindowPos(ImVec2(ImGui::GetIO().DisplaySize.x * layoutMarginX, ImGui::GetIO().DisplaySize.y - footerHeight - (ImGui::GetIO().DisplaySize.y * layoutMarginY)), ImGuiSetCond_Always);
|
||||
ImGui::SetNextWindowSize(ImVec2((ImGui::GetIO().DisplaySize.x * (1.0f - layoutMarginX)) - (ImGui::GetIO().DisplaySize.x * layoutMarginX), footerHeight), ImGuiSetCond_Always);
|
||||
ImGui::Begin("Footer###footer", &footerRender , ImVec2(300, 200), 0.5f, WINDOW_PANE_FLAGS);
|
||||
ImGui::Text("(c)2016 ff");
|
||||
ImGui::SameLine();
|
||||
ImGui::Text(" -<-- -->- ");
|
||||
ImGui::SameLine();
|
||||
ImGui::Text("Compiled:");
|
||||
ImGui::SameLine();
|
||||
ImGui::Text(__DATE__);
|
||||
ImGui::SameLine();
|
||||
ImGui::Text(__TIME__);
|
||||
if (footerRenderFPS) {
|
||||
ImGui::SameLine();
|
||||
ImGui::Text(" - ");
|
||||
ImGui::SameLine();
|
||||
ImGui::Text("(%.1f FPS)",ImGui::GetIO().Framerate);
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
|
||||
void PageWindow::draw() {
|
||||
if (footerRender) {
|
||||
this->renderFooter();
|
||||
}
|
||||
if (pageRender) {
|
||||
this->renderPage();
|
||||
}
|
||||
if (menuRender) {
|
||||
this->renderMenu();
|
||||
}
|
||||
for (auto comp : layers) {
|
||||
comp->drawLayer();
|
||||
}
|
||||
}
|
||||
|
||||
PageDrawLayer* PageWindow::addLayer(PageDrawLayer* layer) {
|
||||
layers.push_back(layer);
|
||||
return layer;
|
||||
}
|
||||
|
||||
PageController* PageWindow::addPage(PageController* page) {
|
||||
pages.insert(std::pair<const char*,PageController*>(page->getId(),page));
|
||||
return page;
|
||||
}
|
||||
|
||||
PageController* PageWindow::addPage(const char* id, const char* title) {
|
||||
return addPage(new PageController(id,title));
|
||||
}
|
||||
|
||||
PageController* PageWindow::findPage(char* id) {
|
||||
for (auto page : pages) {
|
||||
if (strcmp (page.first, id) != 0) {
|
||||
continue;
|
||||
}
|
||||
return page.second;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void PageWindow::setPageCurrent(PageController* page) {
|
||||
if (page != NULL) {
|
||||
this->pageCurrent = page;
|
||||
} else {
|
||||
this->pageCurrent = this->pageNotFound;
|
||||
}
|
||||
if (platformPageCb != NULL) {
|
||||
platformPageCb(this->pageCurrent->getId());
|
||||
}
|
||||
}
|
||||
|
||||
void PageWindow::setPageNotFound(PageController* page) {
|
||||
this->pageNotFound = page;
|
||||
}
|
||||
|
||||
PageWindow PAGE_WINDOW;
|
||||
|
||||
65
src/page/PageWindow.h
Normal file
65
src/page/PageWindow.h
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
#ifndef _PAGE_WINDOW_H
|
||||
#define _PAGE_WINDOW_H
|
||||
|
||||
#include "PageController.h"
|
||||
#include "PageDraw.h"
|
||||
#include "PageFont.h"
|
||||
#include "imgui.h"
|
||||
#include <stdio.h>
|
||||
#include <map>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_opengl.h>
|
||||
|
||||
|
||||
class PageWindow {
|
||||
private:
|
||||
std::map <const char*, PageController*> pages;
|
||||
std::vector<PageDrawLayer*> layers;
|
||||
void renderMenu();
|
||||
void renderPage();
|
||||
void renderFooter();
|
||||
|
||||
|
||||
public:
|
||||
SDL_Window *window;
|
||||
SDL_GLContext glcontext;
|
||||
bool windowRun = true;
|
||||
bool windowFullScreen = false;
|
||||
bool footerRender = true;
|
||||
bool footerRenderFPS = true;
|
||||
int footerHeight = 30;
|
||||
//bool backgroundRender = true;
|
||||
ImVec4 backgroundClearColor = ImColor(8, 54, 127);
|
||||
bool menuRender = true;
|
||||
int menuHeight = 50;
|
||||
bool pageRender = true;
|
||||
PageController* pageCurrent;
|
||||
PageController* pageNotFound;
|
||||
float layoutMarginX = 0.07f;
|
||||
float layoutMarginY = 0.01f;
|
||||
void (*platformOpenUrl)(char* url) = NULL;
|
||||
void (*platformPageCb)(char* pageId) = NULL;
|
||||
|
||||
|
||||
PageWindow();
|
||||
void draw();
|
||||
PageDrawLayer* addLayer(PageDrawLayer* layer);
|
||||
PageController* addPage(PageController* page);
|
||||
PageController* addPage(const char* id, const char* title);
|
||||
PageController* findPage(char* id);
|
||||
void setPageCurrent(PageController* page);
|
||||
void setPageNotFound(PageController* page);
|
||||
|
||||
void printDebug() {
|
||||
for (auto page : pages) {
|
||||
printf("page: %s comp: %i img: %i\n",page.second->getId(),page.second->getDrawCount(),page.second->getImageCount());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
extern ImGuiWindowFlags WINDOW_PANE_FLAGS;
|
||||
extern ImGuiWindowFlags WINDOW_BACKGROUND_FLAGS;
|
||||
|
||||
extern PageWindow PAGE_WINDOW;
|
||||
|
||||
#endif
|
||||
72
src/site/FFSiteBackground.cpp
Normal file
72
src/site/FFSiteBackground.cpp
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
#include "FFSiteBackground.h"
|
||||
|
||||
struct A {
|
||||
const char* text = "ForwardFire";
|
||||
ImVec4 color = ImVec4(0.0f,0.5f,0.3f,1.0f);;
|
||||
int bgSpeed = 1;
|
||||
float x = 10.0f;
|
||||
float xOff = 2.0f;
|
||||
float y = 20.0f;
|
||||
float yOff = 3.0f;
|
||||
};
|
||||
|
||||
static const int LETTERS_MAX = 25;
|
||||
static A letters[LETTERS_MAX];
|
||||
|
||||
static bool rr = true;
|
||||
|
||||
FFSiteBackground::FFSiteBackground() {
|
||||
for (int i=0;i<LETTERS_MAX;i++) {
|
||||
A* a = &letters[i];
|
||||
a->bgSpeed = rand() % 100;
|
||||
a->x = rand() % (int)ImGui::GetIO().DisplaySize.x;
|
||||
a->y = rand() % (int)ImGui::GetIO().DisplaySize.y;
|
||||
a->color = ImVec4(0.0f,(i+1)*0.1f,(i+2)*0.01f,(i+3)*0.01f);
|
||||
|
||||
a->xOff = rand() % 3 + 0.1f;
|
||||
a->yOff = rand() % 4 + 0.1f;
|
||||
|
||||
int r = rand() % 5;
|
||||
if (r == 2) {
|
||||
a->xOff = 0 - a->xOff;
|
||||
}
|
||||
if (r == 3) {
|
||||
a->yOff = 0 - a->yOff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FFSiteBackground::drawLayer(void) {
|
||||
ImGui::SetNextWindowSize(ImGui::GetIO().DisplaySize, ImGuiSetCond_Always);
|
||||
ImGui::Begin("Background###background", &rr , ImGui::GetIO().DisplaySize, 0.0f, WINDOW_BACKGROUND_FLAGS);
|
||||
for (int i=0;i<LETTERS_MAX;i++) {
|
||||
A* a = &letters[i];
|
||||
a->bgSpeed--;
|
||||
if (a->bgSpeed < 0) {
|
||||
a->bgSpeed = 2; //rand() % 10;
|
||||
|
||||
if (a->x > ImGui::GetIO().DisplaySize.x) {
|
||||
a->xOff = 0 - a->xOff;
|
||||
a->x = ImGui::GetIO().DisplaySize.x;
|
||||
}
|
||||
if (a->x < 0) {
|
||||
a->xOff = 0 - a->xOff;
|
||||
a->x = 0;
|
||||
}
|
||||
if (a->y > ImGui::GetIO().DisplaySize.y) {
|
||||
a->yOff = 0 - a->yOff;
|
||||
a->y = ImGui::GetIO().DisplaySize.y;
|
||||
}
|
||||
if (a->y < 0) {
|
||||
a->yOff = 0 - a->yOff;
|
||||
a->y = 0;
|
||||
}
|
||||
a->x = a->x+a->xOff;
|
||||
a->y = a->y+a->yOff;
|
||||
}
|
||||
ImGui::SetCursorPos(ImVec2(a->x, a->y));
|
||||
ImGui::TextColored(a->color, a->text);
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
16
src/site/FFSiteBackground.h
Normal file
16
src/site/FFSiteBackground.h
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef _FF_SITE_BACKGROUND_H
|
||||
#define _FF_SITE_BACKGROUND_H
|
||||
|
||||
#include "../page/PageDraw.h"
|
||||
#include "../page/PageWindow.h"
|
||||
#include "imgui.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
class FFSiteBackground: public PageDrawLayer {
|
||||
private:
|
||||
public:
|
||||
FFSiteBackground();
|
||||
void drawLayer(void);
|
||||
};
|
||||
|
||||
#endif
|
||||
105
src/site/FFSiteDebug.cpp
Normal file
105
src/site/FFSiteDebug.cpp
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
#include "FFSiteDebug.h"
|
||||
|
||||
void FFSiteDebug::showSettingsWindow(bool* p_open) {
|
||||
ImGui::SetNextWindowSize(ImVec2(300, 200), ImGuiSetCond_FirstUseEver);
|
||||
ImGui::Begin("Test Settings", p_open);
|
||||
ImGui::ColorEdit3("Background", (float*) &PAGE_WINDOW.backgroundClearColor);
|
||||
ImGui::SliderFloat("Margin X", &PAGE_WINDOW.layoutMarginX, 0.0, 0.4);
|
||||
ImGui::SliderFloat("Margin Y", &PAGE_WINDOW.layoutMarginY, 0.0, 0.2);
|
||||
ImGui::Checkbox("Render menu", &PAGE_WINDOW.menuRender);
|
||||
ImGui::Checkbox("Render footer", &PAGE_WINDOW.footerRender);
|
||||
ImGui::Checkbox("Render FPS", &PAGE_WINDOW.footerRenderFPS);
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void FFSiteDebug::showLayoutWindow(bool* p_open) {
|
||||
ImGui::SetNextWindowSize(ImVec2(300, 200), ImGuiSetCond_FirstUseEver);
|
||||
ImGui::Begin("Test Layout", p_open);
|
||||
|
||||
ImGui::BeginChild("Sub1", ImVec2(ImGui::GetWindowContentRegionWidth() * 0.33f,100), true, 0);
|
||||
ImGui::SmallButton("Hello 11");ImGui::SameLine();
|
||||
ImGui::SmallButton("Hello 12");ImGui::SameLine();
|
||||
ImGui::SmallButton("Hello 13");ImGui::SameLine();
|
||||
ImGui::SmallButton("Hello 14");
|
||||
ImGui::SmallButton("Hello 15");ImGui::SameLine();
|
||||
ImGui::SmallButton("Hello 16");
|
||||
ImGui::SmallButton("Hello 17");ImGui::SameLine();
|
||||
ImGui::SmallButton("Hello 18");ImGui::SameLine();
|
||||
ImGui::EndChild();
|
||||
ImGui::SameLine();
|
||||
|
||||
static bool bb = true;
|
||||
|
||||
//ImGui::PushStyleVar(ImGuiStyleVar_ChildWindowRounding, 5.0f);
|
||||
ImGui::BeginChild("Sub2", ImVec2(ImGui::GetWindowContentRegionWidth() * 0.66f,100), true, 0);
|
||||
if (bb) {
|
||||
ImGui::Text("Hello 22");
|
||||
} else {
|
||||
ImGui::Text("Hello 22222222222222.....");
|
||||
}
|
||||
bb = !ImGui::IsItemHovered();
|
||||
ImGui::EndChild();
|
||||
|
||||
//ImGui::PopStyleVar();
|
||||
|
||||
static bool bc = true;
|
||||
float f = 15.0f;
|
||||
if (bc) {
|
||||
f+=10;
|
||||
}
|
||||
|
||||
ImGui::BeginGroup();
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ChildWindowRounding, f);
|
||||
ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowContentRegionWidth(),-1), false, ImGuiWindowFlags_ShowBorders);
|
||||
ImGui::Text("Hello Main");
|
||||
ImGui::EndChild();
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::EndGroup();
|
||||
bc = !ImGui::IsItemHovered();
|
||||
bc = !bc;
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void FFSiteDebug::drawComponent(void) {
|
||||
if (ImGui::Button("\uf241 Fullscreen")) {
|
||||
if (PAGE_WINDOW.windowFullScreen) {
|
||||
SDL_SetWindowFullscreen(PAGE_WINDOW.window, 0);
|
||||
} else {
|
||||
SDL_SetWindowFullscreen(PAGE_WINDOW.window, SDL_WINDOW_FULLSCREEN);
|
||||
}
|
||||
PAGE_WINDOW.windowFullScreen = !PAGE_WINDOW.windowFullScreen;
|
||||
}
|
||||
if (ImGui::Button("\uf1fa Test Demo")) {
|
||||
renderDemo ^= 1;
|
||||
}
|
||||
if (ImGui::Button("\uf1fe Test Metrics")) {
|
||||
renderMetrics ^= 1;
|
||||
}
|
||||
if (ImGui::Button("\uf1fb Test Layout")) {
|
||||
renderLayout ^= 1;
|
||||
}
|
||||
if (ImGui::Button("\uf1ff Page Options")) {
|
||||
renderSettings ^= 1;
|
||||
}
|
||||
}
|
||||
|
||||
void FFSiteDebug::drawLayer(void) {
|
||||
if (renderDemo) {
|
||||
ImGui::SetNextWindowPos(ImVec2(50, 50), ImGuiSetCond_FirstUseEver);
|
||||
ImGui::ShowTestWindow(&renderDemo);
|
||||
}
|
||||
if (renderMetrics) {
|
||||
ImGui::SetNextWindowPos(ImVec2(60, 60), ImGuiSetCond_FirstUseEver);
|
||||
ImGui::ShowMetricsWindow(&renderMetrics);
|
||||
}
|
||||
if (renderLayout) {
|
||||
ImGui::SetNextWindowPos(ImVec2(70, 70), ImGuiSetCond_FirstUseEver);
|
||||
showLayoutWindow(&renderLayout);
|
||||
}
|
||||
if (renderSettings) {
|
||||
ImGui::SetNextWindowPos(ImVec2(80, 80), ImGuiSetCond_FirstUseEver);
|
||||
showSettingsWindow(&renderSettings);
|
||||
}
|
||||
}
|
||||
|
||||
23
src/site/FFSiteDebug.h
Normal file
23
src/site/FFSiteDebug.h
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#ifndef _FF_SITE_DEBUG_H
|
||||
#define _FF_SITE_DEBUG_H
|
||||
|
||||
#include "../page/PageDraw.h"
|
||||
#include "../page/PageWindow.h"
|
||||
#include "imgui.h"
|
||||
|
||||
class FFSiteDebug: public PageDrawComponent,public PageDrawLayer {
|
||||
private:
|
||||
bool renderDemo = false;
|
||||
bool renderMetrics = false;
|
||||
bool renderLayout = false;
|
||||
bool renderSettings = false;
|
||||
void showLayoutWindow(bool* p_open);
|
||||
void showSettingsWindow(bool* p_open);
|
||||
public:
|
||||
FFSiteDebug() {
|
||||
}
|
||||
void drawComponent(void);
|
||||
void drawLayer(void);
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue