Skip to content

Commit

Permalink
20231007
Browse files Browse the repository at this point in the history
PainterEngine 2
  • Loading branch information
matrixcascade committed Oct 7, 2023
1 parent b3a08a4 commit 2d95397
Show file tree
Hide file tree
Showing 308 changed files with 14,764 additions and 12,371 deletions.
25 changes: 25 additions & 0 deletions PainterEngine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef PAINTERENGINE
#define PAINTERENGINE
#define main px_main

#ifdef __cplusplus
extern "C" {
#endif
#include "runtime/PainterEngine_Application.h"
extern PX_Object* root;
extern px_memorypool* mp,*mp_static;
extern px_int screen_width;
extern px_int screen_height;
extern px_int surface_width;
extern px_int surface_height;
extern px_surface* render_surface;
extern PX_ResourceLibrary* resource_library;
extern PX_SoundPlay* soundplay;
int px_main();
#ifdef __cplusplus
}
#endif



#endif
101 changes: 73 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,88 @@
![avatar](supports/logo/logo_web.png)
<p align="center"><a href="https://painterengine.com" target="_blank" rel="noopener noreferrer"><img src="images/title.png" alt="PainterEngine Title"></a></p>

PainterEngine 是一个由 C 语言编写的**跨平台图形应用框架**,可运行于 Windows、Linux、Android iOS 支持 WebAssembly 的 Web 端及嵌入式 MCU 上。
## 30秒快速入门PainterEngine

- PainterEngine 由 C99 标准及部分拓展编写,不依赖任何 C 标准库及三方库。
- PainterEngine 是平台、编译环境、运行时无关的。
- 包含一套完整的内存管理及常用数据结构算法的实现。
- 包含一套完整的PNG,JPG,BMP,DEFLATE编码/解码器实现。
- 包含一套完整软 2D/3D 渲染器实现。
- 包含一套完整编译型脚本引擎实现(编译器、虚拟机、调试器)。
- 包含一套完整游戏世界框架(对象及资源管理器,事件调度器,碰撞优化及物理计算模板)。
- 包含一套完整的 Live2D 动画系统实现(骨骼及物理模拟、动作追踪、独立的图元光栅化实现,配套建模编辑器)
- 常用的反走样几何绘制及光栅化算法。
- 图像信号及音频信号处理算法(常用滤波器、声码编码器、ZCR、MFCC 等特征采集算法)。
- 基础的 BP 神经网络框架实现。
- UI框架、粒子系统、调音器、混音器、逐帧动画、网络同步协议、MODBUS,MQTT 等 IoT 协议栈、json/obj/wav Parser..的完整实现。
- 更多内容及使用说明,请参阅教程及《[PainterEngine API Manual](https://www.painterengine.com/manual.html)
## 30-Second Quick Start Guide to PainterEngine

将PainterEngine引入到您的项目中,仅仅需要"#include "PainterEngine.h""

更多内容请访问 [PainterEngine.com](https://www.painterengine.com)
To incorporate PainterEngine into your project, all you need is
```c
#include "PainterEngine.h"
```
使用PainterEngine_Initialize,快速创建一个图形化的交互式界面

社区交流请访问 [faq.PainterEngine.com](https://faq.painterengine.com)
Utilize 'PainterEngine_Initialize' to swiftly create a graphical interactive interface.
```c
#include "PainterEngine.h"
int main()
{
PainterEngine_Initialize(800, 600);
return 1;
}
```

==========================================================================
使用PainterEngine make快速将您的项目编译到Windows Linux WebAssembly Android等任意平台,一键编译部署,源码无需修改,零成本移植

PainterEngine is a complete open-source, cross-platform graphic application framework written in C language that can be ported to Windows, Linux, Android, iOS, WebAssembly-enabled web, and embedded MCU.
- PainterEngine is written in C99 standard and some extensions, without relying on any C standard library or third-party library.
Use "PainterEngine make" to quickly compile and deploy your project to various platforms such as Windows, Linux, WebAssembly, Android, and more. One-click compilation and deployment, with no need to modify the source code, enabling seamless portability at zero cost

- It is platform, compilation environment, and runtime independent and includes a complete set of memory management and commonly used data structure algorithm implementations.
<p align="center"><a href="https://www.painterengine.com/download/PainterEngine_make.zip" target="_blank" rel="noopener noreferrer"><img src="images/onekey.png" alt="PainterEngine make"></a></p>

- It also includes a complete set of PNG, JPG, BMP, DEFLATE codec implementations, as well as a complete software 2D/3D renderer implementation.
## 不仅是图形库,更是应用程序框架

- In addition, it includes a complete compiled script engine implementation (compiler, virtual machine, and debugger), a complete game world framework (object and resource manager, event scheduler, collision optimization, and physics computing template).
## Not just a graphics library but also an application framework.

- a complete Live2D animation system implementation (skeletal and physical simulation, action tracking, independent element rasterization implementation, and modeling editor).
| functions | support | Description |
| --------------------- | ------------------------------------------------------------ | ------------------------------------------------------------------------ |
| 内存池 | alloc/free | 平台无关的内存池实现 |
| 数据结构 | vector/list/map/stack/fifo/circular-buffer... | 平台无关的数据结构算法实现 |
| 图片支持 | PNG/JPG/GIF/BMP | 支持PNG/JPG/GIF/BMP解码及PNG编码. |
| 几何绘制 | Line/Triangle/Rectangle/Circle/Ring/Sector/Rounded..... | 常用几何光栅化实现 |
| 写入安全 | 2D/3D | 2D 3D渲染器实现及一个高质量制图引擎 |
| 动画 | 2dx/live2D | 2D 动画和一个类Live2D 骨骼动画系统 |
| 脚本引擎 | Compiler/VM/Debugger | A一个完整的脚本引擎,包含编译器虚拟机调试器 |
| UI框架 | button/radio/image/edit/label/list.... | UI框架实现 |
| 协议 | MQTT/MODBUS/Game-network-synchronization | 常用的通讯协议 |
| 游戏引擎 | | 集成一个游戏世界框架 |

- a complete designer system implementation (game layout designer, UI designer), and a complete sound code encoder with acoustic modeling implementation for piano (hammer, strings, soundboard) and guitar (karplus-strong).

- as well as commonly used anti-aliasing, geometric drawing, and rasterization algorithms for image and audio signal processing.
///////////////////////////////////////////////////////////////////////////////

- Basic BP neural network framework implementation. Complete implementation of UI framework, particle system, tuner, mixer, frame-by-frame animation, network synchronization protocol, MODBUS, MQTT and other IoT protocol stack...

----->For more information and instructions on how to use, please refer to the tutorial and "PainterEngine API Manual".

| functions | support | Description |
| --------------------- | ------------------------------------------------------------ | ------------------------------------------------------------------------ |
| memorypool | alloc/free | Platform-agnostic memory management implementation. |
| Data structures | vector/list/map/stack/fifo/circular-buffer... | Platform-agnostic common data structures and algorithms. |
| image codec | PNG/JPG/GIF/BMP | Supports decoding of PNG/JPG/GIF/BMP images and encoding of PNG images. |
| Geometric | Line/Triangle/Rectangle/Circle/Ring/Sector/Rounded..... | Geometric rasterization |
| Renderer | 2d/3d | Implementation of a 2D/3D software renderer. A painting engine. |
| Animation | 2dx/live2D | 2D frame-by-frame animation and a Live2D-style animation system. |
| PainterScript | Compiler/VM/Debugger | A complete scripting engine, including a compiler, virtual machine, and debugger. |
| UI | button/radio/image/edit/label/list.... | Implementation of common UI controls. |
| protocals | MQTT/MODBUS/Game-network-synchronization | Common communication protocols. |
| Game framework. | | PainterEngine Game Framework |

Many more to explore....

## 组件化开发,支持设计器模式,简单的不能再简单

## Component-based development with support for a designer mode, making it as simple as it gets

<p align="center"><img src="images/designer.png" alt="PainterEngine designer"></p>

## 海量组件,创意无界

## An abundance of components to unleash your creativity without limitations.

<p align="center"><img width="600" src="images/market.png" alt="PainterEngine market"></p>

<p align="center"><img width="600" src="images/paint.png" alt="PainterEngine market"></p>

<p align="center"><img width="600" src="images/piano.png" alt="PainterEngine market"></p>

<p align="center"><img width="600" src="images/l2d.png" alt="PainterEngine market"></p>

### 现在,访问PainterEngine.com,参与建设

### Now, join the PainterEngine.com contribute to its development.
4 changes: 0 additions & 4 deletions architecture/PainterEngine.h

This file was deleted.

153 changes: 108 additions & 45 deletions core/PX_BaseGeo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1433,9 +1433,90 @@ px_void PX_GeoDrawSolidCircleFast(px_surface* psurface, px_int x, px_int y, px_i
}

}
px_void PX_GeoDrawPenCircleDecay(px_surface* psurface, px_float x, px_float y, px_float Radius, px_color color, px_float Decay)
{
px_int left, top, right, bottom, i, j;
px_float d;
px_color clr;
if (color._argb.a == 0 || Radius <= 0)
{
return;
}
color._argb.a = (px_uchar)(color._argb.a/Decay);
left = (px_int)(x - Radius);
top = (px_int)(y - Radius);
right = (px_int)(x + Radius);
bottom = (px_int)(y + Radius);



if (left < psurface->limit_left)
{
left = psurface->limit_left;
}
else if (left > psurface->limit_right)
{
return;
}

if (top < psurface->limit_top)
{
top = psurface->limit_top;
}
else if (top > psurface->limit_bottom)
{
return;
}

if (right > psurface->limit_right)
{
right = psurface->limit_right;
}
else if (right < psurface->limit_left)
{
return;
}

if (bottom > psurface->limit_bottom)
{
bottom = psurface->limit_bottom;
}
else if (bottom < psurface->limit_top)
{
return;
}


for (i = top; i <= bottom; i++)
{
for (j = left; j <= right; j++)
{
d = PX_sqrt((px_float)((i - y) * (i - y) + (j - x) * (j - x)));
if (d < Radius)
{
if ((px_float)Radius - d < 2)
{
clr = color;
clr._argb.a = (px_uchar)(clr._argb.a * ((px_float)Radius - d) / 2);
PX_SurfaceDrawPixelWithoutLimit(psurface, j, i, clr);
}
else
{
PX_SurfaceDrawPixelWithoutLimit(psurface, j, i, color);
}

}

}
}
}

px_void PX_GeoDrawPenCircle(px_surface *psurface, px_float x,px_float y,px_float Radius,px_color color)
{
PX_GeoDrawPenCircleDecay(psurface, x, y, Radius, color, 5);
}

px_void PX_GeoDrawPenRing(px_surface* psurface, px_float x, px_float y, px_float Radius,px_float linewidth_inside, px_color color)
{
px_int left, top, right, bottom, i, j;
px_float d;
Expand All @@ -1444,7 +1525,7 @@ px_void PX_GeoDrawPenCircle(px_surface *psurface, px_float x,px_float y,px_float
{
return;
}
color._argb.a /= 5;

left = (px_int)(x - Radius);
top = (px_int)(y - Radius);
right = (px_int)(x + Radius);
Expand Down Expand Up @@ -1494,8 +1575,9 @@ px_void PX_GeoDrawPenCircle(px_surface *psurface, px_float x,px_float y,px_float
for (j = left; j <= right; j++)
{
d = PX_sqrt((px_float)((i - y) * (i - y) + (j - x) * (j - x)));
if (d < Radius)
if (d < Radius&&d>Radius - linewidth_inside)
{

if ((px_float)Radius - d < 2)
{
clr = color;
Expand All @@ -1504,9 +1586,18 @@ px_void PX_GeoDrawPenCircle(px_surface *psurface, px_float x,px_float y,px_float
}
else
{
PX_SurfaceDrawPixelWithoutLimit(psurface, j, i, color);
if (d - Radius + linewidth_inside<2)
{
clr = color;
clr._argb.a = (px_uchar)(clr._argb.a * (d - Radius + linewidth_inside) / 2);
PX_SurfaceDrawPixelWithoutLimit(psurface, j, i, clr);
}
else
{
PX_SurfaceDrawPixelWithoutLimit(psurface, j, i, color);
}
}

}

}
Expand Down Expand Up @@ -2678,9 +2769,7 @@ px_void PX_GeoDrawSolidRoundRect(px_surface *psurface, px_int left, px_int top,
}
}

x=(px_int)roundRaduis-(px_int)(PX_sqrt(roundRaduis*roundRaduis-(roundRaduis-y-1)*(roundRaduis-y-1)))-1;
if(x<0) x=0;
for (;x<(px_int)roundRaduis;x++)
for (x = 0;x<(px_int)roundRaduis;x++)
{
if (Width&1)
{
Expand All @@ -2703,12 +2792,12 @@ px_void PX_GeoDrawSolidRoundRect(px_surface *psurface, px_int left, px_int top,
}

dis=PX_sqrt((x-r_x)*(x-r_x)+(y-r_y)*(y-r_y));
if (dis<roundRaduis+0.5f)
if (dis<roundRaduis+1.414f)
{
drawColor=color;

if (dis>roundRaduis)
drawColor._argb.a=(px_uchar)(color._argb.a*(dis-roundRaduis+0.5f));
if (dis > roundRaduis)
drawColor._argb.a = (px_uchar)(color._argb.a * (1 - (dis - roundRaduis) / 1.414f));

PX_SurfaceDrawPixel(psurface,left+x,top+y,drawColor);

Expand Down Expand Up @@ -2789,55 +2878,29 @@ px_void PX_GeoDrawRoundRect(px_surface *psurface, px_int left, px_int top, px_in
r_x=roundRaduis;
for (y=0;y<(px_int)roundRaduis;y++)
{
if (Height&1)
if (y > Height / 2)
{
if (y>Height/2)
{
break;
}
}
else
{
if (y>Height/2-1)
{
break;
}
break;
}

x=(px_int)roundRaduis-(px_int)(PX_sqrt(roundRaduis*roundRaduis-(roundRaduis-y-1)*(roundRaduis-y-1)))-1;
if(x<0)x=0;
for (;x<(px_int)roundRaduis;x++)
for (x = 0;x<(px_int)roundRaduis;x++)
{
if (Width&1)
{
if (x>Width/2)
{
break;
}
}
else
{
if (x>Width/2-1)
{
break;
}
}


if (x>Width/2)
{
break;
}

dis=PX_sqrt((x-r_x)*(x-r_x)+(y-r_y)*(y-r_y));
if (dis<roundRaduis+0.5f&&dis>roundRaduis-linewidth-0.5f)
if (dis<roundRaduis+1.414f&&dis>roundRaduis-linewidth)
{
drawColor=color;

if (dis>roundRaduis)
drawColor._argb.a=(px_uchar)(color._argb.a*(dis-roundRaduis+0.5f));

if (dis<roundRaduis-linewidth+0.5f)
drawColor._argb.a=(px_uchar)(color._argb.a*(1.0f-(roundRaduis-linewidth+0.5f-dis)));
drawColor._argb.a=(px_uchar)(color._argb.a*(1 - (dis - roundRaduis)/1.414f));
else if (dis>roundRaduis-linewidth-0.5f&&dis<roundRaduis - linewidth+1.414f-0.5f)
drawColor._argb.a=(px_uchar)(color._argb.a*(dis-roundRaduis+linewidth+0.5f)/1.414f);

PX_SurfaceDrawPixel(psurface,left+x,top+y,drawColor);

Expand Down
2 changes: 2 additions & 0 deletions core/PX_BaseGeo.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ px_void PX_GeoDrawRect(px_surface *psurface, px_int left, px_int top, px_int rig
px_void PX_GeoDrawSolidCircle(px_surface *psurface, px_int x,px_int y,px_int Radius,px_color color );
px_void PX_GeoDrawSolidCircleFast(px_surface* psurface, px_int x, px_int y, px_int Radius, px_color color);
px_void PX_GeoDrawPenCircle(px_surface *psurface, px_float x,px_float y,px_float Radius,px_color color );
px_void PX_GeoDrawPenCircleDecay(px_surface* psurface, px_float x, px_float y, px_float Radius, px_color color, px_float Decay);
px_void PX_GeoDrawPenRing(px_surface* psurface, px_float x, px_float y, px_float Radius, px_float linewidth_inside, px_color color);
px_void PX_GeoDrawPenCircleEraser(px_surface* psurface, px_float x, px_float y, px_float Radius, px_bool white_background);
px_void PX_GeoDrawSpray(px_surface* psurface, px_float x, px_float y, px_float Radius, px_color color);
px_void PX_GeoDrawBall(px_surface* psurface, px_float x, px_float y, px_float Radius, px_color color);
Expand Down
1 change: 1 addition & 0 deletions core/PX_Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@
#include "PX_Wavelet.h"
#include "PX_Png.h"
#include "PX_Keyboard.h"
#include "px_gif.h"
#endif
Loading

0 comments on commit 2d95397

Please sign in to comment.