-
Notifications
You must be signed in to change notification settings - Fork 0
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
164 changed files
with
18,136 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
|
||
project( | ||
QmlMaterial | ||
VERSION 0.1 | ||
LANGUAGES CXX) | ||
|
||
option(QM_BUILD_STATIC "build static plugin" OFF) | ||
|
||
set(CMAKE_CXX_STANDARD 20) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_POSITION_INDEPENDENT_CODE ON) | ||
|
||
set(QM_BUILD SHARED) | ||
if(QM_BUILD_STATIC) | ||
set(QM_BUILD STATIC) | ||
endif() | ||
|
||
find_package(Qt6 REQUIRED COMPONENTS Core Quick QuickControls2 Gui) | ||
find_package(PkgConfig REQUIRED) | ||
|
||
set(LIBNAME qml_material) | ||
|
||
set(SOURCES | ||
include/qml_material/util.h | ||
include/qml_material/theme.h | ||
include/qml_material/color.h | ||
include/qml_material/corner.h | ||
include/qml_material/icon.h | ||
include/qml_material/input_block.h | ||
include/qml_material/item_holder.h | ||
include/qml_material/type.h | ||
include/qml_material/round_item.h | ||
include/qml_material/helper.h | ||
include/qml_material/type_scale.h | ||
include/qml_material/kirigami/wheelhandler.h | ||
src/kirigami/wheelhandler.cpp | ||
src/type.cpp | ||
src/color.cpp | ||
src/corner.cpp | ||
src/icon.cpp | ||
src/input_block.cpp | ||
src/item_holder.cpp | ||
src/image.cpp | ||
src/util.cpp | ||
src/state.cpp | ||
src/theme.cpp | ||
src/helper.cpp | ||
src/type_scale.cpp | ||
src/round_item.cpp) | ||
set(QML_FILES | ||
qml/Button.qml | ||
qml/Control.qml | ||
qml/ComboBox.qml | ||
qml/Dialog.qml | ||
qml/Divider.qml | ||
qml/Drawer.qml | ||
qml/DrawerItem.qml | ||
qml/Token.qml | ||
qml/IconLabel.qml | ||
qml/IconButton.qml | ||
qml/FAB.qml | ||
qml/Card.qml | ||
qml/CircularIndicator.qml | ||
qml/Menu.qml | ||
qml/MenuItem.qml | ||
qml/Image.qml | ||
qml/ListItem.qml | ||
qml/ListView.qml | ||
qml/Label.qml | ||
qml/FontMetrics.qml | ||
qml/Flickable.qml | ||
qml/GridView.qml | ||
qml/Icon.qml | ||
qml/Text.qml | ||
qml/Pane.qml | ||
qml/Page.qml | ||
qml/StackView.qml | ||
qml/SplitView.qml | ||
qml/Slider.qml | ||
qml/SearchBar.qml | ||
qml/ScrollBar.qml | ||
qml/Switch.qml | ||
qml/Rail.qml | ||
qml/TextInput.qml | ||
qml/TextField.qml | ||
qml/TabBar.qml | ||
qml/TabButton.qml | ||
qml/impl/BoxShadow.qml | ||
qml/impl/Shadow.qml | ||
qml/impl/ListBusyFooter.qml | ||
qml/impl/Ripple.qml | ||
qml/impl/RectangularGlow.qml | ||
qml/impl/CursorDelegate.qml | ||
qml/impl/State.qml | ||
qml/impl/SliderHandle.qml | ||
qml/impl/RoundedElevationEffect.qml | ||
qml/impl/ElevationEffect.qml | ||
qml/impl/TextFieldEmbed.qml | ||
qml/impl/RoundClip.qml) | ||
set(RESOURCES assets/MaterialIconsRound-Regular.otf | ||
assets/MaterialIconsOutlined-Regular.otf) | ||
|
||
set_source_files_properties(qml/Token.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE) | ||
include_directories(include) | ||
|
||
qt_add_qml_module( | ||
${LIBNAME} | ||
URI | ||
Qcm.Material | ||
${QM_BUILD} | ||
RESOURCE_PREFIX | ||
/ | ||
QML_FILES | ||
${QML_FILES} | ||
SOURCES | ||
${SOURCES} | ||
RESOURCES | ||
${RESOURCES} | ||
NO_PLUGIN_OPTIONAL) | ||
|
||
set(SHADER_GLSLS "assets/shader/sdf.glsl") | ||
set(SHADER_SOURCES | ||
"assets/shader/round.frag" | ||
"assets/shader/shadow.frag" | ||
"assets/shader/rect_glow.frag" | ||
) | ||
qt_add_shaders(${LIBNAME} "shader" PREFIX "/Qcm/Material" FILES | ||
${SHADER_SOURCES}) | ||
foreach(file ${SHADER_SOURCES}) | ||
set(output_file ".qsb/${file}.qsb") | ||
add_custom_command( | ||
OUTPUT ${output_file} | ||
DEPENDS ${SHADER_GLSLS} | ||
APPEND) | ||
endforeach() | ||
|
||
target_include_directories( | ||
${LIBNAME} | ||
PUBLIC include | ||
PRIVATE "include/${LIBNAME}" "include/${LIBNAME}/kirigami") | ||
|
||
add_subdirectory(third_party) | ||
|
||
target_link_libraries( | ||
${LIBNAME} | ||
PUBLIC Qt6::Core Qt6::Quick Qt6::QuickControls2 Qt6::GuiPrivate core | ||
PRIVATE material_color) |
Binary file not shown.
Binary file not shown.
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,28 @@ | ||
#version 440 | ||
|
||
layout(location = 0) in vec2 qt_TexCoord0; | ||
layout(location = 0) out vec4 fragColor; | ||
|
||
layout(std140, binding = 0) uniform buf { | ||
mat4 qt_Matrix; | ||
float qt_Opacity; | ||
float relativeSizeX; | ||
float relativeSizeY; | ||
float spread; | ||
vec4 color; | ||
} ubuf; | ||
|
||
float linearstep(float e0, float e1, float x) | ||
{ | ||
return clamp((x - e0) / (e1 - e0), 0.0, 1.0); | ||
} | ||
|
||
void main() | ||
{ | ||
float alpha = | ||
smoothstep(0.0, ubuf.relativeSizeX, 0.5 - abs(0.5 - qt_TexCoord0.x)) * | ||
smoothstep(0.0, ubuf.relativeSizeY, 0.5 - abs(0.5 - qt_TexCoord0.y)); | ||
|
||
float spreadMultiplier = linearstep(ubuf.spread, 1.0 - ubuf.spread, alpha); | ||
fragColor = ubuf.color * ubuf.qt_Opacity * spreadMultiplier * spreadMultiplier; | ||
} |
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,25 @@ | ||
#version 440 | ||
|
||
#extension GL_GOOGLE_include_directive : enable | ||
|
||
#include "sdf.glsl" | ||
|
||
layout(location = 0) in vec2 qt_TexCoord0; | ||
layout(location = 0) out vec4 fragColor; | ||
layout(std140, binding = 0) uniform buf { | ||
mat4 qt_Matrix; | ||
float qt_Opacity; | ||
// tl,tr,bl,br | ||
vec4 radius_; | ||
float size; | ||
float smoothing; | ||
}; | ||
layout(binding = 1) uniform sampler2D source; | ||
|
||
void main() { | ||
vec2 p = qt_TexCoord0 * 2.0 - vec2(1.0); | ||
|
||
float sdf = sdf_rounded_rectangle(p, vec2(1.0), 2.0 * radius_ / size); | ||
|
||
fragColor = sdf_render(sdf, vec4(0), texture(source, qt_TexCoord0), 1.0, smoothing, -1.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,42 @@ | ||
// Signed distance function | ||
|
||
// according to https://iquilezles.org/articles/distfunctions2d/ | ||
|
||
float sdf_circle(vec2 p, float r) { return length(p) - r; } | ||
|
||
float sdf_rectangle(in vec2 p, in vec2 rect) { | ||
vec2 d = abs(p) - rect; | ||
return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0); | ||
} | ||
|
||
// tr,br,bl,tl | ||
float sdf_rounded_rectangle(in vec2 p, in vec2 rect, in vec4 r) { | ||
r.xy = (p.x > 0.0) ? r.xy : r.zw; | ||
r.x = (p.y > 0.0) ? r.x : r.y; | ||
vec2 q = abs(p) - rect + r.x; | ||
return min(max(q.x, q.y), 0.0) + length(max(q, 0.0)) - r.x; | ||
} | ||
|
||
const float sdf_default_smoothing = 0.625; | ||
|
||
vec4 sdf_render(in float sdf, in vec4 sourceColor, in vec4 sdfColor, in float alpha, in float smoothing, in float offset) | ||
{ | ||
// bigger when zoom out | ||
float g = smoothing * fwidth(sdf); | ||
return mix(sourceColor, sdfColor, alpha * (1.0 - clamp((1.0 / g) * sdf - offset, 0.0, 1.0))); | ||
} | ||
|
||
vec4 sdf_render(in float sdf, in vec4 sourceColor, in vec4 sdfColor, in float alpha, in float smoothing) | ||
{ | ||
return sdf_render(sdf, sourceColor, sdfColor, alpha, smoothing, 0); | ||
} | ||
|
||
vec4 sdf_render(in float sdf, in vec4 sourceColor, in vec4 sdfColor, in float alpha) | ||
{ | ||
return sdf_render(sdf, sourceColor, sdfColor, alpha, sdf_default_smoothing); | ||
} | ||
|
||
vec4 sdf_render(in float sdf, in vec4 sourceColor, in vec4 sdfColor) | ||
{ | ||
return sdf_render(sdf, sourceColor, sdfColor, 1.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,70 @@ | ||
#version 440 | ||
|
||
layout(location = 0) in vec2 qt_TexCoord0; | ||
layout(location = 0) out vec4 fragColor; | ||
|
||
layout(std140, binding = 0) uniform buf { | ||
mat4 qt_Matrix; | ||
float qt_Opacity; | ||
|
||
vec2 lower; | ||
vec2 higher; | ||
float sigma; | ||
float corner; | ||
vec4 color; | ||
} ubuf; | ||
|
||
// A standard gaussian function, used for weighting samples | ||
float gaussian(float x, float sigma) { | ||
const float pi = 3.141592653589793; | ||
return exp(-(x * x) / (2.0 * sigma * sigma)) / (sqrt(2.0 * pi) * sigma); | ||
} | ||
|
||
// This approximates the error function, needed for the gaussian integral | ||
vec2 erf(vec2 x) { | ||
vec2 s = sign(x), a = abs(x); | ||
x = 1.0 + (0.278393 + (0.230389 + 0.078108 * (a * a)) * a) * a; | ||
x *= x; | ||
return s - s / (x * x); | ||
} | ||
|
||
// Return the blurred mask along the x dimension | ||
float roundedBoxShadowX(float x, float y, float sigma, float corner, vec2 halfSize) { | ||
float delta = min(halfSize.y - corner - abs(y), 0.0); | ||
float curved = halfSize.x - corner + sqrt(max(0.0, corner * corner - delta * delta)); | ||
vec2 integral = 0.5 + 0.5 * erf((x + vec2(-curved, curved)) * (sqrt(0.5) / sigma)); | ||
return integral.y - integral.x; | ||
} | ||
|
||
// Return the mask for the shadow of a box from lower to upper | ||
float roundedBoxShadow(vec2 lower, vec2 upper, vec2 point, float sigma, float corner) { | ||
// Center everything to make the math easier | ||
vec2 center = (lower + upper) * 0.5; | ||
vec2 halfSize = (upper - lower) * 0.5; | ||
point -= center; | ||
|
||
// The signal is only non-zero in a limited range, so don't waste samples | ||
float low = point.y - halfSize.y; | ||
float high = point.y + halfSize.y; | ||
float start = clamp(-3.0 * sigma, low, high); | ||
float end = clamp(3.0 * sigma, low, high); | ||
|
||
// Accumulate samples (we can get away with surprisingly few samples) | ||
float step = (end - start) / 4.0; | ||
float y = start + step * 0.5; | ||
float value = 0.0; | ||
for (int i = 0; i < 4; i++) { | ||
value += roundedBoxShadowX(point.x, point.y - y, sigma, corner, halfSize) * gaussian(y, sigma) * step; | ||
y += step; | ||
} | ||
|
||
return value; | ||
} | ||
|
||
void main() | ||
{ | ||
vec2 uv = qt_TexCoord0; | ||
|
||
float distShadow = roundedBoxShadow(ubuf.lower, ubuf.higher, uv, ubuf.sigma, ubuf.corner); | ||
fragColor = ubuf.color * ubuf.qt_Opacity * distShadow; | ||
} |
Oops, something went wrong.