-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
88 changed files
with
17,163 additions
and
1,142 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,144 @@ | ||
cmake_minimum_required(VERSION 3.11) | ||
project(zwidget) | ||
|
||
set(ZWIDGET_SOURCES | ||
src/core/canvas.cpp | ||
src/core/font.cpp | ||
src/core/image.cpp | ||
src/core/span_layout.cpp | ||
src/core/timer.cpp | ||
src/core/widget.cpp | ||
src/core/utf8reader.cpp | ||
src/core/schrift/schrift.cpp | ||
src/core/schrift/schrift.h | ||
src/core/picopng/picopng.cpp | ||
src/core/picopng/picopng.h | ||
src/core/nanosvg/nanosvg.cpp | ||
src/core/nanosvg/nanosvg.h | ||
src/core/nanosvg/nanosvgrast.h | ||
src/widgets/lineedit/lineedit.cpp | ||
src/widgets/mainwindow/mainwindow.cpp | ||
src/widgets/menubar/menubar.cpp | ||
src/widgets/scrollbar/scrollbar.cpp | ||
src/widgets/statusbar/statusbar.cpp | ||
src/widgets/textedit/textedit.cpp | ||
src/widgets/toolbar/toolbar.cpp | ||
src/widgets/toolbar/toolbarbutton.cpp | ||
src/widgets/imagebox/imagebox.cpp | ||
src/widgets/textlabel/textlabel.cpp | ||
src/widgets/pushbutton/pushbutton.cpp | ||
src/widgets/checkboxlabel/checkboxlabel.cpp | ||
src/widgets/listview/listview.cpp | ||
src/window/window.cpp | ||
) | ||
|
||
set(ZWIDGET_INCLUDES | ||
include/zwidget/core/canvas.h | ||
include/zwidget/core/colorf.h | ||
include/zwidget/core/font.h | ||
include/zwidget/core/image.h | ||
include/zwidget/core/rect.h | ||
include/zwidget/core/span_layout.h | ||
include/zwidget/core/timer.h | ||
include/zwidget/core/widget.h | ||
include/zwidget/core/utf8reader.h | ||
include/zwidget/core/resourcedata.h | ||
include/zwidget/widgets/lineedit/lineedit.h | ||
include/zwidget/widgets/mainwindow/mainwindow.h | ||
include/zwidget/widgets/menubar/menubar.h | ||
include/zwidget/widgets/scrollbar/scrollbar.h | ||
include/zwidget/widgets/statusbar/statusbar.h | ||
include/zwidget/widgets/textedit/textedit.h | ||
include/zwidget/widgets/toolbar/toolbar.h | ||
include/zwidget/widgets/toolbar/toolbarbutton.h | ||
include/zwidget/widgets/imagebox/imagebox.h | ||
include/zwidget/widgets/textlabel/textlabel.h | ||
include/zwidget/widgets/pushbutton/pushbutton.h | ||
include/zwidget/widgets/checkboxlabel/checkboxlabel.h | ||
include/zwidget/widgets/listview/listview.h | ||
include/zwidget/window/window.h | ||
) | ||
|
||
set(ZWIDGET_WIN32_SOURCES | ||
src/window/win32/win32window.cpp | ||
src/window/win32/win32window.h | ||
) | ||
|
||
set(ZWIDGET_COCOA_SOURCES | ||
) | ||
|
||
set(ZWIDGET_SDL2_SOURCES | ||
src/window/sdl2/sdl2displaywindow.cpp | ||
src/window/sdl2/sdl2displaywindow.h | ||
) | ||
|
||
source_group("src" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/src/.+") | ||
source_group("src\\core" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/src/core/.+") | ||
source_group("src\\core\\schrift" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/src/core/schrift/.+") | ||
source_group("src\\core\\picopng" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/src/core/picopng/.+") | ||
source_group("src\\core\\nanosvg" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/src/core/nanosvg/.+") | ||
source_group("src\\widgets" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/src/widgets/.+") | ||
source_group("src\\widgets\\lineedit" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/src/widgets/lineedit/.+") | ||
source_group("src\\widgets\\mainwindow" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/src/widgets/mainwindow/.+") | ||
source_group("src\\widgets\\menubar" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/src/widgets/menubar/.+") | ||
source_group("src\\widgets\\scrollbar" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/src/widgets/scrollbar/.+") | ||
source_group("src\\widgets\\statusbar" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/src/widgets/statusbar/.+") | ||
source_group("src\\widgets\\textedit" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/src/widgets/textedit/.+") | ||
source_group("src\\widgets\\toolbar" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/src/widgets/toolbar/.+") | ||
source_group("src\\widgets\\imagebox" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/src/widgets/imagebox/.+") | ||
source_group("src\\widgets\\textlabel" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/src/widgets/textlabel/.+") | ||
source_group("src\\widgets\\pushbutton" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/src/widgets/pushbutton/.+") | ||
source_group("src\\widgets\\checkboxlabel" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/src/widgets/checkboxlabel/.+") | ||
source_group("src\\widgets\\listview" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/src/widgets/listview/.+") | ||
source_group("src\\window" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/src/window/.+") | ||
source_group("include" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/include/zwidget/.+") | ||
source_group("include\\core" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/include/zwidget/core/.+") | ||
source_group("include\\widgets" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/include/zwidget/widgets/.+") | ||
source_group("include\\widgets\\lineedit" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/include/zwidget/widgets/lineedit/.+") | ||
source_group("include\\widgets\\mainwindow" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/include/zwidget/widgets/mainwindow/.+") | ||
source_group("include\\widgets\\menubar" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/include/zwidget/widgets/menubar/.+") | ||
source_group("include\\widgets\\scrollbar" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/include/zwidget/widgets/scrollbar/.+") | ||
source_group("include\\widgets\\statusbar" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/include/zwidget/widgets/statusbar/.+") | ||
source_group("include\\widgets\\textedit" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/include/zwidget/widgets/textedit/.+") | ||
source_group("include\\widgets\\toolbar" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/include/zwidget/widgets/toolbar/.+") | ||
source_group("include\\widgets\\imagebox" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/include/zwidget/widgets/imagebox/.+") | ||
source_group("include\\widgets\\textlabel" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/include/zwidget/widgets/textlabel/.+") | ||
source_group("include\\widgets\\pushbutton" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/include/zwidget/widgets/pushbutton/.+") | ||
source_group("include\\widgets\\checkboxlabel" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/include/zwidget/widgets/checkboxlabel/.+") | ||
source_group("include\\widgets\\listview" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/include/zwidget/widgets/listview/.+") | ||
source_group("include\\window" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/include/zwidget/window/.+") | ||
source_group("include\\window\\win32" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/include/zwidget/window/win32/.+") | ||
source_group("include\\window\\sdl2" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/include/zwidget/window/sdl2/.+") | ||
|
||
include_directories(include include/zwidget src) | ||
|
||
if(WIN32) | ||
set(ZWIDGET_SOURCES ${ZWIDGET_SOURCES} ${ZWIDGET_WIN32_SOURCES}) | ||
add_definitions(-DUNICODE -D_UNICODE) | ||
elseif(APPLE) | ||
set(ZWIDGET_SOURCES ${ZWIDGET_SOURCES} ${ZWIDGET_COCOA_SOURCES}) | ||
set(ZWIDGET_LIBS ${CMAKE_DL_LIBS} -ldl) | ||
add_definitions(-DUNIX -D_UNIX) | ||
add_link_options(-pthread) | ||
else() | ||
set(ZWIDGET_SOURCES ${ZWIDGET_SOURCES} ${ZWIDGET_SDL2_SOURCES}) | ||
set(ZWIDGET_LIBS ${CMAKE_DL_LIBS} -ldl) | ||
add_definitions(-DUNIX -D_UNIX) | ||
add_link_options(-pthread) | ||
endif() | ||
|
||
if(MSVC) | ||
# Use all cores for compilation | ||
set(CMAKE_CXX_FLAGS "/MP ${CMAKE_CXX_FLAGS}") | ||
|
||
# Ignore warnings in third party code | ||
#set_source_files_properties(${ZWIDGET_SOURCES} PROPERTIES COMPILE_FLAGS "/wd4244 /wd4267 /wd4005 /wd4018 -D_CRT_SECURE_NO_WARNINGS") | ||
endif() | ||
|
||
add_library(zwidget STATIC ${ZWIDGET_SOURCES} ${ZWIDGET_INCLUDES}) | ||
target_link_libraries(zwidget ${ZWIDGET_LIBS}) | ||
set_target_properties(zwidget PROPERTIES CXX_STANDARD 17) | ||
|
||
if(MSVC) | ||
set_property(TARGET zwidget PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") | ||
endif() |
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,21 @@ | ||
# License information | ||
|
||
## License for ZWidget itself | ||
|
||
// Copyright (c) 2023 Magnus Norddahl | ||
// | ||
// This software is provided 'as-is', without any express or implied | ||
// warranty. In no event will the authors be held liable for any damages | ||
// arising from the use of this software. | ||
// | ||
// Permission is granted to anyone to use this software for any purpose, | ||
// including commercial applications, and to alter it and redistribute it | ||
// freely, subject to the following restrictions: | ||
// | ||
// 1. The origin of this software must not be misrepresented; you must not | ||
// claim that you wrote the original software. If you use this software | ||
// in a product, an acknowledgment in the product documentation would be | ||
// appreciated but is not required. | ||
// 2. Altered source versions must be plainly marked as such, and must not be | ||
// misrepresented as being the original software. | ||
// 3. This notice may not be removed or altered from any source distribution. |
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,2 @@ | ||
# ZWidget | ||
A framework for building user interface applications |
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,63 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
class Font; | ||
class Image; | ||
class Point; | ||
class Rect; | ||
class Colorf; | ||
class DisplayWindow; | ||
struct VerticalTextPosition; | ||
|
||
class FontMetrics | ||
{ | ||
public: | ||
double ascent = 0.0; | ||
double descent = 0.0; | ||
double external_leading = 0.0; | ||
double height = 0.0; | ||
}; | ||
|
||
class Canvas | ||
{ | ||
public: | ||
static std::unique_ptr<Canvas> create(DisplayWindow* window); | ||
|
||
virtual ~Canvas() = default; | ||
|
||
virtual void begin(const Colorf& color) = 0; | ||
virtual void end() = 0; | ||
|
||
virtual void begin3d() = 0; | ||
virtual void end3d() = 0; | ||
|
||
virtual Point getOrigin() = 0; | ||
virtual void setOrigin(const Point& origin) = 0; | ||
|
||
virtual void pushClip(const Rect& box) = 0; | ||
virtual void popClip() = 0; | ||
|
||
virtual void fillRect(const Rect& box, const Colorf& color) = 0; | ||
virtual void line(const Point& p0, const Point& p1, const Colorf& color) = 0; | ||
|
||
virtual void drawText(const Point& pos, const Colorf& color, const std::string& text) = 0; | ||
virtual Rect measureText(const std::string& text) = 0; | ||
virtual VerticalTextPosition verticalTextAlign() = 0; | ||
|
||
virtual void drawText(const std::shared_ptr<Font>& font, const Point& pos, const std::string& text, const Colorf& color) = 0; | ||
virtual void drawTextEllipsis(const std::shared_ptr<Font>& font, const Point& pos, const Rect& clipBox, const std::string& text, const Colorf& color) = 0; | ||
virtual Rect measureText(const std::shared_ptr<Font>& font, const std::string& text) = 0; | ||
virtual FontMetrics getFontMetrics(const std::shared_ptr<Font>& font) = 0; | ||
virtual int getCharacterIndex(const std::shared_ptr<Font>& font, const std::string& text, const Point& hitPoint) = 0; | ||
|
||
virtual void drawImage(const std::shared_ptr<Image>& image, const Point& pos) = 0; | ||
}; | ||
|
||
struct VerticalTextPosition | ||
{ | ||
double top = 0.0; | ||
double baseline = 0.0; | ||
double bottom = 0.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,36 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <cmath> | ||
|
||
class Colorf | ||
{ | ||
public: | ||
Colorf() = default; | ||
Colorf(float r, float g, float b, float a = 1.0f) : r(r), g(g), b(b), a(a) { } | ||
|
||
static Colorf transparent() { return { 0.0f, 0.0f, 0.0f, 0.0f }; } | ||
|
||
static Colorf fromRgba8(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) | ||
{ | ||
float s = 1.0f / 255.0f; | ||
return { r * s, g * s, b * s, a * s }; | ||
} | ||
|
||
uint32_t toBgra8() const | ||
{ | ||
uint32_t cr = (int)(std::max(std::min(r * 255.0f, 255.0f), 0.0f)); | ||
uint32_t cg = (int)(std::max(std::min(g * 255.0f, 255.0f), 0.0f)); | ||
uint32_t cb = (int)(std::max(std::min(b * 255.0f, 255.0f), 0.0f)); | ||
uint32_t ca = (int)(std::max(std::min(a * 255.0f, 255.0f), 0.0f)); | ||
return (ca << 24) | (cr << 16) | (cg << 8) | cb; | ||
} | ||
|
||
bool operator==(const Colorf& v) const { return r == v.r && g == v.g && b == v.b && a == v.a; } | ||
bool operator!=(const Colorf& v) const { return r != v.r || g != v.g || b != v.b || a != v.a; } | ||
|
||
float r = 0.0f; | ||
float g = 0.0f; | ||
float b = 0.0f; | ||
float a = 1.0f; | ||
}; |
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,15 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
class Font | ||
{ | ||
public: | ||
virtual ~Font() = default; | ||
|
||
virtual const std::string& GetName() const = 0; | ||
virtual double GetHeight() const = 0; | ||
|
||
static std::shared_ptr<Font> Create(const std::string& name, double height); | ||
}; |
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,24 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
enum class ImageFormat | ||
{ | ||
R8G8B8A8, | ||
B8G8R8A8 | ||
}; | ||
|
||
class Image | ||
{ | ||
public: | ||
virtual ~Image() = default; | ||
|
||
virtual int GetWidth() const = 0; | ||
virtual int GetHeight() const = 0; | ||
virtual ImageFormat GetFormat() const = 0; | ||
virtual void* GetData() const = 0; | ||
|
||
static std::shared_ptr<Image> Create(int width, int height, ImageFormat format, const void* data); | ||
static std::shared_ptr<Image> LoadResource(const std::string& resourcename, double dpiscale = 1.0); | ||
}; |
Oops, something went wrong.