-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Turbo Badger: Adjusted backend to new integration interface (#236)
Added resources for fonty skin Added stb font renderer to the backend so we can use nebula's copy of stb_truetype Use timer GetTicks instead of GetTime and removed no longer used code from system time
- Loading branch information
Showing
17 changed files
with
1,049 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//------------------------------------------------------------------------------ | ||
// backend/tbuiclipboard.cc | ||
// (C) 2024 Individual contributors, see AUTHORS file | ||
//------------------------------------------------------------------------------ | ||
#include "render/stdneb.h" | ||
#include "tbuiclipboardinterface.h" | ||
|
||
namespace TBUI | ||
{ | ||
|
||
// == TBClipboard ===================================== | ||
|
||
void | ||
TBUIClipboardInterface::Empty() | ||
{ | ||
clipboard.Clear(); | ||
} | ||
|
||
bool | ||
TBUIClipboardInterface::HasText() | ||
{ | ||
return !clipboard.IsEmpty(); | ||
} | ||
|
||
bool | ||
TBUIClipboardInterface::SetText(const char* text) | ||
{ | ||
return clipboard.Set(text); | ||
} | ||
|
||
bool | ||
TBUIClipboardInterface::GetText(tb::TBStr& text) | ||
{ | ||
return text.Set(clipboard); | ||
} | ||
|
||
} // namespace tb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//------------------------------------------------------------------------------ | ||
// backend/tbuiclipboard.cc | ||
// (C) 2024 Individual contributors, see AUTHORS file | ||
//------------------------------------------------------------------------------ | ||
#include "render/stdneb.h" | ||
#include "platform/tb_clipboard_interface.h" | ||
|
||
namespace TBUI | ||
{ | ||
|
||
class TBUIClipboardInterface : public tb::TBClipboardInterface | ||
{ | ||
public: | ||
void Empty() override; | ||
bool HasText() override; | ||
bool SetText(const char* text) override; | ||
bool GetText(tb::TBStr& text) override; | ||
|
||
private: | ||
tb::TBStr clipboard; | ||
}; | ||
|
||
} // namespace tb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
//------------------------------------------------------------------------------ | ||
// backend/tbuifile.cc | ||
// (C) 2024 Individual contributors, see AUTHORS file | ||
//------------------------------------------------------------------------------ | ||
#include "render/stdneb.h" | ||
#include "io/ioserver.h" | ||
#include "io/stream.h" | ||
#include "tbuifileinterface.h" | ||
|
||
namespace | ||
{ | ||
size_t | ||
allocateFileId() | ||
{ | ||
static size_t s_fileId = 0; | ||
return ++s_fileId; | ||
} | ||
} | ||
|
||
namespace TBUI | ||
{ | ||
tb::TBFileHandle | ||
TBUIFileInterface::Open(const char* filename, TBFileMode mode) | ||
{ | ||
if (mode != TBFileMode::MODE_READ) | ||
return 0; | ||
|
||
Ptr<IO::FileStream> stream = IO::IoServer::Instance()->CreateStream(filename).downcast<IO::FileStream>(); | ||
stream->SetAccessMode(IO::Stream::AccessMode::ReadAccess); | ||
if (!stream->Open()) | ||
{ | ||
return 0; | ||
} | ||
|
||
size_t fileId = allocateFileId(); | ||
openFiles.Add(fileId, stream); | ||
return static_cast<tb::TBFileHandle>(fileId); | ||
} | ||
|
||
void | ||
TBUIFileInterface::Close(tb::TBFileHandle file) | ||
{ | ||
size_t fileId = static_cast<size_t>(file); | ||
|
||
if (openFiles.Contains(fileId)) | ||
{ | ||
openFiles[fileId]->Close(); | ||
openFiles.Erase(fileId); | ||
} | ||
} | ||
|
||
long | ||
TBUIFileInterface::Size(tb::TBFileHandle file) | ||
{ | ||
size_t fileId = static_cast<size_t>(file); | ||
|
||
if (openFiles.Contains(fileId)) | ||
{ | ||
return openFiles[fileId]->GetSize(); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
size_t | ||
TBUIFileInterface::Read(tb::TBFileHandle file, void* buf, size_t elemSize, size_t count) | ||
{ | ||
size_t fileId = static_cast<size_t>(file); | ||
|
||
if (openFiles.Contains(fileId)) | ||
{ | ||
return openFiles[fileId]->Read(buf, count); | ||
} | ||
|
||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
//------------------------------------------------------------------------------ | ||
/** | ||
Turbobadger UI File interface | ||
@copyright | ||
(C) 2024 Individual contributors, see AUTHORS file | ||
*/ | ||
//------------------------------------------------------------------------------ | ||
|
||
#include "io/filestream.h" | ||
#include "util/string.h" | ||
#include "util/dictionary.h" | ||
#include "platform/tb_file_interface.h" | ||
|
||
namespace TBUI | ||
{ | ||
class TBUIFileInterface : public tb::TBFileInterface | ||
{ | ||
public: | ||
tb::TBFileHandle Open(const char* filename, TBFileMode mode) override; | ||
void Close(tb::TBFileHandle file) override; | ||
|
||
long Size(tb::TBFileHandle file) override; | ||
size_t Read(tb::TBFileHandle file, void* buf, size_t elemSize, size_t count) override; | ||
|
||
bool IsOpen(tb::TBFileHandle file) const; | ||
|
||
private: | ||
Util::Dictionary<size_t, Ptr<IO::FileStream>> openFiles; | ||
}; | ||
|
||
inline bool | ||
TBUIFileInterface::IsOpen(tb::TBFileHandle file) const | ||
{ | ||
return openFiles.Contains(static_cast<size_t>(file)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// ================================================================================ | ||
// == This file is a part of Turbo Badger. (C) 2011-2014, Emil Segerås == | ||
// == See tb_core.h for more information. == | ||
// ================================================================================ | ||
|
||
#include <math.h> | ||
#include "tb_renderer.h" | ||
#include "platform/tb_system_interface.h" | ||
#include "tb_tempbuffer.h" | ||
#include "tbuifontrenderer.h" | ||
|
||
namespace TBUI | ||
{ | ||
//#define STB_TRUETYPE_IMPLEMENTATION // force following include to generate | ||
#include "stb_truetype.h" | ||
|
||
TBUISTBFontRenderer::TBUISTBFontRenderer() | ||
: render_data(nullptr) | ||
{ | ||
} | ||
|
||
TBUISTBFontRenderer::~TBUISTBFontRenderer() | ||
{ | ||
stbtt_FreeBitmap(render_data, &font); | ||
} | ||
|
||
tb::TBFontMetrics | ||
TBUISTBFontRenderer::GetMetrics() | ||
{ | ||
tb::TBFontMetrics metrics; | ||
int ascent, descent, lineGap; | ||
stbtt_GetFontVMetrics(&font, &ascent, &descent, &lineGap); | ||
metrics.ascent = (int)(ascent * scale + 0.5f); | ||
metrics.descent = (int)((-descent) * scale + 0.5f); | ||
metrics.height = (int)((ascent - descent + lineGap) * scale + 0.5f); | ||
return metrics; | ||
} | ||
|
||
bool | ||
TBUISTBFontRenderer::RenderGlyph(tb::TBFontGlyphData* data, UCS4 cp) | ||
{ | ||
stbtt_FreeBitmap(render_data, &font); | ||
render_data = stbtt_GetCodepointBitmap(&font, 0, scale, cp, &data->w, &data->h, 0, 0); | ||
data->data8 = render_data; | ||
data->stride = data->w; | ||
data->rgb = false; | ||
return data->data8 ? true : false; | ||
} | ||
|
||
void | ||
TBUISTBFontRenderer::GetGlyphMetrics(tb::TBGlyphMetrics* metrics, UCS4 cp) | ||
{ | ||
int advance, leftSideBearing; | ||
const int gi = stbtt_FindGlyphIndex(&font, cp); | ||
stbtt_GetGlyphHMetrics(&font, gi, &advance, &leftSideBearing); | ||
metrics->advance = (int)roundf(advance * scale); | ||
|
||
int ix0, iy0; | ||
stbtt_GetGlyphBitmapBoxSubpixel(&font, gi, scale, scale, 0.f, 0.f, &ix0, &iy0, 0, 0); | ||
metrics->x = ix0; | ||
metrics->y = iy0; | ||
} | ||
|
||
int | ||
TBUISTBFontRenderer::GetAdvance(UCS4 cp1, UCS4 cp2) | ||
{ | ||
int advance, leftSideBearing; | ||
const int gi1 = stbtt_FindGlyphIndex(&font, cp1); | ||
stbtt_GetGlyphHMetrics(&font, gi1, &advance, &leftSideBearing); | ||
if (font.kern) | ||
advance += stbtt_GetGlyphKernAdvance(&font, gi1, stbtt_FindGlyphIndex(&font, cp2)); | ||
return (int)roundf(advance * scale); | ||
} | ||
|
||
bool | ||
TBUISTBFontRenderer::Load(const char* filename, int size) | ||
{ | ||
if (!ttf_buffer.AppendFile(filename)) | ||
return false; | ||
|
||
const unsigned char* ttf_ptr = (const unsigned char*)ttf_buffer.GetData(); | ||
stbtt_InitFont(&font, ttf_ptr, stbtt_GetFontOffsetForIndex(ttf_ptr, 0)); | ||
|
||
scale = stbtt_ScaleForPixelHeight(&font, (float)size); | ||
return true; | ||
} | ||
|
||
tb::TBFontFace* | ||
TBUISTBFontRenderer::Create(tb::TBFontManager* font_manager, const char* filename, const tb::TBFontDescription& font_desc) | ||
{ | ||
if (TBUISTBFontRenderer* fr = new TBUISTBFontRenderer()) | ||
{ | ||
if (fr->Load(filename, (int)font_desc.GetSize())) | ||
if (tb::TBFontFace* font = new tb::TBFontFace(font_manager->GetGlyphCache(), fr, font_desc)) | ||
return font; | ||
delete fr; | ||
} | ||
return nullptr; | ||
} | ||
|
||
} // namespace TBUI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// ================================================================================ | ||
// == This file is a part of Turbo Badger. (C) 2011-2014, Emil Segerås == | ||
// == See tb_core.h for more information. == | ||
// ================================================================================ | ||
|
||
#include <math.h> | ||
#include "tb_font_renderer.h" | ||
#include "tb_renderer.h" | ||
#include "platform/tb_system_interface.h" | ||
#include "tb_tempbuffer.h" | ||
|
||
namespace TBUI | ||
{ | ||
/** STBFontRenderer renders fonts using stb_truetype.h (http://nothings.org/) */ | ||
|
||
class TBUISTBFontRenderer : public tb::TBFontRenderer | ||
{ | ||
public: | ||
TBUISTBFontRenderer(); | ||
~TBUISTBFontRenderer(); | ||
|
||
bool Load(const char* filename, int size); | ||
|
||
virtual tb::TBFontFace* Create(tb::TBFontManager* font_manager, const char* filename, const tb::TBFontDescription& font_desc); | ||
|
||
virtual tb::TBFontMetrics GetMetrics(); | ||
virtual bool RenderGlyph(tb::TBFontGlyphData* dst_bitmap, UCS4 cp); | ||
virtual void GetGlyphMetrics(tb::TBGlyphMetrics* metrics, UCS4 cp); | ||
virtual int GetAdvance(UCS4 cp1, UCS4 cp2); | ||
|
||
private: | ||
stbtt_fontinfo font; | ||
tb::TBTempBuffer ttf_buffer; | ||
unsigned char* render_data; | ||
float scale; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//------------------------------------------------------------------------------ | ||
// backend/tbuisystem.cc | ||
// (C) 2024 Individual contributors, see AUTHORS file | ||
//------------------------------------------------------------------------------ | ||
#include "render/stdneb.h" | ||
#include "core/sysfunc.h" | ||
#include "timing/calendartime.h" | ||
#include "tbuicontext.h" | ||
#include "tbuisysteminterface.h" | ||
|
||
namespace TBUI | ||
{ | ||
void | ||
TBUISystemInterface::DebugOut(const char* str) | ||
{ | ||
Core::SysFunc::DebugOut(str); | ||
} | ||
|
||
double | ||
TBUISystemInterface::GetTimeMS() | ||
{ | ||
n_assert(TBUI::TBUIContext::state.timer.isvalid()); | ||
return TBUI::TBUIContext::state.timer->GetTicks(); | ||
} | ||
|
||
void | ||
TBUISystemInterface::RescheduleTimer(double fire_time) | ||
{ | ||
} | ||
|
||
int | ||
TBUISystemInterface::GetLongClickDelayMS() | ||
{ | ||
return 500; | ||
} | ||
|
||
int | ||
TBUISystemInterface::GetPanThreshold() | ||
{ | ||
return 40; | ||
} | ||
|
||
int | ||
TBUISystemInterface::GetPixelsPerLine() | ||
{ | ||
return 40; | ||
} | ||
|
||
int | ||
TBUISystemInterface::GetDPI() | ||
{ | ||
return 96; | ||
} | ||
} |
Oops, something went wrong.