Format the code via clang-format (#1)

* Format the code via clang-format
This commit is contained in:
Maschell 2022-02-02 19:12:52 +01:00 committed by GitHub
parent e4b5d5920c
commit c82f178943
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 326 additions and 236 deletions

66
.clang-format Normal file
View File

@ -0,0 +1,66 @@
# Generated from CLion C/C++ Code Style settings
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: None
AlignOperands: Align
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Always
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: Yes
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: true
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
ColumnLimit: 0
CompactNamespaces: false
ContinuationIndentWidth: 8
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 2
NamespaceIndentation: All
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PointerAlignment: Right
ReflowComments: false
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 0
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
TabWidth: 4
UseTab: Never

View File

@ -6,8 +6,16 @@ on:
- main - main
jobs: jobs:
clang-format:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: clang-format
run: |
docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source
build-binary: build-binary:
runs-on: ubuntu-18.04 runs-on: ubuntu-18.04
needs: clang-format
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: build binary - name: build binary

View File

@ -3,8 +3,16 @@ name: CI-PR
on: [pull_request] on: [pull_request]
jobs: jobs:
clang-format:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: clang-format
run: |
docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source
build-binary: build-binary:
runs-on: ubuntu-18.04 runs-on: ubuntu-18.04
needs: clang-format
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: build binary - name: build binary

View File

@ -42,6 +42,9 @@ docker run -it --rm -v ${PWD}:/project environmentloader-builder make
docker run -it --rm -v ${PWD}:/project environmentloader-builder make clean docker run -it --rm -v ${PWD}:/project environmentloader-builder make clean
``` ```
## Format the code via docker
`docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source -i`
## Credits ## Credits
- maschell - maschell

View File

@ -1,15 +1,15 @@
#include <coreinit/debug.h> #include "utils/logger.h"
#include <bits/shared_ptr.h>
#include <coreinit/cache.h> #include <coreinit/cache.h>
#include <coreinit/debug.h>
#include <coreinit/dynload.h>
#include <coreinit/memdefaultheap.h> #include <coreinit/memdefaultheap.h>
#include <whb/sdcard.h>
#include <whb/file.h> #include <whb/file.h>
#include <whb/log.h> #include <whb/log.h>
#include <bits/shared_ptr.h> #include <whb/sdcard.h>
#include <coreinit/dynload.h>
#include "utils/logger.h"
#include "elfio/elfio.hpp"
#include "ElfUtils.h" #include "ElfUtils.h"
#include "elfio/elfio.hpp"
int32_t LoadFileToMem(const char *relativefilepath, char **fileOut, uint32_t *sizeOut) { int32_t LoadFileToMem(const char *relativefilepath, char **fileOut, uint32_t *sizeOut) {
char path[256]; char path[256];

View File

@ -1,11 +1,11 @@
#pragma once #pragma once
#include "common/relocation_defines.h"
#include "module/RelocationData.h"
#include <cstdint> #include <cstdint>
#include <cstdio> #include <cstdio>
#include "common/relocation_defines.h"
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "module/RelocationData.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -17,6 +17,7 @@ int32_t LoadFileToMem(const char *relativefilepath, char **fileOut, uint32_t *si
uint32_t load_loader_elf_from_sd(unsigned char *baseAddress, const char *relativePath); uint32_t load_loader_elf_from_sd(unsigned char *baseAddress, const char *relativePath);
uint32_t load_loader_elf(unsigned char *baseAddress, char *elf_data, uint32_t fileSize); uint32_t load_loader_elf(unsigned char *baseAddress, char *elf_data, uint32_t fileSize);
// clang-format off
#define R_PPC_NONE 0 #define R_PPC_NONE 0
#define R_PPC_ADDR32 1 #define R_PPC_ADDR32 1
#define R_PPC_ADDR16_LO 4 #define R_PPC_ADDR16_LO 4
@ -44,6 +45,7 @@ uint32_t load_loader_elf(unsigned char *baseAddress, char *elf_data, uint32_t fi
#define PPC_LOW24 0x03FFFFFC #define PPC_LOW24 0x03FFFFFC
#define PPC_LOW14 0x0020FFFC #define PPC_LOW14 0x0020FFFC
#define PPC_HALF16 0xFFFF #define PPC_HALF16 0xFFFF
// clang-format on
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -17,13 +17,14 @@
#pragma once #pragma once
#include <cstdint>
#include <cstddef> #include <cstddef>
#include <cstdint>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
// clang-format off
#define DYN_LINK_FUNCTION_NAME_LENGTH 351 #define DYN_LINK_FUNCTION_NAME_LENGTH 351
#define DYN_LINK_IMPORT_NAME_LENGTH 50 #define DYN_LINK_IMPORT_NAME_LENGTH 50
@ -31,6 +32,7 @@ extern "C" {
#define DYN_LINK_IMPORT_LIST_LENGTH 50 #define DYN_LINK_IMPORT_LIST_LENGTH 50
#define DYN_LINK_TRAMPOLIN_LIST_LENGTH DYN_LINK_FUNCTION_LIST_LENGTH #define DYN_LINK_TRAMPOLIN_LIST_LENGTH DYN_LINK_FUNCTION_LIST_LENGTH
// clang-format on
typedef struct _dyn_linking_function_t { typedef struct _dyn_linking_function_t {
char functionName[DYN_LINK_FUNCTION_NAME_LENGTH + 1]; char functionName[DYN_LINK_FUNCTION_NAME_LENGTH + 1];

View File

@ -17,10 +17,10 @@
#pragma once #pragma once
#include <cstdint>
#include <cstddef>
#include "dynamic_linking_defines.h" #include "dynamic_linking_defines.h"
#include "relocation_defines.h" #include "relocation_defines.h"
#include <cstddef>
#include <cstdint>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View File

@ -19,6 +19,7 @@
#include <cstdint> #include <cstdint>
// clang-format off
typedef enum RelocationTrampolinStatus { typedef enum RelocationTrampolinStatus {
RELOC_TRAMP_FREE = 0, RELOC_TRAMP_FREE = 0,
RELOC_TRAMP_FIXED = 1, RELOC_TRAMP_FIXED = 1,
@ -35,3 +36,4 @@ typedef struct relocation_trampolin_entry_t {
uint32_t trampolin[4]; uint32_t trampolin[4];
RelocationTrampolinStatus status; RelocationTrampolinStatus status;
} relocation_trampolin_entry_t; } relocation_trampolin_entry_t;
// clang-format on

View File

@ -1,3 +1,4 @@
// clang-format off
/* /*
Copyright (C) 2001-2015 by Serge Lamikhov-Center Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/* /*
Copyright (C) 2001-2015 by Serge Lamikhov-Center Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/* /*
Copyright (C) 2001-2015 by Serge Lamikhov-Center Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/* /*
Copyright (C) 2001-2015 by Serge Lamikhov-Center Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/* /*
Copyright (C) 2001-2015 by Serge Lamikhov-Center Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/* /*
Copyright (C) 2001-2015 by Serge Lamikhov-Center Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/* /*
Copyright (C) 2001-2015 by Serge Lamikhov-Center Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/* /*
Copyright (C) 2001-2015 by Serge Lamikhov-Center Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/* /*
Copyright (C) 2001-2015 by Serge Lamikhov-Center Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/* /*
Copyright (C) 2001-2015 by Serge Lamikhov-Center Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/* /*
Copyright (C) 2001-2015 by Serge Lamikhov-Center Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/* /*
Copyright (C) 2001-2015 by Serge Lamikhov-Center Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,9 +1,9 @@
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <strings.h>
#include <fs/CFile.hpp> #include <fs/CFile.hpp>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
CFile::CFile() { CFile::CFile() {
iFd = -1; iFd = -1;
@ -171,5 +171,3 @@ int32_t CFile::fwrite(const char *format, ...) {
return result; return result;
} }

View File

@ -1,10 +1,10 @@
#ifndef CFILE_HPP_ #ifndef CFILE_HPP_
#define CFILE_HPP_ #define CFILE_HPP_
#include <stdio.h>
#include <string>
#include <string.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include <unistd.h> #include <unistd.h>
#include <wut_types.h> #include <wut_types.h>

View File

@ -24,14 +24,14 @@
* DirList Class * DirList Class
* for WiiXplorer 2010 * for WiiXplorer 2010
***************************************************************************/ ***************************************************************************/
#include <algorithm>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <string> #include <string>
#include <strings.h> #include <strings.h>
#include <algorithm>
#include <sys/stat.h>
#include <sys/dirent.h> #include <sys/dirent.h>
#include <sys/stat.h>
#include <fs/DirList.h> #include <fs/DirList.h>
#include <utils/StringTools.h> #include <utils/StringTools.h>

View File

@ -27,8 +27,8 @@
#ifndef ___DIRLIST_H_ #ifndef ___DIRLIST_H_
#define ___DIRLIST_H_ #define ___DIRLIST_H_
#include <vector>
#include <string> #include <string>
#include <vector>
#include <wut_types.h> #include <wut_types.h>
typedef struct { typedef struct {
@ -97,6 +97,7 @@ public:
Dirs = 0x02, Dirs = 0x02,
CheckSubfolders = 0x08, CheckSubfolders = 0x08,
}; };
protected: protected:
// Internal parser // Internal parser
BOOL InternalLoadPath(std::string &path); BOOL InternalLoadPath(std::string &path);

View File

@ -50,6 +50,5 @@ void __attribute__ ((noinline)) kern_write(void *addr, uint32_t value) {
: :
: "r"(addr), "r"(value) : "r"(addr), "r"(value)
: "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10", : "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10",
"11", "12" "11", "12");
);
} }

View File

@ -2,6 +2,7 @@
#include <cstdint> #include <cstdint>
// clang-format off
#define ADDRESS_main_entry_hook 0x0101C56C #define ADDRESS_main_entry_hook 0x0101C56C
#define KERN_SYSCALL_TBL_1 0xFFE84C70 // unknown #define KERN_SYSCALL_TBL_1 0xFFE84C70 // unknown
@ -9,6 +10,7 @@
#define KERN_SYSCALL_TBL_3 0xFFE85470 // works with loader #define KERN_SYSCALL_TBL_3 0xFFE85470 // works with loader
#define KERN_SYSCALL_TBL_4 0xFFEAAA60 // works with home menu #define KERN_SYSCALL_TBL_4 0xFFEAAA60 // works with home menu
#define KERN_SYSCALL_TBL_5 0xFFEAAE60 // works with browser (previously KERN_SYSCALL_TBL) #define KERN_SYSCALL_TBL_5 0xFFEAAE60 // works with browser (previously KERN_SYSCALL_TBL)
// clang-format on
void RevertMainHook(); void RevertMainHook();

View File

@ -1,41 +1,42 @@
#include <cstring> #include <cstring>
#include <gx2/state.h> #include "utils/StringTools.h"
#include <coreinit/cache.h>
#include <coreinit/debug.h>
#include <coreinit/dynload.h>
#include <coreinit/foreground.h>
#include <coreinit/ios.h>
#include <coreinit/screen.h>
#include <coreinit/title.h>
#include <elfio/elfio.hpp> #include <elfio/elfio.hpp>
#include <fcntl.h>
#include <gx2/state.h>
#include <malloc.h>
#include <memory>
#include <nn/act/client_cpp.h>
#include <proc_ui/procui.h> #include <proc_ui/procui.h>
#include <sysapp/launch.h> #include <sysapp/launch.h>
#include <sysapp/title.h> #include <sysapp/title.h>
#include <coreinit/foreground.h> #include <vector>
#include <coreinit/cache.h> #include <vpad/input.h>
#include <coreinit/ios.h>
#include <nn/act/client_cpp.h>
#include <coreinit/dynload.h>
#include <whb/log_udp.h>
#include <whb/log_cafe.h> #include <whb/log_cafe.h>
#include <whb/log_module.h> #include <whb/log_module.h>
#include <vector> #include <whb/log_udp.h>
#include <coreinit/dynload.h>
#include <coreinit/title.h>
#include <coreinit/screen.h>
#include <memory>
#include <malloc.h>
#include <vpad/input.h>
#include <coreinit/debug.h>
#include <fcntl.h>
#include "utils/StringTools.h"
#include "fs/DirList.h"
#include "module/ModuleDataFactory.h"
#include "ElfUtils.h" #include "ElfUtils.h"
#include "kernel.h"
#include "common/module_defines.h" #include "common/module_defines.h"
#include "fs/DirList.h"
#include "kernel.h"
#include "module/ModuleDataFactory.h"
#include "utils/DrawUtils.h" #include "utils/DrawUtils.h"
// clang-format off
#define MEMORY_REGION_START 0x00A00000 #define MEMORY_REGION_START 0x00A00000
#define MEMORY_REGION_SIZE 0x00600000 #define MEMORY_REGION_SIZE 0x00600000
#define MEMORY_REGION_END (MEMORY_REGION_START + MEMORY_REGION_SIZE) #define MEMORY_REGION_END (MEMORY_REGION_START + MEMORY_REGION_SIZE)
#define AUTOBOOT_CONFIG_PATH "fs:/vol/external01/wiiu/environments/default.cfg" #define AUTOBOOT_CONFIG_PATH "fs:/vol/external01/wiiu/environments/default.cfg"
// clang-format on
bool CheckRunning() { bool CheckRunning() {
switch (ProcUIProcessMessages(true)) { switch (ProcUIProcessMessages(true)) {
@ -200,7 +201,9 @@ int main(int argc, char **argv) {
DEBUG_FUNCTION_LINE("Calling entrypoint @%08X", moduleData.value()->getEntrypoint()); DEBUG_FUNCTION_LINE("Calling entrypoint @%08X", moduleData.value()->getEntrypoint());
char *arr[1]; char *arr[1];
arr[0] = (char *) environment_path.c_str(); arr[0] = (char *) environment_path.c_str();
// clang-format off
((int(*)(int, char **)) moduleData.value()->getEntrypoint())(1, arr); ((int(*)(int, char **)) moduleData.value()->getEntrypoint())(1, arr);
// clang-format on
DEBUG_FUNCTION_LINE("Back from module"); DEBUG_FUNCTION_LINE("Back from module");
} }
} else { } else {
@ -211,7 +214,9 @@ int main(int argc, char **argv) {
if ((i + 1) < argc) { if ((i + 1) < argc) {
i++; i++;
DEBUG_FUNCTION_LINE("call forceDefaultTitleIDToWiiUMenu"); DEBUG_FUNCTION_LINE("call forceDefaultTitleIDToWiiUMenu");
// clang-format off
auto forceDefaultTitleIDToWiiUMenu = (void(*)()) argv[i]; auto forceDefaultTitleIDToWiiUMenu = (void(*)()) argv[i];
// clang-format on
forceDefaultTitleIDToWiiUMenu(); forceDefaultTitleIDToWiiUMenu();
} }
} }
@ -233,6 +238,7 @@ int main(int argc, char **argv) {
return 0; return 0;
} }
// clang-format off
#define COLOR_WHITE Color(0xffffffff) #define COLOR_WHITE Color(0xffffffff)
#define COLOR_BLACK Color(0, 0, 0, 255) #define COLOR_BLACK Color(0, 0, 0, 255)
#define COLOR_RED Color(237, 28, 36, 255) #define COLOR_RED Color(237, 28, 36, 255)
@ -242,7 +248,7 @@ int main(int argc, char **argv) {
#define COLOR_AUTOBOOT Color(0xaeea00ff) #define COLOR_AUTOBOOT Color(0xaeea00ff)
#define COLOR_BORDER Color(204, 204, 204, 255) #define COLOR_BORDER Color(204, 204, 204, 255)
#define COLOR_BORDER_HIGHLIGHTED Color(0x3478e4ff) #define COLOR_BORDER_HIGHLIGHTED Color(0x3478e4ff)
// clang-format on
std::string EnvironmentSelectionScreen(const std::map<std::string, std::string> &payloads, int32_t autobootIndex) { std::string EnvironmentSelectionScreen(const std::map<std::string, std::string> &payloads, int32_t autobootIndex) {
OSScreenInit(); OSScreenInit();

View File

@ -17,10 +17,11 @@
#pragma once #pragma once
#include <string>
#include <optional>
#include <utility>
#include "utils/logger.h" #include "utils/logger.h"
#include <memory>
#include <optional>
#include <string>
#include <utility>
class ImportRPLInformation { class ImportRPLInformation {

View File

@ -17,11 +17,11 @@
#pragma once #pragma once
#include <string> #include "RelocationData.h"
#include <vector>
#include <map> #include <map>
#include <set> #include <set>
#include "RelocationData.h" #include <string>
#include <vector>
class ModuleData { class ModuleData {
public: public:

View File

@ -15,12 +15,12 @@
* 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 <string>
#include <vector>
#include <map>
#include <coreinit/cache.h>
#include "ModuleDataFactory.h" #include "ModuleDataFactory.h"
#include "ElfUtils.h" #include "ElfUtils.h"
#include <coreinit/cache.h>
#include <map>
#include <string>
#include <vector>
using namespace ELFIO; using namespace ELFIO;

View File

@ -17,12 +17,12 @@
#pragma once #pragma once
#include <string> #include "../common/relocation_defines.h"
#include <vector>
#include <map>
#include "ModuleData.h" #include "ModuleData.h"
#include "elfio/elfio.hpp" #include "elfio/elfio.hpp"
#include "../common/relocation_defines.h" #include <map>
#include <string>
#include <vector>
class ModuleDataFactory { class ModuleDataFactory {
public: public:

View File

@ -17,10 +17,10 @@
#pragma once #pragma once
#include <string>
#include <memory>
#include <utility>
#include "ImportRPLInformation.h" #include "ImportRPLInformation.h"
#include <memory>
#include <string>
#include <utility>
class RelocationData { class RelocationData {

View File

@ -1,11 +1,11 @@
#include "DrawUtils.h" #include "DrawUtils.h"
#include <cmath> #include <cmath>
#include <coreinit/cache.h>
#include <coreinit/memory.h> #include <coreinit/memory.h>
#include <coreinit/screen.h> #include <coreinit/screen.h>
#include <coreinit/cache.h>
#include <png.h>
#include <ft2build.h> #include <ft2build.h>
#include <png.h>
#include FT_FREETYPE_H #include FT_FREETYPE_H
// buffer width // buffer width
@ -24,16 +24,14 @@ static FT_Library ft_lib = nullptr;
static FT_Face ft_face = nullptr; static FT_Face ft_face = nullptr;
static Color font_col = {0xFFFFFFFF}; static Color font_col = {0xFFFFFFFF};
void DrawUtils::initBuffers(void* tvBuffer, uint32_t tvSize, void* drcBuffer, uint32_t drcSize) void DrawUtils::initBuffers(void *tvBuffer, uint32_t tvSize, void *drcBuffer, uint32_t drcSize) {
{
DrawUtils::tvBuffer = (uint8_t *) tvBuffer; DrawUtils::tvBuffer = (uint8_t *) tvBuffer;
DrawUtils::tvSize = tvSize; DrawUtils::tvSize = tvSize;
DrawUtils::drcBuffer = (uint8_t *) drcBuffer; DrawUtils::drcBuffer = (uint8_t *) drcBuffer;
DrawUtils::drcSize = drcSize; DrawUtils::drcSize = drcSize;
} }
void DrawUtils::beginDraw() void DrawUtils::beginDraw() {
{
uint32_t pixel = *(uint32_t *) tvBuffer; uint32_t pixel = *(uint32_t *) tvBuffer;
// check which buffer is currently used // check which buffer is currently used
@ -48,8 +46,7 @@ void DrawUtils::beginDraw()
*(uint32_t *) tvBuffer = pixel; *(uint32_t *) tvBuffer = pixel;
} }
void DrawUtils::endDraw() void DrawUtils::endDraw() {
{
// OSScreenFlipBuffersEx already flushes the cache? // OSScreenFlipBuffersEx already flushes the cache?
// DCFlushRange(tvBuffer, tvSize); // DCFlushRange(tvBuffer, tvSize);
// DCFlushRange(drcBuffer, drcSize); // DCFlushRange(drcBuffer, drcSize);
@ -58,14 +55,12 @@ void DrawUtils::endDraw()
OSScreenFlipBuffersEx(SCREEN_TV); OSScreenFlipBuffersEx(SCREEN_TV);
} }
void DrawUtils::clear(Color col) void DrawUtils::clear(Color col) {
{
OSScreenClearBufferEx(SCREEN_TV, col.color); OSScreenClearBufferEx(SCREEN_TV, col.color);
OSScreenClearBufferEx(SCREEN_DRC, col.color); OSScreenClearBufferEx(SCREEN_DRC, col.color);
} }
void DrawUtils::drawPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a) void DrawUtils::drawPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
{
float opacity = a / 255.0f; float opacity = a / 255.0f;
// put pixel in the drc buffer // put pixel in the drc buffer
@ -78,8 +73,7 @@ void DrawUtils::drawPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t
drcBuffer[i] = r; drcBuffer[i] = r;
drcBuffer[i + 1] = g; drcBuffer[i + 1] = g;
drcBuffer[i + 2] = b; drcBuffer[i + 2] = b;
} } else {
else {
drcBuffer[i] = r * opacity + drcBuffer[i] * (1 - opacity); drcBuffer[i] = r * opacity + drcBuffer[i] * (1 - opacity);
drcBuffer[i + 1] = g * opacity + drcBuffer[i + 1] * (1 - opacity); drcBuffer[i + 1] = g * opacity + drcBuffer[i + 1] * (1 - opacity);
drcBuffer[i + 2] = b * opacity + drcBuffer[i + 2] * (1 - opacity); drcBuffer[i + 2] = b * opacity + drcBuffer[i + 2] * (1 - opacity);
@ -98,8 +92,7 @@ void DrawUtils::drawPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t
tvBuffer[i] = r; tvBuffer[i] = r;
tvBuffer[i + 1] = g; tvBuffer[i + 1] = g;
tvBuffer[i + 2] = b; tvBuffer[i + 2] = b;
} } else {
else {
tvBuffer[i] = r * opacity + tvBuffer[i] * (1 - opacity); tvBuffer[i] = r * opacity + tvBuffer[i] * (1 - opacity);
tvBuffer[i + 1] = g * opacity + tvBuffer[i + 1] * (1 - opacity); tvBuffer[i + 1] = g * opacity + tvBuffer[i + 1] * (1 - opacity);
tvBuffer[i + 2] = b * opacity + tvBuffer[i + 2] * (1 - opacity); tvBuffer[i + 2] = b * opacity + tvBuffer[i + 2] * (1 - opacity);
@ -109,8 +102,7 @@ void DrawUtils::drawPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t
} }
} }
void DrawUtils::drawRectFilled(uint32_t x, uint32_t y, uint32_t w, uint32_t h, Color col) void DrawUtils::drawRectFilled(uint32_t x, uint32_t y, uint32_t w, uint32_t h, Color col) {
{
for (uint32_t yy = y; yy < y + h; yy++) { for (uint32_t yy = y; yy < y + h; yy++) {
for (uint32_t xx = x; xx < x + w; xx++) { for (uint32_t xx = x; xx < x + w; xx++) {
drawPixel(xx, yy, col); drawPixel(xx, yy, col);
@ -118,16 +110,14 @@ void DrawUtils::drawRectFilled(uint32_t x, uint32_t y, uint32_t w, uint32_t h, C
} }
} }
void DrawUtils::drawRect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t borderSize, Color col) void DrawUtils::drawRect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t borderSize, Color col) {
{
drawRectFilled(x, y, w, borderSize, col); drawRectFilled(x, y, w, borderSize, col);
drawRectFilled(x, y + h - borderSize, w, borderSize, col); drawRectFilled(x, y + h - borderSize, w, borderSize, col);
drawRectFilled(x, y, borderSize, h, col); drawRectFilled(x, y, borderSize, h, col);
drawRectFilled(x + w - borderSize, y, borderSize, h, col); drawRectFilled(x + w - borderSize, y, borderSize, h, col);
} }
void DrawUtils::drawBitmap(uint32_t x, uint32_t y, uint32_t target_width, uint32_t target_height, const uint8_t* data) void DrawUtils::drawBitmap(uint32_t x, uint32_t y, uint32_t target_width, uint32_t target_height, const uint8_t *data) {
{
if (data[0] != 'B' || data[1] != 'M') { if (data[0] != 'B' || data[1] != 'M') {
// invalid header // invalid header
return; return;
@ -153,16 +143,14 @@ void DrawUtils::drawBitmap(uint32_t x, uint32_t y, uint32_t target_width, uint32
} }
} }
static void png_read_data(png_structp png_ptr, png_bytep outBytes, png_size_t byteCountToRead) static void png_read_data(png_structp png_ptr, png_bytep outBytes, png_size_t byteCountToRead) {
{
void **data = (void **) png_get_io_ptr(png_ptr); void **data = (void **) png_get_io_ptr(png_ptr);
memcpy(outBytes, *data, byteCountToRead); memcpy(outBytes, *data, byteCountToRead);
*((uint8_t **) data) += byteCountToRead; *((uint8_t **) data) += byteCountToRead;
} }
void DrawUtils::drawPNG(uint32_t x, uint32_t y, const uint8_t* data) void DrawUtils::drawPNG(uint32_t x, uint32_t y, const uint8_t *data) {
{
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL) { if (png_ptr == NULL) {
return; return;
@ -197,8 +185,7 @@ void DrawUtils::drawPNG(uint32_t x, uint32_t y, const uint8_t* data)
if (colorType == PNG_COLOR_TYPE_RGB_ALPHA) { if (colorType == PNG_COLOR_TYPE_RGB_ALPHA) {
uint32_t i = (xx - x) * 4; uint32_t i = (xx - x) * 4;
drawPixel(xx, yy, rowData[i], rowData[i + 1], rowData[i + 2], rowData[i + 3]); drawPixel(xx, yy, rowData[i], rowData[i + 1], rowData[i + 2], rowData[i + 3]);
} } else if (colorType == PNG_COLOR_TYPE_RGB) {
else if (colorType == PNG_COLOR_TYPE_RGB) {
uint32_t i = (xx - x) * 3; uint32_t i = (xx - x) * 3;
drawPixel(xx, yy, rowData[i], rowData[i + 1], rowData[i + 2], 0xFF); drawPixel(xx, yy, rowData[i], rowData[i + 1], rowData[i + 2], 0xFF);
} }
@ -209,8 +196,7 @@ void DrawUtils::drawPNG(uint32_t x, uint32_t y, const uint8_t* data)
png_destroy_read_struct(&png_ptr, &info_ptr, NULL); png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
} }
void DrawUtils::initFont() void DrawUtils::initFont() {
{
void *font = NULL; void *font = NULL;
uint32_t size = 0; uint32_t size = 0;
OSGetSharedData(OS_SHAREDDATATYPE_FONT_STANDARD, 0, &font, &size); OSGetSharedData(OS_SHAREDDATATYPE_FONT_STANDARD, 0, &font, &size);
@ -221,24 +207,20 @@ void DrawUtils::initFont()
} }
} }
void DrawUtils::deinitFont() void DrawUtils::deinitFont() {
{
FT_Done_Face(ft_face); FT_Done_Face(ft_face);
FT_Done_FreeType(ft_lib); FT_Done_FreeType(ft_lib);
} }
void DrawUtils::setFontSize(uint32_t size) void DrawUtils::setFontSize(uint32_t size) {
{
FT_Set_Pixel_Sizes(ft_face, 0, size); FT_Set_Pixel_Sizes(ft_face, 0, size);
} }
void DrawUtils::setFontColor(Color col) void DrawUtils::setFontColor(Color col) {
{
font_col = col; font_col = col;
} }
static void draw_freetype_bitmap(FT_Bitmap* bitmap, FT_Int x, FT_Int y) static void draw_freetype_bitmap(FT_Bitmap *bitmap, FT_Int x, FT_Int y) {
{
FT_Int i, j, p, q; FT_Int i, j, p, q;
FT_Int x_max = x + bitmap->width; FT_Int x_max = x + bitmap->width;
FT_Int y_max = y + bitmap->rows; FT_Int y_max = y + bitmap->rows;
@ -255,25 +237,23 @@ static void draw_freetype_bitmap(FT_Bitmap* bitmap, FT_Int x, FT_Int y)
} }
} }
void DrawUtils::print(uint32_t x, uint32_t y, const char* string, bool alignRight) void DrawUtils::print(uint32_t x, uint32_t y, const char *string, bool alignRight) {
{
wchar_t *buffer = new wchar_t[strlen(string) + 1]; wchar_t *buffer = new wchar_t[strlen(string) + 1];
size_t num = mbstowcs(buffer, string, strlen(string)); size_t num = mbstowcs(buffer, string, strlen(string));
if (num > 0) { if (num > 0) {
buffer[num] = 0; buffer[num] = 0;
} } else {
else {
wchar_t *tmp = buffer; wchar_t *tmp = buffer;
while ((*tmp++ = *string++)); while ((*tmp++ = *string++))
;
} }
print(x, y, buffer, alignRight); print(x, y, buffer, alignRight);
delete[] buffer; delete[] buffer;
} }
void DrawUtils::print(uint32_t x, uint32_t y, const wchar_t* string, bool alignRight) void DrawUtils::print(uint32_t x, uint32_t y, const wchar_t *string, bool alignRight) {
{
FT_GlyphSlot slot = ft_face->glyph; FT_GlyphSlot slot = ft_face->glyph;
FT_Vector pen = {(int) x, (int) y}; FT_Vector pen = {(int) x, (int) y};
@ -298,17 +278,16 @@ void DrawUtils::print(uint32_t x, uint32_t y, const wchar_t* string, bool alignR
} }
} }
uint32_t DrawUtils::getTextWidth(const char* string) uint32_t DrawUtils::getTextWidth(const char *string) {
{
wchar_t *buffer = new wchar_t[strlen(string) + 1]; wchar_t *buffer = new wchar_t[strlen(string) + 1];
size_t num = mbstowcs(buffer, string, strlen(string)); size_t num = mbstowcs(buffer, string, strlen(string));
if (num > 0) { if (num > 0) {
buffer[num] = 0; buffer[num] = 0;
} } else {
else {
wchar_t *tmp = buffer; wchar_t *tmp = buffer;
while ((*tmp++ = *string++)); while ((*tmp++ = *string++))
;
} }
uint32_t width = getTextWidth(buffer); uint32_t width = getTextWidth(buffer);
@ -317,8 +296,7 @@ uint32_t DrawUtils::getTextWidth(const char* string)
return width; return width;
} }
uint32_t DrawUtils::getTextWidth(const wchar_t* string) uint32_t DrawUtils::getTextWidth(const wchar_t *string) {
{
FT_GlyphSlot slot = ft_face->glyph; FT_GlyphSlot slot = ft_face->glyph;
uint32_t width = 0; uint32_t width = 0;

View File

@ -11,7 +11,10 @@ union Color {
this->color = color; this->color = color;
} }
Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a) { Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
this->r = r; this->g = g; this->b = b; this->a = a; this->r = r;
this->g = g;
this->b = b;
this->a = a;
} }
uint32_t color; uint32_t color;

View File

@ -23,17 +23,16 @@
* *
* for WiiXplorer 2010 * for WiiXplorer 2010
***************************************************************************/ ***************************************************************************/
#include <vector>
#include <string>
#include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <string.h>
#include <wchar.h> #include <string>
#include <strings.h> #include <strings.h>
#include <wut_types.h>
#include <stdio.h>
#include <utils/StringTools.h> #include <utils/StringTools.h>
#include <vector>
#include <wchar.h>
#include <wut_types.h>
BOOL StringTools::EndsWith(const std::string &a, const std::string &b) { BOOL StringTools::EndsWith(const std::string &a, const std::string &b) {

View File

@ -26,8 +26,8 @@
#ifndef __STRING_TOOLS_H #ifndef __STRING_TOOLS_H
#define __STRING_TOOLS_H #define __STRING_TOOLS_H
#include <vector>
#include <string> #include <string>
#include <vector>
#include <wut_types.h> #include <wut_types.h>
class StringTools { class StringTools {
@ -62,4 +62,3 @@ public:
}; };
#endif /* __STRING_TOOLS_H */ #endif /* __STRING_TOOLS_H */

View File

@ -1,8 +1,8 @@
#ifdef DEBUG #ifdef DEBUG
#include <stdint.h> #include <stdint.h>
#include <whb/log_udp.h>
#include <whb/log_cafe.h> #include <whb/log_cafe.h>
#include <whb/log_module.h> #include <whb/log_module.h>
#include <whb/log_udp.h>
uint32_t moduleLogInit = false; uint32_t moduleLogInit = false;
uint32_t cafeLogInit = false; uint32_t cafeLogInit = false;

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <whb/log.h>
#include <string.h> #include <string.h>
#include <whb/log.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -14,11 +14,13 @@ extern "C" {
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0) #define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \ #define DEBUG_FUNCTION_LINE(FMT, ARGS...) \
do { \
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \ WHBLogPrintf("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \
} while (0) } while (0)
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \ #define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) \
do { \
WHBLogWritef("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \ WHBLogWritef("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \
} while (0) } while (0)
@ -39,4 +41,3 @@ void deinitLogging();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif