mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-25 22:15:14 +00:00
use stb_image for image support
This commit is contained in:
parent
7d191b3db9
commit
0585d127a6
8 changed files with 12114 additions and 3681 deletions
|
@ -572,6 +572,7 @@ extern/imgui_patched/misc/cpp/imgui_stdlib.cpp
|
|||
extern/igfd/ImGuiFileDialog.cpp
|
||||
|
||||
src/gui/plot_nolerp.cpp
|
||||
|
||||
src/gui/font_exo.cpp
|
||||
src/gui/font_liberationSans.cpp
|
||||
src/gui/font_mononoki.cpp
|
||||
|
@ -582,6 +583,10 @@ src/gui/font_ptMono.cpp
|
|||
src/gui/font_unifont.cpp
|
||||
src/gui/font_icon.cpp
|
||||
src/gui/fonts.cpp
|
||||
|
||||
src/gui/image_icon.cpp
|
||||
src/gui/image.cpp
|
||||
|
||||
src/gui/debug.cpp
|
||||
src/gui/fileDialog.cpp
|
||||
|
||||
|
@ -646,9 +651,7 @@ if (APPLE)
|
|||
list(APPEND GUI_SOURCES extern/nfd-modified/src/nfd_cocoa.mm)
|
||||
endif()
|
||||
|
||||
if (NOT APPLE)
|
||||
list(APPEND GUI_SOURCES src/gui/icon.c)
|
||||
|
||||
if (NOT WIN32 AND NOT APPLE)
|
||||
CHECK_INCLUDE_FILE(sys/io.h SYS_IO_FOUND)
|
||||
CHECK_INCLUDE_FILE(linux/input.h LINUX_INPUT_FOUND)
|
||||
CHECK_INCLUDE_FILE(linux/kd.h LINUX_KD_FOUND)
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
|
||||
#include "gui.h"
|
||||
#include "util.h"
|
||||
#include "icon.h"
|
||||
#include "../ta-log.h"
|
||||
#include "../fileutils.h"
|
||||
#include "imgui.h"
|
||||
|
@ -5445,8 +5444,9 @@ bool FurnaceGUI::init() {
|
|||
|
||||
#if !(defined(__APPLE__) || defined(_WIN32))
|
||||
// get the icon (on macOS and Windows the icon is bundled with the app)
|
||||
unsigned char* furIcon=getFurnaceIcon();
|
||||
SDL_Surface* icon=SDL_CreateRGBSurfaceFrom(furIcon,256,256,32,256*4,0xff,0xff00,0xff0000,0xff000000);
|
||||
const FurnaceGUIImage* furIcon=getImage(GUI_IMAGE_ICON);
|
||||
SDL_Surface* icon=NULL;
|
||||
if (furIcon!=NULL) SDL_CreateRGBSurfaceFrom(furIcon->data,furIcon->width,furIcon->height,32,256*4,0xff,0xff00,0xff0000,0xff000000);
|
||||
#endif
|
||||
|
||||
#ifdef IS_MOBILE
|
||||
|
@ -5538,7 +5538,6 @@ bool FurnaceGUI::init() {
|
|||
if (icon!=NULL) {
|
||||
SDL_SetWindowIcon(sdlWin,icon);
|
||||
SDL_FreeSurface(icon);
|
||||
free(furIcon);
|
||||
} else {
|
||||
logW("could not create icon!");
|
||||
}
|
||||
|
|
|
@ -649,6 +649,12 @@ enum FurnaceGUIActions {
|
|||
GUI_ACTION_MAX
|
||||
};
|
||||
|
||||
enum FurnaceGUIImages {
|
||||
GUI_IMAGE_ICON=0,
|
||||
|
||||
GUI_IMAGE_MAX
|
||||
};
|
||||
|
||||
enum FurnaceGUIChanOscRef {
|
||||
GUI_OSCREF_NONE=0,
|
||||
GUI_OSCREF_CENTER,
|
||||
|
@ -1095,6 +1101,16 @@ struct FurnaceGUIQueryResult {
|
|||
}
|
||||
};
|
||||
|
||||
struct FurnaceGUIImage {
|
||||
unsigned char* data;
|
||||
int width, height, ch;
|
||||
FurnaceGUIImage():
|
||||
data(NULL),
|
||||
width(0),
|
||||
height(0),
|
||||
ch(0) {}
|
||||
};
|
||||
|
||||
class FurnaceGUI {
|
||||
DivEngine* e;
|
||||
|
||||
|
@ -1658,6 +1674,8 @@ class FurnaceGUI {
|
|||
int renderTimeBegin, renderTimeEnd, renderTimeDelta;
|
||||
int eventTimeBegin, eventTimeEnd, eventTimeDelta;
|
||||
|
||||
std::map<FurnaceGUIImages,FurnaceGUIImage*> images;
|
||||
|
||||
int chanToMove, sysToMove, sysToDelete, opToMove;
|
||||
|
||||
ImVec2 patWindowPos, patWindowSize;
|
||||
|
@ -1855,6 +1873,8 @@ class FurnaceGUI {
|
|||
void pushToggleColors(bool status);
|
||||
void popToggleColors();
|
||||
|
||||
const FurnaceGUIImage* getImage(FurnaceGUIImages image);
|
||||
|
||||
void drawMobileControls();
|
||||
void drawMobileOrderSel();
|
||||
void drawEditControls();
|
||||
|
|
3668
src/gui/icon.c
3668
src/gui/icon.c
File diff suppressed because it is too large
Load diff
66
src/gui/image.cpp
Normal file
66
src/gui/image.cpp
Normal file
|
@ -0,0 +1,66 @@
|
|||
/**
|
||||
* Furnace Tracker - multi-system chiptune tracker
|
||||
* Copyright (C) 2021-2023 tildearrow and contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* this license only applies to the code. for the license of each font used,
|
||||
* see `papers/`.
|
||||
*/
|
||||
|
||||
#include "gui.h"
|
||||
#include "image.h"
|
||||
#include "../ta-log.h"
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#define STBI_ONLY_PNG
|
||||
#define STBI_NO_STDIO
|
||||
#include "stb_image.h"
|
||||
|
||||
const unsigned char* imageData[GUI_IMAGE_MAX]={
|
||||
image_icon_data
|
||||
};
|
||||
|
||||
const unsigned int imageLen[GUI_IMAGE_MAX]={
|
||||
image_icon_size
|
||||
};
|
||||
|
||||
const FurnaceGUIImage* FurnaceGUI::getImage(FurnaceGUIImages image) {
|
||||
FurnaceGUIImage* ret=NULL;
|
||||
auto retPos=images.find(image);
|
||||
if (retPos!=images.cend()) {
|
||||
ret=retPos->second;
|
||||
} else {
|
||||
ret=new FurnaceGUIImage;
|
||||
logV("loading image %d to pool.",(int)image);
|
||||
ret->data=stbi_load_from_memory(imageData[image],imageLen[image],&ret->width,&ret->height,&ret->ch,STBI_rgb_alpha);
|
||||
|
||||
if (ret->data==NULL) {
|
||||
logE("could not load image %d!",(int)image);
|
||||
delete ret;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
logV("%dx%d",ret->width,ret->height);
|
||||
|
||||
images[image]=ret;
|
||||
}
|
||||
|
||||
// warning silencers
|
||||
stbi__addints_valid(2,2);
|
||||
stbi__mul2shorts_valid(2,2);
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -17,10 +17,8 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
unsigned char* getFurnaceIcon();
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#ifndef _IMAGE_H
|
||||
#define _IMAGE_H
|
||||
extern const unsigned char image_icon_data[];
|
||||
extern const unsigned int image_icon_size;
|
||||
#endif
|
4028
src/gui/image_icon.cpp
Normal file
4028
src/gui/image_icon.cpp
Normal file
File diff suppressed because it is too large
Load diff
7987
src/gui/stb_image.h
Normal file
7987
src/gui/stb_image.h
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue