This commit is contained in:
Maschell 2020-08-30 12:46:49 +02:00
parent 9c189354cb
commit 010c9da01c
17 changed files with 69 additions and 85 deletions

View File

@ -33,12 +33,13 @@ CFLAGS := -g -Wall -O2 -ffunction-sections \
CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__
CXXFLAGS := $(CFLAGS) -std=c++14
CXXFLAGS := $(CFLAGS) -std=c++20
ASFLAGS := -g $(ARCH)
LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map)
LIBS := -lSDL2_mixer -lSDL2 -lSDL2_image -ljpeg -lvorbisidec -logg -lmodplug -lmpg123 -lSDL2_ttf -lfreetype -lpng -lz -lbz2 -lwut
LIBS := -lSDL2_mixer -lmodplug -lstdc++ -lm -lmpg123 -lm -lvorbisfile -lvorbis -lm -logg -lSDL2_ttf -lfreetype -lbz2 -lSDL2_image -lpng16 -lz -lm -lz -ljpeg -lSDL2 /opt/devkitpro/wut/lib/libwut.a -lm -Wl,--no-undefined -lSDL2 /opt/devkitpro/wut/lib/libwut.a
#-------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level

View File

@ -17,4 +17,14 @@ pacman -S git mingw-w64-x86_64-toolchain mingw64/mingw-w64-x86_64-SDL2 mingw64/m
mkdir build && cd build
C:\devkitPro\msys2\mingw64\bin\cmake.exe -DSDL2_PATH=C:/devkitPro/msys2/mingw64 -Wno-dev -G "Unix Makefiles" -DCMAKE_CXX_COMPILER=C:/devkitPro/msys2/mingw64/bin/g++.exe DCMAKE_C_COMPILER=C:/devkitPro/msys2/mingw64/bin/gcc.exe ../
make
```
```
## Wii U
Install these libs from [wiiu-fling](https://gitlab.com/QuarkTheAwesome/wiiu-fling#installing):
- `pacman -S wiiu-fling/wiiu-sdl2 wiiu-fling/wiiu-sdl2_gfx wiiu-fling/wiiu-sdl2_image wiiu-fling/wiiu-sdl2_ttf`
And these from [dkp-libs](https://devkitpro.org/wiki/devkitPro_pacman):
- `pacman -S devkitPPC wut-tools wut wiiu-portlibs dkp-libs/wiiu-sdl2_mixer`
Build via:
`make -f Makefile.wiiu`

View File

@ -91,14 +91,14 @@ public:
void setTrigger(GuiTrigger *t, int32_t idx = -1);
//!
void resetState(void);
void resetState(void) override;
//!Constantly called to draw the GuiButton
void draw(CVideo *video);
void draw(CVideo *video) override;
//!Constantly called to allow the GuiButton to respond to updated input data
//!\param t Pointer to a GuiTrigger, containing the current input data from PAD/WPAD
void update(GuiController *c);
void update(GuiController *c) override;
sigslot::signal2<GuiButton *, const GuiController *> selected;
sigslot::signal2<GuiButton *, const GuiController *> deSelected;

View File

@ -91,14 +91,6 @@ void GuiFrame::removeAll() {
mutex.unlock();
}
void GuiFrame::close() {
//Application::instance()->pushForDelete(this);
}
void GuiFrame::dimBackground(bool d) {
dim = d;
}
GuiElement *GuiFrame::getGuiElementAt(uint32_t index) const {
if (index >= elements.size()) {
return NULL;

View File

@ -68,49 +68,34 @@ public:
//!Sets the visibility of the window
//!\param v visibility (true = visible)
void setVisible(bool v);
void setVisible(bool v) override;
//!Resets the window's state to STATE_DEFAULT
void resetState();
void resetState() override;
//!Sets the window's state
//!\param s State
void setState(int32_t s, int32_t c = -1);
void setState(int32_t s, int32_t c = -1) override;
void clearState(int32_t s, int32_t c = -1);
void clearState(int32_t s, int32_t c = -1) override;
//!Gets the index of the GuiElement inside the window that is currently selected
//!\return index of selected GuiElement
int32_t getSelected();
//!Dim the Window's background
void dimBackground(bool d);
int32_t getSelected() override;
//!Draws all the elements in this GuiFrame
void draw(CVideo *v);
void draw(CVideo *v) override;
//!Updates the window and all elements contains within
//!Allows the GuiFrame and all elements to respond to the input data specified
//!\param t Pointer to a GuiTrigger, containing the current input data from PAD/WPAD
void update(GuiController *t);
//!virtual Close Window - this will put the object on the delete queue in MainWindow
virtual void close();
//!virtual show window function
virtual void show() {}
//!virtual hide window function
virtual void hide() {}
//!virtual enter main loop function (blocking)
virtual void exec() {}
void update(GuiController *t) override;
//!virtual updateEffects which is called by the main loop
virtual void updateEffects();
void updateEffects() override;
//!virtual process which is called by the main loop
virtual void process();
void process() override;
//! Signals
//! On Closing

View File

@ -25,18 +25,16 @@ class GuiImage : public GuiElement {
public:
//!\overload
//!\param img Pointer to GuiImageData element
GuiImage(const std::string &path);
explicit GuiImage(const std::string &path);
//!Destructor
virtual ~GuiImage();
~GuiImage() override;
//!Constantly called to draw the image
void draw(CVideo *pVideo);
void draw(CVideo *pVideo) override;
protected:
SDL_Surface *imgSurface = nullptr;
SDL_Texture *texture = nullptr;
virtual void process();
void process() override;
};

View File

@ -25,10 +25,10 @@ public:
//!Constructor
//!\param sound Pointer to the sound data
//!\param filesize Length of sound data
GuiSound(const char *filepath);
explicit GuiSound(const char *filepath);
//!Destructor
virtual ~GuiSound();
~GuiSound() override;
//!Load a file and replace the old one
bool Load(const char *filepath);

View File

@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include <cstdarg>
#include <SDl2/SDL_surface.h>
#include <SDL2/SDL_surface.h>
#include "GuiText.h"
#include "../CVideo.h"
#include "../logger.h"

View File

@ -30,9 +30,9 @@ public:
//!\param s Font size
//!\param c Font color
GuiText(const std::string &t, int32_t s, SDL_Color c, TTF_Font *gFont);
virtual ~GuiText();
~GuiText() override;
virtual void draw(CVideo *pVideo);
void draw(CVideo *pVideo) override;
protected:
SDL_Surface *textSurface = nullptr;

View File

@ -16,7 +16,7 @@
****************************************************************************/
#pragma once
#include <stdint.h>
#include <cstdint>
class GuiController;

View File

@ -10,11 +10,11 @@
class SDLController : public GuiController {
public:
SDLController(int32_t channel) : GuiController(channel) {
explicit SDLController(int32_t channel) : GuiController(channel) {
}
virtual bool update(SDL_Event *e) = 0;
virtual bool update(SDL_Event *e, int32_t screenWidth, int32_t screenHeight) = 0;
virtual void before() {

View File

@ -6,7 +6,7 @@ public:
}
virtual bool update(SDL_Event *e) override {
bool update(SDL_Event *e, int32_t screenWidth, int32_t screenHeight) override {
if (e->type == SDL_JOYBUTTONDOWN) {
data.buttons_h |= (1 << e->jbutton.button);
} else if (e->type == SDL_JOYBUTTONUP) {

View File

@ -3,11 +3,11 @@
class SDLControllerMouse: public SDLController {
public:
SDLControllerMouse(int32_t channel) : SDLController(channel) {
explicit SDLControllerMouse(int32_t channel) : SDLController(channel) {
}
virtual bool update(SDL_Event *e) override {
virtual bool update(SDL_Event *e, int32_t screenWidth, int32_t screenHeight) override {
if (e->type == SDL_MOUSEMOTION) {
data.y = e->motion.y;
data.x = e->motion.x;

View File

@ -21,14 +21,14 @@ static GuiTrigger::eButtons vpad_button_map[] = {
class SDLControllerWiiUGamepad : public SDLController {
public:
SDLControllerWiiUGamepad(int32_t channel) : SDLController(channel) {
explicit SDLControllerWiiUGamepad(int32_t channel) : SDLController(channel) {
}
virtual bool update(SDL_Event *e) override {
bool update(SDL_Event *e, int32_t screenWidth, int32_t screenHeight) override {
if (e->type == SDL_FINGERMOTION) {
data.y = e->tfinger.y * 720;
data.x = e->tfinger.x * 1280;;
data.y = e->tfinger.y * screenHeight;
data.x = e->tfinger.x * screenWidth;;
data.validPointer = true;
} else if (e->type == SDL_FINGERUP) {
data.validPointer = false;
@ -36,8 +36,7 @@ public:
} else if (e->type == SDL_FINGERDOWN) {
data.validPointer = true;
data.buttons_h |= GuiTrigger::TOUCHED;
}
if (e->type == SDL_JOYBUTTONDOWN) {
} else if (e->type == SDL_JOYBUTTONDOWN) {
data.buttons_h |= vpad_button_map[e->jbutton.button];
} else if (e->type == SDL_JOYBUTTONUP) {
data.buttons_h &= ~vpad_button_map[e->jbutton.button];

View File

@ -4,7 +4,7 @@
class SDLControllerWiiUProContoller : public SDLControllerWiiUGamepad {
public:
SDLControllerWiiUProContoller(int32_t channel) : SDLControllerWiiUGamepad(channel){
explicit SDLControllerWiiUProContoller(int32_t channel) : SDLControllerWiiUGamepad(channel){
}
};

View File

@ -42,11 +42,11 @@ if(axis == targetAxis){ \
class SDLControllerXboxOne : public SDLController {
public:
SDLControllerXboxOne(int32_t channel) : SDLController(channel) {
explicit SDLControllerXboxOne(int32_t channel) : SDLController(channel) {
}
virtual bool update(SDL_Event *e) override {
bool update(SDL_Event *e, int32_t screenWidth, int32_t screenHeight) override {
if (e->type == SDL_JOYBUTTONDOWN) {
data.buttons_h |= xbox_button_map[e->jbutton.button];
} else if (e->type == SDL_JOYBUTTONUP) {

View File

@ -13,7 +13,7 @@
#include "gui/SDLControllerXboxOne.h"
#include "gui/SDLControllerWiiUProContoller.h"
#include <stdio.h>
#include <cstdio>
#include <fcntl.h>
#include <map>
@ -25,7 +25,7 @@
#ifdef __WIIU__
#include <whb/log.h>
#include <whb/log_cafe.h>
#include <whb/log_udp.h>
#include <whb/log_udp.h>
#include <proc_ui/procui.h>
bool CheckRunning(){
switch(ProcUIProcessMessages(true))
@ -51,16 +51,14 @@ bool CheckRunning(){
}
#endif
void proccessEvents();
bool addJoystick(int deviceId, std::map<GuiTrigger::eChannels, SDLController *> &controllerList, std::map<int32_t, GuiTrigger::eChannels>& map);
bool addJoystick(int deviceId, std::map<GuiTrigger::eChannels, SDLController *> &controllerList, std::map<int32_t, GuiTrigger::eChannels>& joystickToChannel);
GuiTrigger::eChannels increaseChannel(GuiTrigger::eChannels channel);
void removeJoystick(int32_t which, std::map<GuiTrigger::eChannels, SDLController *> &controllerList, std::map<int32_t, GuiTrigger::eChannels>& joystickToChannel);
void removeJoystick(int32_t instanceId, std::map<GuiTrigger::eChannels, SDLController *> &controllerList, std::map<int32_t, GuiTrigger::eChannels>& joystickToChannel);
int main(int argc, char *args[]) {
CVideo *video = new CVideo();
auto *video = new CVideo();
#if defined _WIN32
// Create the Console
@ -110,19 +108,21 @@ int main(int argc, char *args[]) {
bool quit = false;
SDL_Event e;
while (SDL_PollEvent(&e)) {
int32_t channel = -1;
SDL_JoystickID jId = -1;
if(e.type == SDL_JOYDEVICEADDED) {
addJoystick(e.jdevice.which, controllerList, joystickToChannel);
continue;
}else if(e.type == SDL_JOYDEVICEREMOVED) {
auto j = SDL_JoystickFromInstanceID(e.jdevice.which);
if (j) {
removeJoystick(e.jdevice.which, controllerList, joystickToChannel);
SDL_JoystickClose(j);
continue;
}
}else if (e.type == SDL_FINGERDOWN || e.type == SDL_FINGERUP || e.type == SDL_FINGERMOTION){
controllerList[GuiTrigger::CHANNEL_1]->update(&e);
} else if (e.type == SDL_MOUSEBUTTONDOWN || e.type == SDL_MOUSEBUTTONUP || e.type == SDL_MOUSEMOTION){
controllerList[GuiTrigger::CHANNEL_1]->update(&e);
}else if (e.type == SDL_FINGERDOWN || e.type == SDL_FINGERUP || e.type == SDL_FINGERMOTION ||
e.type == SDL_MOUSEBUTTONDOWN || e.type == SDL_MOUSEBUTTONUP || e.type == SDL_MOUSEMOTION){
channel = GuiTrigger::CHANNEL_1;
} else if (e.type == SDL_JOYAXISMOTION) {
jId = e.jaxis.which;
} else if (e.type == SDL_JOYHATMOTION) {
@ -136,9 +136,12 @@ int main(int argc, char *args[]) {
if(jId != -1){
if(joystickToChannel.find(jId) != joystickToChannel.end()){
controllerList[joystickToChannel[jId]]->update(&e);
channel = joystickToChannel[jId];
}
}
if(channel != -1){
controllerList[static_cast<GuiTrigger::eChannels>(channel)]->update(&e, video->getWidth(), video->getHeight());
}
}
if(quit){
break;
@ -226,12 +229,8 @@ GuiTrigger::eChannels increaseChannel(GuiTrigger::eChannels channel) {
return GuiTrigger::CHANNEL_4;
case GuiTrigger::CHANNEL_4:
return GuiTrigger::CHANNEL_5;
}
return GuiTrigger::CHANNEL_ALL;
}
void proccessEvents() {
int res = 0;
}
case GuiTrigger::CHANNEL_5:
case GuiTrigger::CHANNEL_ALL:
return GuiTrigger::CHANNEL_ALL;
}
}