@@ -78,7 +78,7 @@ public int OffsetY
7878 /// <summary>
7979 /// Width of the sprite window
8080 /// </summary>
81- private int SpriteWidth
81+ public int SpriteWidth
8282 {
8383 get
8484 {
@@ -95,7 +95,7 @@ private int SpriteWidth
9595 /// <summary>
9696 /// Height of the sprite window
9797 /// </summary>
98- private int SpriteHeight
98+ public int SpriteHeight
9999 {
100100 get
101101 {
@@ -150,6 +150,12 @@ public async void LoadImage(IStorageFile file)
150150 }
151151
152152
153+ public void Refresh ( )
154+ {
155+ this . InvalidateVisual ( ) ;
156+ }
157+
158+
153159 public override void Render ( DrawingContext context )
154160 {
155161 try
@@ -163,16 +169,16 @@ public override void Render(DrawingContext context)
163169 // Background
164170 {
165171 bool yPair = true ;
166- for ( int yy = 0 ; yy < 200 ; yy += z8 )
172+ for ( int yy = 0 ; yy < 400 ; yy += z8 )
167173 {
168174 bool pair = yPair ;
169175 yPair = ! yPair ;
170- for ( int xx = 0 ; xx < 200 ; xx += z8 )
176+ for ( int xx = 0 ; xx < 400 ; xx += z8 )
171177 {
172- int x1 = xx + 200 ;
178+ int x1 = xx ;
173179 int x2 = x1 + z8 ;
174180 int xz = z8 ;
175- int y1 = yy + 200 ;
181+ int y1 = yy ;
176182 int y2 = y1 + z8 ;
177183 int yz = z8 ;
178184 if ( x1 >= 400 || y1 >= 400 )
@@ -188,24 +194,13 @@ public override void Render(DrawingContext context)
188194 yz = 400 - y1 ;
189195 }
190196 Rect r0 = new Rect ( x1 , y1 , xz , yz ) ;
191- Rect r1 = new Rect ( x1 , ( 400 - y1 ) - yz , xz , yz ) ;
192- Rect r2 = new Rect ( ( 400 - x1 ) - xz , y1 , xz , yz ) ;
193- Rect r3 = new Rect ( ( 400 - x1 ) - xz , ( 400 - y1 ) - yz , xz , yz ) ;
194197 if ( pair )
195198 {
196199 context . FillRectangle ( brushGray , r0 ) ;
197- context . FillRectangle ( brushWhite , r1 ) ;
198- context . FillRectangle ( brushWhite , r2 ) ;
199- context . FillRectangle ( brushGray , r3 ) ;
200- //context.DrawRectangle(penRed, r2);
201200 }
202201 else
203202 {
204- context . FillRectangle ( brushWhite , r0 ) ;
205- context . FillRectangle ( brushGray , r1 ) ;
206- context . FillRectangle ( brushGray , r2 ) ;
207- context . FillRectangle ( brushWhite , r3 ) ;
208- //context.DrawRectangle(penRed, r2);
203+ context . FillRectangle ( brushWhite , r0 ) ;
209204 }
210205 pair = ! pair ;
211206 }
@@ -232,8 +227,8 @@ public override void Render(DrawingContext context)
232227 {
233228 try
234229 {
235- int xx = x + 200 - z8 ;
236- int yy = y + 200 - z8 ;
230+ int xx = x ;
231+ int yy = y ;
237232
238233 if ( ( xx + z ) > w )
239234 {
@@ -270,276 +265,24 @@ public override void Render(DrawingContext context)
270265
271266 // Mask
272267 {
273- int sw = SpriteWidth * _Zoom ;
274- int x1 = 200 - ( sw / 2 ) ;
268+ int x2 = SpriteWidth * _Zoom ;
269+ int y2 = SpriteHeight * _Zoom ;
275270
276- var r0 = new Rect ( 0 , 0 , 400 , x1 ) ;
271+ var r0 = new Rect ( x2 , 0 , 400 - x2 , 400 ) ;
277272 context . FillRectangle ( brushMask , r0 ) ;
278- var r1 = new Rect ( 0 , x1 + sw , 400 , x1 ) ;
273+ var r1 = new Rect ( 0 , y2 , x2 , 400 - y2 ) ;
279274 context . FillRectangle ( brushMask , r1 ) ;
280- var r2 = new Rect ( 0 , x1 , x1 , sw ) ;
281- context . FillRectangle ( brushMask , r2 ) ;
282- var r3 = new Rect ( x1 + sw , x1 , x1 , sw ) ;
283- context . FillRectangle ( brushMask , r3 ) ;
284-
285- context . DrawRectangle ( penRed ,
286- new Rect ( x1 , x1 , sw , sw ) ) ;
287- }
288275
289-
290- /*
291- z = _Zoom * 8;
292- int cw = 0;
293- int ch = 0;
294- bool pairRow = false; ;
295- bool pair = false;
296- for (int y = 0; y < h; y += z)
297- {
298- pair = pairRow;
299- pairRow = !pairRow;
300- for (int x = 0; x < w; x += z)
301- {
302- if ((x + z) > w)
303- {
304- cw = w - x;
305- }
306- else
307- {
308- cw = z;
309- }
310- if ((y + z) > h)
311- {
312- ch = h - y;
313- }
314- else
315- {
316- ch = z;
317- }
318- Rect r = new Rect(x, y, cw, ch);
319- if (pair)
320- {
321- context.FillRectangle(brushGray, r);
322- }
323- else
324- {
325- context.FillRectangle(brushWhite, r);
326- }
327- pair = !pair;
328- }
329- }
330- }
331-
332- // Image
333- if (imageData != null)
334- {
335- int iw = imageData.Size.Width;
336- int ih = imageData.Size.Height;
337- //int w = (int)this.Bounds.Width;
338- //int h = (int)this.Bounds.Height;
339- int cw = 0;
340- int ch = 0;
341- z = _Zoom;
342-
343- int yd = offsetY * z;
344- for (int y = 0; y<h; y += z)
345- {
346- int xd = offsetX * z;
347- for (int x = 0; x<w; x += z)
348- {
349- if (xd >= 0 && xd<iw &&
350- yd >= 0 && yd<ih)
351- {
352- try
353- {
354- if ((x + z) > w)
355- {
356- cw = w - x;
357- }
358- else
359- {
360- cw = z;
361- }
362- if ((y + z) > h)
363- {
364- ch = h - y;
365- }
366- else
367- {
368- ch = z;
369- }
370- Rect r = new Rect(x, y, cw, ch);
371- var pixel = imageData[xd, yd];
372- var brush = new SolidColorBrush(Color.FromArgb(
373- pixel.A, pixel.R, pixel.G, pixel.B));
374- context.FillRectangle(brush, r);
375- }
376- catch (Exception ex)
377- {
378-
379- }
380- }
381- xd++;
382- }
383- yd++;
384- }
385- }
386-
387- // Mask
388- {
389- int sw = SpriteWidth * _Zoom;
390- int mx = w / 2;
391- int x1 = mx - (sw / 2);
392- int x2 = w - x1;
393-
394- int sh = SpriteHeight * _Zoom;
395- int my = h / 2;
396- int y1 = my - (sh / 2);
397- int y2 = h - y1;
398-
399- context.FillRectangle(brushMask, new Rect(0, 0, w, y1));
400- context.FillRectangle(brushMask, new Rect(0, y2, w, h - y2));
401- context.FillRectangle(brushMask, new Rect(0, y1, x1, sh + 1));
402- context.FillRectangle(brushMask, new Rect(x2, y1, w - x2, sh + 1));
403- context.DrawRectangle(penRed, new Rect(x1 - 1, y1 - 1, sw + 1, sh + 1));
404- }
405- */
276+ context . DrawRectangle ( penRed , new Rect ( - 1 , - 1 , x2 , y2 ) ) ;
277+ }
406278 }
407279 catch ( Exception ex )
408280 {
409281
410282 }
411283 }
412284
413-
414- #if NO
415- public override void Render ( DrawingContext context )
416- {
417- base . Render ( context ) ;
418-
419- int w = ( int ) this . Bounds . Width ;
420- int h = ( int ) this . Bounds . Height ;
421- int z = 1 ;
422-
423- // Background
424- {
425- z = _Zoom * 8 ;
426- int cw = 0 ;
427- int ch = 0 ;
428- bool pairRow = false ; ;
429- bool pair = false ;
430- for ( int y = 0 ; y < h ; y += z )
431- {
432- pair = pairRow ;
433- pairRow = ! pairRow ;
434- for ( int x = 0 ; x < w ; x += z )
435- {
436- if ( ( x + z ) > w )
437- {
438- cw = w - x ;
439- }
440- else
441- {
442- cw = z ;
443- }
444- if ( ( y + z ) > h )
445- {
446- ch = h - y ;
447- }
448- else
449- {
450- ch = z ;
451- }
452- Rect r = new Rect ( x , y , cw , ch ) ;
453- if ( pair )
454- {
455- context . FillRectangle ( brushGray , r ) ;
456- }
457- else
458- {
459- context . FillRectangle ( brushWhite , r ) ;
460- }
461- pair = ! pair ;
462- }
463- }
464- }
465-
466- // Image
467- if ( imageData != null )
468- {
469- int iw = imageData . Size . Width ;
470- int ih = imageData . Size . Height ;
471- //int w = (int)this.Bounds.Width;
472- //int h = (int)this.Bounds.Height;
473- int cw = 0 ;
474- int ch = 0 ;
475- z = _Zoom ;
476-
477- int yd = offsetY * z ;
478- for ( int y = 0 ; y < h ; y += z )
479- {
480- int xd = offsetX * z ;
481- for ( int x = 0 ; x < w ; x += z )
482- {
483- if ( xd >= 0 && xd < iw &&
484- yd >= 0 && yd < ih )
485- {
486- try
487- {
488- if ( ( x + z ) > w )
489- {
490- cw = w - x ;
491- }
492- else
493- {
494- cw = z ;
495- }
496- if ( ( y + z ) > h )
497- {
498- ch = h - y ;
499- }
500- else
501- {
502- ch = z ;
503- }
504- Rect r = new Rect ( x , y , cw , ch ) ;
505- var pixel = imageData [ xd , yd ] ;
506- var brush = new SolidColorBrush ( Color . FromArgb (
507- pixel . A , pixel . R , pixel . G , pixel . B ) ) ;
508- context . FillRectangle ( brush , r ) ;
509- }
510- catch ( Exception ex )
511- {
512-
513- }
514- }
515- xd ++ ;
516- }
517- yd ++ ;
518- }
519- }
520-
521- // Mask
522- {
523- int sw = SpriteWidth * _Zoom ;
524- int mx = w / 2 ;
525- int x1 = mx - ( sw / 2 ) ;
526- int x2 = w - x1 ;
527-
528- int sh = SpriteHeight * _Zoom ;
529- int my = h / 2 ;
530- int y1 = my - ( sh / 2 ) ;
531- int y2 = h - y1 ;
532-
533- context . FillRectangle ( brushMask , new Rect ( 0 , 0 , w , y1 ) ) ;
534- context . FillRectangle ( brushMask , new Rect ( 0 , y2 , w , h - y2 ) ) ;
535- context . FillRectangle ( brushMask , new Rect ( 0 , y1 , x1 , sh + 1 ) ) ;
536- context . FillRectangle ( brushMask , new Rect ( x2 , y1 , w - x2 , sh + 1 ) ) ;
537- context . DrawRectangle ( penRed , new Rect ( x1 - 1 , y1 - 1 , sw + 1 , sh + 1 ) ) ;
538- }
539- }
540- #endif
541-
542- #endregion
285+ #endregion
543286
544287
545288 #region Mouse
0 commit comments