Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
UIKit plugin example - Page 3 - Gideros Forum

UIKit plugin example

13»

Comments

  • Hi Caroline,
    Thanks for your reply~
    I think I understand the steps which you mentioned, because I can run in Other Plugin in iOS Simulator smoothly.

    I have added uikit.mm into the GiderosiPhonePlayer project but it gives me a warning of "gideros.h file not found " I have attached the screen shot too.

    Thanks

    Kit
    Screen Shot 2012-03-26 at 5.24.59 PM.png
    626 x 433 - 133K
  • The gideros.h file might not be included in your project. I can't remember if I had to do this.

    But you can find it in the subfolder somewhere - I think it's in the Plugins folder in the GiderosiPhonePlayer project folder. Just drag it into Xcode.

    You might have to repeat for all the other ones it complains about.

    This is what my Xcode looks like:
    Screen Shot 2012-03-26 at 7.52.16 PM.png
    278 x 597 - 62K
  • atilimatilim Maintainer
    Hi, You should also put .mm file near to "gideros.h" file (at Plugins directory)
  • Thanks Caroline, I make it finally and they are the things what I'm looking for and Thank MikeHart for sharing this plugin.

    Actually, I just switched from Corona and found there are many bugs and some people suggested to use Gideros. Feel like Gideros will be my final tool to create an app~

  • Hi, You should also put .mm file near to "gideros.h" file (at Plugins directory)
    ? is that a requirement for some reason? I just realised that on disk I've got my plugins in the Classes folder, while my .h files are in the Plugins folder.

    In fact my uikit.mm is not even in the same iPhoneGiderosPlayer folder - it's currently located in a completely different folder (I'm not working on it at the moment, so it's not in the working folder).
  • atilimatilim Maintainer
    If you already added the header files (as you did), then it's not required.
  • Oh *-:), so it's either add the header files, or put the plugin .mm in the correct place, so you don't have to add the header files :).
  • louislouis Member
    edited April 2012
    hi
    @Caroline

    Recently ,I use gideros ,but now I have some trouble with it.
    Actually, I don't develop game using gideros, I would like to develop app with UIKIT plugin,
    1.how to use textfield implement multi-text-input ,

    2.UrlLoader post method how to upload image file ? post content type is The Multipart Content-Type "multipart/form-data",W3C rfc1341,
    url http://www.w3.org/Protocols/rfc1341/7_2_Multipart.html
    local loader = UrlLoader.new(self.exchange_url,UrlLoader.POST,bodydata)
    3.hide status bar method is invalid,now the method is always hidden,I fix it:
    static int hideStatusBar(lua_State* L)
    {
    	bool show = lua_toboolean(L, 1);
        [[UIApplication sharedApplication] setStatusBarHidden:show withAnimation: UIStatusBarAnimationNone];
    //	[[UIApplication sharedApplication] setStatusBarHidden:true withAnimation: UIStatusBarAnimationNone];	
        return 0;
    }
    4.want to implement UINavigationController and UINavigationController
  • Hi, @louis

    MikeHart's UIKit plugin is a first release - in my opinion I don't think that it is ready for a full-on UIKit app. One of the outstanding problems is memory management - that the plugin does not allow hierarchies of views. A simple thing like adding a view to the application's root view is OK, but adding a view to that view becomes difficult.

    (It is possible to add subviews to views by uncommenting the {"addView", addView}, line on line 254, but when the subview is removed from the view, if I remember correctly, the associated View class is not removed from memory. I have been experimenting with ways to get around this, by having the binding on the Lua side rather than the C side, as Lua has automatic garbage collection, but my skills are not good enough to go public with this. I would welcome a forum discussion on how to do this though.)

    4. For that reason, you can't currently implement UINavigationController, as that requires a subview hierarchy.

    3. Thank you for the fix :) - I've updated it on github.

    2. I don't know what you mean by this.

    1. The UIKit plugin only has UITextField implemented. Multi-line is done with UITextView. It shouldn't be too hard to implement UITextView, using UITextField as a pattern.



  • @Caroline,

    with the scrollview, adding other elements (which are views anyway) works perfect so your statement is not totally correct.

    About the statusbar! What was changed in between that the bar was always hidden?
  • @MikeHart - it's only when you come to remove the views that it's problematic - adding them is fine. So yes, if the app has static views, then it works great.

    There was a debugging statement left in there - not sure how that happened. It was possibly me when I was messing around with stuff. Sorry.
  • No need to be sorry for. I was just wandering why there was a problem with the statusbar. It is a long time since I had work with/on that plugin but before the statusbar could be hidden and showing perfectly.
  • louislouis Member
    edited April 2012
    hi @Caroline,
    Thank you for your answers.
    I found the UIImageView is not implement, so I want to implement it, I add some code about UIImage in UIKit.mm, the following code
    //----------------------------------------------------------------------------------------------
    #pragma mark ---- UIImage ----
     
    class Image : public View
    {
    public:
    	Image(lua_State* L) : View(L)
    	{
    		selectorToEvent.type = <a href="/profile/onImageClick">@onImageClick</a>;		
    	}
     
    	virtual ~Image()
    	{
    	}
     
    	virtual void create(NSString *file_name)	
    	{
            UIImageView* image=[[UIImageView alloc] initWithImage:
                                [UIImage imageNamed:file_name]];
     
    		[image retain];
     
    		uiView = image;
    	}
     
    	void setImage(NSString* file_name)
    	{
            [(UIImageView*)uiView setImage:[UIImage imageNamed:file_name]];
    	}
     
    };
     
    //----------------------------------------------------------------------------------------------
    class ImageBinder
    {
    public:
    	ImageBinder(lua_State* L);
     
    private:
    	static int create(lua_State* L);
    	static int destruct(lua_State* L);
    	static int setImage(lua_State* L);
    };
     
    ImageBinder::ImageBinder(lua_State* L)
    {
    	const luaL_Reg functionlist[] = {
    		{"setImage", setImage},
    		{NULL, NULL},
    	};
     
    	g_createClass(L, "Image", "View", create, destruct, functionlist);	
    }
     
    int ImageBinder::create(lua_State* L)
    {
    	Image* image = new Image(L);
        const char* file_name = luaL_checkstring(L, 1);
     
    	image->create([NSString stringWithUTF8String:file_name]);
     
    	g_pushInstance(L, "Image", image->object());
     
    	setObject(L, image);
     
    	return 1;
    }
     
    int ImageBinder::destruct(lua_State* L)
    {
    	void* ptr = *(void**)lua_touserdata(L, 1);
    	GReferenced* object = static_cast<GReferenced*>(ptr);
    	Image* image = static_cast<Image*>(object->proxy());
     
    	image->unref(); 
     
    	return 0;
    }
     
    int ImageBinder::setImage(lua_State* L)
    {
    	GReferenced* imageObject = static_cast<GReferenced*>(g_getInstance(L, "Image", 1));
    	Image* image = static_cast<Image*>(imageObject->proxy());
     
    	const char* file_name = luaL_checkstring(L, 2);
    	image->setImage([NSString stringWithUTF8String:file_name]);
    	return 0;
    }
    //------end UIImage
    in main.lua, I test it,
    lua code beblow:
    require 'ui'
     
     
    image=Image.new("green-plus-sign-md.png")
    image.setPosition(0,0)
    image.setSize(200,200)
    addToRootView(image)
    but execute failed....
    output error is :
    main.lua:2: attempt to index global 'Image' (a nil value)
    stack traceback:
    	main.lua:2: in main chunk
    my question is :

    I did wrong or what I do less?
  • louislouis Member
    edited April 2012
    @Caroline
    Hi, @louis

    2.UrlLoader post method how to upload image file ? post content type is The Multipart Content-Type "multipart/form-data",W3C rfc1341,
    url http://www.w3.org/Protocols/rfc1341/7_2_Multipart.html

    2. I don't know what you mean by this.


    Usually http post body data is string , such as a = 1 & b = 2 & c = 3, but sometimes we'll upload a binary file, such as sending a tweet with a picture, the http the post body t data necessary to use the multipart / form-data encoding mode, this is w3 specification, RFC-1341




  • @louis, I may be missing something, but it seems to me that, in the create() method, you're leaking memory (the Cocoa way): you shouldn't need to "retain" the view, as it was created using an "alloc/init" combination, so the additional retain would prevent it to be dealloc'ed at a later release.
  • @louis

    Two things:

    1. You're trying to access a Lua variable called "Image", which does not exist. All you have to do is add it in the loader() function:
        .....
        ToolbarBinder toolbarBinder(L);
        ScrollViewBinder scrollViewBinder(L);
        TableViewBinder tableViewBinder(L);
     
        --Add this line:
        ImageBinder imageBinder(L);
        .....
    2. In your main.lua, change the . to : as in:
    image:setPosition(0,0)
    image:setSize(200,200)
    You'll also need to send the correct path of the image, which is in the player's Resources folder, and I can't remember for the moment how to access it. I thought it was "|R|filename", but that doesn't seem to be working.


    About the "retain" issue. I remember thinking the same thing a while ago, because all the UIKit items do it. But I *think* I eventually went "Oh - that's why", but my memory is cloudy.
  • @louis - sorry, don't know the answer to the post method question - you could open a separate topic for it, in case people miss it in here.
  • louislouis Member
    edited April 2012
    @Caroline ,


    You'll also need to send the correct path of the image, which is in the player's Resources folder, and I can't remember for the moment how to access it. I thought it was "|R|filename", but that doesn't seem to be working.


    About the "retain" issue. I remember thinking the same thing a while ago, because all the UIKit items do it. But I *think* I eventually went "Oh - that's why", but my memory is cloudy.
    as you said,I have changed that,I also changed the resource fold problem
    image->create([NSString stringWithUTF8String:g_pathForFile(file_name)]);
    but still failed,picture doesn't show in root view...

    :-(
    how to solve it? 8->
    zip
    zip
    uikit.mm.zip
    11K
  • CarolineCaroline Guru
    edited April 2012
    @louis - You should change the filename in main.lua, not in the plugin. The plugin should just take the string that is given from Lua.
  • @louis - also, to be consistent, I think the names of the classes ought to be ImageView and ImageViewBinder, as there is a UIKit class called UIImage as well as UIImageView. It's a bit of work though, so you might not want to.
  • louislouis Member
    edited April 2012
    @Caroline ,
    @louis - also, to be consistent, I think the names of the classes ought to be ImageView and ImageViewBinder, as there is a UIKit class called UIImage as well as UIImageView. It's a bit of work though, so you might not want to.
    haaaa,just now ,I got it .
    	virtual void create(NSString *file_name)	
    	{
            NSLog(file_name);
     
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:
                                    CGRectMake(10.0f, 10.0f, 200.0f, 150.0f)];
     
            UIImage *img = [[[UIImage alloc] initWithContentsOfFile:file_name] autorelease];
            //[subview setImage:[UIImage imageNamed:<a href="/profile/green-plus-sign-md.png">@green-plus-sign-md.png</a>]];
            [imageView setImage:img];
     
            //UIImage* image=[UIImage imageNamed:file_name];
            //UIImageView* imageView=[[UIImageView alloc]init];
            //[imageView setImage:image];
     
            //[image retain];
    		//[imageView retain];
     
    		uiView = imageView;
    	}
     
    	void setImage(NSString* file_name)
    	{
            UIImage *img = [[[UIImage alloc] initWithContentsOfFile:file_name] autorelease];
            [(UIImageView*)uiView setImage:img];
    	}
    zip
    zip
    uikit.mm.zip
    12K
  • CarolineCaroline Guru
    edited April 2012
    @louis - Edited because it's late and I got it wrong again :).

    I think you have it now then?

    You do need the "|R|filename.png" in main.lua to get the right path for the file.
  • louislouis Member
    edited April 2012
    @Caroline-
    @louis - Edited because it's late and I got it wrong again :).

    I think you have it now then?

    You do need the "|R|filename.png" in main.lua to get the right path for the file.
    int ImageBinder::create(lua_State* L)
    {
    	Image* image = new Image(L);
        const char* file_name = luaL_checkstring(L, 1);
     
     
    	image->create([NSString stringWithUTF8String:g_pathForFile(file_name)]);
     
    	g_pushInstance(L, "Image", image->object());
     
    	setObject(L, image);
     
    	return 1;
    }
    use method :g_pathForFile(file_name)
    it auto convent image path

    in my app fold :
    : ~/Library/Application Support/iPhone Simulator/4.3.2/Applications/3C1DF625-D9A4-4AE4-8E20-29ECB828B63B/Documents/TestUIImage/resource

    -documents
    md5.txt
    -resource
    --green-plus-sign-md.png
    --main.lua
    -temporary

    attach image is my test app snapshot:)

    Likes: Caroline

    屏幕快照 2012-04-15 下午10.12.32.png
    402 x 736 - 166K
    +1 -1 (+1 / -0 ) Share on Facebook
Sign In or Register to comment.