// // StandView.m // Awars III // // Created by Killery on 2013/11/07. // Copyright (c) 2013年 Killery. All rights reserved. // #import "StandView.h" @implementation StandView - (id)initWithFrame:(NSRect)frame { self = [super initWithFrame:frame]; if (self) { time = [NSTimer scheduledTimerWithTimeInterval:0.05f target:self selector:@selector(EventLoopSV:) userInfo:nil repeats:YES ]; testImage = [self LoadImage:@"ucb1"]; } return self; } -(void)EventLoopSV:(NSTimer*)time{ [self setNeedsDisplay:YES]; } -(BOOL)isFlipped{ return YES; } -(NSImage*)LoadImage:(NSString*)name{ NSImage *image = [NSImage imageNamed:name]; if(image == nil) return nil; return image; } -(void)DrawImage:(NSImage*)image x:(float)x y:(float)y{ NSRect frRect; frRect.size.height = image.size.height; frRect.size.width = image.size.width; frRect.origin.x = 0; frRect.origin.y = 0; NSRect drRect; drRect.origin.x = x; drRect.origin.y = y; drRect.size.height = image.size.height; drRect.size.width = image.size.width; [image drawInRect:drRect fromRect:frRect operation:NSCompositeSourceOver fraction:1.0f respectFlipped:YES hints:nil]; } -(void)mouseDown:(NSEvent *)theEvent{ I = Itop; for(int i = 0;i < Irow;i++){ I = I->next; } b = I->B; BASE *bTop = b; for (int i = 0; i < TVCrow1; i++) { b = b->next; } LAYER *lTop = b->L; for (int i = 0; i < TVCrow2; i++) { b->L = b->L->next; } if(TV1sglFlag){ imgGx = b->x; imgGy = b->y; } if(TV2sglFlag && b->L->visible){ imgGx = b->L->x; imgGy = b->L->y; } b->L = lTop; b = bTop; I = Itop; startPoint = [self convertPoint:[theEvent locationInWindow] fromView:nil]; startPoint.x = startPoint.x - imgGx; startPoint.y = startPoint.y - imgGy; } -(void)mouseDragged:(NSEvent *)theEvent{ /* endPoint = [self convertPoint:[theEvent locationInWindow] fromView:nil]; imgGx = endPoint.x - startPoint.x; imgGy = endPoint.y - startPoint.y; if(IBLrow < 0) if(I){ I = Itop; for (int i = 0;i < Irow;i++) { I = I->next; } if(I->B){ IBtop = I->B; for (int i = 0;i < IBrow;i++) { I->B = I->B->next; } if(I->B){ I->B->x = imgGx; I->B->y = imgGy; if(I->B->L){ IBLtop = I->B->L; I->B->L = IBLtop; } } I->B = IBtop; } I = Itop; } if(IBLrow >= 0) if(I){ I = Itop; for (int i = 0;i < Irow;i++) { I = I->next; } if(I) if(I->B){ IBtop = I->B; for (int i = 0;i < IBrow;i++) { I->B = I->B->next; } if(I) if(I->B->L){ IBLtop = I->B->L; for (int i = 0;i < IBLrow;i++) { I->B->L = I->B->L->next; } if(I) if(I->B->L){ I->B->L->x = imgGx; I->B->L->y = imgGy; } I->B->L = IBLtop; } I->B = IBtop; } I = Itop; } */ endPoint = [self convertPoint:[theEvent locationInWindow] fromView:nil]; imgGx = endPoint.x - startPoint.x; imgGy = endPoint.y - startPoint.y; I = Itop; for(int i = 0;i < Irow;i++){ I = I->next; } b = I->B; BASE *bTop = b; for (int i = 0; i < TVCrow1; i++) { b = b->next; } LAYER *lTop = b->L; for (int i = 0; i < TVCrow2; i++) { b->L = b->L->next; } if(TV1sglFlag){ b->x = imgGx; b->y = imgGy; } if(TV2sglFlag && b->L->visible){ b->L->x = imgGx; b->L->y = imgGy; } //NSLog(@"%d,%d", b->L->x, b->L->y); b->L = lTop; b = bTop; I->B = b; I = Itop; [self setNeedsDisplay:YES]; } -(void)mouseUp:(NSEvent *)theEvent{ } - (void)drawRect:(NSRect)dirtyRect { /* int layerIndex = 0; if(IBrow >= 0) if(I){ while(layerIndex <= 999){ Itop = I; for (int i = 0;i < Irow;i++) { I = I->next; } if(!I) return; if(I->B){ IBtop = I->B; for (int i = 0;i < IBrow;i++) { I->B = I->B->next; } if(I->B){ if(I->B->z == layerIndex) [self DrawImage:I->B->img x:I->B->x y:I->B->y]; if(I->B->L){ IBLtop = I->B->L; while (I->B->L) { if(I->B->L && I->B->L->visible && I->B->L->z == layerIndex){ [self DrawImage:I->B->L->img x:I->B->L->x y:I->B->L->y]; } I->B->L = I->B->L->next; } I->B->L = IBLtop; } } I->B = IBtop; } I = Itop; layerIndex++; } }*/ I = Itop; for(int i = 0;i < Irow;i++){ I = I->next; } b = I->B; int layerIndex = 0; BASE *bTop = b; while(layerIndex <= 999){ for (int i = 0;b && i <= TVCrow1; i++) { if(i == TVCrow1){ if(layerIndex == b->z && b->img) [self DrawImage:b->img x:b->x y:b->y]; if(1){ LAYER *l = b->L; LAYER *lTop = l; while (l) { if(l->visible){ if(layerIndex == l->z && l->img) [self DrawImage:l->img x:l->x y:l->y]; } l = l->next; } l = lTop; } } b = b->next; } b = bTop; layerIndex++; } I = Itop; } @end