diff --git a/isgl3d.xcodeproj/project.pbxproj b/isgl3d.xcodeproj/project.pbxproj index 41c628a..ada42c2 100644 --- a/isgl3d.xcodeproj/project.pbxproj +++ b/isgl3d.xcodeproj/project.pbxproj @@ -1520,6 +1520,7 @@ 8BDBA1D714CCFABE00BAEB8A /* PVRTShader.h in Headers */ = {isa = PBXBuildFile; fileRef = 8BDBA1C714CCFABE00BAEB8A /* PVRTShader.h */; }; 8BDBA1D814CCFABE00BAEB8A /* PVRTTextureAPI.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8BDBA1C814CCFABE00BAEB8A /* PVRTTextureAPI.cpp */; }; 8BDBA1D914CCFABE00BAEB8A /* PVRTTextureAPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 8BDBA1C914CCFABE00BAEB8A /* PVRTTextureAPI.h */; }; + A0BE2C3F16220D6600ECA56E /* tex.png in Resources */ = {isa = PBXBuildFile; fileRef = 4E6075CB1521C9C40045AEFA /* tex.png */; }; AACBBE4A0F95108600F1A2B1 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AACBBE490F95108600F1A2B1 /* Foundation.framework */; }; /* End PBXBuildFile section */ @@ -6183,6 +6184,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + A0BE2C3F16220D6600ECA56E /* tex.png in Resources */, 17A95EF7132575A700D06694 /* capture.fsh in Resources */, 17A95EF8132575A700D06694 /* capture.vsh in Resources */, 17A95EF9132575A700D06694 /* generic.fsh in Resources */, diff --git a/isgl3d/primitives/Isgl3dPlane.h b/isgl3d/primitives/Isgl3dPlane.h index 5f1870f..fe704de 100644 --- a/isgl3d/primitives/Isgl3dPlane.h +++ b/isgl3d/primitives/Isgl3dPlane.h @@ -30,6 +30,7 @@ /** * The Isgl3dPlane constructs a planar mesh centered in the x-y plane, with z equal to 0. + * Optional offset parameters can be used to "move" the plane around in the x-y plane. * * An Isgl3dUVMap can be added to the plane to fine-tune the rendering of texture maps. * @@ -38,7 +39,9 @@ @interface Isgl3dPlane : Isgl3dPrimitive { @protected float _width; - float _height; + float _height; + float _offsetx; + float _offsety; } @@ -51,6 +54,17 @@ */ + (id)meshWithGeometry:(float)width height:(float)height nx:(int)nx ny:(int)ny; +/** + * Allocates and initialises (autorelease) plane with the specified geometry. + * @param width The width of the plane in the x-direction. + * @param height The height of the plane in the y-direction. + * @param nx The number of segments along the x-axis. + * @param ny The number of segments along the y-axis. + * @param offsetx The offset added to every x coordinate value. + * @param offsety The offset added to every y coordinate value. + */ ++ (id)meshWithGeometry:(float)width height:(float)height nx:(int)nx ny:(int)ny offsetx:(float)offsetx offsety:(float)offsety; + /** * Allocates and initialises (autorelease) plane with the specified geometry and with a specific UV mapping. * Examples of use: @@ -79,6 +93,19 @@ */ + (id)meshWithGeometryAndUVMap:(float)width height:(float)height nx:(int)nx ny:(int)ny uvMap:(Isgl3dUVMap *)uvMap; +/** + * Allocates and initialises (autorelease) plane with the specified geometry and with a specific UV mapping. + * + * @param width The width of the plane in the x-direction. + * @param height The height of the plane in the y-direction. + * @param nx The number of segments along the x-axis. + * @param ny The number of segments along the y-axis. + * @param offsetx The offset added to every x coordinate value. + * @param offsety The offset added to every y coordinate value. + * @param uvMap The Isgl3dUVMap for mapping a texture material. + */ ++ (id)meshWithGeometryAndUVMap:(float)width height:(float)height nx:(int)nx ny:(int)ny offsetx:(float)offsetx offsety:(float)offsety uvMap:(Isgl3dUVMap *)uvMap; + /** * Initialises the plane with the specified geometry. * @param width The width of the plane in the x-direction. @@ -88,6 +115,17 @@ */ - (id)initWithGeometry:(float)width height:(float)height nx:(int)nx ny:(int)ny; +/** + * Initialises the plane with the specified geometry. + * @param width The width of the plane in the x-direction. + * @param height The height of the plane in the y-direction. + * @param nx The number of segments along the x-axis. + * @param ny The number of segments along the y-axis. + * @param offsetx The offset added to every x coordinate value. + * @param offsety The offset added to every y coordinate value. + */ +- (id)initWithGeometry:(float)width height:(float)height nx:(int)nx ny:(int)ny offsetx:(float)offsetx offsety:(float)offsety; + /** * Initialises the plane with the specified geometry and with a specific UV mapping. * Examples of use: @@ -116,4 +154,17 @@ */ - (id)initWithGeometryAndUVMap:(float)width height:(float)height nx:(int)nx ny:(int)ny uvMap:(Isgl3dUVMap *)uvMap; +/** + * Initialises the plane with the specified geometry and with a specific UV mapping. + * + * @param width The width of the plane in the x-direction. + * @param height The height of the plane in the y-direction. + * @param nx The number of segments along the x-axis. + * @param ny The number of segments along the y-axis. + * @param offsetx The offset added to every x coordinate value. + * @param offsety The offset added to every y coordinate value. + * @param uvMap The Isgl3dUVMap for mapping a texture material. + */ +- (id)initWithGeometryAndUVMap:(float)width height:(float)height nx:(int)nx ny:(int)ny offsetx:(float)offsetx offsety:(float)offsety uvMap:(Isgl3dUVMap *)uvMap; + @end diff --git a/isgl3d/primitives/Isgl3dPlane.m b/isgl3d/primitives/Isgl3dPlane.m index 5ce1d65..5b5506c 100644 --- a/isgl3d/primitives/Isgl3dPlane.m +++ b/isgl3d/primitives/Isgl3dPlane.m @@ -46,25 +46,38 @@ + (id)meshWithGeometry:(float)width height:(float)height nx:(int)nx ny:(int)ny { return [[[self alloc] initWithGeometry:width height:height nx:nx ny:ny] autorelease]; } ++ (id)meshWithGeometry:(float)width height:(float)height nx:(int)nx ny:(int)ny offsetx:(float)offsetx offsety:(float)offsety { + return [[[self alloc] initWithGeometry:width height:height nx:nx ny:ny offsetx:offsetx offsety:offsety] autorelease]; +} + + (id)meshWithGeometryAndUVMap:(float)width height:(float)height nx:(int)nx ny:(int)ny uvMap:(Isgl3dUVMap *)uvMap { return [[[self alloc] initWithGeometryAndUVMap:width height:height nx:nx ny:ny uvMap:uvMap] autorelease]; } ++ (id)meshWithGeometryAndUVMap:(float)width height:(float)height nx:(int)nx ny:(int)ny offsetx:(float)offsetx offsety:(float)offsety uvMap:(Isgl3dUVMap *)uvMap { + return [[[self alloc] initWithGeometryAndUVMap:width height:height nx:nx ny:ny offsetx:offsetx offsety:offsety uvMap:uvMap] autorelease]; +} + - (id)initWithGeometry:(float)width height:(float)height nx:(int)nx ny:(int)ny { - - if (self = [self initWithGeometryAndUVMap:width height:height nx:nx ny:ny uvMap:nil]) { - // Empty. - } - - return self; + return [self initWithGeometryAndUVMap:width height:height nx:nx ny:ny offsetx:0.0 offsety:0.0 uvMap:nil]; +} + +- (id)initWithGeometry:(float)width height:(float)height nx:(int)nx ny:(int)ny offsetx:(float)offsetx offsety:(float)offsety { + return [self initWithGeometryAndUVMap:width height:height nx:nx ny:ny offsetx:offsetx offsety:offsety uvMap:nil]; } - (id)initWithGeometryAndUVMap:(float)width height:(float)height nx:(int)nx ny:(int)ny uvMap:(Isgl3dUVMap *)uvMap { + return [self initWithGeometryAndUVMap:width height:height nx:nx ny:ny offsetx:0.0 offsety:0.0 uvMap:uvMap]; +} + +- (id)initWithGeometryAndUVMap:(float)width height:(float)height nx:(int)nx ny:(int)ny offsetx:(float)offsetx offsety:(float)offsety uvMap:(Isgl3dUVMap *)uvMap { if (self = [super init]) { _width = width; _height = height; _nx = nx; _ny = ny; + _offsetx = offsetx; + _offsety = offsety; if (uvMap) { _uvMap = [uvMap retain]; @@ -94,13 +107,13 @@ - (void)fillVertexData:(Isgl3dFloatArray *)vertexData andIndices:(Isgl3dUShortAr float uX, vX, uXY, vXY, iRatio, jRatio; for (int i = 0; i <= _nx; i++) { - float x = -(_width / 2) + i * (_width / _nx); + float x = -(_width / 2) + i * (_width / _nx) + _offsetx; iRatio = (float)i / _nx; uX = _uvMap.uA + iRatio * uABVector; vX = _uvMap.vA + iRatio * vABVector; for (int j = 0; j <= _ny; j++) { - float y = -(_height / 2) + j * (_height / _ny); + float y = -(_height / 2) + j * (_height / _ny) + _offsety; jRatio = 1. - (float)j / _ny; uXY = uX + jRatio * uACVector; vXY = vX + jRatio * vACVector; diff --git a/isgl3d/primitives/Isgl3dPrimitiveFactory.m b/isgl3d/primitives/Isgl3dPrimitiveFactory.m index 6e4de38..3e994d1 100644 --- a/isgl3d/primitives/Isgl3dPrimitiveFactory.m +++ b/isgl3d/primitives/Isgl3dPrimitiveFactory.m @@ -88,7 +88,10 @@ - (Isgl3dGLMesh *) boneMesh { - (Isgl3dGLMesh *) UIButtonMesh { Isgl3dGLMesh * buttonMesh = [_primitives objectForKey:GLUIBUTTON_MESH]; if (!buttonMesh) { - buttonMesh = [Isgl3dPlane meshWithGeometry:GLUIBUTTON_WIDTH * [Isgl3dDirector sharedInstance].contentScaleFactor height:GLUIBUTTON_HEIGHT * [Isgl3dDirector sharedInstance].contentScaleFactor nx:2 ny:2]; + float width = GLUIBUTTON_WIDTH * [Isgl3dDirector sharedInstance].contentScaleFactor; + float height = GLUIBUTTON_HEIGHT * [Isgl3dDirector sharedInstance].contentScaleFactor; + // UI components have the bottom-left corner at (width, height), so offset the plane by (width/2, height/2). + buttonMesh = [Isgl3dPlane meshWithGeometry:width height:height nx:2 ny:2 offsetx:width/2 offsety:height/2]; [_primitives setObject:buttonMesh forKey:GLUIBUTTON_MESH]; } return buttonMesh; @@ -98,7 +101,8 @@ - (Isgl3dGLMesh *) UILabelMeshWithWidth:(unsigned int)width height:(unsigned int float uMax = contentSize.width / width; float vMax = contentSize.height / height; - Isgl3dGLMesh * labelMesh = [Isgl3dPlane meshWithGeometryAndUVMap:contentSize.width height:contentSize.height nx:2 ny:2 uvMap:[Isgl3dUVMap uvMapWithUA:0 vA:0 uB:uMax vB:0 uC:0 vC:vMax]]; + // UI components have the bottom-left corner at (width, height), so offset the plane by (width/2, height/2). + Isgl3dGLMesh * labelMesh = [Isgl3dPlane meshWithGeometryAndUVMap:contentSize.width height:contentSize.height nx:2 ny:2 offsetx:(float)contentSize.width/2 offsety:(float)contentSize.height/2 uvMap:[Isgl3dUVMap uvMapWithUA:0 vA:0 uB:uMax vB:0 uC:0 vC:vMax]]; // GLMesh * labelMesh = [[Plane alloc] initWithGeometryAndUVMap:width height:height nx:2 ny:2 uvMap:[UVMap uvMapWithUA:0 vA:0 uB:0.5 vB:0 uC:0 vC:0.5]]; return labelMesh; } @@ -107,7 +111,7 @@ - (Isgl3dPlane *) planeWithGeometry:(float)width height:(float)height nx:(int)nx float uMax = material.contentSize.width / material.width; float vMax = material.contentSize.height / material.height; - Isgl3dPlane * plane = [Isgl3dPlane meshWithGeometryAndUVMap:width height:height nx:nx ny:ny uvMap:[Isgl3dUVMap uvMapWithUA:0 vA:0 uB:uMax vB:0 uC:0 vC:vMax]]; + Isgl3dPlane * plane = [Isgl3dPlane meshWithGeometryAndUVMap:width height:height nx:nx ny:ny offsetx:width/2 offsety:height/2 uvMap:[Isgl3dUVMap uvMapWithUA:0 vA:0 uB:uMax vB:0 uC:0 vC:vMax]]; return plane; } diff --git a/isgl3d/ui/Isgl3dGLUIButton.m b/isgl3d/ui/Isgl3dGLUIButton.m index 0c25a77..91356ed 100644 --- a/isgl3d/ui/Isgl3dGLUIButton.m +++ b/isgl3d/ui/Isgl3dGLUIButton.m @@ -53,10 +53,13 @@ - (id)initWithMaterial:(Isgl3dMaterial *)material { - (id)initWithMaterial:(Isgl3dMaterial *)material width:(unsigned int)width height:(unsigned int)height { float contentScaleFactor = [Isgl3dDirector sharedInstance].contentScaleFactor; + // UI components have the bottom-left corner at (width, height), so offset the plane by (width/2, height/2). if ((self = [super initWithMesh:[Isgl3dPlane meshWithGeometry:width * contentScaleFactor height:height * contentScaleFactor nx:2 - ny:2] + ny:2 + offsetx:(float)width * contentScaleFactor / 2 + offsety:(float)height * contentScaleFactor / 2] andMaterial:material])) { [self setWidth:width andHeight:height]; self.interactive = YES; diff --git a/isgl3d/ui/Isgl3dGLUIComponent.h b/isgl3d/ui/Isgl3dGLUIComponent.h index 166fbde..030073c 100644 --- a/isgl3d/ui/Isgl3dGLUIComponent.h +++ b/isgl3d/ui/Isgl3dGLUIComponent.h @@ -50,13 +50,6 @@ unsigned int _heightInPixels; BOOL _meshDirty; - - // "Fix left & top" stop pixel movement of component on specified side when resizing - BOOL _fixLeft; - BOOL _fixTop; - - BOOL _centerX; - BOOL _centerY; } /** @@ -103,29 +96,6 @@ */ @property (nonatomic, readonly) unsigned int heightInPixels; -/** - * Fix left is used to correct undesirable behaviour when the component it resized (such as with an Isgl3dProgressBar). With - * fixLeft the left hand side of the component will not move. - */ -@property (nonatomic) BOOL fixLeft; - -/** - * Fix top is used to correct undesirable behaviour when the component it resized (such as with an Isgl3dProgressBar). With - * fixTop the top of the component will not move. - */ -@property (nonatomic) BOOL fixTop; - -/** - * Specifies whether the component should be centered horizontally on its x value. - */ -@property (nonatomic) BOOL centerX; - -/** - * Specifies whether the component should be centered vertically on its y value. - */ -@property (nonatomic) BOOL centerY; - - /** * Initialises the component with a mesh and material. * This is called automatically by the concrete Isgl3DGLUI components. diff --git a/isgl3d/ui/Isgl3dGLUIComponent.m b/isgl3d/ui/Isgl3dGLUIComponent.m index 08b1b98..5d29335 100644 --- a/isgl3d/ui/Isgl3dGLUIComponent.m +++ b/isgl3d/ui/Isgl3dGLUIComponent.m @@ -38,10 +38,6 @@ @implementation Isgl3dGLUIComponent @synthesize widthInPixels = _widthInPixels; @synthesize height = _height; @synthesize heightInPixels = _heightInPixels; -@synthesize fixLeft = _fixLeft; -@synthesize fixTop = _fixTop; -@synthesize centerX = _centerX; -@synthesize centerY = _centerY; - (id)initWithMesh:(Isgl3dGLMesh *)mesh andMaterial:(Isgl3dMaterial *)material { if ((self = [super initWithMesh:mesh andMaterial:material])) { @@ -56,10 +52,6 @@ - (id)initWithMesh:(Isgl3dGLMesh *)mesh andMaterial:(Isgl3dMaterial *)material { _heightInPixels = 0; _meshDirty = YES; - _fixLeft = YES; - _fixTop = YES; - _centerX = NO; - _centerY = NO; self.lightingEnabled = NO; } return self; @@ -105,27 +97,8 @@ - (void)setWidthInPixels:(unsigned int)width andHeightInPixels:(unsigned int)hei - (void)updateWorldTransformation:(Isgl3dMatrix4 *)parentTransformation { if (_meshDirty) { - float x; - float y; - if (_centerX) { - x = 1.0 * _xInPixels; - } else { - if (_fixLeft) { - x = _xInPixels + (_widthInPixels + 1)/ 2; - } else { - x = _xInPixels + _widthInPixels / 2; - } - } - - if (_centerY) { - y = _yInPixels; - } else { - if (_fixTop) { - y = (float)(_yInPixels + (_heightInPixels + 1) / 2); - } else { - y = (float)(_yInPixels + _heightInPixels / 2); - } - } + unsigned int x = _xInPixels; + unsigned int y = _yInPixels; [self setPositionValues:x y:y z:self.z]; // NSLog(@"setting x = %f y = %f z = %f", x, y, self.z); diff --git a/isgl3d/ui/Isgl3dGLUIImage.m b/isgl3d/ui/Isgl3dGLUIImage.m index beceb33..ebc42fa 100644 --- a/isgl3d/ui/Isgl3dGLUIImage.m +++ b/isgl3d/ui/Isgl3dGLUIImage.m @@ -43,8 +43,9 @@ + (id)imageWithMaterial:(Isgl3dMaterial *)material andRectangle:(CGRect)rectangl - (id)initWithMaterial:(Isgl3dMaterial *)material width:(unsigned int)width height:(unsigned int)height { float widthInPixels = width * [Isgl3dDirector sharedInstance].contentScaleFactor; - float heightInPixels = height * [Isgl3dDirector sharedInstance].contentScaleFactor; - if ((self = [super initWithMesh:[Isgl3dPlane meshWithGeometry:widthInPixels height:heightInPixels nx:2 ny:2] andMaterial:material])) { + float heightInPixels = height * [Isgl3dDirector sharedInstance].contentScaleFactor; + // UI components have the bottom-left corner at (width, height), so offset the plane by (width/2, height/2). + if ((self = [super initWithMesh:[Isgl3dPlane meshWithGeometry:widthInPixels height:heightInPixels nx:2 ny:2 offsetx:widthInPixels/2 offsety:heightInPixels/2] andMaterial:material])) { [self setWidth:width andHeight:height]; } @@ -75,8 +76,10 @@ - (id)initWithMaterial:(Isgl3dMaterial *)material andRectangle:(CGRect)rectangle float vc = va + size.height * scaleFactor / materialHeight; float widthInPixels = width * [Isgl3dDirector sharedInstance].contentScaleFactor; - float heightInPixels = height * [Isgl3dDirector sharedInstance].contentScaleFactor; - if ((self = [super initWithMesh:[Isgl3dPlane meshWithGeometryAndUVMap:widthInPixels height:heightInPixels nx:2 ny:2 uvMap:[Isgl3dUVMap uvMapWithUA:ua vA:va uB:ub vB:vb uC:uc vC:vc]] andMaterial:material])) { + float heightInPixels = height * [Isgl3dDirector sharedInstance].contentScaleFactor; + + // UI components have the bottom-left corner at (width, height), so offset the plane by (width/2, height/2). + if ((self = [super initWithMesh:[Isgl3dPlane meshWithGeometryAndUVMap:widthInPixels height:heightInPixels nx:2 ny:2 offsetx:widthInPixels/2 offsety:heightInPixels/2 uvMap:[Isgl3dUVMap uvMapWithUA:ua vA:va uB:ub vB:vb uC:uc vC:vc]] andMaterial:material])) { [self setWidth:width andHeight:height]; } diff --git a/isgl3d/ui/Isgl3dGLUIProgressBar.m b/isgl3d/ui/Isgl3dGLUIProgressBar.m index b983dfa..6b58028 100644 --- a/isgl3d/ui/Isgl3dGLUIProgressBar.m +++ b/isgl3d/ui/Isgl3dGLUIProgressBar.m @@ -27,13 +27,6 @@ #import "Isgl3dPlane.h" #import "Isgl3dUVMap.h" -@interface Isgl3dGLUIProgressBar (PrivateMethods) -/** - * @result (autorelease) Plane with desired width and height reduced by factor proportional to progress - */ -- (Isgl3dPlane *) createProgressBarPlane:(float)width height:(float)height progress:(float)progress vertical:(BOOL)isVertical; -@end - @implementation Isgl3dGLUIProgressBar @synthesize progressStepSize = _progressStepSize; @@ -67,31 +60,60 @@ - (void)dealloc { } - (void)setProgress:(float)progress { - if (progress > 100) { - progress = 100; + if (progress > 100.0) { + progress = 100.0; } - if (progress <= 0) { - progress = 0; + if (progress < 0.0) { + progress = 0.0; } + + // If nothing has changed, we have nothing to do. + if (progress == _progress) { + return; + } - if (fabs(_progress - progress) > _progressStepSize || (_progress != progress && progress == 0) || (_progress != progress && progress == 100)) { + if (fabs(_progress - progress) >= _progressStepSize || (progress == 0.0) || (progress == 100.0)) { _progress = progress; - [self setMesh:[self createProgressBarPlane:_fullWidth height:_fullHeight progress:progress vertical:_isVertical]]; + float reduc = progress / 100.0; + Isgl3dPlane* plane = nil; + if (_isVertical) { - float height = _fullHeight * _progress / 100.0; - [self setWidth:_fullWidth andHeight:height]; + // Find the height of the component in full pixels. Once we have that, find out + // what the screen reduction is, and use that to scale the UV mapping. This avoids + // the texture jitter. + unsigned int height = _fullHeight * reduc; + [super setWidth:_fullWidth andHeight:height]; + reduc = (float)height / _fullHeight; + + Isgl3dUVMap* uvmap = nil; if (_isSwapped) { [super setX:_originalX andY:_originalY + _fullHeight - height]; - } + uvmap = [Isgl3dUVMap uvMapWithUA:0 vA:0 uB:1 vB:0 uC:0 vC:reduc]; + } else { + uvmap = [Isgl3dUVMap uvMapWithUA:0 vA:1-reduc uB:1 vB:1-reduc uC:0 vC:1]; + } + plane = [Isgl3dPlane meshWithGeometryAndUVMap:_fullWidth height:height nx:2 ny:2 offsetx:(float)_fullWidth/2 offsety:(float)height/2 uvMap:uvmap]; } else { - float width = _fullWidth * _progress / 100.0; - [self setWidth:width andHeight:_fullHeight]; + // Find the width of the component in full pixels. Once we have that, find out + // what the screen reduction is, and use that to scale the UV mapping. This avoids + // the texture jitter. + unsigned int width = _fullWidth * reduc; + [super setWidth:width andHeight:_fullHeight]; + reduc = (float)width / _fullWidth; + + Isgl3dUVMap* uvmap = nil; if (_isSwapped) { [super setX:_originalX + _fullWidth - width andY:_originalY]; - } + uvmap = [Isgl3dUVMap uvMapWithUA:1-reduc vA:0 uB:1 vB:0 uC:1-reduc vC:1]; + } else { + uvmap = [Isgl3dUVMap uvMapWithUA:0 vA:0 uB:reduc vB:0 uC:0 vC:1]; + } + plane = [Isgl3dPlane meshWithGeometryAndUVMap:width height:_fullHeight nx:2 ny:2 offsetx:(float)width/2 offsety:(float)_fullHeight/2 uvMap:uvmap]; } + + [self setMesh:plane]; } } @@ -106,38 +128,19 @@ - (void)setX:(unsigned int)x andY:(unsigned int)y { _originalY = y; } -- (Isgl3dPlane *) createProgressBarPlane:(float)width height:(float)height progress:(float)progress vertical:(BOOL)isVertical { - if (progress <= 0) { - return nil; - } - - float reduc = progress * 0.01; - if (isVertical) { - if (_isSwapped) { - return [Isgl3dPlane meshWithGeometryAndUVMap:width height:height*reduc nx:2 ny:2 uvMap:[Isgl3dUVMap uvMapWithUA:0 vA:reduc uB:1 vB:reduc uC:0 vC:0]]; - } else { - return [Isgl3dPlane meshWithGeometryAndUVMap:width height:height*reduc nx:2 ny:2 uvMap:[Isgl3dUVMap uvMapWithUA:0 vA:0 uB:1 vB:0 uC:0 vC:reduc]]; - } - } else { - if (_isSwapped) { - return [Isgl3dPlane meshWithGeometryAndUVMap:width*reduc height:height nx:2 ny:2 uvMap:[Isgl3dUVMap uvMapWithUA:reduc vA:0 uB:0 vB:0 uC:reduc vC:1]]; - } else { - return [Isgl3dPlane meshWithGeometryAndUVMap:width*reduc height:height nx:2 ny:2 uvMap:[Isgl3dUVMap uvMapWithUA:0 vA:0 uB:reduc vB:0 uC:0 vC:1]]; - } - } +- (void)setWidth:(unsigned int)width andHeight:(unsigned int)height { + _fullWidth = width; + _fullHeight = height; + [self setProgress:_progress]; } - (void)setIsSwapped:(BOOL)isSwapped { _isSwapped = isSwapped; - if (isSwapped) { - self.fixLeft = NO; - } else { - self.fixLeft = YES; - } // Force re-rendering of progress bar float oldProgress = _progress; _progress = -1; self.progress = oldProgress; } + @end diff --git a/tests/ui/UITestView.h b/tests/ui/UITestView.h index 12f5fef..b99a97f 100644 --- a/tests/ui/UITestView.h +++ b/tests/ui/UITestView.h @@ -26,6 +26,12 @@ #import "isgl3d.h" @interface UITestView : Isgl3dBasic2DView { +@private + float progress; + Isgl3dGLUIProgressBar* horizontalRegularProgress; + Isgl3dGLUIProgressBar* horizontalSwappedProgress; + Isgl3dGLUIProgressBar* verticalRegularProgress; + Isgl3dGLUIProgressBar* verticalSwappedProgress; } @end diff --git a/tests/ui/UITestView.m b/tests/ui/UITestView.m index 0be1639..dbd8af3 100644 --- a/tests/ui/UITestView.m +++ b/tests/ui/UITestView.m @@ -56,6 +56,35 @@ - (id)init { [self.scene addChild:cameraButton]; [cameraButton setX:8 andY:8]; [cameraButton addEvent3DListener:self method:@selector(cameraButtonPressed:) forEventType:TOUCH_EVENT]; + + // Create a number of progress bars to test each variation. + + progress = 0.0; + Isgl3dTextureMaterial* progressMaterial = [Isgl3dTextureMaterial materialWithTextureFile:@"tex.png" shininess:0.0 precision:Isgl3dTexturePrecisionMedium repeatX:NO repeatY:NO]; + + horizontalRegularProgress = [Isgl3dGLUIProgressBar progressBarWithMaterial:progressMaterial width:64 height:64 vertical:NO]; + [horizontalRegularProgress setX:64 andY:8]; + horizontalRegularProgress.progress = progress; + [self.scene addChild:horizontalRegularProgress]; + + horizontalSwappedProgress = [Isgl3dGLUIProgressBar progressBarWithMaterial:progressMaterial width:64 height:64 vertical:NO]; + horizontalSwappedProgress.isSwapped = YES; + [horizontalSwappedProgress setX:128 andY:8]; + horizontalSwappedProgress.progress = progress; + [self.scene addChild:horizontalSwappedProgress]; + + verticalRegularProgress = [Isgl3dGLUIProgressBar progressBarWithMaterial:progressMaterial width:64 height:64 vertical:YES]; + [verticalRegularProgress setX:192 andY:8]; + verticalRegularProgress.progress = progress; + [self.scene addChild:verticalRegularProgress]; + + verticalSwappedProgress = [Isgl3dGLUIProgressBar progressBarWithMaterial:progressMaterial width:64 height:64 vertical:YES]; + verticalSwappedProgress.isSwapped = YES; + [verticalSwappedProgress setX:256 andY:8]; + verticalSwappedProgress.progress = progress; + [self.scene addChild:verticalSwappedProgress]; + + [self schedule:@selector(tick:)]; } return self; @@ -80,6 +109,14 @@ - (void) cameraButtonPressed:(Isgl3dEvent3D *)event { NSLog(@"Camera button pressed"); } +- (void) tick:(float)dt { + progress = (progress >= 100.0 ? 0.0 : progress + 1.0); + horizontalRegularProgress.progress = progress; + horizontalSwappedProgress.progress = progress; + verticalRegularProgress.progress = progress; + verticalSwappedProgress.progress = progress; +} + @end #pragma mark UIBackgroundView