Just a quick post - I've been playing with some plugin's with a view to extending the UIKit one and I thought someone might find the following code useful.
It add's an animated UIActivityIndicator to the root view which you can use to show that your app is busy (ie dealing with a UrlLoader request).
You need to add the following code to UIKit.mm
//----------------------------------------------------------------------------------------------
static bool busyActive = false;
static int showBusyIcon(lua_State* L)
{
static UIActivityIndicatorView *myBusy = NULL;
UIViewController* controller = g_getRootViewController();
UIView* rootView = controller.view;
bool show = lua_toboolean(L,1);
lua_Number lx = lua_tonumber(L,2);
lua_Number ly = lua_tonumber(L,3);
// NSLog(<a href="https://forum.gideros.rocks/profile/Show%20Busy%20Icon%20%25d%2C%25d%20%28%25s%29" rel="nofollow">@Show Busy Icon %d,%d (%s)</a>,(int)lx,(int)ly,show==true?"show":"hide"); // So far so good! 8-)
if(show)
{
if(!busyActive)
{
busyActive = true;
if((lx == 0) && (ly == 0)) { lx = 160; ly = 240; } // default to center
myBusy = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
myBusy.center = CGPointMake(lx,ly);
myBusy.hidesWhenStopped = NO;
[rootView addSubview:myBusy];
[myBusy startAnimating];
}
}
else
{
if(busyActive)
{
busyActive = false;
[myBusy stopAnimating];
[myBusy removeFromSuperview];
[myBusy dealloc];
myBusy = NULL;
}
}
return 0;
} |
And then in the function "loader" add the following line after the 4 lua_pushcfunction() calls
// Add in my simple busy icon element!
lua_pushcfunction(L, showBusyIcon); lua_setglobal(L, "showBusyIcon"); busyActive = false; // Assume off to start! |
To use from within Lua simply call it like so
showBusyIcon(true,x,y) -- display the busy icon at the specified position (default 160,240 if x & y not specified)
showBusyIcon(false) -- remove the busy icon from the display |
Feel free to add feedback or (ab)use as you see fit.
Anyone fancy doing an Android version?
WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
#MakeABetterGame! "Never give up, Never
NEVER give up!" -
Winston Churchill
Comments
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
She said she will review my changes and merge it tomorrow.
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
I modified the implementation a bit to match the other UIKit elements
Where you create the object then set the position after.
You can set White, White Large or Gray and I added a setColor method
local activity = ActivityIndicator.new("White Large")
activity:setPosition(135,200)
activity:setColor(1.0,0,0,1.0) --red
addToRootView(activity)
Likes: chipster123
Thanks for sharing!
does your version include the work from @ianchia? On Github
Also i was thinking that an example file showing the possibilities + a few screenshots in your original posts would be great to get more downloads and feedback.
I's sad if this doesn't get as much attention as possible.
@SimpleLoop - no worries, I'd have probably implemented it like that if I'd known how to I think your way is better, I just needed the function and it was my first attempt, I'll be sure to look at your version to see how to do it properly for next time
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
@techDojo thanks . I just copied the way all the others were written but I'm sure @Caroline will spot some mistakes as it is was the first plugin I have done anything with in Gideros.
I have to say the way plugins are made is brilliant, very easy to do once you wrap your head around all the lua binding stuff.
1. Changed uikit.mm to accept button.new() as being "Rounded Rect" by
default, in case people are already using it that way.
2. Project demonstrates label:setFont()
3. Project includes Gideros Studio icon for demonstrating ImageView.
4. Project demonstrates ImageView
5. Project demonstrates ActivityIndicator.
I didn't check out TableView, as I need at some time to refresh myself on what the problems that I came across it were. I seem to remember that simple TableViews were OK, but if you wanted to add views to rows, then garbage collection becomes a problem. I think, but could be wrong, it is because the view gets released, but the view binder doesn't.
Yes, plugins are great, but if you take a couple of months away from them, beware 8-}!
@techDojo - I haven't much of a clue with github either - and it didn't occur to me that you might be dissing me .
Likes: gorkem, techdojo
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
I'm new to Git/GitHub, and unsure of the best way to put forth these diffs for consideration, so, here they are...:
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
1) Slider -- pass in arg to have continuous value sent or final value after the slider stops
2) set the alpha value for a labels BGColor
3) set the alpha value for a labels TextColor
Hopefully, these will be useful for others and can be incorporated in the github version.
Note: I'm a novice at iOS development and Object-C, so someone with a better understanding should take a look at the below diff. The changes work in my Gideros code, so I think its fine.
I've now added the shadowColor, shadowOffset and textAlignment parameters as well. I've added in the number of lines, but have to figure out why this line:
[(UILabel*)uiView sizeToFit];
is not working (it is commented out in the current code base). Currently, it resets the label o a single line. I think it has to do with the UIView not having a width setting, but not sure.
If I get it working, I'll post up a new diff.
Thanks again!
this is the function I have to turn it on and off.
Any help appreciated.
In Cocoa Touch Objective C, if I have a function (pseudo code):
Show Activity indicator
Do a ton of stuff
Hide Activity indicator
Then the Activity indicator will never show.
If you were writing in Objective C, then you would need to do this:
Show Activity Indicator
Call a second function with the ton of stuff using performSelector:withObject:afterDelay: and Hide the Activity Indicator at the end of that function.
This is because the device display is only updated at the end of a "run loop".
Anything within a single function (or functions called from that function) is performed in a single run loop. So if you want the Activity Indicator to show, then you need to perform the ton of stuff on a second run loop.
Did that make sense?
http://stackoverflow.com/questions/8600125/activity-indicator-not-showing-up?rq=1
Most of the answers suggest using performSelectorInBackground:withObject: but I haven't tried background threading with Gideros Studio.
performSelector:withObject:afterDelay: will work in foreground and block user input. (I use afterDelay of 0.0 seconds, if I remember correctly, and it's also possible you don't need to use afterDelay at all.)
My hack workaround is to set a timer in Gideros that calls the function. In Pseudo code:
Show Activity Indicator
set Timer.new(1,1) to do a bunch of stuff
on TIMER_COMPLETE Hide Activity Indicator
Seems to work OK.
Obviously it can take a "little" longer (up to 16ms depending on the frame rate) to complete the task, but that's generally not a problem as the task already takes long enough to require the indicator and an extra 16ms isn't that much of an issue
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill