Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - DaCarSoft

#1
Con la salida de la beta "12" parece que se han implementado correctamente todas las mejoras y correcciones de bugs que envié a Gernot, como siempre en mi caso, enfocadas a iOS, especialmente iOS 7 y Xcode 5.

Algunos de los cambios (para quién le pueda interesar) son la corrección del sistema de giro de elementos propios de iOS, es decir: La pantalla de multitarea, las persianas del "Notification Center", la persiana del nuevo "Control Center", y los wrappers... todos ahora deben aparecer y funcionar en la orientación adecuada sin hacer nada, y con esto quiero decir "sin escribir código" para controlar el giro.

Esto no quiere decir que no haya que controlar las rotaciones de las imágenes que queramos mostrar desde GLBasic, necesitaremos SETORIENTATION igualmente, pero sin preocuparnos de la parte de elementos propios de iOS...

Por otro lado, también se respeta el bloqueo de giro que puede usar el usuario, ya sabéis, desde el icono del "candado" en los menús de iOS o en el botón lateral para quién lo tenga configurado. Si el usuario lo activa para bloquearlo, los elementos de iOS no serán girados tampoco desde nuestro programa GLBasic.

En cuanto pueda, publicaré un wrapper para obtener la orientación del dispositivo desde iOS. Algo así como un "GetiOSDeviceOrientation".   ;)

#2
Hi all!

I have a question rounding my mind  :S, related to a new project that I have to do, and I'm trying to suppose if it is possible to do directly from GLBasic or I need to use some other programming language:

I would like to open a high resolution picture (a JPEG of 1,3 megapixels, for example) from GLBasic and read every pixel from the picture to found where are located the pixels of a specific color (the red ones or RGB = #FF0000 for example).

I know, for example, that in Visual Basic you can do this by loading a picture in a control object like "image box" and read every individual pixel as you need, it does not matter if the image does not fit into screen, you can read pixels wich are not showed just on screen, these pixels may be hidden behind the limits of the control that could have scrolling bars.

But...   Is this possible in GLBasic??   Can I open in any way a full 1,3 Mpx JPEG at full resolution and read the colour from some pixels in a X,Y coordinate??

May be that I need a back buffer??

I was thinking about a possible way: To convert from JPEG to BMP and try to read pixels from the file directly as text...   Is that possible from GLBasic??  O_O

All suggestions will be highly appreciated...  :giveup:

Thanks in advance.


EDIT:   I will test with LOADSPRITE and GETPIXEL using high resolution pictures to know wich are the resolution limits for GLBasic, but I suppose these limits are low...    ??   I read in this forums some comments related to this limits some time ago, almost for iPhone/iPad...   I would like my solution could be cross platform.

??
#3
Tal y como se ha sugerido, abro este nuevo hilo y yo mismo copio el comentario desde el otro hilo (http://www.glbasic.com/forum/index.php?topic=9087.msg78062#msg78062) en donde nos hemos ido "off topic"...

He copiado los comentarios de los otros miembros yo mismo, para que nadie empiece a hablar entre comentarios rompiendo el orden sin querer...   No he incluido las citas o "quotes" completas porque creo que se leería peor...   

A continuación pongo el que creo que ha sido el primer comentario del tema, y mi respuesta:

Quote from: mentalthink on 2013-Apr-17
Yo no se mucho sobre universidades, pero a mi me da que esto es un poco como con el tema del 3D, ahora les ha dado por decir que la licenciatura o la carrera o como quieran, pero luego entrar en la industria no creo que sea tan sencillo, a parte conozco gente que curra o ha currado en empresas grandes y no es que hablen muy bien, en 3D y en videojuegos... Al parecer somos muchos para pocas sillas.



Cuánta razón tienes Mentalthink, se valoran demasiado los "títulos" para algunas cosas, pero a la hora de la verdad siempre es la misma historia...    Y me explico a continuación...       (sospecho que más de uno se va a sentir identificado con esto...)

Yo, me considero informático desde que tengo uso de razón.

Mi mejor "juguete" cuando era niño era un ZX Spectrum, con el que programaba "cosas" desde que tenía 8 años. He trabajado toda mi vida como informático. A los 18 en cuanto pude, empecé a trabajar y desde entonces (por suerte) no he parado...  (ahora tengo 33)...

Pero nunca, NUNCA, jamás, me he sentido suficientemente valorado ni por mis jefes, ni por mis clientes. NADIE sabe lo que es esto, ni quieren saberlo...     ya que no lo entienden...    no saben el esfuerzo que cuesta ser bueno en algo, y programar bien o la cantidad de tiempo y dinero que hay que dedicar a tu propia "autoformación" para no perder el hilo de los avances y dispositivos...   Porque nos gastamos una PA$TA en dispositivos simplemente para poder averiguar, entender y probar cómo funciona algo, cuando tenemos algún proyecto en mente, que rara vez se rentabiliza...

He montado servidores de archivos, servidores web, proxys, servidores virtualizados, con y sin SAIs, páginas web con gestores de contenidos y mil "florituras" (pensando en que se vean en todos los dispositivos móviles y navegadores), he hecho programas para PDAs, para PC...  Para iPhone, para iPad...   A medida, por encargo...   Por hobby...   He diseñado bases de datos complejísimas (creedme)...   He instalado redes incluso grapando cable por las paredes...   He conectado naves separadas más de 500 metros con antenas WiFi y puntos de acceso/repetidores...       He cargado escaleras arriba y abajo con pesados monitores Phillips de 21" de los de tubo de imagen...    He creado mis propias distribuciones de Linux hechas a medida para funcionar como Live-CDs...     He instalado Windows sin licencia (si, sí...   lo confieso sin escrúpulos) a gente que no valora que tal vez te estas "jugando el tipo" para que ellos se ahorren "X" dinero, porque además, todos sabíamos que por un producto así no merece la pena pagar (todos sabemos que a los de Micro$oft les venía bien que sus productos se extendieran como la pólvora aunque después los informáticos sintiéramos estrés y frustraciones cada vez que teníamos que formatear un equipo o "salvarle la vida" a la gente que no tenía copias de seguridad de los discos duros de sus servidores de empresa, o PCs repletos de fotos de "sus niños"), he limpiado miles y miles y miles y miles de virus, para que la gente pudiera salvar su colección de películas ilegalmente descargadas que jamás les dará tiempo a ver...   etc...   etc...   etc...

Pero...   a pesar de todo este trabajo "sucio" y "limpio", de "despacho" o de "campo"...   Y de considerarme "bueno" en lo que hago...   Sigo siendo igual de POBRE que hace 10 años, porque siempre he cobrado una miseria...   Y siempre he sufrido las consecuencias de discusiones absurdas en las que la otra persona no tiene ni p**ta idea de nada, pero le lleva a uno la contraria haciendo patente su ignorancia (que nadie más que uno mismo podrá apreciar), forzándome a deshacer y desperdiciar horas y horas (y horas...) de trabajo bien hecho, que en todo caso, nunca se llegan a cobrar al precio que realmente valen...  (Si es que se cobran...)

Pero mientras los informáticos simplemente "sobrevivimos"... un técnico de lavadoras cruza la puerta de una casa, cambia un trozo de manguera de una lavadora que pierde agua, y sin ningún conocimiento "avanzado" de electrónica, de la API de Windows, de C++ o del álgebra de Boole... le sopla al cliente 200 € (en dinero B, sin factura) y se va tan contento al domicilio del siguiente cliente para seguir cobrando bien, sin dolores de cabeza y con cara sonriente (que conste que no tengo nada en contra de los técnicos de lavadoras...  espero no encontrarme a los del sindicato de técnicos alzando las antorchas delante de la puerta de mi casa al asomarme por la ventana)

Conclusión:  Somos unos pringados, a los que nadie aprecia ni paga lo suficiente, pero nos encanta nuestro trabajo, y por eso precísamente no podemos dejarlo...   No queremos dejar de ser lo que somos y de hacer lo que hacemos cada día... Pero lamentablemente, al menos en España, la mentalidad debe cambiar, y mucho...    O habrá cada vez menos gente con vocación (y paciencia) trabajando en esto...  Y por lo tanto sólo quedarán "en pie" los incapaces de hacer las cosas bien...



P.D.:   Perdón por el testamento que he soltado...   
#4
Hi...

I'm translating today all my wrappers published under the spanish forum :P

This is a code that shows a little web view embedded into an alert...

I tried to make it pretty with the functions to make the rounded corners to the Web control...   using the Quartz core library.

Please, test it with care, because I wrote it so fast...

WARNING: I don't know If Apple may reject an App that uses this code, because it does not use illegal or undocumented functions, but uses an alert in a very strange way that bypasses the purpose of an alert...   XDDDDDDDDD

PLEASE, paste in your reply some photos to see the results, I have no time today to paste it myself...

Be careful also, the web showed by the wrapper should not contain any text control, or then you will see a keyboard that you can't use...

One more time, the code should be in a .mm file in your XCode project, please see my other codesnippet posts:

Code (glbasic) Select

#if defined (TARGET_OS_IPHONE)

// UIWEBALERT

//#import <UIKit/UIAlert.h>    // It is not needed to duplicate an import done before
#import <QuartzCore/QuartzCore.h>    // Needed libraries for the rounded corners

@interface GLBasicWebBoxer: NSObject <UIAlertViewDelegate>
{
    // Pointer declarations
    NSString* resValues;
    NSString* pTitle,* pURL,* pButtons;
}
@end

@implementation GLBasicWebBoxer

// Code that shows the alert from the main thread
- (void)showWebAlertCaller:(NSString*)cTitle andURL:(NSString*)cURL andButtons:(NSString*)cButtons
{
    // Obtaining the values from "showWebAlert"
    pTitle = [[NSString alloc] initWithString:cTitle];
    pURL = [[NSString alloc] initWithString:cURL];
    pButtons = [[NSString alloc] initWithString:cButtons];
    // "showWebAlert" call sending it to the main thread
    [self performSelectorOnMainThread:@selector(showWebAlert) withObject:nil waitUntilDone:NO];
}

- (void)showWebAlert
{
// View creation for the alert
    UIAlertView* alert = [[UIAlertView alloc] init];
alert.title = pTitle;
alert.message = @"\n\n\n\n\n\n\n\n\n\n\n\n";    // We need some space for the web in the alert XD
alert.delegate = self;
    // We need that the button with an index of 0 does not cancel the alert
    alert.cancelButtonIndex = -1;
// Buttons array creation from the values separated with "|"
NSArray* aButtons = [pButtons componentsSeparatedByString:@"|"];
    // Button creation from each value
for (NSString* iObject in aButtons){
[alert addButtonWithTitle:iObject];
}
   
// We need to create the control and adjust it to the Alert view
UIWebView* webview = [[UIWebView alloc] initWithFrame:CGRectMake(10, 40, 264, 254)];
    webview.scalesPageToFit = YES;   // You can change it if you don't need to shrink the page...
    // Rounded corners thanks to our friend CALayer
    [[webview layer] setCornerRadius:10];
    [webview setClipsToBounds:YES];
    // We can create a little black border to be freaks  XDDDD
    [[webview layer] setBorderColor:
     [[UIColor colorWithRed:0.00 green:0.00 blue:0.00 alpha:1] CGColor]];
    [[webview layer] setBorderWidth:1.00];
   
    // Addition of the control to the view
    [alert addSubview:webview];
    [webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:pURL]]];
    [webview release];
    webview = nil;



[alert show];
[alert release];
}

// We need to recover the values using "delegate" (= self) in the "showAlert"
- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
resValues = [[NSString alloc] initWithFormat:@"%d", buttonIndex];
}

// Code that obtains the value of the button pressed
- (void)getValues
{
    // We need the "NSData" to avoid possible errors related to "encodings" (all this code may not be needed... I have not tested it yet)
    NSData* tmpValuesEncoded = [[NSData alloc] init];
    // Conversión to a Windows Latin "encoding" avoiding not recognized chars using "allowLossyConversion"
    tmpValuesEncoded = [resValues dataUsingEncoding:NSWindowsCP1252StringEncoding allowLossyConversion:YES];
    // We now can use the string from "getValuesCaller"
    resValues = [[NSString alloc] initWithData:tmpValuesEncoded encoding:NSWindowsCP1252StringEncoding];
    // Liberar la memoria
    tmpValuesEncoded = nil;
}

// Obtaining the values from the pressed button
- (const char*)getValuesCaller
{
    // Was a button pressed?
    if (resValues != nil){
        // Calling to "getValues" in the main thread
        [self performSelectorOnMainThread:@selector(getValues) withObject:nil waitUntilDone:YES];
        // You can return the string from "getValues"
        return [resValues cStringUsingEncoding:NSWindowsCP1252StringEncoding];
        // Freeing memory
        [resValues release];
        resValues = nil;
        [pTitle release];
        pTitle = nil;
        [pURL release];
        pURL = nil;
        [pButtons release];
        pButtons = nil;
        [self release];
        [super dealloc];
    }
    else
    {
        // If a button was not pressed then...
        return "";
    }
}

@end

// Pointer for the wrapper
GLBasicWebBoxer* newWebAlert;



// External function creation
extern "C" void iOSWebBox(const char* cTitle, const char* cURL, const char* cButtons)
{
newWebAlert = [[GLBasicWebBoxer alloc] init];
    // Convert from "C" to "NSString" and showing the alert...
[newWebAlert showWebAlertCaller:[NSString stringWithCString:cTitle encoding:NSASCIIStringEncoding] andURL:[NSString stringWithCString:cURL encoding:NSASCIIStringEncoding] andButtons:[NSString stringWithCString:cButtons encoding:NSASCIIStringEncoding]];
}

// Function to use from GLBasic (symbol separated values are returned)
extern "C" const char* GetiOSWebBoxValues()
{
    // Now you can recover the button pressed value
return [newWebAlert getValuesCaller];
}

// END UIWEBALERT

#endif



Now from GLBasic:

Code (glbasic) Select


GLOBAL BOTONPULSADOWEBBOXER$

IMPORT "C" void iOSWebBox(const char*, const char*, const char*)

IMPORT "C" const char* GetiOSWebBoxValues()

GOSUB WebBox_iOS

PRINT BOTONPULSADOWEBBOXER$, 50, 100, TRUE

// Here we can use an IF to do something if certain button was pressed, and use (for example:) NETWEBEND to go to the real navigator...

SHOWSCREEN

SUB WebBox_iOS:

iOSWebBox("Title","http://www.glbasic.com","OK|Cancel")

LOCAL InstanteComienzo% = GETTIMERALL()

BOTONPULSADOWEBBOXER$ = ""
WHILE BOTONPULSADOWEBBOXER$ = ""
SLEEP 500
WHILE ABS(GETTIMERALL() - InstanteComienzo%) < 500
HIBERNATE
WEND

BOTONPULSADOWEBBOXER$ = GetiOSWebBoxValues()
WEND

ENDSUB




I hope that this code could be helpful  ;D

Please tell us the results and comment if all goes fine (or not)  :P


Regards.



#5
Hi again...


To continue with my "XCode-Snippets", I will publish a code that solves the problem related to the GLBasic screen orientation and the iOS dock-bar when you double-click the home button in the iPad. And I says iPad because in the iPhone that bar is ever in portrait mode XDDDDDD but this code also can be used in an iPhone, someone knows why? Please, try to use this code before the code to call from GLBasic to the keyboard snippet that I published a couple of minutes ago...   XDDDD

Lets go:

In a ".mm" that you have to put into your XCode project:

Code (glbasic) Select

#if defined (TARGET_OS_IPHONE)

// UIINTERFACEORIENTATION

extern "C" void iOSSetOrientation(const char* cOrientation) {
    // Force the statusbar orientation avoiding confusions related to the parameters' case used from GLBasic
    if (strncasecmp(cOrientation,"landscapeleft",strlen(cOrientation)) == 0) {
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft];
    }
    if (strncasecmp(cOrientation,"landscaperight",strlen(cOrientation)) == 0) {
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
    }
    if (strncasecmp(cOrientation,"portrait",strlen(cOrientation)) == 0) {
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
    }
    if (strncasecmp(cOrientation,"portraitupsidedown",strlen(cOrientation)) == 0) {
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortraitUpsideDown];
    }
}

// FIN UIINTERFACEORIENTATION

#endif


If someone have code in a  .mm file generated before then does not include the lines started with the # symbol

After, from GLBasic, you can do something like this:

Code (glbasic) Select


IMPORT "C" void iOSSetOrientation(const char*)

iOSSetOrientation("Portrait")

PRINT "PRESS HOME TWICE!!!",100,100

SHOWSCREEN
HIBERNATE
MOUSEWAIT

iOSSetOrientation("PortraitUpsideDown")

PRINT "PRESS HOME TWICE AGAIN!!!",100,100

SHOWSCREEN
HIBERNATE
MOUSEWAIT

iOSSetOrientation("LandscapeLeft")

PRINT "AND... PRESS TWO TIMES AGAIN!",100,100

SHOWSCREEN
HIBERNATE
MOUSEWAIT

iOSSetOrientation("LandscapeRight")

PRINT "¡¡¡ROLLING!!!!",100,100

SHOWSCREEN
HIBERNATE
MOUSEWAIT




With this you can rotate the GLBasic graphics, for example when you read the accelerometers values, and you can set the same orientation to iOS statusbar.

This code is ideal for use with the new rotation functions included in GLBasic 10.


Tell here your experience or questions...



Regards.
#6
Hello!

Some time ago, I started to create my own keyboard for iPhone/iPad...    (you can see at: http://www.glbasic.com/forum/index.php?topic=5747.0)

I wanted to obtain a solid way to make appear the native iOS keyboard, trying to found the best way to mix the appearances of GLBasic results and native iOS controls. I supposed that the best way was to use the Xcode's "UIAlert", with a native textbox into. I saw some solutions in this forums related to this way, but none was working well because it may crash if you do a second call to the same functions to make appears the keyboard two times or more...   or it may crash if you (for example) try to write some non english characters and return them...

Now, I think that the "wrapper" is finished and the code is as simple as it could be...  (I know that it could look scary, I know...)  :D

The code supports non english characters to be returned to GLBasic, several text boxes and buttons that may vary from the GLBasic's code, and in combination with another codesnippet related to the screen orientation that I will publish immediately, you can also change the orientation of the controls to make it appears in the right way if you need it.

Here is the code:


In a file with ".mm" extensión that we should drag and drop into our Xcode project generated by GLBasic, we add:
Code (glbasic) Select


#if defined (TARGET_OS_IPHONE)



// UIALERT

//#import <UIKit/UIAlert.h>    // We don't need to import something imported before in the project...

@interface GLBasicMessageBoxer: NSObject <UIAlertViewDelegate>
{
    // Pointer declarations for the common elements
    UITextField* txtObject;
    NSMutableArray* resObjects;
    NSString* resValues;
    NSString* pTitle,* pMessage,* pLabels,* pButtons;
}
@end

@implementation GLBasicMessageBoxer

// Call needed to throw the code that shows an alert in the main thread
- (void)showAlertCaller:(NSString*)cTitle andMessage:(NSString*)cMessage andLabels:(NSString*)cLabels andButtons:(NSString*)cButtons
{
    // Addition of the needed values to accessible pointers from "showAlert"
    pTitle = [[NSString alloc] initWithString:cTitle];
    pMessage = [[NSString alloc] initWithString:cMessage];
    pLabels = [[NSString alloc] initWithString:cLabels];
    pButtons = [[NSString alloc] initWithString:cButtons];
    // Llamada a "showAlert" enviándola al proceso principal
    [self performSelectorOnMainThread:@selector(showAlert) withObject:nil waitUntilDone:NO];
}
   
- (void)showAlert
{
// Alert's view creation
    UIAlertView* alert = [[UIAlertView alloc] init];
alert.title = pTitle;
alert.message = pMessage;
alert.delegate = self;
    // We need to force that the button with index 0 does not cancel the alert
    alert.cancelButtonIndex = -1;
// Creation of the button array using the separator "|"
NSArray* aButtons = [pButtons componentsSeparatedByString:@"|"];
    // Button creation
for (NSString* iObject in aButtons){
[alert addButtonWithTitle:iObject];
}
// Text controls array creation from the values separated by "|" from GLBasic
if (pLabels != @"") {
double iPos = 70.0;
NSArray* aLabels = [pLabels componentsSeparatedByString:@"|"];
        resObjects = [[NSMutableArray alloc] init];
        // Text control creation ensuring a not "(null)" value with .text = @""
for (NSString* iObject in aLabels){
txtObject = [[UITextField alloc] init];
txtObject.frame = CGRectMake(12.0, iPos, 260.0, 25.0);
            txtObject.text = @"";
txtObject.placeholder = iObject;
txtObject.backgroundColor = [UIColor whiteColor];
txtObject.clearButtonMode = UITextFieldViewModeWhileEditing;
txtObject.keyboardType = UIKeyboardTypeAlphabet;
txtObject.keyboardAppearance = UIKeyboardAppearanceAlert;
txtObject.autocapitalizationType = UITextAutocapitalizationTypeNone;
txtObject.autocorrectionType = UITextAutocorrectionTypeNo;
txtObject.borderStyle = UITextBorderStyleLine;
            // We need to put the focus in this text control if it is the first
if ([aLabels indexOfObject:iObject] == 0) {
[txtObject becomeFirstResponder];
                // The keyboard appears magically when the focus is received by a control that can handle text
}
            // We need to calculate the value for the "top" coordinate of each text control
iPos = iPos + 30.0;
// Each control should be "linked" to the mutable array
            [resObjects addObject:txtObject];
            // XCode supports direct addition of text controls to an Alert, but Apple has not documented it and you can't use it for App store...
            // The workaround is to add "subviews" to an Alert with the needed controls
[alert addSubview:txtObject];
            [txtObject release];
            txtObject = nil;

}

}

[alert show];
[alert release];
}

// We need to obtain the button tapped using the "delegate" (= self) property in the "showAlert"
- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
resValues = [[NSString alloc] initWithFormat:@"%d", buttonIndex];
}

// We need to obtain and modify the values parsed from GLBasic to make a string with values separated with "|"
- (void)getValues
{
    // We need to add the button pressed index to the string that will contain all the values needed
    for (UITextField* iObject in resObjects){
        // Addition of the text control to a NSMutableString
        NSMutableString* tmpObjectValue = [[NSMutableString alloc] initWithString:iObject.text];
        // We need to replace the separator character if the user try to use it...
        [tmpObjectValue replaceOccurrencesOfString:@"|" withString:@"!" options:0 range:NSMakeRange(0, [tmpObjectValue length])];
        // All the values should be added to the same string
        resValues = [resValues stringByAppendingFormat:@"|%@", tmpObjectValue];
        // We need to free memory?
        [tmpObjectValue release];
        tmpObjectValue = nil;
    }
    // Creation of a "NSData" temo pointer that will contain the obtained values but after the process that adjust the "encodings"
    NSData* tmpValuesEncoded = [[NSData alloc] init];
    // String conversion to a Windows Latin "encoding" avoiding the not recognized chars using "allowLossyConversion"
    tmpValuesEncoded = [resValues dataUsingEncoding:NSWindowsCP1252StringEncoding allowLossyConversion:YES];
    // We need to use the correct "encoding" when "getValuesCaller" will return the string
    resValues = [[NSString alloc] initWithData:tmpValuesEncoded encoding:NSWindowsCP1252StringEncoding];
    // Freeing memory
    tmpValuesEncoded = nil;
}

// We need to obtain the pressed button values from the main thread
- (const char*)getValuesCaller
{
    // Was a button pressed before?
    if (resValues != nil){
        // Call to "getValues" from the main thread
        [self performSelectorOnMainThread:@selector(getValues) withObject:nil waitUntilDone:YES];
        // We need to return the values generated from "getValues"
        return [resValues cStringUsingEncoding:NSWindowsCP1252StringEncoding];
        // We need to free memory?
        [resObjects release];
        resObjects = nil;
        [resValues release];
        resValues = nil;
        [pTitle release];
        pTitle = nil;
        [pMessage release];
        pMessage = nil;
        [pLabels release];
        pLabels = nil;
        [pButtons release];
        pButtons = nil;
        [self release];
        [super dealloc];
    }
    else
    {
        // If none of the buttons was pressed we should return a "" string
        return "";
    }
}

@end

// Pointer for "GLBasicMessageBoxer" declaration
GLBasicMessageBoxer* newAlert;



// External function for the use from GLBasic (The "labels" and "buttons" values may contain several values separated with "$")
extern "C" void iOSMessageBox(const char* cTitle, const char* cMessage, const char* cLabels, const char* cButtons)
{
newAlert = [[GLBasicMessageBoxer alloc] init];
    // Conversion from "C" to "NSString"
[newAlert showAlertCaller:[NSString stringWithCString:cTitle encoding:NSASCIIStringEncoding] andMessage:[NSString stringWithCString:cMessage encoding:NSASCIIStringEncoding] andLabels:[NSString stringWithCString:cLabels encoding:NSASCIIStringEncoding] andButtons:[NSString stringWithCString:cButtons encoding:NSASCIIStringEncoding]];
}

// External function for GLBasic (The returned values are separated by "$")
extern "C" const char* GetiOSMessageBoxValues()
{
    // You obtain the índex for the pressed button first, and the text wrote in each control after...
return [newAlert getValuesCaller];
}

// FIN UIALERT



#endif



Now, from GLBasic we can do something like this:

Code (glbasic) Select


IMPORT "C" void iOSMessageBox(const char*,const char*, const char*, const char*)
IMPORT "C" const char* GetiOSMessageBoxValues()

// Please, let me this time to do not translate the vars of my code...   :P
GLOBAL MENSAJE$

// Remember: the symbol is "|" now, but before in old versions of my code was "$"...
iOSMessageBox("Título","Mensaje" + CHR$(0xD) + CHR$(0xD) + CHR$(0xD) + CHR$(0xD), "Esto es una prueba ó ü Ñ |:P", "Send|Cancel")

LOCAL InstanteComienzo% = GETTIMERALL()

MENSAJE$ = ""
WHILE MENSAJE$ = ""
SLEEP 500
WHILE ABS(GETTIMERALL() - InstanteComienzo%) < 500
HIBERNATE
WEND

MENSAJE$ = GetiOSMessageBoxValues()
WEND

PRINT MENSAJE$, 100, 100

SHOWSCREEN
HIBERNATE
MOUSEWAIT



iOSMessageBox("Title","Message" + CHR$(0xD) + CHR$(0xD), "This is a second test", "OK|Cancel")   
// You should use the trick of CHR$(0xD) or "\n" to make the height of the alert grows...  (example: "Message\n\n")

InstanteComienzo% = GETTIMERALL()

MENSAJE$ = ""
WHILE MENSAJE$ = ""
SLEEP 500
WHILE ABS(GETTIMERALL() - InstanteComienzo%) < 500
HIBERNATE
WEND

MENSAJE$ = GetiOSMessageBoxValues()
WEND

PRINT MENSAJE$, 100, 100

SHOWSCREEN
HIBERNATE
MOUSEWAIT




As you can see, the values are sent as symbol separated strings and you can use it easily from GLBasic...  :)    also GetiOSMessageBoxValues returns as first parameter the button index pressed in the "alert".

You can try to put more or less values separated with "|" in the GLBasic call to iOSMessageBox    ;)

We can obtain a simple "alert" doing something like this:

Code (glbasic) Select


iOSMessageBox("Title","Test string", "", "OK")





Now...   someone can paste some photos of the results???



Regards
#7
Buenas...

Aquí os dejo otro Wrapper de los míos, esta vez para mostrar una pequeña web dentro de un alert   :P

Ya que alguién (OMADAN) pidió algo así en un post, he decidido mostrados cómo hacerlo, intentando además hacerlo bonito redondeando el borde del control Web y demás...   PROBADLO bien, repitiendo la muestra de la "pequeña" web varias veces repetidas, porque lo he hecho muy rápido, la verdad...   y no me ha dado tiempo a probarlo del todo.

CUIDADO: Tengo mis dudas acerca de que Apple admita esto cuando revisen la App, en principio no hay nada de código ilegal, pero nunca se sabe si Apple podría decidir que esto es una aberración muy retorcida del uso de sus "UIAlerts"    XDDDDDDD

OS PIDO UN FAVOR, que alguien coloque aquí una captura de pantalla del resultado, ya que a mí tampoco me ha dado tiempo...

Os recuerdo que el siguiente código hay que colocarlo en un archivo con extensión ".mm" que arrastréis hasta vuestro proyecto en XCode generado por GLBasic:

Code (glbasic) Select

#if defined (TARGET_OS_IPHONE)

// UIWEBALERT

//#import <UIKit/UIAlert.h>    // No es necesario duplicar la importación hecha con anterioridad
#import <QuartzCore/QuartzCore.h>    // Importamos las librerías necesarias para el redondeo de esquinas

@interface GLBasicWebBoxer: NSObject <UIAlertViewDelegate>
{
    // Declaración de los punteros para los elementos comunes
    NSString* resValues;
    NSString* pTitle,* pURL,* pButtons;
}
@end

@implementation GLBasicWebBoxer

// Llamada necesaria para llamar al código que muestra el Alert en el proceso principal
- (void)showWebAlertCaller:(NSString*)cTitle andURL:(NSString*)cURL andButtons:(NSString*)cButtons
{
    // Introducción de los valores pasados como parámetro en los punteros accesibles por "showAlert"
    pTitle = [[NSString alloc] initWithString:cTitle];
    pURL = [[NSString alloc] initWithString:cURL];
    pButtons = [[NSString alloc] initWithString:cButtons];
    // Llamada a "showWebAlert" enviándola al proceso principal
    [self performSelectorOnMainThread:@selector(showWebAlert) withObject:nil waitUntilDone:NO];
}

- (void)showWebAlert
{
// Creación de la vista para el Alert
    UIAlertView* alert = [[UIAlertView alloc] init];
alert.title = pTitle;
alert.message = @"\n\n\n\n\n\n\n\n\n\n\n\n";
alert.delegate = self;
    // Anulación de la asignación de la función de cancelar al botón con índice 0
    alert.cancelButtonIndex = -1;
// Creación de la matriz de botones introduciendo valores según los parámetros pasados separados por "|"
NSArray* aButtons = [pButtons componentsSeparatedByString:@"|"];
    // Creación de cada botón a partir de cada valor de la matriz
for (NSString* iObject in aButtons){
[alert addButtonWithTitle:iObject];
}
   
// Creación del control web ajustado a la vista del alert
UIWebView* webview = [[UIWebView alloc] initWithFrame:CGRectMake(10, 40, 264, 254)];
    webview.scalesPageToFit = YES;
    // Redondeo de esquinas usando la propiedad CALayer
    [[webview layer] setCornerRadius:10];
    [webview setClipsToBounds:YES];
    // Creamos un borde coloreado para el control
    [[webview layer] setBorderColor:
     [[UIColor colorWithRed:0.00 green:0.00 blue:0.00 alpha:1] CGColor]];
    [[webview layer] setBorderWidth:1.00];
   
    // Agregamos el control a la vista
    [alert addSubview:webview];
    [webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:pURL]]];
    [webview release];
    webview = nil;



[alert show];
[alert release];
}

// Recogida del botón pulsado en la memoria mediante la propiedad "delegate" (= self) asignada en "showAlert"
- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
resValues = [[NSString alloc] initWithFormat:@"%d", buttonIndex];
}

// Código que obtiene y trata los valores para construir el resultado
- (void)getValues
{
    // Creación de un puntero "NSData" temporal para albergar los valores obtenidos transformados para evitar errores por "encodings"
    NSData* tmpValuesEncoded = [[NSData alloc] init];
    // Conversión de la cadena obtenida a un "encoding" Windows Latin obviando los caracteres no reconocidos mediante "allowLossyConversion"
    tmpValuesEncoded = [resValues dataUsingEncoding:NSWindowsCP1252StringEncoding allowLossyConversion:YES];
    // Reintroducción de la cadena final convertida al "encoding" adecuado para que pueda devolverse desde "getValuesCaller"
    resValues = [[NSString alloc] initWithData:tmpValuesEncoded encoding:NSWindowsCP1252StringEncoding];
    // Liberar la memoria
    tmpValuesEncoded = nil;
}

// Obtención de los valores del botón pulsado y texto introducido en los controles recuperando los valores desde el proceso principal
- (const char*)getValuesCaller
{
    // Comprobación de si se ha pulsado un botón del Alert
    if (resValues != nil){
        // Llamada a "getValues" en el proceso principal
        [self performSelectorOnMainThread:@selector(getValues) withObject:nil waitUntilDone:YES];
        // Devolvemos el valor de la cadena preparada desde "getValues"
        return [resValues cStringUsingEncoding:NSWindowsCP1252StringEncoding];
        // Liberar la memoria
        [resValues release];
        resValues = nil;
        [pTitle release];
        pTitle = nil;
        [pURL release];
        pURL = nil;
        [pButtons release];
        pButtons = nil;
        [self release];
        [super dealloc];
    }
    else
    {
        // Si no se ha pulsado ningún botón se devuelve una cadena vacía
        return "";
    }
}

@end

// Creación del puntero para las funciones contenidas en "GLBasicMessageBoxer" a usar cada vez que se requiera un Alert
GLBasicWebBoxer* newWebAlert;



// Creación de función "externalizada" a usar desde GLBasic (el parámetro "buttons" pueden contener varios valores separados con "|")
extern "C" void iOSWebBox(const char* cTitle, const char* cURL, const char* cButtons)
{
newWebAlert = [[GLBasicWebBoxer alloc] init];
    // Conversión de tipos "C" a "NSString" al recuperar los parámetros enviados desde GLBasic y lanzado del Alert
[newWebAlert showWebAlertCaller:[NSString stringWithCString:cTitle encoding:NSASCIIStringEncoding] andURL:[NSString stringWithCString:cURL encoding:NSASCIIStringEncoding] andButtons:[NSString stringWithCString:cButtons encoding:NSASCIIStringEncoding]];
}

// Creación de la función "externalizada" a usar desde GLBasic
extern "C" const char* GetiOSWebBoxValues()
{
    // Se recupera el índice del botón pulsado
return [newWebAlert getValuesCaller];
}

// FIN UIWEBALERT

#endif



Ahora vamos con el código GLBasic:

Quote

GLOBAL BOTONPULSADOWEBBOXER$
   
IMPORT "C" void iOSWebBox(const char*, const char*, const char*)
   
IMPORT "C" const char* GetiOSWebBoxValues()

GOSUB WebBox_iOS

PRINT BOTONPULSADOWEBBOXER$, 50, 100, TRUE

// Aquí podemos colocar una sentencia IF para analizar cual de los botones se ha pulsado, y decidir si (por ejemplo) llamar a NETWEBEND

SHOWSCREEN
   
SUB WebBox_iOS:

   iOSWebBox("Título","http://www.glbasic.com","Aceptar|Cancelar")
   
   LOCAL InstanteComienzo% = GETTIMERALL()

   BOTONPULSADOWEBBOXER$ = ""
   WHILE BOTONPULSADOWEBBOXER$ = ""
      SLEEP 500
      WHILE ABS(GETTIMERALL() - InstanteComienzo%) < 500
         HIBERNATE
      WEND

      BOTONPULSADOWEBBOXER$ = GetiOSWebBoxValues()
   WEND

ENDSUB



Si alguien tiene alguna duda que me lo comente y si es necesario se lo explico más despacio  ;D


#8
Igual ya lo conoceis, pero hoy he visto en el AppStore la App "Spectaculator", que emula a los Spectrum de 48K y 128K...

Permite programar desde el emulador y guardar el "snapshot" (no sé si los de Apple se habrán dado cuenta de esto...).

No he podido echarle un vistazo a fondo, pero debe ser fácil añadirle nuevas ROMs, supongo que es necesario el Jailbreak y el iFile (por ejemplo) para ello.

¡Espero que esto os sirva!
#9
Hola de nuevo...


Para continuar con mi ración de "XCode-Snippets", os publico un código que soluciona el problema (detectado por Hark0 hace ya tiempo ;)) de la independencia de las imágenes generadas desde GLBasic y la orientación de la barra que aparece en iOS al hacer doble click sobre el botón home en el iPad. Y digo iPad porque en iPhone la barra siempre aparece en el mismo sitio XDDDDDD aunque el código también puede servir para iPhone, ¿a alguien se le ocurre alguna utilidad? ¿Nadie? Os doy una pista: Probad a usar las siguientes llamadas GLBasic ántes de utilizar las llamadas del código que publiqué para mostrar Alerts/Teclado en iOS...

De nuevo, vamos al grano:

En un archivo ".mm" que debeis colocar en vuestro proyecto XCode:

Code (glbasic) Select

#if defined (TARGET_OS_IPHONE)

// UIINTERFACEORIENTATION

extern "C" void iOSSetOrientation(const char* cOrientation) {
    // Forzar la orientación de la barra de estado de iOS a partir del parámetro pasado evitando distinguir entre mayúsculas y minúsculas
    if (strncasecmp(cOrientation,"landscapeleft",strlen(cOrientation)) == 0) {
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft];
    }
    if (strncasecmp(cOrientation,"landscaperight",strlen(cOrientation)) == 0) {
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
    }
    if (strncasecmp(cOrientation,"portrait",strlen(cOrientation)) == 0) {
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
    }
    if (strncasecmp(cOrientation,"portraitupsidedown",strlen(cOrientation)) == 0) {
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortraitUpsideDown];
    }
}

// FIN UIINTERFACEORIENTATION

#endif


Si alguien ya tiene código en un archivo .mm puede obviar el incluir las líneas que comienzan con #

Después, desde GLBasic, podríamos hacer algo como esto, por ejemplo:

Code (glbasic) Select


IMPORT "C" void iOSSetOrientation(const char*)

iOSSetOrientation("Portrait")

PRINT "PULSA AHORA EL BOTÓN HOME DOS VECES",100,100

SHOWSCREEN
HIBERNATE
MOUSEWAIT

iOSSetOrientation("PortraitUpsideDown")

PRINT "PULSA OTRA VEZ EL BOTÓN HOME DOS VECES",100,100

SHOWSCREEN
HIBERNATE
MOUSEWAIT

iOSSetOrientation("LandscapeLeft")

PRINT "VENGA, DALE OTRA VEZ DOS CLICKS",100,100

SHOWSCREEN
HIBERNATE
MOUSEWAIT

iOSSetOrientation("LandscapeRight")

PRINT "¡¡¡CENTRIFUGANDOOO!!!!",100,100

SHOWSCREEN
HIBERNATE
MOUSEWAIT




Con esto, lo que conseguimos es que si giramos nuestros gráficos desde GLBasic, a partir de los valores devueltos por los acelerómetros, podemos hacer coincidir nuestra orientación con la que "seteamos" o forzamos en iOS...

Como veis, además evito distinguir entre mayúsculas y minúsculas al pasar el parámetro desde GLBasic, para facilitar las cosas al programar.

Esto parece el complemento ideal para las nuevas funciones de rotación que parece que incluirá Gernot en las próximas versiones finales de GLBasic (gracias por la noticia Jordi  :)).


Ya me contareis que tal...


#10
¡Hola a todos!

Para celebrar que por fin he puesto un avatar en mi perfil...   :D  y animado al ver las últimas publicaciones (como la de iAds) y el buen "rollo" de este foro en español... he decidido hacer público este código, y así estrenar mi avatar por todo lo alto   :booze:   aunque, igual me ha quedado un poco grande   :S

Creo que cuando este tipo de "codesnippets" se hacen públicos pueden ser una gran ayuda para todos, porque así podremos avanzar más rápidamente con nuestros proyectos individuales y eliminar poco a poco las barreras que GLBasic pueda tener bajo iOS :P


Cuando empecé a escribir el código no tenía demasiados conocimientos de XCode, pero decidí que podría ser muy útil aprender lo necesario del lenguaje original de Apple para poder cubrir cualquier necesidad (fuese cual fuese) y llegar donde GLBasic no pudiera llegar, complementándolo...

Así que puede que alguno de vosotros ya se haya topado con este hilo: http://www.glbasic.com/forum/index.php?topic=5747.0
Lo arranqué para ver si alguien me echaba "un cable"...     pero al final nadie pudo ayudarme demasiado con los problemas más importantes (bajo mi punto de vista)  :'(  y me pareció que el código que alguien presentó no era muy "definitivo" o correcto del todo...
Añadiendo el hecho de que (y no es que me importen esas cosas) todo el mérito parecía al final de otros...     :blink:

En fin, no me enrollo más, vamos al grano:

En un archivo con extensión ".mm" que debemos arrastrar hasta nuestro proyecto en XCode (si es que no tenemos uno ya) agregamos:
Code (glbasic) Select


#if defined (TARGET_OS_IPHONE)



// UIALERT

//#import <UIKit/UIAlert.h>    // No es necesario duplicar la importación hecha con anterioridad

@interface GLBasicMessageBoxer: NSObject <UIAlertViewDelegate>
{
    // Declaración de los punteros para los elementos comunes
    UITextField* txtObject;
    NSMutableArray* resObjects;
    NSString* resValues;
    NSString* pTitle,* pMessage,* pLabels,* pButtons;
}
@end

@implementation GLBasicMessageBoxer

// Llamada necesaria para llamar al código que muestra el Alert en el proceso principal
- (void)showAlertCaller:(NSString*)cTitle andMessage:(NSString*)cMessage andLabels:(NSString*)cLabels andButtons:(NSString*)cButtons
{
    // Introducción de los valores pasados como parámetro punteros accesibles por "showAlert"
    pTitle = [[NSString alloc] initWithString:cTitle];
    pMessage = [[NSString alloc] initWithString:cMessage];
    pLabels = [[NSString alloc] initWithString:cLabels];
    pButtons = [[NSString alloc] initWithString:cButtons];
    // Llamada a "showAlert" enviándola al proceso principal
    [self performSelectorOnMainThread:@selector(showAlert) withObject:nil waitUntilDone:NO];
}
   
- (void)showAlert
{
// Creación de la vista para el Alert
    UIAlertView* alert = [[UIAlertView alloc] init];
alert.title = pTitle;
alert.message = pMessage;
alert.delegate = self;
    // Anulación de la asignación de la función de cancelar al botón con índice 0
    alert.cancelButtonIndex = -1;
// Creación de la matriz de botones introduciendo valores según los parámetros pasados separados por "|"
NSArray* aButtons = [pButtons componentsSeparatedByString:@"|"];
    // Creación de cada botón a partir de cada valor de la matriz
for (NSString* iObject in aButtons){
[alert addButtonWithTitle:iObject];
}
// Creación de la matriz de controles de texto introduciendo valores según los parámetros pasados separados por "|"
if (pLabels != @"") {
double iPos = 70.0;
NSArray* aLabels = [pLabels componentsSeparatedByString:@"|"];
        resObjects = [[NSMutableArray alloc] init];
        // Creación de cada control de texto con las propiedades adecuadas asegurando que no devuelve un valor "(null)" mediante .text = @""
for (NSString* iObject in aLabels){
txtObject = [[UITextField alloc] init];
txtObject.frame = CGRectMake(12.0, iPos, 260.0, 25.0);
            txtObject.text = @"";
txtObject.placeholder = iObject;
txtObject.backgroundColor = [UIColor whiteColor];
txtObject.clearButtonMode = UITextFieldViewModeWhileEditing;
txtObject.keyboardType = UIKeyboardTypeAlphabet;
txtObject.keyboardAppearance = UIKeyboardAppearanceAlert;
txtObject.autocapitalizationType = UITextAutocapitalizationTypeNone;
txtObject.autocorrectionType = UITextAutocorrectionTypeNo;
txtObject.borderStyle = UITextBorderStyleLine;
            // Colocación del foco si es el primer control creado para introducción de texto
if ([aLabels indexOfObject:iObject] == 0) {
[txtObject becomeFirstResponder];
                // El teclado aparece automáticamente al colocar el foco en un control de texto
}
            // Aumentar el valor de la variable que controla la coordenada de posición del "top" de cada control de texto
iPos = iPos + 30.0;
// Asociación de cada control a la matriz mutable
            [resObjects addObject:txtObject];
            // XCode soporta añadir controles de texto directamente a un Alert pero Apple no permite su uso directo al no estar documentado
            // Para poder imitar el comportamiento pueden agregarse "subvistas" al Alert e introducir los controles necesarios en ellas
[alert addSubview:txtObject];
            [txtObject release];
            txtObject = nil;

}

}

[alert show];
[alert release];
}

// Recogida del botón pulsado en la memoria mediante la propiedad "delegate" (= self) asignada en "showAlert"
- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
resValues = [[NSString alloc] initWithFormat:@"%d", buttonIndex];
}

// Código que obtiene y trata los valores para construir el resultado mediante valores separados por "|"
- (void)getValues
{
    // Agregado a la cadena del botón pulsado de los valores de cada control de texto en el Alert
    for (UITextField* iObject in resObjects){
        // Insertar el texto recogido del control en un NSMutableString
        NSMutableString* tmpObjectValue = [[NSMutableString alloc] initWithString:iObject.text];
        // Reemplazar el caracter usado en el código como separador de valores si el usuario lo ha introducido en los controles
        [tmpObjectValue replaceOccurrencesOfString:@"|" withString:@"!" options:0 range:NSMakeRange(0, [tmpObjectValue length])];
        // Agregar el valor obtenido al contenido anterior de la memoria
        resValues = [resValues stringByAppendingFormat:@"|%@", tmpObjectValue];
        // Liberar la memoria
        [tmpObjectValue release];
        tmpObjectValue = nil;
    }
    // Creación de otro puntero "NSData" temporal para albergar los valores obtenidos transformados para evitar errores por "encodings"
    NSData* tmpValuesEncoded = [[NSData alloc] init];
    // Conversión de la cadena obtenida a un "encoding" Windows Latin obviando los caracteres no reconocidos mediante "allowLossyConversion"
    tmpValuesEncoded = [resValues dataUsingEncoding:NSWindowsCP1252StringEncoding allowLossyConversion:YES];
    // Reintroducción de la cadena final convertida al "encoding" adecuado para que pueda devolverse desde "getValuesCaller"
    resValues = [[NSString alloc] initWithData:tmpValuesEncoded encoding:NSWindowsCP1252StringEncoding];
    // Liberar la memoria
    tmpValuesEncoded = nil;
}

// Obtención de los valores del botón pulsado y texto introducido en los controles recuperando los valores desde el proceso principal
- (const char*)getValuesCaller
{
    // Comprobación de si se ha pulsado un botón del Alert
    if (resValues != nil){
        // Llamada a "getValues" en el proceso principal
        [self performSelectorOnMainThread:@selector(getValues) withObject:nil waitUntilDone:YES];
        // Devolvemos el valor de la cadena preparada desde "getValues"
        return [resValues cStringUsingEncoding:NSWindowsCP1252StringEncoding];
        // Liberar la memoria
        [resObjects release];
        resObjects = nil;
        [resValues release];
        resValues = nil;
        [pTitle release];
        pTitle = nil;
        [pMessage release];
        pMessage = nil;
        [pLabels release];
        pLabels = nil;
        [pButtons release];
        pButtons = nil;
        [self release];
        [super dealloc];
    }
    else
    {
        // Si no se ha pulsado ningún botón se devuelve una cadena vacía
        return "";
    }
}

@end

// Creación del puntero para las funciones contenidas en "GLBasicMessageBoxer" a usar cada vez que se requiera un Alert
GLBasicMessageBoxer* newAlert;



// Creación de función "externalizada" a usar desde GLBasic (los parámetros "labels" y "buttons" pueden contener varios valores separados con "$")
extern "C" void iOSMessageBox(const char* cTitle, const char* cMessage, const char* cLabels, const char* cButtons)
{
newAlert = [[GLBasicMessageBoxer alloc] init];
    // Conversión de tipos "C" a "NSString" al recuperar los parámetros enviados desde GLBasic y lanzado del Alert
[newAlert showAlertCaller:[NSString stringWithCString:cTitle encoding:NSASCIIStringEncoding] andMessage:[NSString stringWithCString:cMessage encoding:NSASCIIStringEncoding] andLabels:[NSString stringWithCString:cLabels encoding:NSASCIIStringEncoding] andButtons:[NSString stringWithCString:cButtons encoding:NSASCIIStringEncoding]];
}

// Creación de la función "externalizada" a usar desde GLBasic (los parámetros devueltos son valores separados con "$")
extern "C" const char* GetiOSMessageBoxValues()
{
    // Se recuperan en primer lugar el índice de botón pulsado y a continuación los textos introducidos en los controles generados
return [newAlert getValuesCaller];
}

// FIN UIALERT



#endif



Después, desde GLBasic, podríamos hacer algo como esto:

Code (glbasic) Select


IMPORT "C" void iOSMessageBox(const char*,const char*, const char*, const char*)
IMPORT "C" const char* GetiOSMessageBoxValues()

GLOBAL MENSAJE$

// El nuevo símbolo de separación para los parámetros a pasar a la función es la "tubería", antes era $, en mi código anterior...
iOSMessageBox("Título","Mensaje" + CHR$(0xD) + CHR$(0xD) + CHR$(0xD) + CHR$(0xD), "Esto es una prueba  ü Ñ |:P", "Aceptar|Cancelar")

LOCAL InstanteComienzo% = GETTIMERALL()

MENSAJE$ = ""
WHILE MENSAJE$ = ""
SLEEP 500
WHILE ABS(GETTIMERALL() - InstanteComienzo%) < 500
HIBERNATE
WEND

MENSAJE$ = GetiOSMessageBoxValues()
WEND

PRINT MENSAJE$, 100, 100

SHOWSCREEN
HIBERNATE
MOUSEWAIT



iOSMessageBox("Título","Mensaje" + CHR$(0xD) + CHR$(0xD), "Esto es otra prueba", "Aceptar|Cancelar")

InstanteComienzo% = GETTIMERALL()

MENSAJE$ = ""
WHILE MENSAJE$ = ""
SLEEP 500
WHILE ABS(GETTIMERALL() - InstanteComienzo%) < 500
HIBERNATE
WEND

MENSAJE$ = GetiOSMessageBoxValues()
WEND

PRINT MENSAJE$, 100, 100

SHOWSCREEN
HIBERNATE
MOUSEWAIT




Como vereis, las funciones envían y recogen los valores como una cadena de valores separados por "|" (tubería), que desde GLBasic es muy fácil tratar...  :)     además GetiOSMessageBoxValues devuelve como primer parámetro el índice del botón pulsado en el "alert".

También es totalmente parametrizable en cuanto a botones y cantidad de casillas de texto, probad a introducir más o menos valores separados por "|" en iOSMessageBox    ;)

Así, podemos conseguir un simple "alert" desde GLBasic haciendo algo como esto:

Code (glbasic) Select


iOSMessageBox("Título","Mensaje de prueba", "", "Aceptar")



Y bueno...   si alguien tiene alguna duda que lo pregunte por aquí y estaré encantado de hacer cualquier aclaración...

Tengo planeadas muchas "ampliaciones" al código a partir de aquí, como por ejemplo hacer aparecer el teclado, y recoger los caracteres, sin necesidad de un alert...  aunque si alguien se atreve con ello ántes que yo...   :D


Si alguien lo va probando me encantaría que posteara que tal le ha ido...

Y ya... si alguien que utilice éste código quiere simplemente mencionarme de pasada en los "agradecimientos" de los créditos de su juego...   Hago una fiesta, vamos...    XDDDDDDDDDDDD


Weno, ahí queda eso, ánimo con vuestro código!!!!


-David-
#11
Hello!

After the reading of several posts in this forums, I found that many people were searching (like me) a way to obtain data using the native iOS keyboard   :S

I was trying the untested code from Trucidare (http://pastebin.com/vLcTxCX5), but it didn't work "as is" for me   :'(

As I need a way for the user to input data (usernames mostly), I was trying and thinking harder to obtain the correct source code to show an alert box on screen, expand the native iOS keyboard and wait for the user input.

And the good news are: It works!!!!   but there are also bad news: The working is not totally OK.

Its to say: I can't obtain a string longer than 8 characters (the string appears corrupt if the user input is longer) and I can't show Spanish characters like "á" or "Ñ" in the alert messages or titles...

I'm not a newbie in programming but I'm a newbie in XCode and GLBasic, and I remember only a bit of C/C++.

Someone could help???  Gernot???  Trucidare???    =D    It is near of completion...     :P

This is the code:

in the XCode project I added the next lines to a .mm file:
Code (glbasic) Select

#if defined (TARGET_OS_IPHONE)
#import <UIKit/UIAlert.h>



@interface GLBasicMessageBoxer: NSObject <UIAlertViewDelegate>
{
UITextField* txtValue;
const char* resString;
const char* resButton;
}
- (void)showAlert:(NSString*)pTitle andMessage:(NSString*)pMessage andLabel:(NSString*)pLabel;
- (const char*)getValue;
@end

@implementation GLBasicMessageBoxer

- (void)showAlert:(NSString*)pTitle andMessage:(NSString*)pMessage andLabel:(NSString*)pLabel
{
UIAlertView* alert = [[UIAlertView alloc] init];
alert.title = pTitle;
alert.message = pMessage;
alert.delegate = self;
[alert addButtonWithTitle:@"No"];
[alert addButtonWithTitle:@"Yes"];

//[alert addTextFieldWithValue:@"" label:@"T1"];    ---> This do not pass the App Store review because it is undocumented
//[alert addTextFieldWithValue:@"" label:@"T2"];    ---> This do not pass the App Store review because it is undocumented
//txtValue = [alert textFieldAtIndex:0];   

txtValue = [[UITextField alloc] init];
txtValue.frame = CGRectMake(12.0, 70.0, 260.0, 25.0);
txtValue.placeholder = pLabel;
txtValue.backgroundColor = [UIColor whiteColor];
txtValue.clearButtonMode = UITextFieldViewModeWhileEditing;
txtValue.keyboardType = UIKeyboardTypeAlphabet;
txtValue.keyboardAppearance = UIKeyboardAppearanceAlert;
txtValue.autocapitalizationType = UITextAutocapitalizationTypeNone;
txtValue.autocorrectionType = UITextAutocorrectionTypeNo;
[txtValue becomeFirstResponder];

[alert addSubview:txtValue];

[alert show];
//[alert release];
}

- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch(buttonIndex)
{         
case 0:
break;         
case 1:
resButton = "1";
resString = [txtValue.text UTF8String];
break;     
}
}

- (const char*)getValue
{
if (resButton == "1"){
return resString;
}
else
{
return "";
}
}

@end

GLBasicMessageBoxer* newAlert;

extern "C" void iOSMessageBox(const char* pTitle, const char* pMessage, const char* pLabel)
{
newAlert = [[GLBasicMessageBoxer alloc]init];
[newAlert showAlert:[NSString stringWithUTF8String:pTitle] andMessage:[NSString stringWithUTF8String:pMessage] andLabel:[NSString stringWithUTF8String:pLabel]];
}

extern "C" const char* GetiOSMessageBoxValues()
{
return [newAlert getValue];
}



#endif


and from GLBasic I can use this code:
Code (glbasic) Select

IMPORT "C" void iOSMessageBox(const char*,const char*, const char*)

IMPORT "C" const char* GetiOSMessageBoxValues()

iOSMessageBox("Title12345678","Text12345678" + CHR$(0xD) + CHR$(0xD), "Example")

GLOBAL MESSAGE$

WHILE MESSAGE$ = ""
SLEEP 500
MESSAGE$ = GetiOSMessageBoxValues()
WEND

PRINT MESSAGE$, 100, 100
SHOWSCREEN


My next steps would be to convert in parameters the number of buttons, text of each button, number of text boxes, content of the label of each text box... to return the index of the button pressed...   but before I need to obtain the correct string from the UITextField and use characters of languages different than english (may be some thing related to the UTF8/ASCII format or may be that I have to use roman codepages...)  :rant:

Any ideas???

Thanks in advance, hope this helps someone!