![]() |
AppEasy Core SDK
1.5.0
Cross platform mobile and desktop app and game development SDK - The easy way to make apps
|
00001 // 00002 // 00003 // AppEasy SDK - Cross Platform Multi-purpose Game and App Engine 00004 // 00005 // Developed by Matthew Hopwood of Pocketeers Limited - www.pocketeers.co.uk 00006 // 00007 // For updates, tutorials and more details check out www.appeasymobile.com 00008 // 00009 // This code is provided free of charge and without any warranty whatsoever. You must ensure that this whole notice is present in all files and derivatives, so the reader knows its origin. 00010 // If you use this SDK in your product then please ensure that you credit AppEasy's usage appropriately. Please see www.appeasymobile.com for licensing details and support 00011 // 00012 // 00013 00014 #if !defined(_CZ_ADS_VIEW_H_) 00015 #define _CZ_ADS_VIEW_H_ 00016 00017 #include "CzUtil.h" 00018 #include "CzHttp.h" 00019 #include "CzImage.h" 00020 #include "CzSprite.h" 00021 #include "CzTime.h" 00022 #include "CzAds.h" 00023 #include "CzBitmapSprite.h" 00024 00025 #define CZ_ADS_VIEW (CzAdsView::getInstance()) 00026 00027 class CzScene; 00028 class CzAdsViewAnimator; 00029 00030 // 00031 // 00032 // CzAdsViewData - The CzAdsViewData structure contains data used to display a single ad uhit 00033 // 00034 // 00035 struct CzAdsViewData 00036 { 00037 CzIVec2 Position; // Position of ad on screem 00038 float Scale; // Scale of the ad 00039 float Angle; // Scale of the ad 00040 bool Visible; // Ad visibility 00041 CzColour Colour; // Colour of ad 00042 CzList<CzAdsViewAnimator*> Animators; // Attached animators will animate the ad 00043 CzAds::eAdsError Error; // Contains error code if any if ad not received 00044 00045 CzAd* Ad; // Ad that this view should draw 00046 CzBitmapSprite* AdSprite; // Sprite used by the ad view to display the ad 00047 bool Tapped; 00048 CzIVec2 tv[4]; // Transformed vertices 00049 00050 CzAdsViewData(); 00051 virtual ~CzAdsViewData(); 00052 }; 00053 00054 // 00055 // 00056 // CzAdsView - The CzAdsView class is responsible for collecting ads, rendering them, detecting clicks and launching the ad URL 00057 // 00058 // 00059 class CzAdsView 00060 { 00061 public: 00062 CDEFINE_SINGLETON(CzAdsView) 00063 00064 // Properties 00065 protected: 00066 int NewAdInterval; // The number of seconds between collecting new ads (minimum is 5 seconds) 00067 CzAds::eAdsError MinError; // Minimum allowed error before displaying an ad 00068 CzAdsViewData AdData[CZ_MAX_CACHED_ADS]; 00069 int NumAdsVisible; // number of ads visible 00070 bool Visible; // Ad visibility 00071 bool Looped; // Loops animations if true 00072 CzAds::eAdProvider AdProvider; // Ad provider used for automated ad collection 00073 public: 00074 void setVisible(bool visible) { Visible = visible; } 00075 bool isVisible() const { return Visible; } 00076 void setVisible(int index, bool visible) { AdData[index].Visible = visible; } 00077 bool isVisible(int index) const { return AdData[index].Visible; } 00078 void setPosition(int index, int x, int y) { AdData[index].Position.x = x; AdData[index].Position.y = y; } 00079 CzIVec2& getPosition(int index) { return AdData[index].Position; } 00080 void setScale(int index, float scale) { AdData[index].Scale = scale; } 00081 float getScale(int index) const { return AdData[index].Scale; } 00082 void setAngle(int index, float angle) { AdData[index].Angle = angle; } 00083 float getAngle(int index) const { return AdData[index].Angle; } 00084 void setColour(int index, int r, int g, int b, int a) { AdData[index].Colour.r = r; AdData[index].Colour.g = g; AdData[index].Colour.b = b; AdData[index].Colour.a = a;} 00085 void addAnimator(int index, CzAdsViewAnimator* animator) { AdData[index].Animators.push_back(animator); } 00086 void setNumAdsVisible(int count) { NumAdsVisible = count; } 00087 int getNumAdsVisible() const { return NumAdsVisible; } 00088 void setAllowHouseAds(bool allow) { if (allow) MinError = CzAds::ErrorHouseAd; else MinError = CzAds::ErrorNone; } 00089 void setNewAdInterval(int interval); 00090 CzAdsViewData* getAdViewData(int index) { return &AdData[index]; } 00091 void setLooped(bool looped) { Looped = looped; } 00092 void setAdProvider(CzAds::eAdProvider ad_provider) { AdProvider = ad_provider; } 00093 00094 // Properties end 00095 00096 protected: 00097 bool PreviousTouch; 00098 CzAdsViewData* PrevTappedAd; 00099 CzTimer NewAdTimer; // Used to time new ad collection 00100 00101 void Transform(); 00102 CzAdsViewData* getOldestAdSlot(); 00103 00104 public: 00105 virtual bool Init(const char* id); // Initialises the Ads view system (returns true if ads are supported) 00106 virtual void Release(); // Releases data used by the Ads view system 00107 virtual void Update(float dt = 1.0f); // Updates the Ads view system, called every frame 00108 virtual void Draw(CzScene* scene = NULL); // Renders the ads view 00109 00110 // Utility 00111 void RequestNewAd(CzAds::eAdProvider ad_provider, bool text_ads = false); // Forcesthe collection of a new ad 00112 void ResetAllAnims(); // Resets all ad slot animations 00113 void ResetAnims(CzAdsViewData* data); // Resets ad slot animations 00114 00115 // Internal 00116 00117 }; 00118 00119 00120 00121 #endif // _CZ_ADS_VIEW_H_