Isgl3dGLUILabel left align

23 views
Skip to first unread message

Miguel

unread,
Nov 16, 2013, 11:39:35 AM11/16/13
to isg...@googlegroups.com
i'm trying to left align a Isgl3dGLUILabel in a Isgl3dBasic2DView orthogonal view.

There problem is that, when text is largest than a few characters, text moves away from the x position.

In the example below, if the text change to @"NNNNNNNNNN", the text will move away from 0 position.

    Isgl3dGLUILabel * label = [Isgl3dGLUILabel labelWithText:@"N" fontName:[UIFont preferredFontForTextStyle:UIFontTextStyleBody].fontName   fontSize:25];
        [label setX:0 andY:0];
        label.centerX = false;
        [self.scene addChild:label];


leftFix property don't fix this problem.

Its clearly a lib bug, but i don't know isgl3d to correct it
version is 1.3.0-unstable

Problem should be on the setText method.

- (void)setText:(NSString *)text {
    if (text && ![text isEqualToString:_text]) {
        [_text release];
        _text = [text retain];
       
        if (_useCharacterSet) {
            // Remove all previous character nodes
            [self clearAll];
           
            unsigned int width = 0;
            unsigned int offset = 0;
            unsigned int height = 0;
           
            // Iterate over characters
            for (int i = 0; i < text.length; i++) {
                NSRange range = {i, 1};
                NSString * character = [text substringWithRange:range];
               
                // See if character mesh and texture exist already, create if not
                Isgl3dGLCharacter * glCharacter = [_characters objectForKey:character];
                if (!glCharacter) {
                    Isgl3dTextureMaterial * textureMaterial = [Isgl3dTextureMaterial materialWithText:character fontName:_fontName fontSize:_size];
                    Isgl3dGLMesh * mesh = [[Isgl3dPrimitiveFactory sharedInstance] UILabelMeshWithWidth:textureMaterial.width height:textureMaterial.height contentSize:textureMaterial.contentSize];
                   
                    glCharacter = [[Isgl3dGLCharacter alloc] init];
                    glCharacter.mesh = mesh;
                    glCharacter.material = textureMaterial;
                   
                    //characterNode = [self createNodeWithMesh:mesh andMaterial:textureMaterial];
                    [_characters setObject:[glCharacter autorelease] forKey:character];
                }

                // Re-use mesh node if enough exist, otherwise create a new one
                Isgl3dMeshNode * characterNode;
                if ([_characterNodes count] <= i) {
                    characterNode = [Isgl3dMeshNode nodeWithMesh:nil andMaterial:nil];
                    characterNode.lightingEnabled = NO;
                    [_characterNodes addObject:characterNode];
                }
                characterNode = [_characterNodes objectAtIndex:i];
               
                // Set the character mesh and material
                characterNode.mesh = glCharacter.mesh;
                characterNode.material = glCharacter.material;
                [self addChild:characterNode];

                // Calculate the dimensions of the text
                Isgl3dTextureMaterial * textureMaterial = glCharacter.material;

                if (i > 0) {
                    offset += 0.5 * textureMaterial.contentSize.width;
                }
               
                // Offset the character
                characterNode.x = offset;
                width += textureMaterial.contentSize.width;
                offset += 0.5 * textureMaterial.contentSize.width;
               
                // Store the maximum height of the text
                unsigned int texHeight = textureMaterial.contentSize.height;
                height = height > texHeight ? height : texHeight;
               
                // Add character child
                [self addChild:characterNode];
            }

            [self setWidth:width andHeight:height];
           
        } else {
            Isgl3dTextureMaterial * textureMaterial = [Isgl3dTextureMaterial materialWithText:_text fontName:_fontName fontSize:_size];
            Isgl3dGLMesh * mesh = [[Isgl3dPrimitiveFactory sharedInstance] UILabelMeshWithWidth:textureMaterial.width height:textureMaterial.height contentSize:textureMaterial.contentSize];
       
            [self setMesh:mesh];
            [self setMaterial:textureMaterial];
            [self setWidth:textureMaterial.contentSize.width andHeight:textureMaterial.contentSize.height];
           
        }
       
    }
   
}


Reply all
Reply to author
Forward
0 new messages