2019-11-23 20:27:39 +08:00
|
|
|
/* Copyright (c) 2012 Scott Lembcke and Howling Moon Software
|
|
|
|
* Copyright (c) 2012 cocos2d-x.org
|
|
|
|
* Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
* Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2023-12-08 00:13:39 +08:00
|
|
|
* Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
|
2019-11-23 20:27:39 +08:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Code copied & pasted from SpacePatrol game https://github.com/slembcke/SpacePatrol
|
|
|
|
*
|
|
|
|
* Renamed and added some changes for cocos2d
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2024-09-06 21:31:18 +08:00
|
|
|
#ifndef __DRAW_NODE_H__
|
|
|
|
#define __DRAW_NODE_H__
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2023-06-11 13:08:08 +08:00
|
|
|
#include "2d/Node.h"
|
2024-09-08 00:17:47 +08:00
|
|
|
#include "base/axstd.h"
|
2023-06-11 13:08:08 +08:00
|
|
|
#include "base/Types.h"
|
|
|
|
#include "renderer/CustomCommand.h"
|
|
|
|
#include "math/Math.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2024-08-26 00:25:33 +08:00
|
|
|
namespace ax
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
static const int DEFAULT_LINE_WIDTH = 2;
|
|
|
|
|
|
|
|
class PointArray;
|
2024-09-06 21:31:18 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup _2d
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @class DrawNode
|
|
|
|
* @brief Node that draws dots, segments and polygons.
|
|
|
|
* Faster than the "drawing primitives" since they draws everything in one single batch.
|
|
|
|
* @since v2.1
|
|
|
|
*/
|
2022-07-16 10:43:05 +08:00
|
|
|
class AX_DLL DrawNode : public Node
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
public:
|
2023-12-05 17:20:31 +08:00
|
|
|
/** Different draw modus types.
|
|
|
|
*
|
|
|
|
*.
|
|
|
|
*/
|
|
|
|
enum DrawMode
|
|
|
|
{
|
|
|
|
Fill,
|
|
|
|
Outline,
|
|
|
|
Line,
|
|
|
|
Semi,
|
|
|
|
};
|
|
|
|
|
2024-09-06 21:31:18 +08:00
|
|
|
enum PointType
|
|
|
|
{
|
|
|
|
Circle,
|
|
|
|
Rect,
|
|
|
|
};
|
|
|
|
|
|
|
|
// See also example on https://www.angusj.com/clipper2/Docs/Units/Clipper/Types/EndType.htm
|
|
|
|
enum EndType
|
|
|
|
{
|
|
|
|
Square,
|
|
|
|
Round,
|
|
|
|
Butt,
|
|
|
|
};
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/** creates and initialize a DrawNode node.
|
|
|
|
*
|
|
|
|
* @return Return an autorelease object.
|
|
|
|
*/
|
2024-09-23 22:13:12 +08:00
|
|
|
static DrawNode* create(void);
|
2024-09-06 21:31:18 +08:00
|
|
|
// DrawNode();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/** Draw a point.
|
|
|
|
*
|
|
|
|
* @param point A Vec2 used to point.
|
|
|
|
* @param pointSize The point size.
|
|
|
|
* @param color The point color.
|
|
|
|
* @js NA
|
|
|
|
*/
|
2024-09-06 21:31:18 +08:00
|
|
|
void drawPoint(const Vec2& point,
|
|
|
|
const float pointSize,
|
|
|
|
const Color4B& color,
|
|
|
|
DrawNode::PointType pointType = DrawNode::PointType::Rect);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/** Draw a group point.
|
|
|
|
*
|
|
|
|
* @param position A Vec2 pointer.
|
|
|
|
* @param numberOfPoints The number of points.
|
|
|
|
* @param color The point color.
|
|
|
|
* @js NA
|
|
|
|
*/
|
2024-09-06 21:31:18 +08:00
|
|
|
void drawPoints(const Vec2* position,
|
|
|
|
unsigned int numberOfPoints,
|
|
|
|
const Color4B& color,
|
|
|
|
DrawNode::PointType pointType = DrawNode::PointType::Rect);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/** Draw a group point.
|
|
|
|
*
|
|
|
|
* @param position A Vec2 pointer.
|
|
|
|
* @param numberOfPoints The number of points.
|
|
|
|
* @param pointSize The point size.
|
|
|
|
* @param color The point color.
|
|
|
|
* @js NA
|
|
|
|
*/
|
2024-09-06 21:31:18 +08:00
|
|
|
void drawPoints(const Vec2* position,
|
|
|
|
unsigned int numberOfPoints,
|
|
|
|
const float pointSize,
|
|
|
|
const Color4B& color,
|
|
|
|
DrawNode::PointType pointType = DrawNode::PointType::Rect);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
/** Draw an line from origin to destination with color.
|
|
|
|
*
|
2019-11-23 20:27:39 +08:00
|
|
|
* @param origin The line origin.
|
|
|
|
* @param destination The line destination.
|
|
|
|
* @param color The line color.
|
|
|
|
* @js NA
|
|
|
|
*/
|
2024-09-06 21:31:18 +08:00
|
|
|
void drawLine(const Vec2& origin,
|
|
|
|
const Vec2& destination,
|
|
|
|
const Color4B& color,
|
|
|
|
float thickness = 1.0f,
|
|
|
|
DrawNode::EndType etStart = DrawNode::EndType::Round,
|
|
|
|
DrawNode::EndType etEnd = DrawNode::EndType::Round);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/** Draws a rectangle given the origin and destination point measured in points.
|
|
|
|
* The origin and the destination can not have the same x and y coordinate.
|
|
|
|
*
|
|
|
|
* @param origin The rectangle origin.
|
|
|
|
* @param destination The rectangle destination.
|
|
|
|
* @param color The rectangle color.
|
|
|
|
*/
|
2024-09-06 21:31:18 +08:00
|
|
|
void drawRect(const Vec2& origin, const Vec2& destination, const Color4B& color, float thickness = 1.0f);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/** Draws a polygon given a pointer to point coordinates and the number of vertices measured in points.
|
|
|
|
* The polygon can be closed or open.
|
|
|
|
*
|
|
|
|
* @param poli A pointer to point coordinates.
|
|
|
|
* @param numberOfPoints The number of vertices measured in points.
|
|
|
|
* @param closePolygon The polygon can be closed or open.
|
|
|
|
* @param color The polygon color.
|
|
|
|
*/
|
2024-09-06 21:31:18 +08:00
|
|
|
void drawPoly(const Vec2* poli,
|
|
|
|
unsigned int numberOfPoints,
|
|
|
|
bool closedPolygon,
|
|
|
|
const Color4B& color,
|
|
|
|
float thickness = 1.0f);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/** Draws a circle given the center, radius and number of segments.
|
|
|
|
*
|
|
|
|
* @param center The circle center point.
|
|
|
|
* @param radius The circle rotate of radius.
|
|
|
|
* @param angle The circle angle.
|
|
|
|
* @param segments The number of segments.
|
|
|
|
* @param drawLineToCenter Whether or not draw the line from the origin to center.
|
|
|
|
* @param scaleX The scale value in x.
|
|
|
|
* @param scaleY The scale value in y.
|
|
|
|
* @param color Set the circle color.
|
2024-09-06 21:31:18 +08:00
|
|
|
* @param thickness (default 1.0f)
|
2019-11-23 20:27:39 +08:00
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
void drawCircle(const Vec2& center,
|
|
|
|
float radius,
|
|
|
|
float angle,
|
|
|
|
unsigned int segments,
|
|
|
|
bool drawLineToCenter,
|
|
|
|
float scaleX,
|
|
|
|
float scaleY,
|
2023-01-06 23:25:31 +08:00
|
|
|
const Color4B& color,
|
2024-09-06 21:31:18 +08:00
|
|
|
float thickness = 1.0f);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/** Draws a circle given the center, radius and number of segments.
|
|
|
|
*
|
|
|
|
* @param center The circle center point.
|
|
|
|
* @param radius The circle rotate of radius.
|
|
|
|
* @param angle The circle angle.
|
|
|
|
* @param segments The number of segments.
|
|
|
|
* @param drawLineToCenter Whether or not draw the line from the origin to center.
|
|
|
|
* @param color Set the circle color.
|
2024-09-06 21:31:18 +08:00
|
|
|
* @param thickness (default 1.0f)
|
2019-11-23 20:27:39 +08:00
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
void drawCircle(const Vec2& center,
|
|
|
|
float radius,
|
|
|
|
float angle,
|
|
|
|
unsigned int segments,
|
|
|
|
bool drawLineToCenter,
|
2023-01-06 23:25:31 +08:00
|
|
|
const Color4B& color,
|
2024-09-06 21:31:18 +08:00
|
|
|
float thickness = 1.0f);
|
|
|
|
|
|
|
|
/** Draws a star given the center, radiusI, radiusO and number of segments.
|
|
|
|
*
|
|
|
|
* @param center The circle center point.
|
|
|
|
* @param radiusI The inner radius.
|
|
|
|
* @param radiusO The outer radius.
|
|
|
|
* @param segments The number of segments.
|
|
|
|
* @param color Set the star color.
|
|
|
|
* @param thickness (default = 1.0f)
|
|
|
|
*/
|
|
|
|
void drawStar(const Vec2& center,
|
|
|
|
float radiusI,
|
|
|
|
float radiusO,
|
|
|
|
unsigned int segments,
|
|
|
|
const Color4B& color,
|
|
|
|
float thickness = 1.0f);
|
|
|
|
|
|
|
|
/** Draws a solid star given the center, radiusI, radiusO and number of segments.
|
|
|
|
*
|
|
|
|
* @param center The circle center point.
|
|
|
|
* @param radiusI The inner radius.
|
|
|
|
* @param radiusO The outer radius.
|
|
|
|
* @param segments The number of segments.
|
|
|
|
* @param color Set the star color.
|
|
|
|
* @param thickness (default = 1.0f)
|
|
|
|
*/
|
|
|
|
void drawSolidStar(const Vec2& center,
|
|
|
|
float radiusI,
|
|
|
|
float radiusO,
|
|
|
|
unsigned int segments,
|
|
|
|
const Color4B& color,
|
|
|
|
const Color4B& filledColor,
|
|
|
|
float thickness = 1.0f);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/** Draws a quad bezier path.
|
|
|
|
*
|
|
|
|
* @param origin The origin of the bezier path.
|
|
|
|
* @param control The control of the bezier path.
|
|
|
|
* @param destination The destination of the bezier path.
|
|
|
|
* @param segments The number of segments.
|
|
|
|
* @param color Set the quad bezier color.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
void drawQuadBezier(const Vec2& origin,
|
|
|
|
const Vec2& control,
|
|
|
|
const Vec2& destination,
|
|
|
|
unsigned int segments,
|
2024-09-06 21:31:18 +08:00
|
|
|
const Color4B& color,
|
|
|
|
float thickness = 1.0f);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/** Draw a cubic bezier curve with color and number of segments
|
|
|
|
*
|
|
|
|
* @param origin The origin of the bezier path.
|
|
|
|
* @param control1 The first control of the bezier path.
|
|
|
|
* @param control2 The second control of the bezier path.
|
|
|
|
* @param destination The destination of the bezier path.
|
|
|
|
* @param segments The number of segments.
|
|
|
|
* @param color Set the cubic bezier color.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
void drawCubicBezier(const Vec2& origin,
|
|
|
|
const Vec2& control1,
|
|
|
|
const Vec2& control2,
|
|
|
|
const Vec2& destination,
|
|
|
|
unsigned int segments,
|
2024-09-06 21:31:18 +08:00
|
|
|
const Color4B& color,
|
|
|
|
float thickness = 1.0f);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/** Draws a Cardinal Spline path.
|
|
|
|
*
|
|
|
|
* @param config A array point.
|
|
|
|
* @param tension The tension of the spline.
|
|
|
|
* @param segments The number of segments.
|
|
|
|
* @param color Set the Spline color.
|
|
|
|
*/
|
2024-09-06 21:31:18 +08:00
|
|
|
void drawCardinalSpline(PointArray* config,
|
|
|
|
float tension,
|
|
|
|
unsigned int segments,
|
|
|
|
const Color4B& color,
|
|
|
|
float thickness = 1.0f);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/** Draws a Catmull Rom path.
|
|
|
|
*
|
|
|
|
* @param points A point array of control point.
|
|
|
|
* @param segments The number of segments.
|
|
|
|
* @param color The Catmull Rom color.
|
|
|
|
*/
|
2024-09-06 21:31:18 +08:00
|
|
|
void drawCatmullRom(PointArray* points, unsigned int segments, const Color4B& color, float thickness = 1.0f);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
/** draw a dot at a position, with a given radius and color.
|
2019-11-23 20:27:39 +08:00
|
|
|
*
|
|
|
|
* @param pos The dot center.
|
|
|
|
* @param radius The dot radius.
|
|
|
|
* @param color The dot color.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
void drawDot(const Vec2& pos, float radius, const Color4B& color);
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/** Draws a rectangle with 4 points.
|
|
|
|
*
|
|
|
|
* @param p1 The rectangle vertex point.
|
|
|
|
* @param p2 The rectangle vertex point.
|
|
|
|
* @param p3 The rectangle vertex point.
|
|
|
|
* @param p4 The rectangle vertex point.
|
|
|
|
* @param color The rectangle color.
|
|
|
|
*/
|
2024-09-06 21:31:18 +08:00
|
|
|
void drawRect(const Vec2& p1,
|
|
|
|
const Vec2& p2,
|
|
|
|
const Vec2& p3,
|
|
|
|
const Vec2& p4,
|
|
|
|
const Color4B& color,
|
|
|
|
float thickness = 1.0f);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/** Draws a solid rectangle given the origin and destination point measured in points.
|
|
|
|
* The origin and the destination can not have the same x and y coordinate.
|
|
|
|
*
|
|
|
|
* @param origin The rectangle origin.
|
|
|
|
* @param destination The rectangle destination.
|
|
|
|
* @param color The rectangle color.
|
|
|
|
* @js NA
|
|
|
|
*/
|
2024-09-06 21:31:18 +08:00
|
|
|
void drawSolidRect(const Vec2& origin,
|
|
|
|
const Vec2& destination,
|
|
|
|
const Color4B& color,
|
|
|
|
float thickness = 0,
|
|
|
|
const Color4B& borderColor = Color4B(0, 0, 0, 0));
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
/** Draws a solid polygon given a pointer to CGPoint coordinates, the number of vertices measured in points, and a
|
|
|
|
* color.
|
2019-11-23 20:27:39 +08:00
|
|
|
*
|
|
|
|
* @param poli A solid polygon given a pointer to CGPoint coordinates.
|
|
|
|
* @param numberOfPoints The number of vertices measured in points.
|
|
|
|
* @param color The solid polygon color.
|
|
|
|
* @js NA
|
|
|
|
*/
|
2024-09-06 21:31:18 +08:00
|
|
|
void drawSolidPoly(const Vec2* poli,
|
|
|
|
unsigned int numberOfPoints,
|
|
|
|
const Color4B& color,
|
|
|
|
float thickness = 0,
|
|
|
|
const Color4B& borderColor = Color4B(0, 0, 0, 0),
|
|
|
|
bool isconvex = false);
|
2021-08-19 14:35:44 +08:00
|
|
|
|
|
|
|
/** Draws a solid circle given the center, radius and number of segments.
|
|
|
|
* @param center The circle center point.
|
|
|
|
* @param radius The circle rotate of radius.
|
|
|
|
* @param angle The circle angle.
|
|
|
|
* @param segments The number of segments.
|
|
|
|
* @param scaleX The scale value in x.
|
|
|
|
* @param scaleY The scale value in y.
|
|
|
|
* @param fillColor The color will fill in polygon.
|
2024-09-06 21:31:18 +08:00
|
|
|
* @param thickness The border of line width.
|
2021-08-19 14:35:44 +08:00
|
|
|
* @param borderColor The border of line color.
|
2024-09-17 22:09:05 +08:00
|
|
|
* @param drawLineToCenter Whether or not draw the line from the origin to center.
|
2021-08-19 14:35:44 +08:00
|
|
|
* @js NA
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
void drawSolidCircle(const Vec2& center,
|
|
|
|
float radius,
|
|
|
|
float angle,
|
|
|
|
unsigned int segments,
|
|
|
|
float scaleX,
|
|
|
|
float scaleY,
|
|
|
|
const Color4B& fillColor,
|
2024-09-06 21:31:18 +08:00
|
|
|
float thickness,
|
2024-09-17 22:09:05 +08:00
|
|
|
const Color4B& borderColor,
|
|
|
|
bool drawLineToCenter = false);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/** Draws a solid circle given the center, radius and number of segments.
|
|
|
|
* @param center The circle center point.
|
|
|
|
* @param radius The circle rotate of radius.
|
|
|
|
* @param angle The circle angle.
|
|
|
|
* @param segments The number of segments.
|
|
|
|
* @param scaleX The scale value in x.
|
|
|
|
* @param scaleY The scale value in y.
|
|
|
|
* @param color The solid circle color.
|
|
|
|
* @js NA
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
void drawSolidCircle(const Vec2& center,
|
|
|
|
float radius,
|
|
|
|
float angle,
|
|
|
|
unsigned int segments,
|
|
|
|
float scaleX,
|
|
|
|
float scaleY,
|
|
|
|
const Color4B& color);
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/** Draws a solid circle given the center, radius and number of segments.
|
|
|
|
* @param center The circle center point.
|
|
|
|
* @param radius The circle rotate of radius.
|
|
|
|
* @param angle The circle angle.
|
|
|
|
* @param segments The number of segments.
|
|
|
|
* @param color The solid circle color.
|
|
|
|
* @js NA
|
|
|
|
*/
|
2024-09-06 21:31:18 +08:00
|
|
|
void drawSolidCircle(const Vec2& center, float radius, float angle, unsigned int segments, const Color4B& color);
|
|
|
|
|
|
|
|
/** Draws a pie given the center, radius, angle, start angle, end angle and number of segments.
|
|
|
|
* @param center The circle center point.
|
|
|
|
* @param radius The circle rotate of radius.
|
|
|
|
* @param angle The circle angle.
|
|
|
|
* @param startAngle The start angle.
|
|
|
|
* @param endAngle The end angle.
|
|
|
|
* @param scaleX The scale value in x.
|
|
|
|
* @param scaleY The scale value in y.
|
|
|
|
* @param fillColor The solid circle color.
|
|
|
|
* @param borderColor The borderColor.
|
|
|
|
* @param DrawMode The draw mode
|
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
void drawPie(const Vec2& center,
|
2023-12-05 17:20:31 +08:00
|
|
|
float radius,
|
2024-09-06 21:31:18 +08:00
|
|
|
float rotation,
|
|
|
|
int startAngle,
|
|
|
|
int endAngle,
|
|
|
|
float scaleX,
|
|
|
|
float scaleY,
|
|
|
|
const Color4B& fillColor,
|
|
|
|
const Color4B& borderColor,
|
|
|
|
DrawMode drawMode = DrawMode::Outline,
|
|
|
|
float thickness = 1.0f);
|
2023-12-05 17:20:31 +08:00
|
|
|
|
2024-09-06 21:31:18 +08:00
|
|
|
// Cocos2dx/Axmol 1.0 API backwards compatibhility
|
|
|
|
/** Draws a pie given the center, radius, angle, start angle, end angle and number of segments.
|
2023-12-05 17:20:31 +08:00
|
|
|
* @param center The circle center point.
|
|
|
|
* @param radius The circle rotate of radius.
|
|
|
|
* @param angle The circle angle.
|
|
|
|
* @param startAngle The start angle.
|
|
|
|
* @param endAngle The end angle.
|
|
|
|
* @param scaleX The scale value in x.
|
|
|
|
* @param scaleY The scale value in y.
|
|
|
|
* @param color The solid circle color.
|
2024-08-15 12:14:02 +08:00
|
|
|
* @param DrawMode The draw mode
|
2023-12-05 17:20:31 +08:00
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
void drawPie(const Vec2& center,
|
|
|
|
float radius,
|
|
|
|
float angle,
|
|
|
|
int startAngle,
|
|
|
|
int endAngle,
|
|
|
|
float scaleX,
|
|
|
|
float scaleY,
|
|
|
|
const Color4B& color,
|
2024-09-06 21:31:18 +08:00
|
|
|
DrawMode drawMode = DrawMode::Outline);
|
|
|
|
|
|
|
|
void setIsConvex(bool isConvex)
|
|
|
|
{
|
|
|
|
AXLOGW("'setIsConvex()' No longer supported. Use the new drawPolygon API.");
|
2024-09-21 23:55:26 +08:00
|
|
|
};
|
2024-09-06 21:31:18 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2024-09-06 21:31:18 +08:00
|
|
|
/** draw a segment with a radius and color.
|
2019-11-23 20:27:39 +08:00
|
|
|
*
|
|
|
|
* @param from The segment origin.
|
|
|
|
* @param to The segment destination.
|
|
|
|
* @param radius The segment radius.
|
|
|
|
* @param color The segment color.
|
|
|
|
*/
|
2024-09-06 21:31:18 +08:00
|
|
|
void drawSegment(const Vec2& from,
|
|
|
|
const Vec2& to,
|
|
|
|
float radius,
|
|
|
|
const Color4B& color,
|
|
|
|
DrawNode::EndType etStart = DrawNode::EndType::Round,
|
|
|
|
DrawNode::EndType etEnd = DrawNode::EndType::Round);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/** draw a polygon with a fill color and line color
|
2021-12-25 10:04:45 +08:00
|
|
|
* @code
|
|
|
|
* When this function bound into js or lua,the parameter will be changed
|
|
|
|
* In js: var drawPolygon(var Arrayofpoints, var fillColor, var width, var borderColor)
|
|
|
|
* In lua:local drawPolygon(local pointTable,local tableCount,local fillColor,local width,local borderColor)
|
|
|
|
* @endcode
|
|
|
|
* @param verts A pointer to point coordinates.
|
|
|
|
* @param count The number of verts measured in points.
|
|
|
|
* @param fillColor The color will fill in polygon.
|
2024-09-06 21:31:18 +08:00
|
|
|
* @param thickness The border of line width.
|
2021-12-25 10:04:45 +08:00
|
|
|
* @param borderColor The border of line color.
|
|
|
|
* @js NA
|
|
|
|
*/
|
2024-09-06 21:31:18 +08:00
|
|
|
void drawPolygon(Vec2* verts,
|
2021-12-25 10:04:45 +08:00
|
|
|
int count,
|
|
|
|
const Color4B& fillColor,
|
2024-09-06 21:31:18 +08:00
|
|
|
float thickness,
|
|
|
|
const Color4B& borderColor,
|
|
|
|
bool isconvex = false);
|
|
|
|
|
|
|
|
void drawPolygon(Vec2* verts, int count, float thickness, const Color4B& borderColor, bool isconvex = false);
|
|
|
|
|
|
|
|
void drawSolidPolygon(Vec2* verts,
|
|
|
|
int count,
|
|
|
|
const Color4B& fillColor,
|
|
|
|
float thickness,
|
|
|
|
const Color4B& borderColor,
|
|
|
|
bool isconvex = false);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
/** draw a triangle with color.
|
2019-11-23 20:27:39 +08:00
|
|
|
*
|
|
|
|
* @param p1 The triangle vertex point.
|
|
|
|
* @param p2 The triangle vertex point.
|
|
|
|
* @param p3 The triangle vertex point.
|
|
|
|
* @param color The triangle color.
|
|
|
|
* @js NA
|
|
|
|
*/
|
2021-12-06 21:09:15 +08:00
|
|
|
|
2024-09-17 22:09:05 +08:00
|
|
|
void drawTriangle(const Vec2* vertices3, const Color4B& color);
|
2024-09-06 21:31:18 +08:00
|
|
|
|
2024-09-17 22:09:05 +08:00
|
|
|
void drawTriangle(const Vec2& p1, const Vec2& p2, const Vec2& p3, const Color4B& color);
|
2024-09-06 21:31:18 +08:00
|
|
|
|
|
|
|
void drawSolidTriangle(const Vec2* vertices3,
|
|
|
|
const Color4B& fillColor,
|
|
|
|
const Color4B& borderColor,
|
|
|
|
float thickness = 1.0f);
|
|
|
|
|
|
|
|
void drawSolidTriangle(const Vec2& p1,
|
|
|
|
const Vec2& p2,
|
|
|
|
const Vec2& p3,
|
|
|
|
const Color4B& fillColor,
|
|
|
|
const Color4B& borderColor,
|
|
|
|
float thickness = 1.0f);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/** Clear the geometry in the node's buffer. */
|
|
|
|
void clear();
|
|
|
|
/** Get the color mixed mode.
|
2021-12-25 10:04:45 +08:00
|
|
|
* @lua NA
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
const BlendFunc& getBlendFunc() const;
|
|
|
|
/** Set the color mixed mode.
|
2021-12-25 10:04:45 +08:00
|
|
|
* @code
|
|
|
|
* When this function bound into js or lua,the parameter will be changed
|
|
|
|
* In js: var setBlendFunc(var src, var dst)
|
|
|
|
* @endcode
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
void setBlendFunc(const BlendFunc& blendFunc);
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
// Overrides
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void draw(Renderer* renderer, const Mat4& transform, uint32_t flags) override;
|
|
|
|
|
|
|
|
virtual void visit(Renderer* renderer, const Mat4& parentTransform, uint32_t parentFlags) override;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* When isolated is set, the position of the node is no longer affected by parent nodes.
|
|
|
|
* Which means it will be drawn just like a root node.
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
void setIsolated(bool isolated) { _isolated = isolated; }
|
|
|
|
|
|
|
|
bool isIsolated() const { return _isolated; }
|
|
|
|
|
2024-09-23 22:13:12 +08:00
|
|
|
DrawNode();
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~DrawNode();
|
|
|
|
virtual bool init() override;
|
|
|
|
|
|
|
|
protected:
|
2024-09-21 23:55:26 +08:00
|
|
|
void updateBuffers();
|
2019-11-23 20:27:39 +08:00
|
|
|
void updateShader();
|
2021-12-25 10:04:45 +08:00
|
|
|
void updateShaderInternal(CustomCommand& cmd,
|
|
|
|
uint32_t programType,
|
|
|
|
CustomCommand::DrawType drawType,
|
|
|
|
CustomCommand::PrimitiveType primitiveType);
|
2020-10-26 14:49:14 +08:00
|
|
|
void freeShaderInternal(CustomCommand& cmd);
|
2022-10-20 20:22:28 +08:00
|
|
|
|
|
|
|
void setVertexLayout(CustomCommand& cmd);
|
2020-10-26 14:49:14 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
void updateBlendState(CustomCommand& cmd);
|
2021-12-25 10:04:45 +08:00
|
|
|
void updateUniforms(const Mat4& transform, CustomCommand& cmd);
|
|
|
|
|
2024-09-21 23:55:26 +08:00
|
|
|
bool _trianglesDirty: 1 = false;
|
|
|
|
bool _pointsDirty: 1 = false;
|
|
|
|
bool _linesDirty: 1 = false;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2024-09-21 23:55:26 +08:00
|
|
|
bool _isolated: 1 = false;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2024-09-21 23:55:26 +08:00
|
|
|
BlendFunc _blendFunc;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2024-09-21 23:55:26 +08:00
|
|
|
CustomCommand _customCommandTriangle;
|
2020-10-26 14:49:14 +08:00
|
|
|
CustomCommand _customCommandPoint;
|
|
|
|
CustomCommand _customCommandLine;
|
2024-09-06 21:31:18 +08:00
|
|
|
|
2024-09-21 23:55:26 +08:00
|
|
|
axstd::pod_vector<V2F_C4B_T2F> _triangles;
|
|
|
|
axstd::pod_vector<V2F_C4B_T2F> _points;
|
|
|
|
axstd::pod_vector<V2F_C4B_T2F> _lines;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2024-09-21 23:55:26 +08:00
|
|
|
|
2024-09-06 21:31:18 +08:00
|
|
|
private:
|
|
|
|
// Internal function _drawPoint
|
|
|
|
void _drawPoint(const Vec2& position,
|
|
|
|
const float pointSize,
|
|
|
|
const Color4B& color,
|
|
|
|
const DrawNode::PointType pointType);
|
|
|
|
|
|
|
|
// Internal function _drawPoints
|
|
|
|
void _drawPoints(const Vec2* position,
|
|
|
|
unsigned int numberOfPoints,
|
|
|
|
const float pointSize,
|
|
|
|
const Color4B& color,
|
|
|
|
const DrawNode::PointType pointType);
|
|
|
|
|
|
|
|
// Internal function _drawDot
|
|
|
|
void _drawDot(const Vec2& pos, float radius, const Color4B& color);
|
|
|
|
|
|
|
|
// Internal function _drawTriangle
|
2024-09-21 23:55:26 +08:00
|
|
|
// Note: modifies supplied vertex array
|
|
|
|
void _drawTriangle(Vec2* vertices3,
|
2024-09-06 21:31:18 +08:00
|
|
|
const Color4B& borderColor,
|
|
|
|
const Color4B& fillColor,
|
|
|
|
bool solid = true,
|
|
|
|
float thickness = 0.0f);
|
|
|
|
|
|
|
|
// Internal function _drawAStar
|
|
|
|
void _drawAStar(const Vec2& center,
|
|
|
|
float radiusI,
|
|
|
|
float radiusO,
|
|
|
|
unsigned int segments,
|
|
|
|
const Color4B& color,
|
|
|
|
const Color4B& filledColor,
|
|
|
|
float thickness = 1.0f,
|
|
|
|
bool solid = false);
|
|
|
|
|
|
|
|
// Internal function _drawPoly
|
|
|
|
void _drawPoly(const Vec2* poli,
|
|
|
|
unsigned int numberOfPoints,
|
|
|
|
bool closedPolygon,
|
|
|
|
const Color4B& color,
|
|
|
|
float thickness = 1.0f,
|
|
|
|
bool isconvex = true);
|
|
|
|
|
|
|
|
// Internal function _drawPolygon
|
|
|
|
void _drawPolygon(const Vec2* verts,
|
|
|
|
unsigned int count,
|
|
|
|
const Color4B& fillColor,
|
|
|
|
const Color4B& borderColor,
|
|
|
|
bool closedPolygon = true,
|
|
|
|
float thickness = 1.0f,
|
|
|
|
bool isconvex = true);
|
|
|
|
|
|
|
|
// Internal function _drawSegment
|
|
|
|
void _drawSegment(const Vec2& origin,
|
|
|
|
const Vec2& destination,
|
|
|
|
const Color4B& color,
|
|
|
|
float thickness = 1.0f,
|
|
|
|
DrawNode::EndType etStart = DrawNode::EndType::Square,
|
|
|
|
DrawNode::EndType etEnd = DrawNode::EndType::Square);
|
|
|
|
|
|
|
|
// Internal function _drawCircle
|
|
|
|
void _drawCircle(const Vec2& center,
|
|
|
|
float radius,
|
|
|
|
float angle,
|
|
|
|
unsigned int segments,
|
|
|
|
bool drawLineToCenter,
|
|
|
|
float scaleX,
|
|
|
|
float scaleY,
|
|
|
|
const Color4B& borderColor,
|
|
|
|
const Color4B& fillColor,
|
|
|
|
bool solid,
|
|
|
|
float thickness = 1.0f);
|
|
|
|
|
|
|
|
// Internal function _drawPie
|
|
|
|
void _drawPie(const Vec2& center,
|
|
|
|
float radius,
|
|
|
|
float rotation,
|
|
|
|
int startAngle,
|
|
|
|
int endAngle,
|
|
|
|
float scaleX,
|
|
|
|
float scaleY,
|
|
|
|
const Color4B& fillColor,
|
|
|
|
const Color4B& borderColor,
|
|
|
|
DrawMode drawMode,
|
|
|
|
float thickness = 1.0f);
|
|
|
|
|
|
|
|
/* Internal function _transform
|
|
|
|
* @param vertices A Vec2 vertices list.
|
|
|
|
* @param count The number of vertices.
|
|
|
|
* @param closedPolygon The closedPolygon flag.
|
|
|
|
* @js NA
|
|
|
|
*/
|
2024-09-08 00:17:47 +08:00
|
|
|
axstd::pod_vector<Vec2> _transform(const Vec2* vertices, unsigned int& count, bool closedPolygon = false);
|
2023-12-31 11:33:49 +08:00
|
|
|
|
2024-09-21 23:55:26 +08:00
|
|
|
void applyTransform(const Vec2* from, Vec2* to, unsigned int count);
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
private:
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_DISALLOW_COPY_AND_ASSIGN(DrawNode);
|
2024-09-06 21:31:18 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
class Properties
|
|
|
|
{
|
|
|
|
public:
|
2024-09-23 22:13:12 +08:00
|
|
|
float factor = 0.5f; /// thickness factor
|
2024-09-06 21:31:18 +08:00
|
|
|
|
|
|
|
// transforming stuff
|
|
|
|
Vec2 scale;
|
|
|
|
Vec2 center;
|
|
|
|
float rotation;
|
|
|
|
Vec2 position;
|
|
|
|
|
|
|
|
|
|
|
|
// Drawing flags
|
2024-09-21 23:55:26 +08:00
|
|
|
bool transform = false;
|
2024-09-06 21:31:18 +08:00
|
|
|
bool drawOrder = false;
|
|
|
|
|
|
|
|
/** Set the DrawNode drawOrder
|
|
|
|
*
|
|
|
|
* @param drawOrder. true/false = On/Off
|
|
|
|
* Its for performance there
|
|
|
|
* false = cocos2dx behaviour => faster but works only on 1.0f thickness
|
|
|
|
|
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
void setDrawOrder(bool dO) { drawOrder = dO; };
|
|
|
|
|
|
|
|
/** Get the DrawNode drawOrder
|
|
|
|
*
|
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
bool getDrawOrder(void) { return drawOrder; };
|
|
|
|
|
|
|
|
/** Set the DrawNode transform
|
|
|
|
*
|
|
|
|
* @param transform. true/false = On/Off
|
|
|
|
*
|
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
void setTransform(bool t) { transform = t; };
|
|
|
|
|
|
|
|
/** Get the DrawNode transform
|
|
|
|
*
|
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
bool getTransform(void) { return transform; };
|
|
|
|
|
|
|
|
/** Set the DrawNode scale for each drawing primitive after this.
|
|
|
|
|
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
void setScale(Vec2 s) { scale = s; };
|
|
|
|
|
|
|
|
/** Set the DrawNode rotation for each drawing primitive after this.
|
|
|
|
|
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
void setRotation(float r) { rotation = r; };
|
|
|
|
|
|
|
|
/** Get the DrawNode rotation for each drawing primitive after this.
|
|
|
|
|
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
float getRotation() { return rotation; };
|
|
|
|
|
|
|
|
/** Set the DrawNode center of rotation for each drawing primitive after this.
|
|
|
|
|
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
void setCenter(Vec2 c) { center = c; };
|
|
|
|
|
|
|
|
/** Get the DrawNode center of rotation for each drawing primitive after this.
|
|
|
|
|
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
Vec2 getCenter() { return center; };
|
|
|
|
|
|
|
|
/** Set the DrawNode position for each drawing primitive after this.
|
|
|
|
|
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
void setPosition(Vec2 p) { position = p; };
|
|
|
|
|
|
|
|
/** Get the DrawNode position for drawing primitive.
|
|
|
|
|
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
Vec2 getPosition() { return position; };
|
|
|
|
|
|
|
|
/** Set all default DrawNode properties.
|
|
|
|
|
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
void setDefaultValues()
|
|
|
|
{
|
|
|
|
scale = Vec2(1.0f, 1.0f);
|
|
|
|
center = Vec2(0.0f, 0.0f);
|
|
|
|
rotation = 0.0f;
|
|
|
|
position = Vec2(0.0f, 0.0f);
|
|
|
|
drawOrder = false;
|
|
|
|
};
|
|
|
|
} properties;
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
2024-09-06 21:31:18 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/** @} */
|
2024-09-06 21:31:18 +08:00
|
|
|
} // namespace ax
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2024-09-06 21:31:18 +08:00
|
|
|
#endif // __DRAW_NODE_EX_H__
|