OSDN Git Service

Merge branch 'workSpace'
[awarsiii/AwarsIV.git] / Awars III / StandView.m
1 //
2 //  StandView.m
3 //  Awars III
4 //
5 //  Created by Killery on 2013/11/07.
6 //  Copyright (c) 2013年 Killery. All rights reserved.
7 //
8
9 #import "StandView.h"
10
11 @implementation StandView
12
13 - (id)initWithFrame:(NSRect)frame
14 {
15     self = [super initWithFrame:frame];
16     if (self) {
17         time  = [NSTimer
18                   scheduledTimerWithTimeInterval:0.05f
19                   target:self
20                   selector:@selector(EventLoopSV:)
21                   userInfo:nil
22                   repeats:YES
23                   ];
24         
25         testImage = [self LoadImage:@"ucb1"];
26         
27     }
28     
29     return self;
30 }
31 -(void)EventLoopSV:(NSTimer*)time{
32     
33     [self setNeedsDisplay:YES];
34 }
35
36
37 -(BOOL)isFlipped{
38     return YES;
39 }
40
41 -(NSImage*)LoadImage:(NSString*)name{
42     NSImage *image = [NSImage imageNamed:name];
43     if(image == nil) return nil;
44     
45     return image;
46 }
47
48 -(void)DrawImage:(NSImage*)image x:(float)x y:(float)y{
49     NSRect frRect;
50     frRect.size.height = image.size.height;
51     frRect.size.width = image.size.width;
52     
53     frRect.origin.x = 0;
54     frRect.origin.y = 0;
55     
56     NSRect drRect;
57     drRect.origin.x = x;
58     drRect.origin.y = y;
59     drRect.size.height = image.size.height;
60     drRect.size.width = image.size.width;
61     
62     [image drawInRect:drRect fromRect:frRect operation:NSCompositeSourceOver fraction:1.0f respectFlipped:YES hints:nil];
63     
64 }
65
66 -(void)mouseDown:(NSEvent *)theEvent{
67
68     I = Itop;
69     for(int i = 0;i < Irow;i++){
70     
71         I = I->next;
72     }
73     b = I->B;
74     
75     BASE *bTop = b;
76     
77     for (int i = 0; i < TVCrow1; i++) {
78         b = b->next;
79     }
80     LAYER *lTop = b->L;
81     for (int i = 0; i < TVCrow2; i++) {
82         b->L = b->L->next;
83     }
84     
85     
86     if(TV1sglFlag){
87         imgGx = b->x;
88         imgGy = b->y;
89     }
90     if(TV2sglFlag && b->L->visible){
91         imgGx = b->L->x;
92         imgGy = b->L->y;
93     }
94     
95     
96     b->L = lTop;
97     b = bTop;
98     I = Itop;
99     
100     startPoint = [self convertPoint:[theEvent locationInWindow] fromView:nil];
101     
102     startPoint.x = startPoint.x - imgGx;
103     startPoint.y = startPoint.y - imgGy;
104 }
105
106
107 -(void)mouseDragged:(NSEvent *)theEvent{
108 /*
109     endPoint = [self convertPoint:[theEvent locationInWindow] fromView:nil];
110     
111     imgGx = endPoint.x - startPoint.x;
112     imgGy = endPoint.y - startPoint.y;
113     
114     if(IBLrow < 0)
115     if(I){
116         I = Itop;
117         for (int i = 0;i < Irow;i++) {
118             I = I->next;
119         }
120         
121         if(I->B){
122             IBtop = I->B;
123             for (int i = 0;i < IBrow;i++) {
124                 I->B = I->B->next;
125             }
126             
127             if(I->B){
128                 I->B->x = imgGx;
129                 I->B->y = imgGy;
130                 
131                 if(I->B->L){
132                     IBLtop = I->B->L;
133                     
134                     
135                     I->B->L = IBLtop;
136                 }
137             }
138             I->B = IBtop;
139         }
140         I = Itop;
141     }
142
143     if(IBLrow >= 0)
144         if(I){
145             I = Itop;
146             for (int i = 0;i < Irow;i++) {
147                 I = I->next;
148             }
149             
150             if(I)
151             if(I->B){
152                 IBtop = I->B;
153                 for (int i = 0;i < IBrow;i++) {
154                     I->B = I->B->next;
155                 }
156                 
157                 if(I)
158                 if(I->B->L){
159                     IBLtop = I->B->L;
160                     for (int i = 0;i < IBLrow;i++) {
161                         I->B->L = I->B->L->next;
162                     }
163                     
164                     if(I)
165                     if(I->B->L){
166                         I->B->L->x = imgGx;
167                         I->B->L->y = imgGy;
168                     }
169                     I->B->L = IBLtop;
170                 }
171                 I->B = IBtop;
172             }
173             I = Itop;
174         }
175     */
176     
177     endPoint = [self convertPoint:[theEvent locationInWindow] fromView:nil];
178     
179     imgGx = endPoint.x - startPoint.x;
180     imgGy = endPoint.y - startPoint.y;
181     
182     I = Itop;
183     for(int i = 0;i < Irow;i++){
184         
185         I = I->next;
186     }
187     b = I->B;
188     
189     BASE *bTop = b;
190     
191     for (int i = 0; i < TVCrow1; i++) {
192         b = b->next;
193     }
194     LAYER *lTop = b->L;
195     for (int i = 0; i < TVCrow2; i++) {
196         b->L = b->L->next;
197     }
198     
199     if(TV1sglFlag){
200         b->x = imgGx;
201         b->y = imgGy;
202     }
203     if(TV2sglFlag && b->L->visible){
204         b->L->x = imgGx;
205         b->L->y = imgGy;
206     }
207     
208     //NSLog(@"%d,%d", b->L->x, b->L->y);
209     
210     b->L = lTop;
211     b = bTop;
212     I->B = b;
213     
214     I = Itop;
215     [self setNeedsDisplay:YES];
216     
217 }
218
219 -(void)mouseUp:(NSEvent *)theEvent{
220  
221 }
222
223 - (void)drawRect:(NSRect)dirtyRect
224 {
225     /*
226     int layerIndex = 0;
227     
228     
229     
230     if(IBrow >= 0)
231     if(I){
232         while(layerIndex <= 999){
233             Itop = I;
234             for (int i = 0;i < Irow;i++) {
235                 I = I->next;
236             }
237             if(!I) return;
238             if(I->B){
239                 IBtop = I->B;
240                 for (int i = 0;i < IBrow;i++) {
241                     I->B = I->B->next;
242                 }
243                 
244                 if(I->B){
245                     if(I->B->z == layerIndex)
246                     [self DrawImage:I->B->img x:I->B->x y:I->B->y];
247             
248             
249                     if(I->B->L){
250                         IBLtop = I->B->L;
251                         while (I->B->L) {
252                             if(I->B->L && I->B->L->visible && I->B->L->z == layerIndex){
253                                 [self DrawImage:I->B->L->img x:I->B->L->x y:I->B->L->y];
254                             }
255                             I->B->L = I->B->L->next;
256                         }
257                 
258                         I->B->L = IBLtop;
259                     }
260                 }
261                 I->B = IBtop;
262             }
263             I = Itop;
264             layerIndex++;
265         }
266     }*/
267     
268     
269     I = Itop;
270     
271     for(int i = 0;i < Irow;i++){
272         I = I->next;
273     }
274     
275     b = I->B;
276     
277     int layerIndex = 0;
278     BASE *bTop = b;
279     while(layerIndex <= 999){
280         
281         for (int i = 0;b && i <= TVCrow1; i++) {
282             
283             if(i == TVCrow1){
284                 
285                 if(layerIndex == b->z && b->img) [self DrawImage:b->img x:b->x y:b->y];
286                 
287                 if(1){
288                     LAYER *l = b->L;
289                     LAYER *lTop = l;
290                     while (l) {
291                         if(l->visible){
292                             
293                             if(layerIndex == l->z && l->img)
294                                 [self DrawImage:l->img x:l->x y:l->y];
295                             
296                         }
297                         l = l->next;
298                     }
299                     l = lTop;
300                 }
301                 
302                 
303             }
304             
305             b = b->next;
306         }
307         b = bTop;
308         layerIndex++;
309     }
310     
311     I = Itop;
312 }
313
314 @end