Conceived a UI engine that imitates OBJC-based animation layer UI programming under Windows

Source: Internet
Author: User

Programming in C + + for some years, 10 fingers can be counted, and when involved in iOS OBJC development, there is a sense of comfort, especially in UI development.

Many effects, such as animations and transparent windows, become so convenient and natural in quartzcore.framework. Because there is no engine layer for effects such as animations and transparent windows (except Aero) in Windows window mechanics, and ARGB is not supported in GDI, development relies on repeated and large numbers of BitBlt and timer, and the workload is not comparable to developing iOS.

It's basically trying to introduce a programming experience like uikit.framework. First of all, there should be quartzcore.framework Calayer and catransition, and OBJC's nsobject support.

The first phase has completed the following basic functions:

NSObject.h,

NSObjectRuntime.h, (Obj_class)

NSAutoreleasePool.h,

Nsarrary,

CALayer.h,

CGContext.h,

CGAffineTransform.h,

CAAnimation.h,

CoreGraphics.h (definition of cgpoint, etc.)

Because not objc,runtime in the implementation is obj_class instead of Objc_class.

You can build layer animations in the Windows window at this stage.

The code style is as follows:

_testlayer = nsobject::alloct<catestlayer>(); _testlayer->setframe (CGRect ( -. F, -. F, +. F, +. f)); _testlayer-Set_backgroundcolor (Cgcolor (cgcolor::P ink)); _normallayer= nsobject::alloct<calayer>(); _normallayer->setframe (CGRect ( -. F, -. F, +. F, +. f)); _normallayer-Set_backgroundcolor (Cgcolor (cgcolor::P ink)); Catestlayer* _testlayer2 = (catestlayer*) nsobject::alloct<catestlayer> ()autorelease (); _testlayer2->setframe (CGRect (5. F,5. F,Ten. F,Ten. f)); _testlayer2->set_backgroundcolor (Cgcolor (123, -, -)); _normallayer-Addsublayer (_testlayer2);:: Iskindofclass<CALayer>(_testlayer2);:: Iskindofclass<NSArray> (_TESTLAYER2);

Delivery animations:

{_0_autoreleasepool _normallayer->setframe (CGRect ( -. F, -. F, +. F, +. f)); _normallayer-SetTransform (Cgaffinetransform ()); :: Caanimation* Anime = caanimation::beginanimating (_normallayer,1. f); {Anime->setframe (CGRect ( the. F, -. F, -. F, -. f)); Anime->translate (0. F,- -. f); Anime->rotate ( the. f); Anime-commit (); } _1_autoreleasepool}
View Code

Class definition:

classCalayer: Publicnsobject{ Public:    Virtual~Calayer ();    Calayer (); voidsetneedslayout ();    BOOL needslayout (); voidlayoutifneeded (); Virtual voidlayoutsublayers (); voidDisplay (cgcontext*CTX); Virtual voidDrawincontext (cgcontext*CTX); voidRenderincontext (cgcontext*CTX); voidAddsublayer (calayer*layer);Private:    Virtual voidapplyanimating ();protected: _0_property_setter01 (Setframe, CGRect, frame);    _0_property_setter01 (SetBounds, CGRect, bounds);    _0_property_setter (Setanchorpoint, Cgpoint, Anchorpoint);    _0_property_setter (Setzposition, CGFloat, zposition); //_0_property_pri_pwi_pti (public:, transform,;, public:, SetTransform,;, protected:, Cgaffinetransform, TRANSFO RM);_0_property_setter (SetTransform, cgaffinetransform, transform);    _0_property_getset (Ishidden,sethidden, BOOL, Hidden); _0_property_assign2 (Setsuperlayer, Calayer*, Superlayer); _0_property_retain2 (setsublayers, Nsarray*, sublayers); _0_property_retain2 (Setmask, Calayer*, mask);//No Impl_0_property_getset (Ismasktobounds, Setmasktobounds, BOOL, masktobounds);//No Impl#ifdef calayer_impl_contents NSObject* _contents;//No ImplCGRect _contentrect; NSString*_contentsgravity;    CGFloat _contentscale; CGFloat _contentconter;#endif_0_property_getset (Isopaque, Setopaque, BOOL, opaque);    _0_property_getter (Isneedsdisplayonboundschange, BOOL, Needsdisplayonboundschange);    _0_property_getter (isdrawsasynchronously, BOOL, drawsasynchronously); //No Impl_0_property (Cgcolor, backgroundcolor);    _0_property (Cgcolor, Cornerradius);    _0_property (CGFloat, borderWidth);    _0_property (Cgcolor, bordercolor);    _0_property (cgfloat, opacity);    _0_property_setter (isallowsgroupopacity, BOOL, allowsgroupopacity); _0_property_retain2 (setfilters, Nsarray*, filters); _0_property_retain2 (setbackgroundfilters, Nsarray*, backgroundfilters);    _0_property_setter (Isshouldrasterize, BOOL, shouldrasterize);    _0_property (CGFloat, Rasterizationscale);    _0_property (Cgcolor, Shadowcolor);    _0_property (CGFloat, shadowopacity); _0_property (CGFloat, Shadowradius);

1. Classes inherited by NSObject cannot explicitly call new, delete. Must pass template Nsobject::alloctx<typename t> (...) To allocate objects, as well as release () or autorelease () member functions. However, because the COM interface is not used (interfaces and implementations are completely detached, the factory class constructs objects to return interfaces), there is no way to prevent objects from being built in local and global.

2. Support Autorelease (), and Autorelease () in the local range.

3. Support affine transformation, sub-layer model transformation coordinates.

4. Supports the Iskindofclass method, which helps to access elements in containers such as nsarray in the correct type.

5. Support the opaque between layer and layer, and ARGB color.

The next stage prepares to introduce UIView and Uiviewcontroller, fisrtresponder these concepts. Complete some basic function classes like nsstring, nsdictionary, etc.

PS: _0_property_xxx in code is a macro that automatically completes getter and setter, because the macro definition does not allow the letter "@" to be used instead of "_0_".

Nowadays, like the Thunderbolt UI Development Library has been a lot of good, this is only interested in and used for personal skills self-cultivation.

Conceived a UI engine that imitates OBJC-based animation layer UI programming under Windows

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.