//
//  LTQuickMacro.h
//  LTToolSDK
//
//  Created by 孙泉 on 2018/5/29.
//  Copyright © 2018年 longtugame. All rights reserved.
//

#ifndef LTQuickMacro_h
#define LTQuickMacro_h

#pragma mark - 系统版本

#define LTCURRENTDEVICE                             (UIDevice.currentDevice)

#define LTSYSTEMVERSION                             (LTCURRENTDEVICE.systemVersion.floatValue)

#define LTISIOS6                                    (LTSYSTEMVERSION >= 6.0f)

#define LTISIOS7                                    (LTSYSTEMVERSION >= 7.0f)

#define LTISIOS8                                    (LTSYSTEMVERSION >= 8.0f)

#define LTISIOS10                                   (LTSYSTEMVERSION >= 10.f)

#define LTISIOS11                                   (LTSYSTEMVERSION >= 11.0f)

#pragma mark - UIApplication

#define LTAPPLICATION                               (UIApplication.sharedApplication)

#define LTKEYWINDOW                                 (LTAPPLICATION.keyWindow)

#define LTROOTVC                                    (LTKEYWINDOW.rootViewController)

#define LTROOTVE                                    (LTROOTVC.view)

#define LTROOTPRESENTVC                             (LTROOTVC.presentedViewController ? : LTROOTVC)

#define LTROOTPRESENTVE                             (LTROOTPRESENTVC.view)


#pragma mark - 屏幕方向

#define LTBARORIENTATION                            (LTAPPLICATION.statusBarOrientation)

#define LTISLANDSCAPELEFT(ORIENTATION)              (ORIENTATION == UIInterfaceOrientationLandscapeLeft)

#define LTISLANDSCAPERIGHT(ORIENTATION)             (ORIENTATION == UIInterfaceOrientationLandscapeRight)

#define LTISPORTRAIT(ORIENTATION)                   (ORIENTATION == UIInterfaceOrientationPortrait)

#define LTISPORTRAITUPSIDEDOWN(ORIENTATION)         (ORIENTATION == UIInterfaceOrientationPortraitUpsideDown)

#define LTISBARPORTRAIT                             (LTISPORTRAIT(LTBARORIENTATION) || LTISPORTRAITUPSIDEDOWN(LTBARORIENTATION))

#define LTISBARLANDSCAPE                            (LTISLANDSCAPELEFT(LTBARORIENTATION) || LTISLANDSCAPERIGHT(LTBARORIENTATION))


#pragma mark - CGRect

#define LTORIGINX(RECT)                             (RECT.origin.x)

#define LTORIGINY(RECT)                             (RECT.origin.y)

#define LTSIZEWIDTH(RECT)                           (RECT.size.width)

#define LTSIZEHEIGHT(RECT)                          (RECT.size.height)


#pragma mark - Center

#define LTCENTERX(VIEW)                             (VIEW.center.x)

#define LTCENTERY(VIEW)                             (VIEW.center.y)


#pragma mark - UIScreen

#define LTMAINSCREEN                                (UIScreen.mainScreen)

#define LTSCREENBOUNDS                              (LTMAINSCREEN.bounds)

#define LTSCREENWIDTH                               (LTSIZEWIDTH(LTSCREENBOUNDS))

#define LTSCREENHEIGHT                              (LTSIZEHEIGHT(LTSCREENBOUNDS))


#pragma mark - 布局

#define LTAUTOFRAME(RECT)                           (LTISIOS8 || LTISBARPORTRAIT ? RECT : CGRectMake(LTORIGINY(RECT), LTORIGINX(RECT), LTSIZEHEIGHT(RECT), LTSIZEWIDTH(RECT)))

#define LTAUTOCENTER(POINT)                         (LTISIOS8 || LTISBARPORTRAIT ? POINT : CGPointMake(POINT.y, POINT.x))

#define LTROTATEFRAME(RECT)                         (CGRectMake(LTORIGINY(RECT), LTORIGINX(RECT), LTSIZEHEIGHT(RECT), LTSIZEWIDTH(RECT)))

#pragma mark - UI

#define LTRGBCOLOR(R, G, B, ALPHA)                  ([UIColor colorWithRed:R / 255.0f green:G / 255.0f blue:B / 255.0f alpha:ALPHA])

#define LTHEXCOLOR(HEX, ALPHA)                      ([UIColor colorWithRed:((float)((HEX & 0xFF0000) >> 16))/255.0 green:((float)((HEX & 0xFF00) >> 8))/255.0 blue:((float)(HEX & 0xFF))/255.0 alpha:ALPHA])

#define LTSYSTEMFONT(SIZE)                          ([UIFont systemFontOfSize:SIZE])

#define LTBOLDERFONT(SIZE)                          ([UIFont boldSystemFontOfSize:SIZE])

#pragma mark - RunLoop

#define LTCURRENTRUNLOOP                            (NSRunLoop.currentRunLoop)

#pragma mark - weak && strong

#define LTWEAKOBJECT(OBJECT)                        @try{}@finally{} __weak typeof(OBJECT) OBJECT##Weak = OBJECT

#define LTSTRONGOBJECT(OBJECT)                      @try{}@finally{} __strong typeof(OBJECT) OBJECT = OBJECT##Weak


#pragma mark - 其他

#define LTOPENURL(URL)                              ({\
                                                        if([LTAPPLICATION canOpenURL:URL])\
                                                        {\
                                                            [LTAPPLICATION openURL:URL];\
                                                        }\
                                                      })

#define mark - Bundle

#define LTMAINBUNDLE                                (NSBundle.mainBundle)

#define LTINFOPLIST(KEY)                            (LTMAINBUNDLE.infoDictionary[KEY])

#pragma mark - Date

#define LTNOWDATE                                   (NSDate.date)

#define LTNOWTIMESTAMP                              (LTNOWDATE.timeIntervalSince1970)

#define LTWEAKSECONDS                               (60 * 60 * 24 * 7)


#pragma mark - String

#define LTISSTRINGEQUAL(STRING1, STRING2)           ([STRING1 isEqualToString:STRING2])

#define LTISNUMSAME(STRING1, STRING2)               ([STRING1 compare:STRING2 options:NSNumericSearch] == NSOrderedSame)

#define LTISNUMASCEND(STRING1, STRING2)             ([STRING1 compare:STRING2 options:NSNumericSearch] == NSOrderedAscending)

#define LTISNUMDESEND(STRING1, STRING2)             ([STRING1 compare:STRING2 options:NSNumericSearch] == NSOrderedDescending)


#pragma mark - Range

#define LTRANGEFOUND(RANGE)                         (RANGE.location != NSNotFound && RANGE.length)

#define LTRANGENOTFOUND(RANGE)                      (RANGE.location == NSNotFound && !RANGE.length)

#endif /* LTQuickMacro_h */
