mirror of
https://github.com/blanking003/cx-cocos.git
synced 2025-11-04 21:35:33 +00:00
init
This commit is contained in:
20
cx-framework3.1/cx-native/cxMask/cxMaskIntf.h
Normal file
20
cx-framework3.1/cx-native/cxMask/cxMaskIntf.h
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cxDefine.h"
|
||||
|
||||
class CxMaskIntf : public NativeIntfClass
|
||||
{
|
||||
public:
|
||||
static CxMaskIntf* ins();
|
||||
|
||||
virtual std::string call(std::string fname, cc::ValueVector params, const DataCallback& callback) override;
|
||||
|
||||
void addNativeView(std::string maskName, void* view);
|
||||
bool hasNativeView(std::string maskName, void* view);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
};
|
||||
|
||||
127
cx-framework3.1/cx-native/cxMask/cxMaskIntf.mm
Normal file
127
cx-framework3.1/cx-native/cxMask/cxMaskIntf.mm
Normal file
@@ -0,0 +1,127 @@
|
||||
|
||||
#include "cxMaskIntf.h"
|
||||
|
||||
#include "AppController.h"
|
||||
#include "cxMaskView.h"
|
||||
|
||||
std::unordered_map<std::string, CxMaskView*> m_maskViewList;
|
||||
CxMaskView* getMaskView(std::string name)
|
||||
{
|
||||
auto itr = m_maskViewList.find(name);
|
||||
if (itr != m_maskViewList.end())
|
||||
return itr->second;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static CxMaskIntf* s_sharedCxMaskIntf = nullptr;
|
||||
CxMaskIntf* CxMaskIntf::ins()
|
||||
{
|
||||
if (!s_sharedCxMaskIntf)
|
||||
s_sharedCxMaskIntf = new CxMaskIntf();
|
||||
return s_sharedCxMaskIntf;
|
||||
}
|
||||
|
||||
std::string CxMaskIntf::call(std::string fname, cc::ValueVector params, const DataCallback& callback)
|
||||
{
|
||||
if (fname == "createMask")
|
||||
{
|
||||
std::string name = params.at(0).asString();
|
||||
float rectX = params.at(1).asFloat();
|
||||
float rectY = params.at(2).asFloat();
|
||||
float rectW = params.at(3).asFloat();
|
||||
float rectH = params.at(4).asFloat();
|
||||
|
||||
if (getMaskView(name))
|
||||
return "";
|
||||
|
||||
CxMaskView* maskView = [[CxMaskView alloc] initWithFrame:CGRectMake(rectX, rectY, rectW, rectH)];
|
||||
//maskView.contentView.backgroundColor = [UIColor colorWithRed:100 green:0 blue:0 alpha:0.4];
|
||||
[[AppController ins] addView:maskView];
|
||||
|
||||
m_maskViewList.emplace(name, maskView);
|
||||
}
|
||||
|
||||
else if (fname == "setMaskVisible")
|
||||
{
|
||||
std::string name = params.at(0).asString();
|
||||
bool visible = params.at(1).asBool();
|
||||
|
||||
auto maskView = getMaskView(name);
|
||||
if (maskView)
|
||||
[maskView setHidden:!visible];
|
||||
}
|
||||
|
||||
else if (fname == "setMaskSize")
|
||||
{
|
||||
std::string name = params.at(0).asString();
|
||||
float rectW = params.at(1).asFloat();
|
||||
float rectH = params.at(2).asFloat();
|
||||
|
||||
auto maskView = getMaskView(name);
|
||||
if (maskView)
|
||||
maskView.frame = CGRectMake(maskView.frame.origin.x, maskView.frame.origin.y, rectW, rectH);
|
||||
}
|
||||
|
||||
else if (fname == "setMaskMask")
|
||||
{
|
||||
std::string name = params.at(0).asString();
|
||||
auto maskView = getMaskView(name);
|
||||
if (maskView)
|
||||
{
|
||||
float maskX = params.at(1).asFloat();
|
||||
float maskY = params.at(2).asFloat();
|
||||
float maskW = params.at(3).asFloat();
|
||||
float maskH = params.at(4).asFloat();
|
||||
float radius = params.at(5).asFloat();
|
||||
UIBezierPath* path = [UIBezierPath bezierPathWithRect:maskView.contentView.bounds];
|
||||
UIBezierPath* round = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(maskX, maskY, maskW, maskH) cornerRadius:radius];
|
||||
CAShapeLayer* maskLayer = [CAShapeLayer layer];
|
||||
[path appendPath:round];
|
||||
maskLayer.path = [path CGPath];
|
||||
maskLayer.fillRule = kCAFillRuleEvenOdd;
|
||||
maskView.contentView.layer.mask = maskLayer;
|
||||
}
|
||||
}
|
||||
|
||||
else if (fname == "clearMaskMask")
|
||||
{
|
||||
std::string name = params.at(0).asString();
|
||||
auto maskView = getMaskView(name);
|
||||
if (maskView)
|
||||
maskView.contentView.layer.mask = nil;
|
||||
}
|
||||
|
||||
else if (fname == "removeMask")
|
||||
{
|
||||
std::string name = params.at(0).asString();
|
||||
auto maskView = getMaskView(name);
|
||||
if (maskView)
|
||||
{
|
||||
[maskView removeFromSuperview];
|
||||
m_maskViewList.erase(name);
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
void CxMaskIntf::addNativeView(std::string maskName, void* view)
|
||||
{
|
||||
auto maskView = getMaskView(maskName);
|
||||
if (maskView)
|
||||
[maskView.contentView addSubview:(UIView*)view];
|
||||
}
|
||||
|
||||
bool CxMaskIntf::hasNativeView(std::string maskName, void* view)
|
||||
{
|
||||
auto maskView = getMaskView(maskName);
|
||||
if (maskView)
|
||||
{
|
||||
for (UIView* subview in maskView.contentView.subviews)
|
||||
{
|
||||
if (subview == view)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
9
cx-framework3.1/cx-native/cxMask/cxMaskView.h
Normal file
9
cx-framework3.1/cx-native/cxMask/cxMaskView.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface CxMaskView : UIView
|
||||
|
||||
@property (strong, nonatomic) UIView* contentView;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
25
cx-framework3.1/cx-native/cxMask/cxMaskView.mm
Normal file
25
cx-framework3.1/cx-native/cxMask/cxMaskView.mm
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
#import "cxMaskView.h"
|
||||
|
||||
#define pop_height 200
|
||||
#define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
|
||||
|
||||
@implementation CxMaskView
|
||||
|
||||
|
||||
- (id)initWithFrame:(CGRect)frame
|
||||
{
|
||||
self = [super initWithFrame:frame];
|
||||
self.userInteractionEnabled = false;
|
||||
self.clipsToBounds = true;
|
||||
|
||||
CGSize screen = [[UIScreen mainScreen] bounds].size;
|
||||
self.contentView = [[UIView alloc] initWithFrame:CGRectMake(-frame.origin.x, -frame.origin.y, screen.width, screen.height)];
|
||||
self.contentView.userInteractionEnabled = false;
|
||||
[self addSubview:self.contentView];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user