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__ CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__
CXXFLAGS := $(CFLAGS) -std=c++14 CXXFLAGS := $(CFLAGS) -std=c++20
ASFLAGS := -g $(ARCH) ASFLAGS := -g $(ARCH)
LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) 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 # 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 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 ../ 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 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 setTrigger(GuiTrigger *t, int32_t idx = -1);
//! //!
void resetState(void); void resetState(void) override;
//!Constantly called to draw the GuiButton //!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 //!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 //!\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 *> selected;
sigslot::signal2<GuiButton *, const GuiController *> deSelected; sigslot::signal2<GuiButton *, const GuiController *> deSelected;

View File

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

View File

@ -68,49 +68,34 @@ public:
//!Sets the visibility of the window //!Sets the visibility of the window
//!\param v visibility (true = visible) //!\param v visibility (true = visible)
void setVisible(bool v); void setVisible(bool v) override;
//!Resets the window's state to STATE_DEFAULT //!Resets the window's state to STATE_DEFAULT
void resetState(); void resetState() override;
//!Sets the window's state //!Sets the window's state
//!\param 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 //!Gets the index of the GuiElement inside the window that is currently selected
//!\return index of selected GuiElement //!\return index of selected GuiElement
int32_t getSelected(); int32_t getSelected() override;
//!Dim the Window's background
void dimBackground(bool d);
//!Draws all the elements in this GuiFrame //!Draws all the elements in this GuiFrame
void draw(CVideo *v); void draw(CVideo *v) override;
//!Updates the window and all elements contains within //!Updates the window and all elements contains within
//!Allows the GuiFrame and all elements to respond to the input data specified //!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 //!\param t Pointer to a GuiTrigger, containing the current input data from PAD/WPAD
void update(GuiController *t); void update(GuiController *t) override;
//!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() {}
//!virtual updateEffects which is called by the main loop //!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 process which is called by the main loop
virtual void process(); void process() override;
//! Signals //! Signals
//! On Closing //! On Closing

View File

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

View File

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

View File

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

View File

@ -30,9 +30,9 @@ public:
//!\param s Font size //!\param s Font size
//!\param c Font color //!\param c Font color
GuiText(const std::string &t, int32_t s, SDL_Color c, TTF_Font *gFont); 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: protected:
SDL_Surface *textSurface = nullptr; SDL_Surface *textSurface = nullptr;

View File

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

View File

@ -10,11 +10,11 @@
class SDLController : public GuiController { class SDLController : public GuiController {
public: 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() { 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) { if (e->type == SDL_JOYBUTTONDOWN) {
data.buttons_h |= (1 << e->jbutton.button); data.buttons_h |= (1 << e->jbutton.button);
} else if (e->type == SDL_JOYBUTTONUP) { } else if (e->type == SDL_JOYBUTTONUP) {

View File

@ -3,11 +3,11 @@
class SDLControllerMouse: public SDLController { class SDLControllerMouse: public SDLController {
public: 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) { if (e->type == SDL_MOUSEMOTION) {
data.y = e->motion.y; data.y = e->motion.y;
data.x = e->motion.x; data.x = e->motion.x;

View File

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

View File

@ -4,7 +4,7 @@
class SDLControllerWiiUProContoller : public SDLControllerWiiUGamepad { class SDLControllerWiiUProContoller : public SDLControllerWiiUGamepad {
public: 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 { class SDLControllerXboxOne : public SDLController {
public: 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) { if (e->type == SDL_JOYBUTTONDOWN) {
data.buttons_h |= xbox_button_map[e->jbutton.button]; data.buttons_h |= xbox_button_map[e->jbutton.button];
} else if (e->type == SDL_JOYBUTTONUP) { } else if (e->type == SDL_JOYBUTTONUP) {

View File

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