+/GENN
genetically evolving neural networks
git clone https://git.julia.blue/+/GENN
d7063ee
imdone-todo-updates
1//////// Start of inlined file: tigr_amalgamated.c //////// 2 3 4#include "tigr.h" 5 6//////// Start of inlined file: tigr_bitmaps.c //////// 7 8//////// Start of inlined file: tigr_internal.h //////// 9 10// can't use pragma once here because this file probably will endup in .c 11#ifndef __TIGR_INTERNAL_H__ 12#define __TIGR_INTERNAL_H__ 13 14#define _CRT_SECURE_NO_WARNINGS NOPE 15 16// Creates a new bitmap, with extra payload bytes. 17Tigr * tigrBitmap2 (int w ,int h ,int extra ); 18 19// Resizes an existing bitmap. 20void tigrResize (Tigr * bmp ,int w ,int h ); 21 22// Calculates the biggest scale that a bitmap can fit into an area at. 23int tigrCalcScale (int bmpW ,int bmpH ,int areaW ,int areaH ); 24 25// Calculates a new scale, taking minimum-scale flags into account. 26int tigrEnforceScale (int scale ,int flags ); 27 28// Calculates the correct position for a bitmap to fit into a window. 29void tigrPosition (Tigr * bmp ,int scale ,int windowW ,int windowH ,int out [4 ]); 30 31// ---------------------------------------------------------- 32#ifdef _WIN32 33#define WIN32_LEAN_AND_MEAN 34#include <windows.h> 35#endif 36 37#ifdef TIGR_GAPI_D3D9 38#include <d3d9.h> 39typedef struct { 40int lost ; 41IDirect3DDevice9 * dev ; 42D3DPRESENT_PARAMETERS params ; 43IDirect3DTexture9 * sysTex [2 ],* vidTex [2 ]; 44IDirect3DVertexShader9 * vs ; 45IDirect3DPixelShader9 * ps ; 46}D3D9Stuff ; 47#endif 48 49#ifdef TIGR_GAPI_GL 50#ifdef _WIN32 51#include <GL/gl.h> 52#else 53#include <OpenGL/gl3.h> 54#endif 55typedef struct { 56#ifdef _WIN32 57HGLRC hglrc ; 58HDC dc ; 59#endif 60GLuint tex [2 ]; 61GLuint vao ; 62GLuint program ; 63GLuint uniform_projection ; 64GLuint uniform_model ; 65GLuint uniform_parameters ; 66int gl_legacy ; 67}GLStuff ; 68#endif 69 70typedef struct { 71int shown ,closed ; 72#ifdef TIGR_GAPI_D3D9 73D3D9Stuff d3d9 ; 74#endif 75#ifdef TIGR_GAPI_GL 76GLStuff gl ; 77#endif 78 79#ifdef _WIN32 80wchar_t * wtitle ; 81DWORD dwStyle ; 82RECT oldPos ; 83#endif 84#ifdef __APPLE__ 85void * glContext ; 86#endif 87 88Tigr * widgets ; 89int widgetsWanted ; 90unsigned char widgetAlpha ; 91float widgetsScale ; 92 93int hblur ,vblur ; 94float scanlines ,contrast ; 95 96int flags ; 97int scale ; 98int pos [4 ]; 99int lastChar ; 100char keys [256 ],prev [256 ]; 101#ifdef __APPLE__ 102int mouseButtons ; 103#endif 104}TigrInternal ; 105// ---------------------------------------------------------- 106 107TigrInternal * tigrInternal (Tigr * bmp ); 108 109void tigrGAPICreate (Tigr * bmp ); 110void tigrGAPIDestroy (Tigr * bmp ); 111void tigrGAPIBegin (Tigr * bmp ); 112void tigrGAPIEnd (Tigr * bmp ); 113void tigrGAPIResize (Tigr * bmp ,int width ,int height ); 114void tigrGAPIPresent (Tigr * bmp ,int w ,int h ); 115 116#endif 117 118 119//////// End of inlined file: tigr_internal.h //////// 120 121#include <stdlib.h> 122#include <string.h> 123 124// Expands 0-255 into 0-256 125#define EXPAND (X ) ((X) + ((X) > 0)) 126 127#define CLIP0 (X ,X2 ,W ) if (X < 0) { W += X; X2 -= X; X = 0; } 128#define CLIP1 (X ,DW ,W ) if (X + W > DW) W = DW - X; 129#define CLIP () \ 130 CLIP0(dx, sx, w); \ 131 CLIP0(dy, sy, h); \ 132 CLIP0(sx, dx, w); \ 133 CLIP0(sy, dy, h); \ 134 CLIP1(dx, dst->w, w); \ 135 CLIP1(dy, dst->h, h); \ 136 CLIP1(sx, src->w, w); \ 137 CLIP1(sy, src->h, h); \ 138 if (w <= 0 || h <= 0) \ 139 return 140 141 142Tigr * tigrBitmap2 (int w ,int h ,int extra ) 143{ 144Tigr * tigr = (Tigr * )calloc (1 ,sizeof (Tigr )+ extra ); 145tigr -> w = w ; 146tigr -> h = h ; 147tigr -> pix = (TPixel * )calloc (w * h ,sizeof (TPixel )); 148return tigr ; 149} 150 151Tigr * tigrBitmap (int w ,int h ) 152{ 153return tigrBitmap2 (w ,h ,0 ); 154} 155 156void tigrResize (Tigr * bmp ,int w ,int h ) 157{ 158int y ,cw ,ch ; 159TPixel * newpix = (TPixel * )calloc (w * h ,sizeof (TPixel )); 160cw = (w < bmp -> w ) ?w :bmp -> w ; 161ch = (h < bmp -> h ) ?h :bmp -> h ; 162 163// Copy any old data across. 164for (y = 0 ;y < ch ;y ++ ) 165memcpy (newpix + y * w ,bmp -> pix + y * bmp -> w ,cw * sizeof (TPixel )); 166 167free (bmp -> pix ); 168bmp -> pix = newpix ; 169bmp -> w = w ; 170bmp -> h = h ; 171} 172 173int tigrCalcScale (int bmpW ,int bmpH ,int areaW ,int areaH ) 174{ 175// We want it as big as possible in the window, but still 176// maintaining the correct aspect ratio, and always 177// having an integer pixel size. 178int scale = 0 ; 179for (;;) 180 { 181scale ++ ; 182if (bmpW * scale > areaW || bmpH * scale > areaH ) 183 { 184scale -- ; 185break ; 186 } 187 } 188return (scale > 1 ) ?scale :1 ; 189} 190 191int tigrEnforceScale (int scale ,int flags ) 192{ 193if ((flags & TIGR_4X )&& scale < 4 )scale = 4 ; 194if ((flags & TIGR_3X )&& scale < 3 )scale = 3 ; 195if ((flags & TIGR_2X )&& scale < 2 )scale = 2 ; 196return scale ; 197} 198 199void tigrPosition (Tigr * bmp ,int scale ,int windowW ,int windowH ,int out [4 ]) 200{ 201// Center the image on screen at this scale. 202out [0 ]= (windowW - bmp -> w * scale ) /2 ; 203out [1 ]= (windowH - bmp -> h * scale ) /2 ; 204out [2 ]= out [0 ]+ bmp -> w * scale ; 205out [3 ]= out [1 ]+ bmp -> h * scale ; 206} 207 208void tigrClear (Tigr * bmp ,TPixel color ) 209{ 210int count = bmp -> w * bmp -> h ; 211int n ; 212for (n = 0 ;n < count ;n ++ ) 213bmp -> pix [n ]= color ; 214} 215 216void tigrFill (Tigr * bmp ,int x ,int y ,int w ,int h ,TPixel color ) 217{ 218TPixel * td ; 219int dt ,i ; 220 221if (x < 0 ) {w += x ;x = 0 ; } 222if (y < 0 ) {h += y ;y = 0 ; } 223if (x + w > bmp -> w ) {w = bmp -> w - x ; } 224if (y + h > bmp -> h ) {h = bmp -> h - y ; } 225if (w <=0 || h <=0 ) 226return ; 227 228td = & bmp -> pix [y * bmp -> w + x ]; 229dt = bmp -> w ; 230do { 231for (i = 0 ;i < w ;i ++ ) 232td [i ]= color ; 233td += dt ; 234 }while (-- h ); 235} 236 237void tigrLine (Tigr * bmp ,int x0 ,int y0 ,int x1 ,int y1 ,TPixel color ) 238{ 239int sx ,sy ,dx ,dy ,err ,e2 ; 240dx = abs (x1 - x0 ); 241dy = abs (y1 - y0 ); 242if (x0 < x1 )sx = 1 ;else sx = -1 ; 243if (y0 < y1 )sy = 1 ;else sy = -1 ; 244err = dx - dy ; 245 246tigrPlot (bmp ,x0 ,y0 ,color ); 247while (x0 != x1 || y0 != y1 ) 248 { 249tigrPlot (bmp ,x0 ,y0 ,color ); 250e2 = 2 * err ; 251if (e2 > - dy ) {err -= dy ;x0 += sx ; } 252if (e2 < dx ) {err += dx ;y0 += sy ; } 253 } 254} 255 256void tigrRect (Tigr * bmp ,int x ,int y ,int w ,int h ,TPixel color ) 257{ 258int x1 ,y1 ; 259if (w <=0 || h <=0 ) 260return ; 261 262x1 = x + w - 1 ; 263y1 = y + h - 1 ; 264tigrLine (bmp ,x ,y ,x1 ,y ,color ); 265tigrLine (bmp ,x1 ,y ,x1 ,y1 ,color ); 266tigrLine (bmp ,x1 ,y1 ,x ,y1 ,color ); 267tigrLine (bmp ,x ,y1 ,x ,y ,color ); 268} 269 270TPixel tigrGet (Tigr * bmp ,int x ,int y ) 271{ 272TPixel empty = {0 ,0 ,0 ,0 }; 273if (x >=0 && y >=0 && x < bmp -> w && y < bmp -> h ) 274return bmp -> pix [y * bmp -> w + x ]; 275return empty ; 276} 277 278void tigrPlot (Tigr * bmp ,int x ,int y ,TPixel pix ) 279{ 280int xa ,i ,a ; 281if (x >=0 && y >=0 && x < bmp -> w && y < bmp -> h ) 282 { 283xa = EXPAND (pix .a ); 284i = y * bmp -> w + x ; 285 286a = xa * EXPAND (pix .a ); 287bmp -> pix [i ].r += (unsigned char )((pix .r - bmp -> pix [i ].r )* a >>16 ); 288bmp -> pix [i ].g += (unsigned char )((pix .g - bmp -> pix [i ].g )* a >>16 ); 289bmp -> pix [i ].b += (unsigned char )((pix .b - bmp -> pix [i ].b )* a >>16 ); 290bmp -> pix [i ].a += (unsigned char )((pix .a - bmp -> pix [i ].a )* a >>16 ); 291 } 292} 293 294void tigrBlit (Tigr * dst ,Tigr * src ,int dx ,int dy ,int sx ,int sy ,int w ,int h ) 295{ 296TPixel * td ,* ts ; 297int st ,dt ; 298CLIP (); 299 300ts = & src -> pix [sy * src -> w + sx ]; 301td = & dst -> pix [dy * dst -> w + dx ]; 302st = src -> w ; 303dt = dst -> w ; 304do { 305memcpy (td ,ts ,w * sizeof (TPixel )); 306ts += st ; 307td += dt ; 308 }while (-- h ); 309} 310 311void tigrBlitTint (Tigr * dst ,Tigr * src ,int dx ,int dy ,int sx ,int sy ,int w ,int h ,TPixel tint ) 312{ 313TPixel * td ,* ts ; 314int x ,st ,dt ,xr ,xg ,xb ,xa ; 315CLIP (); 316 317xr = EXPAND (tint .r ); 318xg = EXPAND (tint .g ); 319xb = EXPAND (tint .b ); 320xa = EXPAND (tint .a ); 321 322ts = & src -> pix [sy * src -> w + sx ]; 323td = & dst -> pix [dy * dst -> w + dx ]; 324st = src -> w ; 325dt = dst -> w ; 326do { 327for (x = 0 ;x < w ;x ++ ) 328 { 329unsigned r = (xr * ts [x ].r ) >>8 ; 330unsigned g = (xg * ts [x ].g ) >>8 ; 331unsigned b = (xb * ts [x ].b ) >>8 ; 332unsigned a = xa * EXPAND (ts [x ].a ); 333td [x ].r += (unsigned char )((r - td [x ].r )* a >>16 ); 334td [x ].g += (unsigned char )((g - td [x ].g )* a >>16 ); 335td [x ].b += (unsigned char )((b - td [x ].b )* a >>16 ); 336td [x ].a += (unsigned char )((ts [x ].a - td [x ].a )* a >>16 ); 337 } 338ts += st ; 339td += dt ; 340 }while (-- h ); 341} 342 343void tigrBlitAlpha (Tigr * dst ,Tigr * src ,int dx ,int dy ,int sx ,int sy ,int w ,int h ,float alpha ) 344{ 345alpha = (alpha < 0 ) ?0 : (alpha > 1 ?1 :alpha ); 346tigrBlitTint (dst ,src ,dx ,dy ,sx ,sy ,w ,h ,tigrRGBA (0xff ,0xff ,0xff ,(unsigned char )(alpha * 255 ))); 347} 348 349#undef CLIP0 350#undef CLIP1 351#undef CLIP 352 353//////// End of inlined file: tigr_bitmaps.c //////// 354 355//////// Start of inlined file: tigr_loadpng.c //////// 356 357//#include "tigr_internal.h" 358#include <stdlib.h> 359#include <string.h> 360#include <errno.h> 361 362typedef struct { 363const unsigned char * p ,* end ; 364}PNG ; 365 366static unsigned get32 (const unsigned char * v ) 367{ 368return (v [0 ] <<24 ) | (v [1 ] <<16 ) | (v [2 ] <<8 ) |v [3 ]; 369} 370 371static const unsigned char * find (PNG * png ,const char * chunk ,unsigned minlen ) 372{ 373const unsigned char * start ; 374while (png -> p < png -> end ) 375 { 376unsigned len = get32 (png -> p + 0 ); 377start = png -> p ; 378png -> p += len + 12 ; 379if (memcmp (start + 4 ,chunk ,4 )== 0 && len >=minlen && png -> p <=png -> end ) 380return start + 8 ; 381 } 382 383return NULL ; 384} 385 386static unsigned char paeth (unsigned char a ,unsigned char b ,unsigned char c ) 387{ 388int p = a + b - c ; 389int pa = abs (p - a ),pb = abs (p - b ),pc = abs (p - c ); 390return (pa <=pb && pa <=pc ) ?a : (pb <=pc ) ?b :c ; 391} 392 393static int unfilter (int w ,int h ,int bpp ,unsigned char * raw ) 394{ 395int len = w * bpp ,x ,y ; 396unsigned char * prev = raw ; 397for (y = 0 ;y < h ;y ++ ,prev = raw ,raw += len ) 398 { 399#define LOOP (A ,B ) for (x=0;x<bpp;x++) raw[x] += A; for (;x<len;x++) raw[x] += B; break 400switch (* raw ++ ) 401 { 402case 0 :break ; 403case 1 :LOOP (0 ,raw [x - bpp ]); 404case 2 :LOOP (prev [x ],prev [x ]); 405case 3 :LOOP (prev [x ]/2 , (raw [x - bpp ]+ prev [x ])/2 ); 406case 4 :LOOP (prev [x ],paeth (raw [x - bpp ],prev [x ],prev [x - bpp ])); 407default :return 0 ; 408 } 409#undef LOOP 410 } 411return 1 ; 412} 413 414static void convert (int bpp ,int w ,int h ,unsigned char * src ,TPixel * dest ) 415{ 416int x ,y ; 417for (y = 0 ;y < h ;y ++ ) 418 { 419src ++ ;// skip filter byte 420for (x = 0 ;x < w ;x ++ ,src += bpp ) 421 { 422switch (bpp ) { 423case 1 :* dest ++ = tigrRGB (src [0 ],src [0 ],src [0 ]);break ; 424case 2 :* dest ++ = tigrRGBA (src [0 ],src [0 ],src [0 ],src [1 ]);break ; 425case 3 :* dest ++ = tigrRGB (src [0 ],src [1 ],src [2 ]);break ; 426case 4 :* dest ++ = tigrRGBA (src [0 ],src [1 ],src [2 ],src [3 ]);break ; 427 } 428 } 429 } 430} 431 432static void depalette (int w ,int h ,unsigned char * src ,TPixel * dest ,const unsigned char * plte ) 433{ 434int x ,y ,c ; 435for (y = 0 ;y < h ;y ++ ) 436 { 437src ++ ;// skip filter byte 438for (x = 0 ;x < w ;x ++ ,src ++ ) 439 { 440c = src [0 ]; 441* dest ++ = tigrRGBA (plte [c * 3 + 0 ],plte [c * 3 + 1 ],plte [c * 3 + 2 ],c ?255 :0 ); 442 } 443 } 444} 445 446#define FAIL () { errno = EINVAL; goto err; } 447#define CHECK (X ) if (!(X)) FAIL() 448static int outsize (Tigr * bmp ,int bpp ) {return (bmp -> w + 1 )* bmp -> h * bpp ; } 449 450static Tigr * tigrLoadPng (PNG * png ) 451{ 452const unsigned char * ihdr ,* idat ,* plte ,* first ; 453int depth ,ctype ,bpp ; 454int datalen = 0 ; 455unsigned char * data = NULL ,* out ; 456Tigr * bmp = NULL ; 457 458CHECK (memcmp (png -> p ,"\211PNG\r\n\032\n" ,8 )== 0 );// PNG signature 459png -> p += 8 ; 460first = png -> p ; 461 462// Read IHDR 463ihdr = find (png ,"IHDR" ,13 ); 464CHECK (ihdr ); 465depth = ihdr [8 ]; 466ctype = ihdr [9 ]; 467switch (ctype ) { 468case 0 :bpp = 1 ;break ;// greyscale 469case 2 :bpp = 3 ;break ;// RGB 470case 3 :bpp = 1 ;break ;// paletted 471case 4 :bpp = 2 ;break ;// grey+alpha 472case 6 :bpp = 4 ;break ;// RGBA 473default :FAIL (); 474 } 475 476// Allocate bitmap (+1 width to save room for stupid PNG filter bytes) 477bmp = tigrBitmap (get32 (ihdr + 0 )+ 1 ,get32 (ihdr + 4 )); 478CHECK (bmp ); 479bmp -> w -- ; 480 481// We don't support non-8bpp, interlacing, or wacky filter types. 482CHECK (depth == 8 && ihdr [10 ]== 0 && ihdr [11 ]== 0 && ihdr [12 ]== 0 ); 483 484// Join IDAT chunks. 485for (idat = find (png ,"IDAT" ,0 );idat ;idat = find (png ,"IDAT" ,0 )) 486 { 487unsigned len = get32 (idat - 8 ); 488data = (unsigned char * )realloc (data ,datalen + len ); 489if (!data ) 490break ; 491 492memcpy (data + datalen ,idat ,len ); 493datalen += len ; 494 } 495 496// Find palette. 497png -> p = first ; 498plte = find (png ,"PLTE" ,0 ); 499 500CHECK (data && datalen >=6 ); 501CHECK ((data [0 ]& 0x0f )== 0x08 // compression method (RFC 1950) 502&& (data [0 ]& 0xf0 ) <=0x70 // window size 503&& (data [1 ]& 0x20 )== 0 );// preset dictionary present 504 505out = (unsigned char * )bmp -> pix + outsize (bmp ,4 )- outsize (bmp ,bpp ); 506CHECK (tigrInflate (out ,outsize (bmp ,bpp ),data + 2 ,datalen - 6 )); 507CHECK (unfilter (bmp -> w ,bmp -> h ,bpp ,out )); 508 509if (ctype == 3 ) { 510CHECK (plte ); 511depalette (bmp -> w ,bmp -> h ,out ,bmp -> pix ,plte ); 512 }else { 513convert (bpp ,bmp -> w ,bmp -> h ,out ,bmp -> pix ); 514 } 515 516free (data ); 517return bmp ; 518 519err : 520if (data )free (data ); 521if (bmp )tigrFree (bmp ); 522return NULL ; 523} 524 525#undef CHECK 526#undef FAIL 527 528Tigr * tigrLoadImageMem (const void * data ,int length ) 529{ 530PNG png ; 531png .p = (unsigned char * )data ; 532png .end = (unsigned char * )data + length ; 533return tigrLoadPng (& png ); 534} 535 536Tigr * tigrLoadImage (const char * fileName ) 537{ 538int len ; 539void * data ; 540Tigr * bmp ; 541 542data = tigrReadFile (fileName ,& len ); 543if (!data ) 544return NULL ; 545 546bmp = tigrLoadImageMem (data ,len ); 547free (data ); 548return bmp ; 549} 550 551 552//////// End of inlined file: tigr_loadpng.c //////// 553 554//////// Start of inlined file: tigr_savepng.c //////// 555 556//#include "tigr_internal.h" 557#include <stdio.h> 558#include <stdlib.h> 559#include <string.h> 560#include <errno.h> 561 562typedef struct { 563unsigned crc ,adler ,bits ,prev ,runlen ; 564FILE * out ; 565unsigned crcTable [256 ]; 566}Save ; 567 568static const unsigned crctable [16 ]= {0 ,0x1db71064 ,0x3b6e20c8 ,0x26d930ac ,0x76dc4190 ,0x6b6b51f4 ,0x4db26158 ,0x5005713c , 5690xedb88320 ,0xf00f9344 ,0xd6d6a3e8 ,0xcb61b38c ,0x9b64c2b0 ,0x86d3d2d4 ,0xa00ae278 ,0xbdbdf21c }; 570 571static void put (Save * s ,unsigned v ) 572{ 573fputc (v ,s -> out ); 574s -> crc = (s -> crc >>4 ) ^crctable [(s -> crc & 15 ) ^ (v & 15 )]; 575s -> crc = (s -> crc >>4 ) ^crctable [(s -> crc & 15 ) ^ (v >>4 )]; 576} 577 578static void updateAdler (Save * s ,unsigned v ) 579{ 580unsigned s1 = s -> adler & 0xffff ,s2 = (s -> adler >>16 )& 0xffff ; 581s1 = (s1 + v ) %65521 ; 582s2 = (s2 + s1 ) %65521 ; 583s -> adler = (s2 <<16 )+ s1 ; 584} 585 586static void put32 (Save * s ,unsigned v ) 587{ 588put (s , (v >>24 )& 0xff ); 589put (s , (v >>16 )& 0xff ); 590put (s , (v >>8 )& 0xff ); 591put (s ,v & 0xff ); 592} 593 594void putbits (Save * s ,unsigned data ,unsigned bitcount ) 595{ 596while (bitcount -- ) 597 { 598unsigned prev = s -> bits ; 599s -> bits = (s -> bits >>1 ) | ((data & 1 ) <<7 ); 600data >>=1 ; 601if (prev & 1 ) 602 { 603put (s ,s -> bits ); 604s -> bits = 0x80 ; 605 } 606 } 607} 608 609void putbitsr (Save * s ,unsigned data ,unsigned bitcount ) 610{ 611while (bitcount -- ) 612putbits (s ,data >>bitcount ,1 ); 613} 614 615static void begin (Save * s ,const char * id ,unsigned len ) 616{ 617put32 (s ,len ); 618s -> crc = 0xffffffff ; 619put (s ,id [0 ]);put (s ,id [1 ]);put (s ,id [2 ]);put (s ,id [3 ]); 620} 621 622static void literal (Save * s ,unsigned v ) 623{ 624// Encode a literal/length using the built-in tables. 625// Could do better with a custom table but whatever. 626if (v < 144 )putbitsr (s ,0x030 + v - 0 ,8 ); 627else if (v < 256 )putbitsr (s ,0x190 + v - 144 ,9 ); 628else if (v < 280 )putbitsr (s ,0x000 + v - 256 ,7 ); 629else putbitsr (s ,0x0c0 + v - 280 ,8 ); 630} 631 632static void encodelen (Save * s ,unsigned code ,unsigned bits ,unsigned len ) 633{ 634literal (s ,code + (len >>bits )); 635putbits (s ,len ,bits ); 636putbits (s ,0 ,5 ); 637} 638 639static void endrun (Save * s ) 640{ 641s -> runlen -- ; 642literal (s ,s -> prev ); 643 644if (s -> runlen >=67 )encodelen (s ,277 ,4 ,s -> runlen - 67 ); 645else if (s -> runlen >=35 )encodelen (s ,273 ,3 ,s -> runlen - 35 ); 646else if (s -> runlen >=19 )encodelen (s ,269 ,2 ,s -> runlen - 19 ); 647else if (s -> runlen >=11 )encodelen (s ,265 ,1 ,s -> runlen - 11 ); 648else if (s -> runlen >=3 )encodelen (s ,257 ,0 ,s -> runlen - 3 ); 649else while (s -> runlen -- )literal (s ,s -> prev ); 650} 651 652static void encodeByte (Save * s ,unsigned char v ) 653{ 654updateAdler (s ,v ); 655 656// Simple RLE compression. We could do better by doing a search 657// to find matches, but this works pretty well TBH. 658if (s -> prev == v && s -> runlen < 115 ) 659 { 660s -> runlen ++ ; 661 }else { 662if (s -> runlen ) 663endrun (s ); 664 665s -> prev = v ; 666s -> runlen = 1 ; 667 } 668} 669 670static void savePngHeader (Save * s ,Tigr * bmp ) 671{ 672fwrite ("\211PNG\r\n\032\n" ,8 ,1 ,s -> out ); 673begin (s ,"IHDR" ,13 ); 674put32 (s ,bmp -> w ); 675put32 (s ,bmp -> h ); 676put (s ,8 );// bit depth 677put (s ,6 );// RGBA 678put (s ,0 );// compression (deflate) 679put (s ,0 );// filter (standard) 680put (s ,0 );// interlace off 681put32 (s , ~s -> crc ); 682} 683 684static long savePngData (Save * s ,Tigr * bmp ,long dataPos ) 685{ 686int x ,y ; 687long dataSize ; 688begin (s ,"IDAT" ,0 ); 689put (s ,0x08 );// zlib compression method 690put (s ,0x1d );// zlib compression flags 691putbits (s ,3 ,3 );// zlib last block + fixed dictionary 692for (y = 0 ;y < bmp -> h ;y ++ ) 693 { 694TPixel * row = & bmp -> pix [y * bmp -> w ]; 695TPixel prev = tigrRGBA (0 ,0 ,0 ,0 ); 696 697encodeByte (s ,1 );// sub filter 698for (x = 0 ;x < bmp -> w ;x ++ ) 699 { 700encodeByte (s ,row [x ].r - prev .r ); 701encodeByte (s ,row [x ].g - prev .g ); 702encodeByte (s ,row [x ].b - prev .b ); 703encodeByte (s ,row [x ].a - prev .a ); 704prev = row [x ]; 705 } 706 } 707endrun (s ); 708literal (s ,256 );// terminator 709while (s -> bits != 0x80 ) 710putbits (s ,0 ,1 ); 711put32 (s ,s -> adler ); 712dataSize = (ftell (s -> out )- dataPos )- 8 ; 713put32 (s , ~s -> crc ); 714return dataSize ; 715} 716 717int tigrSaveImage (const char * fileName ,Tigr * bmp ) 718{ 719Save s ; 720long dataPos ,dataSize ,err ; 721 722// TODO - unicode? id:0 gh:1 723FILE * out = fopen (fileName ,"wb" ); 724if (!out ) 725return 1 ; 726 727s .out = out ; 728s .adler = 1 ; 729s .bits = 0x80 ; 730s .prev = 0xffff ; 731s .runlen = 0 ; 732 733savePngHeader (& s ,bmp ); 734dataPos = ftell (s .out ); 735dataSize = savePngData (& s ,bmp ,dataPos ); 736 737// End chunk. 738begin (& s ,"IEND" ,0 ); 739put32 (& s , ~s .crc ); 740 741// Write back payload size. 742fseek (out ,dataPos ,SEEK_SET ); 743put32 (& s ,dataSize ); 744 745err = ferror (out ); 746fclose (out ); 747return !err ; 748} 749 750//////// End of inlined file: tigr_savepng.c //////// 751 752//////// Start of inlined file: tigr_utils.c //////// 753 754//#include "tigr_internal.h" 755#include <stdio.h> 756#include <stdlib.h> 757 758void * tigrReadFile (const char * fileName ,int * length ) 759{ 760// TODO - unicode? id:3 gh:4 761FILE * file ; 762char * data ; 763size_t len ; 764 765if (length ) 766* length = 0 ; 767 768file = fopen (fileName ,"rb" ); 769if (!file ) 770return NULL ; 771 772fseek (file ,0 ,SEEK_END ); 773len = ftell (file ); 774fseek (file ,0 ,SEEK_SET ); 775 776data = (char * )malloc (len + 1 ); 777if (!data ) 778 { 779fclose (file ); 780return NULL ; 781 } 782 783if (fread (data ,1 ,len ,file )!= len ) { 784free (data ); 785fclose (file ); 786return NULL ; 787 } 788data [len ]= '\0' ; 789fclose (file ); 790 791if (length ) 792* length = len ; 793 794return data ; 795} 796 797// Reads a single UTF8 codepoint. 798const char * tigrDecodeUTF8 (const char * text ,int * cp ) 799{ 800unsigned char c = * text ++ ; 801int extra = 0 ,min = 0 ; 802* cp = 0 ; 803if (c >=0xf0 ) {* cp = c & 0x07 ;extra = 3 ;min = 0x10000 ; } 804else if (c >=0xe0 ) {* cp = c & 0x0f ;extra = 2 ;min = 0x800 ; } 805else if (c >=0xc0 ) {* cp = c & 0x1f ;extra = 1 ;min = 0x80 ; } 806else if (c >=0x80 ) {* cp = 0xfffd ; } 807else * cp = c ; 808while (extra -- ) { 809c = * text ++ ; 810if ((c & 0xc0 )!= 0x80 ) {* cp = 0xfffd ;break ; } 811 (* cp )= ((* cp ) <<6 ) | (c & 0x3f ); 812 } 813if (* cp < min )* cp = 0xfffd ; 814return text ; 815} 816 817char * tigrEncodeUTF8 (char * text ,int cp ) 818{ 819if (cp < 0 || cp > 0x10ffff )cp = 0xfffd ; 820 821#define EMIT (X ,Y ,Z ) *text++ = X | ((cp >> Y)&Z) 822if (cp < 0x80 ) {EMIT (0x00 ,0 ,0x7f ); } 823else if (cp < 0x800 ) {EMIT (0xc0 ,6 ,0x1f );EMIT (0x80 ,0 ,0x3f ); } 824else if (cp < 0x10000 ) {EMIT (0xe0 ,12 ,0xf );EMIT (0x80 ,6 ,0x3f );EMIT (0x80 ,0 ,0x3f ); } 825else {EMIT (0xf0 ,18 ,0x7 );EMIT (0x80 ,12 ,0x3f );EMIT (0x80 ,6 ,0x3f );EMIT (0x80 ,0 ,0x3f ); } 826return text ; 827#undef EMIT 828} 829 830void tigrSetPostFX (Tigr * bmp ,int hblur ,int vblur ,float scanlines ,float contrast ) 831{ 832TigrInternal * win = tigrInternal (bmp ); 833win -> hblur = hblur ; 834win -> vblur = vblur ; 835win -> scanlines = scanlines ; 836win -> contrast = contrast ; 837} 838 839//////// End of inlined file: tigr_utils.c //////// 840 841//////// Start of inlined file: tigr_inflate.c //////// 842 843//#include "tigr_internal.h" 844#include <stdlib.h> 845#include <setjmp.h> 846 847typedef struct { 848unsigned bits ,count ; 849const unsigned char * in ,* inend ; 850unsigned char * out ,* outend ; 851jmp_buf jmp ; 852unsigned litcodes [288 ],distcodes [32 ],lencodes [19 ]; 853int tlit ,tdist ,tlen ; 854}State ; 855 856#define FAIL () longjmp(s->jmp, 1) 857#define CHECK (X ) if (!(X)) FAIL() 858 859// Built-in DEFLATE standard tables. 860static char order []= {16 ,17 ,18 ,0 ,8 ,7 ,9 ,6 ,10 ,5 ,11 ,4 ,12 ,3 ,13 ,2 ,14 ,1 ,15 }; 861static char lenBits [29 + 2 ]= {0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,1 ,1 ,2 ,2 ,2 ,2 ,3 ,3 ,3 ,3 ,4 ,4 ,4 ,4 ,5 ,5 ,5 ,5 ,0 ,0 ,0 }; 862static int lenBase [29 + 2 ]= {3 ,4 ,5 ,6 ,7 ,8 ,9 ,10 ,11 ,13 ,15 ,17 ,19 ,23 ,27 ,31 ,35 ,43 ,51 ,59 ,67 ,83 ,99 ,115 ,131 ,163 ,195 ,227 ,258 ,0 ,0 }; 863static char distBits [30 + 2 ]= {0 ,0 ,0 ,0 ,1 ,1 ,2 ,2 ,3 ,3 ,4 ,4 ,5 ,5 ,6 ,6 ,7 ,7 ,8 ,8 ,9 ,9 ,10 ,10 ,11 ,11 ,12 ,12 ,13 ,13 ,0 ,0 }; 864static int distBase [30 + 2 ]= {1 ,2 ,3 ,4 ,5 ,7 ,9 ,13 ,17 ,25 ,33 ,49 ,65 ,97 ,129 ,193 ,257 ,385 ,513 ,769 ,1025 ,1537 ,2049 ,3073 ,4097 ,6145 ,8193 ,12289 ,16385 ,24577 }; 865 866// Table to bit-reverse a byte. 867static const unsigned char reverseTable [256 ]= { 868#define R2 (n )n ,n + 128 ,n + 64 ,n + 192 869#define R4 (n )R2 (n ),R2 (n + 32 ),R2 (n + 16 ),R2 (n + 48 ) 870#define R6 (n )R4 (n ),R4 (n + 8 ),R4 (n + 4 ),R4 (n + 12 ) 871R6 (0 ),R6 (2 ),R6 (1 ),R6 (3 ) 872}; 873 874static unsigned rev16 (unsigned n ) {return (reverseTable [n & 0xff ] <<8 ) |reverseTable [(n >>8 )& 0xff ]; } 875 876static int bits (State * s ,int n ) 877{ 878int v = s -> bits & ((1 <<n )- 1 ); 879s -> bits >>=n ; 880s -> count -= n ; 881while (s -> count < 16 ) 882 { 883CHECK (s -> in != s -> inend ); 884s -> bits |= (* s -> in ++ ) <<s -> count ; 885s -> count += 8 ; 886 } 887return v ; 888} 889 890static unsigned char * emit (State * s ,int len ) 891{ 892s -> out += len ; 893CHECK (s -> out <=s -> outend ); 894return s -> out - len ; 895} 896 897static void copy (State * s ,const unsigned char * src ,int len ) 898{ 899unsigned char * dest = emit (s ,len ); 900while (len -- )* dest ++ = * src ++ ; 901} 902 903static int build (State * s ,unsigned * tree ,unsigned char * lens ,int symcount ) 904{ 905int n ,codes [16 ],first [16 ],counts [16 ]= {0 }; 906 907// Frequency count. 908for (n = 0 ;n < symcount ;n ++ )counts [lens [n ]]++ ; 909 910// Distribute codes. 911counts [0 ]= codes [0 ]= first [0 ]= 0 ; 912for (n = 1 ;n <=15 ;n ++ ) { 913codes [n ]= (codes [n - 1 ]+ counts [n - 1 ]) <<1 ; 914first [n ]= first [n - 1 ]+ counts [n - 1 ]; 915 } 916CHECK (first [15 ]+ counts [15 ] <=symcount ); 917 918// Insert keys into the tree for each symbol. 919for (n = 0 ;n < symcount ;n ++ ) 920 { 921int len = lens [n ]; 922if (len != 0 ) { 923int code = codes [len ]++ ,slot = first [len ]++ ; 924tree [slot ]= (code << (32 - len )) | (n <<4 ) |len ; 925 } 926 } 927 928return first [15 ]; 929} 930 931static int decode (State * s ,unsigned tree [],int max ) 932{ 933// Find the next prefix code. 934unsigned lo = 0 ,hi = max ,key ; 935unsigned search = (rev16 (s -> bits ) <<16 ) |0xffff ; 936while (lo < hi ) { 937unsigned guess = (lo + hi ) /2 ; 938if (search < tree [guess ])hi = guess ; 939else lo = guess + 1 ; 940 } 941 942// Pull out the key and check it. 943key = tree [lo - 1 ]; 944CHECK (((search ^key ) >> (32 - (key & 0xf )))== 0 ); 945 946bits (s ,key & 0xf ); 947return (key >>4 )& 0xfff ; 948} 949 950static void run (State * s ,int sym ) 951{ 952int length = bits (s ,lenBits [sym ])+ lenBase [sym ]; 953int dsym = decode (s ,s -> distcodes ,s -> tdist ); 954int offs = bits (s ,distBits [dsym ])+ distBase [dsym ]; 955copy (s ,s -> out - offs ,length ); 956} 957 958static void block (State * s ) 959{ 960for (;;) { 961int sym = decode (s ,s -> litcodes ,s -> tlit ); 962if (sym < 256 )* emit (s ,1 )= (unsigned char )sym ; 963else if (sym > 256 )run (s ,sym - 257 ); 964else break ; 965 } 966} 967 968static void stored (State * s ) 969{ 970// Uncompressed data block. 971int len ; 972bits (s ,s -> count & 7 ); 973len = bits (s ,16 ); 974CHECK (((len ^s -> bits )& 0xffff )== 0xffff ); 975CHECK (s -> in + len <=s -> inend ); 976 977copy (s ,s -> in ,len ); 978s -> in += len ; 979bits (s ,16 ); 980} 981 982static void fixed (State * s ) 983{ 984// Fixed set of Huffman codes. 985int n ; 986unsigned char lens [288 + 32 ]; 987for (n = 0 ;n <=143 ;n ++ )lens [n ]= 8 ; 988for (n = 144 ;n <=255 ;n ++ )lens [n ]= 9 ; 989for (n = 256 ;n <=279 ;n ++ )lens [n ]= 7 ; 990for (n = 280 ;n <=287 ;n ++ )lens [n ]= 8 ; 991for (n = 0 ;n < 32 ;n ++ )lens [288 + n ]= 5 ; 992 993// Build lit/dist trees. 994s -> tlit = build (s ,s -> litcodes ,lens ,288 ); 995s -> tdist = build (s ,s -> distcodes ,lens + 288 ,32 ); 996} 997 998static void dynamic (State * s ) 999{ 1000int n ,i ,nlit ,ndist ,nlen ; 1001unsigned char lenlens [19 ]= {0 },lens [288 + 32 ]; 1002nlit = 257 + bits (s ,5 ); 1003ndist = 1 + bits (s ,5 ); 1004nlen = 4 + bits (s ,4 ); 1005for (n = 0 ;n < nlen ;n ++ ) 1006lenlens [order [n ]]= (unsigned char )bits (s ,3 ); 1007 1008// Build the tree for decoding code lengths. 1009s -> tlen = build (s ,s -> lencodes ,lenlens ,19 ); 1010 1011// Decode code lengths. 1012for (n = 0 ;n < nlit + ndist ;) 1013 { 1014int sym = decode (s ,s -> lencodes ,s -> tlen ); 1015switch (sym ) { 1016case 16 :for (i = 3 + bits (s ,2 );i ;i -- ,n ++ )lens [n ]= lens [n - 1 ];break ; 1017case 17 :for (i = 3 + bits (s ,3 );i ;i -- ,n ++ )lens [n ]= 0 ;break ; 1018case 18 :for (i = 11 + bits (s ,7 );i ;i -- ,n ++ )lens [n ]= 0 ;break ; 1019default :lens [n ++ ]= (unsigned char )sym ;break ; 1020 } 1021 } 1022 1023// Build lit/dist trees. 1024s -> tlit = build (s ,s -> litcodes ,lens ,nlit ); 1025s -> tdist = build (s ,s -> distcodes ,lens + nlit ,ndist ); 1026} 1027 1028int tigrInflate (void * out ,unsigned outlen ,const void * in ,unsigned inlen ) 1029{ 1030int last ; 1031State * s = (State * )calloc (1 ,sizeof (State )); 1032 1033// We assume we can buffer 2 extra bytes from off the end of 'in'. 1034s -> in = (unsigned char * )in ;s -> inend = s -> in + inlen + 2 ; 1035s -> out = (unsigned char * )out ;s -> outend = s -> out + outlen ; 1036s -> bits = 0 ;s -> count = 0 ;bits (s ,0 ); 1037 1038if (setjmp (s -> jmp )== 1 ) { 1039free (s ); 1040return 0 ; 1041 } 1042 1043do { 1044last = bits (s ,1 ); 1045switch (bits (s ,2 )) { 1046case 0 :stored (s );break ; 1047case 1 :fixed (s );block (s );break ; 1048case 2 :dynamic (s );block (s );break ; 1049case 3 :FAIL (); 1050 } 1051 }while (!last ); 1052 1053free (s ); 1054return 1 ; 1055} 1056 1057#undef CHECK 1058#undef FAIL 1059 1060//////// End of inlined file: tigr_inflate.c //////// 1061 1062//////// Start of inlined file: tigr_print.c //////// 1063 1064//#include "tigr_internal.h" 1065//////// Start of inlined file: tigr_font.h //////// 1066 1067// Auto-generated by incbin.pl from font.png 1068 1069const unsigned char tigr_font []= { 10700x89 ,0x50 ,0x4e ,0x47 ,0x0d ,0x0a ,0x1a ,0x0a ,0x00 ,0x00 ,0x00 ,0x0d ,0x49 ,0x48 ,0x44 ,0x52 , 10710x00 ,0x00 ,0x00 ,0xfd ,0x00 ,0x00 ,0x00 ,0x5c ,0x08 ,0x03 ,0x00 ,0x00 ,0x00 ,0x92 ,0xab ,0x43 , 10720x85 ,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0xdf ,0x3a , 13090xec ,0xbf ,0xdd ,0x97 ,0xf3 ,0x3f ,0xca ,0x1b ,0xaa ,0xdf ,0xfc ,0xa4 ,0x05 ,0x0a ,0x00 ,0x00 , 13100x00 ,0x00 ,0x49 ,0x45 ,0x4e ,0x44 ,0xae ,0x42 ,0x60 ,0x82 }; 1311 1312int tigr_font_size = (int )sizeof (tigr_font ); 1313 1314 1315//////// End of inlined file: tigr_font.h //////// 1316 1317#include <stdlib.h> 1318#include <stdarg.h> 1319#include <errno.h> 1320#include <stdio.h> 1321 1322#ifdef _MSC_VER 1323#define vsnprintf _vsnprintf 1324#endif 1325 1326TigrFont tigrStockFont ; 1327TigrFont * tfont = & tigrStockFont ; 1328 1329// Converts 8-bit codepage entries into Unicode code points. 1330static int cp1252 []= { 13310x20ac ,0xfffd ,0x201a ,0x0192 ,0x201e ,0x2026 ,0x2020 ,0x2021 ,0x02c6 ,0x2030 ,0x0160 ,0x2039 ,0x0152 ,0xfffd ,0x017d ,0xfffd , 13320xfffd ,0x2018 ,0x2019 ,0x201c ,0x201d ,0x2022 ,0x2013 ,0x2014 ,0x02dc ,0x2122 ,0x0161 ,0x203a ,0x0153 ,0xfffd ,0x017e ,0x0178 , 13330x00a0 ,0x00a1 ,0x00a2 ,0x00a3 ,0x00a4 ,0x00a5 ,0x00a6 ,0x00a7 ,0x00a8 ,0x00a9 ,0x00aa ,0x00ab ,0x00ac ,0x00ad ,0x00ae ,0x00af , 13340x00b0 ,0x00b1 ,0x00b2 ,0x00b3 ,0x00b4 ,0x00b5 ,0x00b6 ,0x00b7 ,0x00b8 ,0x00b9 ,0x00ba ,0x00bb ,0x00bc ,0x00bd ,0x00be ,0x00bf , 13350x00c0 ,0x00c1 ,0x00c2 ,0x00c3 ,0x00c4 ,0x00c5 ,0x00c6 ,0x00c7 ,0x00c8 ,0x00c9 ,0x00ca ,0x00cb ,0x00cc ,0x00cd ,0x00ce ,0x00cf , 13360x00d0 ,0x00d1 ,0x00d2 ,0x00d3 ,0x00d4 ,0x00d5 ,0x00d6 ,0x00d7 ,0x00d8 ,0x00d9 ,0x00da ,0x00db ,0x00dc ,0x00dd ,0x00de ,0x00df , 13370x00e0 ,0x00e1 ,0x00e2 ,0x00e3 ,0x00e4 ,0x00e5 ,0x00e6 ,0x00e7 ,0x00e8 ,0x00e9 ,0x00ea ,0x00eb ,0x00ec ,0x00ed ,0x00ee ,0x00ef , 13380x00f0 ,0x00f1 ,0x00f2 ,0x00f3 ,0x00f4 ,0x00f5 ,0x00f6 ,0x00f7 ,0x00f8 ,0x00f9 ,0x00fa ,0x00fb ,0x00fc ,0x00fd ,0x00fe ,0x00ff , 1339}; 1340static int border (Tigr * bmp ,int x ,int y ) 1341{ 1342TPixel top = tigrGet (bmp ,0 ,0 ); 1343TPixel c = tigrGet (bmp ,x ,y ); 1344return (c .r == top .r && c .g == top .g && c .b == top .b )|| x >=bmp -> w || y >=bmp -> h ; 1345} 1346 1347static void scan (Tigr * bmp ,int * x ,int * y ,int * rowh ) 1348{ 1349while (* y < bmp -> h ) 1350 { 1351if (* x >=bmp -> w ) { 1352* x = 0 ; 1353 (* y )+= * rowh ; 1354* rowh = 1 ; 1355 } 1356if (!border (bmp ,* x ,* y )) 1357return ; 1358 (* x )++ ; 1359 } 1360} 1361 1362int tigrLoadGlyphs (TigrFont * font ,int codepage ) 1363{ 1364int i ,x = 0 ,y = 0 ,w ,h ,rowh = 1 ; 1365TigrGlyph * g ; 1366switch (codepage ) { 1367case 0 :font -> numGlyphs = 128 - 32 ;break ; 1368case 1252 :font -> numGlyphs = 256 - 32 ;break ; 1369 } 1370 1371font -> glyphs = (TigrGlyph * )calloc (font -> numGlyphs ,sizeof (TigrGlyph )); 1372for (i = 32 ;i < font -> numGlyphs + 32 ;i ++ ) 1373 { 1374// Find the next glyph. 1375scan (font -> bitmap ,& x ,& y ,& rowh ); 1376if (y >=font -> bitmap -> h ) 1377 { 1378errno = EINVAL ; 1379return 0 ; 1380 } 1381 1382// Scan the width and height 1383w = h = 0 ; 1384while (!border (font -> bitmap ,x + w ,y ))w ++ ; 1385while (!border (font -> bitmap ,x ,y + h ))h ++ ; 1386 1387// Look up the Unicode code point. 1388g = & font -> glyphs [i - 32 ]; 1389if (i < 128 )g -> code = i ;// ASCII 1390else if (codepage == 1252 )g -> code = cp1252 [i - 128 ]; 1391else {errno = EINVAL ;return 0 ; } 1392 1393g -> x = x ;g -> y = y ;g -> w = w ;g -> h = h ; 1394x += w ; 1395if (h != font -> glyphs [0 ].h ) {errno = EINVAL ;return 0 ; } 1396 1397if (h > rowh ) 1398rowh = h ; 1399 } 1400 1401// Sort by code point. 1402for (i = 1 ;i < font -> numGlyphs ;i ++ ) 1403 { 1404int j = i ; 1405TigrGlyph g = font -> glyphs [i ]; 1406while (j > 0 && font -> glyphs [j - 1 ].code > g .code ) { 1407font -> glyphs [j ]= font -> glyphs [j - 1 ]; 1408j -- ; 1409 } 1410font -> glyphs [j ]= g ; 1411 } 1412 1413return 1 ; 1414} 1415 1416TigrFont * tigrLoadFont (Tigr * bitmap ,int codepage ) 1417{ 1418TigrFont * font = (TigrFont * )calloc (1 ,sizeof (TigrFont )); 1419font -> bitmap = bitmap ; 1420if (!tigrLoadGlyphs (font ,codepage )) 1421 { 1422tigrFreeFont (font ); 1423return NULL ; 1424 } 1425return font ; 1426} 1427 1428void tigrFreeFont (TigrFont * font ) 1429{ 1430tigrFree (font -> bitmap ); 1431free (font -> glyphs ); 1432free (font ); 1433} 1434 1435static TigrGlyph * get (TigrFont * font ,int code ) 1436{ 1437unsigned lo = 0 ,hi = font -> numGlyphs ; 1438while (lo < hi ) { 1439unsigned guess = (lo + hi ) /2 ; 1440if (code < font -> glyphs [guess ].code )hi = guess ; 1441else lo = guess + 1 ; 1442 } 1443 1444if (lo == 0 || font -> glyphs [lo - 1 ].code != code ) 1445return & font -> glyphs ['?' - 32 ]; 1446else 1447return & font -> glyphs [lo - 1 ]; 1448} 1449 1450void tigrSetupFont (TigrFont * font ) 1451{ 1452// Load the stock font if needed. 1453if (font == tfont && !tfont -> bitmap ) 1454 { 1455tfont -> bitmap = tigrLoadImageMem (tigr_font ,tigr_font_size ); 1456tigrLoadGlyphs (tfont ,1252 ); 1457 } 1458} 1459 1460void tigrPrint (Tigr * dest ,TigrFont * font ,int x ,int y ,TPixel color ,const char * text , ...) 1461{ 1462char tmp [1024 ]; 1463TigrGlyph * g ; 1464va_list args ; 1465const char * p ; 1466int start = x ,c ; 1467 1468tigrSetupFont (font ); 1469 1470// Expand the formatting string. 1471va_start (args ,text ); 1472vsnprintf (tmp ,sizeof (tmp ),text ,args ); 1473tmp [sizeof (tmp )- 1 ]= 0 ; 1474va_end (args ); 1475 1476// Print each glyph. 1477p = tmp ; 1478while (* p ) 1479 { 1480p = tigrDecodeUTF8 (p ,& c ); 1481if (c == '\r' ) 1482continue ; 1483if (c == '\n' ) { 1484x = start ; 1485y += tigrTextHeight (font ,"" ); 1486continue ; 1487 } 1488g = get (font ,c ); 1489tigrBlitTint (dest ,font -> bitmap ,x ,y ,g -> x ,g -> y ,g -> w ,g -> h ,color ); 1490x += g -> w ; 1491 } 1492} 1493 1494int tigrTextWidth (TigrFont * font ,const char * text ) 1495{ 1496int x = 0 ,w = 0 ,c ; 1497tigrSetupFont (font ); 1498 1499while (* text ) 1500 { 1501text = tigrDecodeUTF8 (text ,& c ); 1502if (c == '\n' || c == '\r' ) { 1503x = 0 ; 1504 }else { 1505x += get (font ,c )-> w ; 1506w = (x > w ) ?x :w ; 1507 } 1508 } 1509return w ; 1510} 1511 1512int tigrTextHeight (TigrFont * font ,const char * text ) 1513{ 1514int rowh ,h ,c ; 1515tigrSetupFont (font ); 1516 1517h = rowh = get (font ,0 )-> h ; 1518while (* text ) 1519 { 1520text = tigrDecodeUTF8 (text ,& c ); 1521if (c == '\n' && * text ) 1522h += rowh ; 1523 } 1524return h ; 1525} 1526 1527//////// End of inlined file: tigr_print.c //////// 1528 1529 1530#ifdef _WIN32 1531#define WIN32_LEAN_AND_MEAN 1532#include <windows.h> 1533//////// Start of inlined file: tigr_upscale_d3d9_vs.h //////// 1534 1535#if 0 1536// 1537// Generated by Microsoft (R) HLSL Shader Compiler 10.0.10011.16384 1538// 1539// Parameters: 1540// 1541// float4 screenSize; 1542// float4 texSize; 1543// 1544// 1545// Registers: 1546// 1547// Name Reg Size 1548// ------------ ----- ---- 1549// screenSize c0 1 1550// texSize c1 1 1551// 1552 1553vs_2_0 1554def c2 ,-0.5 ,2 ,-1 ,0 1555def c3 ,1 ,-1 ,0 ,0 1556dcl_position v0 1557dcl_texcoord v1 1558mul oT0 .xy ,v1 ,c1 1559add r0 .xyz ,v0 .xyxw ,c2 .x 1560rcp r1 .xw ,c0 .x 1561rcp r1 .y ,c0 .y 1562mul r0 .xyz ,r0 ,r1 .xyww 1563mad r0 .xyz ,r0 ,c2 .y ,c2 .z 1564mad oPos .xyw ,r0 .xyzz ,c3 .xyzz ,c3 .zzzx 1565mov oPos .z ,v0 .z 1566 1567// approximately 8 instruction slots used 1568#endif 1569 1570const BYTE tigrUpscaleVSCode []= 1571{ 15720 ,2 ,254 ,255 ,254 ,255 , 157342 ,0 ,67 ,84 ,65 ,66 , 157428 ,0 ,0 ,0 ,111 ,0 , 15750 ,0 ,0 ,2 ,254 ,255 , 15762 ,0 ,0 ,0 ,28 ,0 , 15770 ,0 ,8 ,131 ,0 ,0 , 1578104 ,0 ,0 ,0 ,68 ,0 , 15790 ,0 ,2 ,0 ,0 ,0 , 15801 ,0 ,2 ,0 ,80 ,0 , 15810 ,0 ,0 ,0 ,0 ,0 , 158296 ,0 ,0 ,0 ,2 ,0 , 15831 ,0 ,1 ,0 ,6 ,0 , 158480 ,0 ,0 ,0 ,0 ,0 , 15850 ,0 ,115 ,99 ,114 ,101 , 1586101 ,110 ,83 ,105 ,122 ,101 , 15870 ,171 ,1 ,0 ,3 ,0 , 15881 ,0 ,4 ,0 ,1 ,0 , 15890 ,0 ,0 ,0 ,0 ,0 , 1590116 ,101 ,120 ,83 ,105 ,122 , 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,42 ,160 , 16321 ,0 ,0 ,2 ,0 ,0 , 16334 ,192 ,0 ,0 ,170 ,144 , 1634255 ,255 ,0 ,0 1635}; 1636 1637//////// End of inlined file: tigr_upscale_d3d9_vs.h //////// 1638 1639//////// Start of inlined file: tigr_upscale_d3d9_ps.h //////// 1640 1641#if 0 1642// 1643// Generated by Microsoft (R) HLSL Shader Compiler 10.0.10011.16384 1644// 1645// Parameters: 1646// 1647// sampler2D image; 1648// float4 params; 1649// float4 texSize; 1650// 1651// 1652// Registers: 1653// 1654// Name Reg Size 1655// ------------ ----- ---- 1656// texSize c1 1 1657// params c2 1 1658// image s0 1 1659// 1660 1661ps_2_0 1662def c0 ,0.5 ,-0.5 ,0 ,0 1663dcl t0 .xy 1664dcl_2d s0 1665frc r0 .w ,t0 .y 1666add r0 .x ,- r0 .w ,c0 .x 1667mov r1 .w ,c0 .x 1668mad r0 .x ,c2 .z ,r0 .x ,r1 .w 1669add r0 .x ,r0 .x ,r0 .x 1670frc r0 .yz ,t0 .zxyw 1671add r0 .yz ,- r0 ,t0 .zxyw 1672add r0 .yz ,r0 ,c0 .x 1673lrp r1 .xy ,c2 ,t0 ,r0 .yzxw 1674mul r2 .x ,r1 .x ,c1 .z 1675mul r2 .y ,r1 .y ,c1 .w 1676texld r2 ,r2 ,s0 1677mad r0 .xyz ,r2 ,r0 .x ,c0 .y 1678mad r2 .xyz ,c2 .w ,r0 ,r1 .w 1679mov oC0 ,r2 1680 1681// approximately 15 instruction slots used (1 texture, 14 arithmetic) 1682#endif 1683 1684const BYTE tigrUpscalePSCode []= 1685{ 16860 ,2 ,255 ,255 ,254 ,255 , 168752 ,0 ,67 ,84 ,65 ,66 , 168828 ,0 ,0 ,0 ,151 ,0 , 16890 ,0 ,0 ,2 ,255 ,255 , 16903 ,0 ,0 ,0 ,28 ,0 , 16910 ,0 ,8 ,131 ,0 ,0 , 1692144 ,0 ,0 ,0 ,88 ,0 , 16930 ,0 ,3 ,0 ,0 ,0 , 16941 ,0 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 17350 ,2 ,1 ,0 ,8 ,128 , 17360 ,0 ,0 ,160 ,4 ,0 , 17370 ,4 ,0 ,0 ,1 ,128 , 17382 ,0 ,170 ,160 ,0 ,0 , 17390 ,128 ,1 ,0 ,255 ,128 , 17402 ,0 ,0 ,3 ,0 ,0 , 17411 ,128 ,0 ,0 ,0 ,128 , 17420 ,0 ,0 ,128 ,19 ,0 , 17430 ,2 ,0 ,0 ,6 ,128 , 17440 ,0 ,210 ,176 ,2 ,0 , 17450 ,3 ,0 ,0 ,6 ,128 , 17460 ,0 ,228 ,129 ,0 ,0 , 1747210 ,176 ,2 ,0 ,0 ,3 , 17480 ,0 ,6 ,128 ,0 ,0 , 1749228 ,128 ,0 ,0 ,0 ,160 , 175018 ,0 ,0 ,4 ,1 ,0 , 17513 ,128 ,2 ,0 ,228 ,160 , 17520 ,0 ,228 ,176 ,0 ,0 , 1753201 ,128 ,5 ,0 ,0 ,3 , 17542 ,0 ,1 ,128 ,1 ,0 , 17550 ,128 ,1 ,0 ,170 ,160 , 17565 ,0 ,0 ,3 ,2 ,0 , 17572 ,128 ,1 ,0 ,85 ,128 , 17581 ,0 ,255 ,160 ,66 ,0 , 17590 ,3 ,2 ,0 ,15 ,128 , 17602 ,0 ,228 ,128 ,0 ,8 , 1761228 ,160 ,4 ,0 ,0 ,4 , 17620 ,0 ,7 ,128 ,2 ,0 , 1763228 ,128 ,0 ,0 ,0 ,128 , 17640 ,0 ,85 ,160 ,4 ,0 , 17650 ,4 ,2 ,0 ,7 ,128 , 17662 ,0 ,255 ,160 ,0 ,0 , 1767228 ,128 ,1 ,0 ,255 ,128 , 17681 ,0 ,0 ,2 ,0 ,8 , 176915 ,128 ,2 ,0 ,228 ,128 , 1770255 ,255 ,0 ,0 1771}; 1772 1773//////// End of inlined file: tigr_upscale_d3d9_ps.h //////// 1774 1775//////// Start of inlined file: tigr_d3d9.c //////// 1776 1777//#include "tigr_internal.h" 1778 1779#ifdef TIGR_GAPI_D3D9 1780IDirect3D9 * tigrD3D = NULL ; 1781extern const unsigned char tigrUpscaleVSCode [],tigrUpscalePSCode []; 1782 1783void tigrGAPICreate (Tigr * bmp ) 1784{ 1785TigrInternal * win = tigrInternal (bmp ); 1786D3D9Stuff * d3d = & win -> d3d9 ; 1787DWORD flags ; 1788D3DCAPS9 caps ; 1789 1790if (!tigrD3D ) 1791 { 1792tigrD3D = Direct3DCreate9 (D3D_SDK_VERSION ); 1793if (!tigrD3D ) 1794tigrError (bmp ,"Cannot initialize Direct3D 9." ); 1795 } 1796 1797// Initialize D3D 1798ZeroMemory (& d3d -> params ,sizeof (d3d -> params )); 1799d3d -> params .Windowed = TRUE; 1800d3d -> params .SwapEffect = D3DSWAPEFFECT_DISCARD ; 1801d3d -> params .BackBufferFormat = D3DFMT_A8R8G8B8 ; 1802d3d -> params .EnableAutoDepthStencil = FALSE; 1803d3d -> params .PresentationInterval = D3DPRESENT_INTERVAL_ONE ;// TODO- vsync off if fps suffers? 1804d3d -> params .Flags = 0 ; 1805d3d -> params .BackBufferWidth = bmp -> w ; 1806d3d -> params .BackBufferHeight = bmp -> h ; 1807 1808// Check device caps. 1809if (FAILED (IDirect3D9_GetDeviceCaps (tigrD3D ,D3DADAPTER_DEFAULT ,D3DDEVTYPE_HAL ,& caps ))) 1810tigrError (bmp ,"Cannot query Direct3D 9 capabilities.\n" ); 1811 1812// Check vertex processing mode. Ideally I'd just always use software, 1813// but some hardware only supports hardware mode (!) 1814flags = D3DCREATE_PUREDEVICE |D3DCREATE_FPU_PRESERVE ; 1815if (caps .VertexProcessingCaps != 0 ) 1816flags |=D3DCREATE_HARDWARE_VERTEXPROCESSING ; 1817else 1818flags |=D3DCREATE_SOFTWARE_VERTEXPROCESSING ; 1819 1820// Create the device. 1821if (IDirect3D9_CreateDevice (tigrD3D ,D3DADAPTER_DEFAULT ,D3DDEVTYPE_HAL , (HWND )bmp -> handle , 1822flags ,& d3d -> params ,& d3d -> dev )) 1823tigrError (bmp ,"Cannot create Direct3D 9 device.\n" ); 1824 1825// Create upscaling shaders. 1826if (FAILED (IDirect3DDevice9_CreateVertexShader (d3d -> dev , (DWORD * )tigrUpscaleVSCode ,& d3d -> vs )) 1827|| FAILED (IDirect3DDevice9_CreatePixelShader (d3d -> dev , (DWORD * )tigrUpscalePSCode ,& d3d -> ps ))) 1828tigrError (bmp ,"Cannot create Direct3D 9 shaders.\n" ); 1829} 1830 1831void tigrGAPIBegin (Tigr * bmp ) 1832{ 1833HRESULT hr ; 1834TigrInternal * win = tigrInternal (bmp ); 1835D3D9Stuff * d3d = & win -> d3d9 ; 1836 1837if (d3d -> lost ) 1838 { 1839// Check if it's OK to resume work yet. 1840if (IDirect3DDevice9_TestCooperativeLevel (d3d -> dev )== D3DERR_DEVICELOST ) 1841return ; 1842 1843hr = IDirect3DDevice9_Reset (d3d -> dev ,& d3d -> params ); 1844if (hr == D3DERR_DEVICELOST ) 1845return ; 1846 1847if (FAILED (hr ) 1848|| FAILED (IDirect3DDevice9_CreateTexture (d3d -> dev ,bmp -> w ,bmp -> h ,1 ,D3DUSAGE_DYNAMIC ,D3DFMT_A8R8G8B8 , 1849D3DPOOL_SYSTEMMEM ,& d3d -> sysTex [0 ],NULL )) 1850|| FAILED (IDirect3DDevice9_CreateTexture (d3d -> dev ,bmp -> w ,bmp -> h ,1 ,0 ,D3DFMT_A8R8G8B8 , 1851D3DPOOL_DEFAULT ,& d3d -> vidTex [0 ],NULL )) 1852|| FAILED (IDirect3DDevice9_CreateTexture (d3d -> dev ,win -> widgets -> w ,win -> widgets -> h ,1 ,D3DUSAGE_DYNAMIC ,D3DFMT_A8R8G8B8 , 1853D3DPOOL_SYSTEMMEM ,& d3d -> sysTex [1 ],NULL )) 1854|| FAILED (IDirect3DDevice9_CreateTexture (d3d -> dev ,win -> widgets -> w ,win -> widgets -> h ,1 ,0 ,D3DFMT_A8R8G8B8 , 1855D3DPOOL_DEFAULT ,& d3d -> vidTex [1 ],NULL ))) 1856 { 1857tigrError (bmp ,"Error creating Direct3D 9 textures.\n" ); 1858 } 1859 1860d3d -> lost = 0 ; 1861 } 1862} 1863 1864void tigrGAPIEnd (Tigr * bmp ) 1865{ 1866TigrInternal * win = tigrInternal (bmp ); 1867D3D9Stuff * d3d = & win -> d3d9 ; 1868if (!d3d -> lost ) 1869 { 1870IDirect3DTexture9_Release (d3d -> sysTex [0 ]); 1871IDirect3DTexture9_Release (d3d -> vidTex [0 ]); 1872IDirect3DTexture9_Release (d3d -> sysTex [1 ]); 1873IDirect3DTexture9_Release (d3d -> vidTex [1 ]); 1874IDirect3DDevice9_Reset (d3d -> dev ,& d3d -> params ); 1875d3d -> lost = 1 ; 1876 } 1877} 1878 1879void tigrGAPIDestroy (Tigr * bmp ) 1880{ 1881TigrInternal * win = tigrInternal (bmp ); 1882D3D9Stuff * d3d = & win -> d3d9 ; 1883 1884IDirect3DVertexShader9_Release (d3d -> vs ); 1885IDirect3DPixelShader9_Release (d3d -> ps ); 1886IDirect3DDevice9_Release (d3d -> dev ); 1887} 1888 1889void tigrGAPIResize (Tigr * bmp ,int width ,int height ) 1890{ 1891TigrInternal * win = tigrInternal (bmp ); 1892D3D9Stuff * d3d = & win -> d3d9 ; 1893 1894tigrGAPIEnd (bmp ); 1895d3d -> params .BackBufferWidth = width ; 1896d3d -> params .BackBufferHeight = height ; 1897tigrGAPIBegin (bmp ); 1898} 1899 1900void tigrDxUpdate (IDirect3DDevice9 * dev ,IDirect3DTexture9 * sysTex ,IDirect3DTexture9 * vidTex ,Tigr * bmp ) 1901{ 1902D3DLOCKED_RECT rect ; 1903TPixel * src ,* dest ; 1904int y ; 1905 1906// Lock the system memory texture. 1907IDirect3DTexture9_LockRect (sysTex ,0 ,& rect ,NULL ,D3DLOCK_DISCARD ); 1908 1909// Copy our bitmap into it. 1910src = bmp -> pix ; 1911for (y = 0 ;y < bmp -> h ;y ++ ) 1912 { 1913dest = (TPixel * )( (char * )rect .pBits + rect .Pitch * y ); 1914memcpy (dest ,src ,bmp -> w * sizeof (TPixel )); 1915src += bmp -> w ; 1916 } 1917 1918IDirect3DTexture9_UnlockRect (sysTex ,0 ); 1919 1920// Update that into somewhere useful. 1921IDirect3DDevice9_UpdateTexture (dev , (IDirect3DBaseTexture9 * )sysTex , (IDirect3DBaseTexture9 * )vidTex ); 1922} 1923 1924void tigrDxQuad (IDirect3DDevice9 * dev ,IDirect3DTexture9 * tex ,int ix0 ,int iy0 ,int ix1 ,int iy1 ) 1925{ 1926float tri [6 ][5 ]; 1927float x0 = (float )ix0 ; 1928float y0 = (float )iy0 ; 1929float x1 = (float )ix1 ; 1930float y1 = (float )iy1 ; 1931 1932// x y z u v 1933tri [0 ][0 ]= x0 ;tri [0 ][1 ]= y0 ;tri [0 ][2 ]= 0 ;tri [0 ][3 ]= 0 ;tri [0 ][4 ]= 0 ; 1934tri [1 ][0 ]= x1 ;tri [1 ][1 ]= y0 ;tri [1 ][2 ]= 0 ;tri [1 ][3 ]= 1 ;tri [1 ][4 ]= 0 ; 1935tri [2 ][0 ]= x0 ;tri [2 ][1 ]= y1 ;tri [2 ][2 ]= 0 ;tri [2 ][3 ]= 0 ;tri [2 ][4 ]= 1 ; 1936 1937tri [3 ][0 ]= x1 ;tri [3 ][1 ]= y0 ;tri [3 ][2 ]= 0 ;tri [3 ][3 ]= 1 ;tri [3 ][4 ]= 0 ; 1938tri [4 ][0 ]= x1 ;tri [4 ][1 ]= y1 ;tri [4 ][2 ]= 0 ;tri [4 ][3 ]= 1 ;tri [4 ][4 ]= 1 ; 1939tri [5 ][0 ]= x0 ;tri [5 ][1 ]= y1 ;tri [5 ][2 ]= 0 ;tri [5 ][3 ]= 0 ;tri [5 ][4 ]= 1 ; 1940 1941IDirect3DDevice9_SetTexture (dev ,0 , (IDirect3DBaseTexture9 * )tex ); 1942IDirect3DDevice9_DrawPrimitiveUP (dev ,D3DPT_TRIANGLELIST ,2 ,& tri ,5 * 4 ); 1943} 1944 1945void tigrGAPIPresent (Tigr * bmp ,int dw ,int dh ) 1946{ 1947TigrInternal * win ; 1948D3D9Stuff * d3d ; 1949HWND hWnd ; 1950HRESULT hr ; 1951 1952win = tigrInternal (bmp ); 1953d3d = & win -> d3d9 ; 1954hWnd = (HWND )bmp -> handle ; 1955 1956// Make sure we have a device. 1957// If we don't, then sleep to simulate the vsync until it comes back. 1958if (d3d -> lost ) 1959 { 1960tigrGAPIBegin (bmp ); 1961if (d3d -> lost ) { 1962Sleep (15 ); 1963return ; 1964 } 1965 } 1966 1967IDirect3DDevice9_BeginScene (d3d -> dev ); 1968 1969// Upload the pixel data. 1970tigrDxUpdate (d3d -> dev ,d3d -> sysTex [0 ],d3d -> vidTex [0 ],bmp ); 1971tigrDxUpdate (d3d -> dev ,d3d -> sysTex [1 ],d3d -> vidTex [1 ],win -> widgets ); 1972 1973// Set up our upscale shader. 1974IDirect3DDevice9_SetRenderState (d3d -> dev ,D3DRS_ALPHABLENDENABLE , FALSE); 1975IDirect3DDevice9_SetVertexShader (d3d -> dev ,d3d -> vs ); 1976IDirect3DDevice9_SetPixelShader (d3d -> dev ,d3d -> ps ); 1977IDirect3DDevice9_SetFVF (d3d -> dev ,D3DFVF_XYZ |D3DFVF_TEX1 ); 1978IDirect3DDevice9_SetSamplerState (d3d -> dev ,0 ,D3DSAMP_ADDRESSU ,D3DTADDRESS_BORDER ); 1979IDirect3DDevice9_SetSamplerState (d3d -> dev ,0 ,D3DSAMP_ADDRESSV ,D3DTADDRESS_BORDER ); 1980IDirect3DDevice9_SetSamplerState (d3d -> dev ,0 ,D3DSAMP_MINFILTER ,D3DTEXF_LINEAR ); 1981IDirect3DDevice9_SetSamplerState (d3d -> dev ,0 ,D3DSAMP_MAGFILTER ,D3DTEXF_LINEAR ); 1982 1983// Let the shader know about the window size. 1984 { 1985float consts [12 ]; 1986consts [0 ]= (float )dw ; 1987consts [1 ]= (float )dh ; 1988consts [2 ]= 1.0f /dw ; 1989consts [3 ]= 1.0f /dh ; 1990consts [4 ]= (float )bmp -> w ; 1991consts [5 ]= (float )bmp -> h ; 1992consts [6 ]= 1.0f /bmp -> w ; 1993consts [7 ]= 1.0f /bmp -> h ; 1994consts [8 ]= win -> hblur ?1.0f :0.0f ; 1995consts [9 ]= win -> vblur ?1.0f :0.0f ; 1996consts [10 ]= win -> scanlines ; 1997consts [11 ]= win -> contrast ; 1998IDirect3DDevice9_SetVertexShaderConstantF (d3d -> dev ,0 ,consts ,3 ); 1999IDirect3DDevice9_SetPixelShaderConstantF (d3d -> dev ,0 ,consts ,3 ); 2000 } 2001 2002// We clear so that a) we fill the border, and b) to let the driver 2003// know it can discard the contents. 2004IDirect3DDevice9_Clear (d3d -> dev ,0 ,NULL ,D3DCLEAR_TARGET ,0 ,0 ,0 ); 2005 2006// Blit the final image to the screen. 2007tigrDxQuad (d3d -> dev ,d3d -> vidTex [0 ],win -> pos [0 ],win -> pos [1 ],win -> pos [2 ],win -> pos [3 ]); 2008 2009// Draw the widget overlay. 2010IDirect3DDevice9_SetRenderState (d3d -> dev ,D3DRS_ALPHABLENDENABLE , TRUE); 2011IDirect3DDevice9_SetRenderState (d3d -> dev ,D3DRS_SRCBLEND ,D3DBLEND_SRCALPHA ); 2012IDirect3DDevice9_SetRenderState (d3d -> dev ,D3DRS_DESTBLEND ,D3DBLEND_INVSRCALPHA ); 2013tigrDxQuad (d3d -> dev ,d3d -> vidTex [1 ], 2014 (int )(dw - win -> widgets -> w * win -> widgetsScale ),0 , 2015dw , (int )(win -> widgets -> h * win -> widgetsScale )); 2016 2017// Et fini. 2018IDirect3DDevice9_EndScene (d3d -> dev ); 2019hr = IDirect3DDevice9_Present (d3d -> dev ,NULL ,NULL ,hWnd ,NULL ); 2020 2021// See if we lost our device. 2022if (hr == D3DERR_DEVICELOST ) 2023tigrGAPIEnd (bmp ); 2024} 2025 2026#endif 2027 2028//////// End of inlined file: tigr_d3d9.c //////// 2029 2030#endif // _WIN32 2031 2032//////// Start of inlined file: tigr_upscale_gl_vs.h //////// 2033 2034// Auto-generated by incbin.pl from tigr_upscale_gl_vs.glsl 2035 2036const unsig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,0x6f ,0x69 ,0x64 ,0x20 ,0x6d ,0x61 ,0x69 ,0x6e ,0x28 ,0x29 , 20480x0d ,0x0a ,0x7b ,0x0d ,0x0a ,0x09 ,0x75 ,0x76 ,0x20 ,0x3d ,0x20 ,0x75 ,0x76 ,0x5f ,0x69 ,0x6e , 20490x3b ,0x0d ,0x0a ,0x09 ,0x67 ,0x6c ,0x5f ,0x50 ,0x6f ,0x73 ,0x69 ,0x74 ,0x69 ,0x6f ,0x6e ,0x20 , 20500x3d ,0x20 ,0x70 ,0x72 ,0x6f ,0x6a ,0x65 ,0x63 ,0x74 ,0x69 ,0x6f ,0x6e ,0x20 ,0x2a ,0x20 ,0x6d , 20510x6f ,0x64 ,0x65 ,0x6c ,0x20 ,0x2a ,0x20 ,0x76 ,0x65 ,0x63 ,0x34 ,0x28 ,0x70 ,0x6f ,0x73 ,0x5f , 20520x69 ,0x6e ,0x2c ,0x20 ,0x30 ,0x2e ,0x30 ,0x2c ,0x20 ,0x31 ,0x2e ,0x30 ,0x29 ,0x3b ,0x0d ,0x0a , 20530x7d ,0x0d ,0x0a }; 2054 2055int tigr_upscale_gl_vs_size = (int )sizeof (tigr_upscale_gl_vs ); 2056 2057 2058//////// End of inlined file: tigr_upscale_gl_vs.h //////// 2059 2060//////// Start of inlined file: tigr_upscale_gl_fs.h //////// 2061 2062// Auto-generated by incbin.pl from tigr_upscale_gl_fs.glsl 2063 2064const unsigned char tigr_upscale_gl_fs []= { 20650x23 ,0x76 ,0x65 ,0x72 ,0x73 ,0x69 ,0x6f ,0x6e ,0x20 ,0x33 ,0x33 ,0x30 ,0x20 ,0x63 ,0x6f ,0x72 , 20660x65 ,0x0d ,0x0a ,0x0d ,0x0a ,0x69 ,0x6e ,0x20 ,0x76 ,0x65 ,0x63 ,0x32 ,0x20 ,0x75 ,0x76 ,0x3b , 20670x0d ,0x0a ,0x0d ,0x0a ,0x6f ,0x75 ,0x74 ,0x20 ,0x76 ,0x65 ,0x63 ,0x34 ,0x20 ,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,0x69 , 20890x78 ,0x28 ,0x76 ,0x65 ,0x63 ,0x34 ,0x28 ,0x30 ,0x2e ,0x35 ,0x29 ,0x2c ,0x20 ,0x63 ,0x2c ,0x20 , 20900x70 ,0x61 ,0x72 ,0x61 ,0x6d ,0x65 ,0x74 ,0x65 ,0x72 ,0x73 ,0x2e ,0x77 ,0x29 ,0x3b ,0x20 ,0x2f , 20910x2f ,0x63 ,0x6f ,0x6e ,0x74 ,0x72 ,0x61 ,0x73 ,0x74 ,0x20 ,0x0d ,0x0a ,0x09 ,0x63 ,0x6f ,0x6c , 20920x6f ,0x72 ,0x20 ,0x3d ,0x20 ,0x63 ,0x3b ,0x0d ,0x0a ,0x7d ,0x0d ,0x0a }; 2093 2094int tigr_upscale_gl_fs_size = (int )sizeof (tigr_upscale_gl_fs ); 2095 2096 2097//////// End of inlined file: tigr_upscale_gl_fs.h //////// 2098 2099//////// Start of inlined file: tigr_win.c //////// 2100 2101//#include "tigr_internal.h" 2102#include <assert.h> 2103 2104// not really windows stuff 2105TigrInternal * tigrInternal (Tigr * bmp ) 2106{ 2107assert (bmp -> handle ); 2108return (TigrInternal * )(bmp + 1 ); 2109} 2110 2111#ifdef _WIN32 2112#define WIN32_LEAN_AND_MEAN 2113#include <windows.h> 2114#include <shellapi.h> 2115#include <stdio.h> 2116#include <stdlib.h> 2117 2118#define WIDGET_SCALE 3 2119#define WIDGET_FADE 16 2120 2121int main (int argc ,char * argv []); 2122 2123#ifndef TIGR_DO_NOT_PRESERVE_WINDOW_POSITION 2124HKEY tigrRegKey ; 2125#endif 2126 2127static wchar_t * unicode (const char * str ) 2128{ 2129int len = MultiByteToWideChar (CP_UTF8 ,0 ,str ,-1 ,0 ,0 ); 2130wchar_t * dest = (wchar_t * )malloc (sizeof (wchar_t )* len ); 2131MultiByteToWideChar (CP_UTF8 ,0 ,str ,-1 ,dest ,len ); 2132return dest ; 2133} 2134 2135void tigrError (Tigr * bmp ,const char * message , ...) 2136{ 2137char tmp [1024 ]; 2138 2139va_list args ; 2140va_start (args ,message ); 2141_vsnprintf (tmp ,sizeof (tmp ),message ,args ); 2142tmp [sizeof (tmp )- 1 ]= 0 ; 2143va_end (args ); 2144 2145MessageBoxW (bmp ? (HWND )bmp -> handle :NULL ,unicode (tmp ),bmp ?tigrInternal (bmp )-> wtitle :L"Error" ,MB_OK |MB_ICONERROR ); 2146exit (1 ); 2147} 2148 2149void tigrEnterBorderlessWindowed (Tigr * bmp ) 2150{ 2151// Enter borderless windowed mode. 2152MONITORINFO mi = {sizeof (mi ) }; 2153TigrInternal * win = tigrInternal (bmp ); 2154 2155GetWindowRect ((HWND )bmp -> handle ,& win -> oldPos ); 2156 2157GetMonitorInfo (MonitorFromWindow ((HWND )bmp -> handle ,MONITOR_DEFAULTTONEAREST ),& mi ); 2158win -> dwStyle = WS_VISIBLE |WS_POPUP ; 2159SetWindowLong ((HWND )bmp -> handle ,GWL_STYLE ,win -> dwStyle ); 2160SetWindowPos ((HWND )bmp -> handle ,HWND_TOP , 2161mi .rcMonitor .left , 2162mi .rcMonitor .top , 2163mi .rcMonitor .right - mi .rcMonitor .left , 2164mi .rcMonitor .bottom - mi .rcMonitor .top , 21650 ); 2166} 2167 2168void tigrLeaveBorderlessWindowed (Tigr * bmp ) 2169{ 2170TigrInternal * win = tigrInternal (bmp ); 2171 2172win -> dwStyle = WS_VISIBLE |WS_OVERLAPPEDWINDOW ; 2173SetWindowLong ((HWND )bmp -> handle ,GWL_STYLE ,win -> dwStyle ); 2174 2175SetWindowPos ((HWND )bmp -> handle ,NULL , 2176win -> oldPos .left , 2177win -> oldPos .top , 2178win -> oldPos .right - win -> oldPos .left , 2179win -> oldPos .bottom - win -> oldPos .top , 21800 ); 2181} 2182 2183void tigrDxUpdateWidgets (Tigr * bmp ,int dw ,int dh ) 2184{ 2185POINT pt ; 2186int i ,x ,clicked = 0 ; 2187char str [8 ]; 2188TPixel col ; 2189TPixel off = tigrRGB (255 ,255 ,255 ); 2190TPixel on = tigrRGB (0 ,200 ,255 ); 2191TigrInternal * win = tigrInternal (bmp ); 2192 (void )dh ; 2193 2194tigrClear (win -> widgets ,tigrRGBA (0 ,0 ,0 ,0 )); 2195 2196if (!(win -> dwStyle & WS_POPUP )) 2197 { 2198win -> widgetsWanted = 0 ; 2199win -> widgetAlpha = 0 ; 2200return ; 2201 } 2202 2203// See if we want to be showing widgets or not. 2204GetCursorPos (& pt ); 2205ScreenToClient ((HWND )bmp -> handle ,& pt ); 2206if (pt .y == 0 ) 2207win -> widgetsWanted = 1 ; 2208if (pt .y > win -> widgets -> h * WIDGET_SCALE ) 2209win -> widgetsWanted = 0 ; 2210 2211// Track the alpha. 2212if (win -> widgetsWanted ) 2213win -> widgetAlpha = (win -> widgetAlpha <=255 - WIDGET_FADE ) ?win -> widgetAlpha + WIDGET_FADE :255 ; 2214else 2215win -> widgetAlpha = (win -> widgetAlpha >=WIDGET_FADE ) ?win -> widgetAlpha - WIDGET_FADE :0 ; 2216 2217// Get relative coords. 2218pt .x -= (dw - win -> widgets -> w * WIDGET_SCALE ); 2219pt .x /=WIDGET_SCALE ; 2220pt .y /=WIDGET_SCALE ; 2221 2222tigrClear (win -> widgets ,tigrRGBA (0 ,0 ,0 ,win -> widgetAlpha )); 2223 2224// Render it. 2225for (i = 0 ;i < 3 ;i ++ ) 2226 { 2227switch (i ) { 2228case 0 :str [0 ]= '_' ;str [1 ]= 0 ;break ;// "_" (minimize) 2229case 1 :str [0 ]= 0xEF ;str [1 ]= 0xBF ;str [2 ]= 0xBD ;str [3 ]= 0 ;break ;// "[]" (maximize) 2230case 2 :str [0 ]= 0xC3 ;str [1 ]= 0x97 ;str [2 ]= 0 ;break ;// "x" (close) 2231 } 2232x = win -> widgets -> w + (i - 3 )* 12 ; 2233if (i == 2 ) 2234off = tigrRGB (255 ,0 ,0 ); 2235if (pt .x >=x && pt .x < x + 10 && pt .y < win -> widgets -> h ) 2236 { 2237col = on ; 2238if (GetAsyncKeyState (VK_LBUTTON )& 0x8000 ) 2239clicked |=1 <<i ; 2240 }else { 2241col = off ; 2242 } 2243col .a = win -> widgetAlpha ; 2244tigrPrint (win -> widgets ,tfont ,x ,2 ,col ,str ); 2245 } 2246 2247if (clicked & 1 ) 2248ShowWindow ((HWND )bmp -> handle ,SW_MINIMIZE ); 2249if (clicked & 2 ) 2250tigrLeaveBorderlessWindowed (bmp ); 2251if (clicked & 4 ) 2252SendMessage ((HWND )bmp -> handle ,WM_CLOSE ,0 ,0 ); 2253} 2254 2255void tigrUpdate (Tigr * bmp ) 2256{ 2257MSG msg ; 2258RECT rc ; 2259int dw ,dh ; 2260TigrInternal * win = tigrInternal (bmp ); 2261 2262if (!win -> shown ) 2263 { 2264win -> shown = 1 ; 2265UpdateWindow ((HWND )bmp -> handle ); 2266ShowWindow ((HWND )bmp -> handle ,SW_SHOW ); 2267 } 2268 2269// Get the window size. 2270GetClientRect ((HWND )bmp -> handle ,& rc ); 2271dw = rc .right - rc .left ; 2272dh = rc .bottom - rc .top ; 2273 2274// Update the widget overlay. 2275tigrDxUpdateWidgets (bmp ,dw ,dh ); 2276 2277tigrGAPIPresent (bmp ,dw ,dh ); 2278 2279memcpy (win -> prev ,win -> keys ,256 ); 2280 2281// Run the message pump. 2282while (PeekMessage (& msg , (HWND )bmp -> handle ,0 ,0 ,PM_REMOVE )) 2283 { 2284if (msg .message == WM_QUIT ) 2285break ; 2286 2287TranslateMessage (& msg ); 2288DispatchMessage (& msg ); 2289 } 2290} 2291 2292static BOOL UnadjustWindowRectEx (LPRECT prc ,DWORD dwStyle ,BOOL fMenu ,DWORD dwExStyle ) 2293{ 2294BOOL fRc ; 2295RECT rc ; 2296SetRectEmpty (& rc ); 2297fRc = AdjustWindowRectEx (& rc ,dwStyle ,fMenu ,dwExStyle ); 2298if (fRc ) { 2299prc -> left -= rc .left ; 2300prc -> top -= rc .top ; 2301prc -> right -= rc .right ; 2302prc -> bottom -= rc .bottom ; 2303 } 2304return fRc ; 2305} 2306 2307LRESULT CALLBACK tigrWndProc (HWND hWnd ,UINT message ,WPARAM wParam ,LPARAM lParam ) 2308{ 2309Tigr * bmp ; 2310TigrInternal * win = NULL ; 2311RECT rc ; 2312int dw ,dh ; 2313 2314GetClientRect (hWnd ,& rc ); 2315dw = rc .right - rc .left ; 2316dh = rc .bottom - rc .top ; 2317 2318bmp = (Tigr * )GetPropW (hWnd ,L"Tigr" ); 2319if (bmp ) 2320win = tigrInternal (bmp ); 2321 2322switch (message ) 2323 { 2324case WM_PAINT : 2325tigrGAPIPresent (bmp ,dw ,dh ); 2326ValidateRect (hWnd ,NULL ); 2327break ; 2328case WM_CLOSE : 2329if (win ) 2330win -> closed = 1 ; 2331break ; 2332case WM_GETMINMAXINFO : 2333if (bmp ) 2334 { 2335MINMAXINFO * info = (MINMAXINFO * )lParam ; 2336RECT rc ; 2337rc .left = 0 ; 2338rc .top = 0 ; 2339if (win -> flags & TIGR_AUTO ) 2340 { 2341rc .right = 32 ; 2342rc .bottom = 32 ; 2343 }else { 2344int minscale = tigrEnforceScale (1 ,win -> flags ); 2345rc .right = bmp -> w * minscale ; 2346rc .bottom = bmp -> h * minscale ; 2347 } 2348AdjustWindowRectEx (& rc ,win -> dwStyle , FALSE,0 ); 2349info -> ptMinTrackSize .x = rc .right - rc .left ; 2350info -> ptMinTrackSize .y = rc .bottom - rc .top ; 2351 } 2352return 0 ; 2353case WM_SIZING : 2354if (win ) 2355 { 2356// Calculate scale-constrained sizes. 2357RECT * rc = (RECT * )lParam ; 2358int dx ,dy ; 2359UnadjustWindowRectEx (rc ,win -> dwStyle , FALSE,0 ); 2360dx = (rc -> right - rc -> left ) %win -> scale ; 2361dy = (rc -> bottom - rc -> top ) %win -> scale ; 2362switch (wParam ) { 2363case WMSZ_LEFT :rc -> left += dx ;break ; 2364case WMSZ_RIGHT :rc -> right -= dx ;break ; 2365case WMSZ_TOP :rc -> top += dy ;break ; 2366case WMSZ_TOPLEFT :rc -> left += dx ;rc -> top += dy ;break ; 2367case WMSZ_TOPRIGHT :rc -> right -= dx ;rc -> top += dy ;break ; 2368case WMSZ_BOTTOM :rc -> bottom -= dy ;break ; 2369case WMSZ_BOTTOMLEFT :rc -> left += dx ;rc -> bottom -= dy ;break ; 2370case WMSZ_BOTTOMRIGHT :rc -> right -= dx ;rc -> bottom -= dy ;break ; 2371 } 2372AdjustWindowRectEx (rc ,win -> dwStyle , FALSE,0 ); 2373 } 2374return TRUE; 2375case WM_SIZE : 2376if (win ) 2377 { 2378if (wParam != SIZE_MINIMIZED ) 2379 { 2380// Detect window size changes and update our bitmap accordingly. 2381dw = LOWORD (lParam ); 2382dh = HIWORD (lParam ); 2383if (win -> flags & TIGR_AUTO ) 2384 { 2385tigrResize (bmp ,dw /win -> scale ,dh /win -> scale ); 2386 }else { 2387win -> scale = tigrEnforceScale (tigrCalcScale (bmp -> w ,bmp -> h ,dw ,dh ),win -> flags ); 2388 } 2389tigrPosition (bmp ,win -> scale ,dw ,dh ,win -> pos ); 2390tigrGAPIResize (bmp ,dw ,dh ); 2391 } 2392 2393// If someone tried to maximize us (e.g. via shortcut launch options), 2394// prefer instead to be borderless. 2395if (wParam == SIZE_MAXIMIZED ) 2396 { 2397ShowWindow ((HWND )bmp -> handle ,SW_NORMAL ); 2398tigrEnterBorderlessWindowed (bmp ); 2399 } 2400 } 2401return 0 ; 2402#ifndef TIGR_DO_NOT_PRESERVE_WINDOW_POSITION 2403case WM_WINDOWPOSCHANGED : 2404 { 2405// Save our position. 2406WINDOWPLACEMENT wp = {sizeof (WINDOWPLACEMENT ) }; 2407GetWindowPlacement (hWnd ,& wp ); 2408if (win -> dwStyle & WS_POPUP ) 2409wp .showCmd = SW_MAXIMIZE ; 2410RegSetValueExW (tigrRegKey ,win -> wtitle ,0 ,REG_BINARY , (BYTE * )& wp ,sizeof (wp )); 2411return DefWindowProcW (hWnd ,message ,wParam ,lParam ); 2412 } 2413#endif 2414case WM_ACTIVATE : 2415if (win ) { 2416memset (win -> keys ,0 ,256 ); 2417memset (win -> prev ,0 ,256 ); 2418win -> lastChar = 0 ; 2419 } 2420return 0 ; 2421case WM_CHAR : 2422if (win ) { 2423if (wParam == '\r' )wParam = '\n' ; 2424win -> lastChar = wParam ; 2425 } 2426return DefWindowProcW (hWnd ,message ,wParam ,lParam ); 2427case WM_MENUCHAR : 2428// Disable beep on Alt+Enter 2429if (LOWORD (wParam )== VK_RETURN ) 2430return MNC_CLOSE <<16 ; 2431return DefWindowProcW (hWnd ,message ,wParam ,lParam ); 2432case WM_SYSKEYDOWN : 2433if (win ) 2434 { 2435if (wParam == VK_RETURN ) 2436 { 2437// Alt+Enter 2438if (win -> dwStyle & WS_POPUP ) 2439tigrLeaveBorderlessWindowed (bmp ); 2440else 2441tigrEnterBorderlessWindowed (bmp ); 2442return 0 ; 2443 } 2444 } 2445// fall-thru 2446case WM_KEYDOWN : 2447if (win ) 2448win -> keys [wParam ]= 1 ; 2449return DefWindowProcW (hWnd ,message ,wParam ,lParam ); 2450case WM_SYSKEYUP : 2451// fall-thru 2452case WM_KEYUP : 2453if (win ) 2454win -> keys [wParam ]= 0 ; 2455return DefWindowProcW (hWnd ,message ,wParam ,lParam ); 2456default : 2457return DefWindowProcW (hWnd ,message ,wParam ,lParam ); 2458 } 2459return 0 ; 2460} 2461 2462Tigr * tigrWindow (int w ,int h ,const char * title ,int flags ) 2463{ 2464WNDCLASSEXW wcex = {0 }; 2465int maxW ,maxH ,scale ; 2466HWND hWnd ; 2467DWORD dwStyle ; 2468RECT rc ; 2469DWORD err ; 2470Tigr * bmp ; 2471TigrInternal * win ; 2472#ifndef TIGR_DO_NOT_PRESERVE_WINDOW_POSITION 2473WINDOWPLACEMENT wp ; 2474DWORD wpsize = sizeof (wp ); 2475#endif 2476 2477wchar_t * wtitle = unicode (title ); 2478 2479// Find our registry key. 2480#ifndef TIGR_DO_NOT_PRESERVE_WINDOW_POSITION 2481RegCreateKeyExW (HKEY_CURRENT_USER ,L"Software\\TIGR" ,0 ,NULL ,REG_OPTION_NON_VOLATILE ,KEY_ALL_ACCESS ,NULL ,& tigrRegKey ,NULL ); 2482#endif 2483 2484// Register a window class. 2485wcex .cbSize = sizeof (WNDCLASSEXW ); 2486wcex .style = CS_HREDRAW |CS_VREDRAW |CS_OWNDC ; 2487wcex .lpfnWndProc = tigrWndProc ; 2488wcex .hInstance = GetModuleHandle (NULL ); 2489wcex .hIcon = NULL ; 2490wcex .hCursor = LoadCursor (NULL ,IDC_ARROW ); 2491wcex .lpszClassName = L"TIGR" ; 2492RegisterClassExW (& wcex ); 2493 2494if (flags & TIGR_AUTO ) 2495 { 2496// Always use a 1:1 pixel size. 2497scale = 1 ; 2498 }else { 2499// See how big we can make it and still fit on-screen. 2500maxW = GetSystemMetrics (SM_CXSCREEN )* 3 /4 ; 2501maxH = GetSystemMetrics (SM_CYSCREEN )* 3 /4 ; 2502scale = tigrCalcScale (w ,h ,maxW ,maxH ); 2503 } 2504 2505scale = tigrEnforceScale (scale ,flags ); 2506 2507// Get the final window size. 2508dwStyle = WS_OVERLAPPEDWINDOW ; 2509rc .left = 0 ;rc .top = 0 ;rc .right = w * scale ;rc .bottom = h * scale ; 2510AdjustWindowRect (& rc ,dwStyle , FALSE); 2511 2512// Make a window. 2513hWnd = CreateWindowW (L"TIGR" ,wtitle ,dwStyle , 2514CW_USEDEFAULT ,CW_USEDEFAULT ,rc .right - rc .left ,rc .bottom - rc .top , 2515NULL ,NULL ,wcex .hInstance ,NULL ); 2516err = GetLastError (); 2517if (!hWnd ) 2518ExitProcess (1 ); 2519 2520// Wrap a bitmap around it. 2521bmp = tigrBitmap2 (w ,h ,sizeof (TigrInternal )); 2522bmp -> handle = hWnd ; 2523 2524// Set up the Windows parts. 2525win = tigrInternal (bmp ); 2526win -> dwStyle = dwStyle ; 2527win -> wtitle = wtitle ; 2528win -> shown = 0 ; 2529win -> closed = 0 ; 2530#ifdef TIGR_GAPI_D3D9 2531win -> d3d9 .lost = 1 ; 2532#endif 2533win -> scale = scale ; 2534win -> lastChar = 0 ; 2535win -> flags = flags ; 2536 2537win -> hblur = win -> vblur = 0 ; 2538win -> scanlines = 0.0f ; 2539win -> contrast = 1.0f ; 2540 2541win -> widgetsWanted = 0 ; 2542win -> widgetAlpha = 0 ; 2543win -> widgetsScale = WIDGET_SCALE ; 2544win -> widgets = tigrBitmap (40 ,14 ); 2545 2546SetPropW (hWnd ,L"Tigr" ,bmp ); 2547 2548tigrGAPICreate (bmp ); 2549tigrGAPIBegin (bmp ); 2550 2551// Try and restore our window position. 2552#ifndef TIGR_DO_NOT_PRESERVE_WINDOW_POSITION 2553if (RegQueryValueExW (tigrRegKey ,wtitle ,NULL ,NULL , (BYTE * )& wp ,& wpsize )== ERROR_SUCCESS ) 2554 { 2555if (wp .showCmd == SW_MAXIMIZE ) 2556tigrEnterBorderlessWindowed (bmp ); 2557else 2558SetWindowPlacement (hWnd ,& wp ); 2559 } 2560#endif 2561 2562return bmp ; 2563} 2564 2565void tigrFree (Tigr * bmp ) 2566{ 2567if (bmp -> handle ) 2568 { 2569TigrInternal * win = tigrInternal (bmp ); 2570DestroyWindow ((HWND )bmp -> handle ); 2571tigrGAPIEnd (bmp ); 2572tigrGAPIDestroy (bmp ); 2573free (win -> wtitle ); 2574tigrFree (win -> widgets ); 2575 } 2576free (bmp -> pix ); 2577free (bmp ); 2578} 2579 2580int tigrClosed (Tigr * bmp ) 2581{ 2582TigrInternal * win = tigrInternal (bmp ); 2583int val = win -> closed ; 2584win -> closed = 0 ; 2585return val ; 2586} 2587 2588float tigrTime () 2589{ 2590static int first = 1 ; 2591static LARGE_INTEGER prev ; 2592 2593LARGE_INTEGER cnt ,freq ; 2594ULONGLONG diff ; 2595QueryPerformanceCounter (& cnt ); 2596QueryPerformanceFrequency (& freq ); 2597 2598if (first ) 2599 { 2600first = 0 ; 2601prev = cnt ; 2602 } 2603 2604diff = cnt .QuadPart - prev .QuadPart ; 2605prev = cnt ; 2606return (float )(diff / (double )freq .QuadPart ); 2607} 2608 2609void tigrMouse (Tigr * bmp ,int * x ,int * y ,int * buttons ) 2610{ 2611POINT pt ; 2612TigrInternal * win ; 2613 2614win = tigrInternal (bmp ); 2615GetCursorPos (& pt ); 2616ScreenToClient ((HWND )bmp -> handle ,& pt ); 2617* x = (pt .x - win -> pos [0 ]) /win -> scale ; 2618* y = (pt .y - win -> pos [1 ]) /win -> scale ; 2619* buttons = 0 ; 2620if (GetFocus ()!= bmp -> handle ) 2621return ; 2622if (GetAsyncKeyState (VK_LBUTTON )& 0x8000 )* buttons |=1 ; 2623if (GetAsyncKeyState (VK_MBUTTON )& 0x8000 )* buttons |=2 ; 2624if (GetAsyncKeyState (VK_RBUTTON )& 0x8000 )* buttons |=4 ; 2625} 2626 2627static int tigrWinVK (int key ) 2628{ 2629if (key >='A' && key <='Z' )return key ; 2630if (key >='0' && key <='9' )return key ; 2631switch (key ) { 2632case TK_BACKSPACE :return VK_BACK ; 2633case TK_TAB :return VK_TAB ; 2634case TK_RETURN :return VK_RETURN ; 2635case TK_SHIFT :return VK_SHIFT ; 2636case TK_CONTROL :return VK_CONTROL ; 2637case TK_ALT :return VK_MENU ; 2638case TK_PAUSE :return VK_PAUSE ; 2639case TK_CAPSLOCK :return VK_CAPITAL ; 2640case TK_ESCAPE :return VK_ESCAPE ; 2641case TK_SPACE :return VK_SPACE ; 2642case TK_PAGEUP :return VK_PRIOR ; 2643case TK_PAGEDN :return VK_NEXT ; 2644case TK_END :return VK_END ; 2645case TK_HOME :return VK_HOME ; 2646case TK_LEFT :return VK_LEFT ; 2647case TK_UP :return VK_UP ; 2648case TK_RIGHT :return VK_RIGHT ; 2649case TK_DOWN :return VK_DOWN ; 2650case TK_INSERT :return VK_INSERT ; 2651case TK_DELETE :return VK_DELETE ; 2652case TK_LWIN :return VK_LWIN ; 2653case TK_RWIN :return VK_RWIN ; 2654//case TK_APPS: return VK_APPS; // this key doesn't exist on OS X 2655case TK_PAD0 :return VK_NUMPAD0 ; 2656case TK_PAD1 :return VK_NUMPAD1 ; 2657case TK_PAD2 :return VK_NUMPAD2 ; 2658case TK_PAD3 :return VK_NUMPAD3 ; 2659case TK_PAD4 :return VK_NUMPAD4 ; 2660case TK_PAD5 :return VK_NUMPAD5 ; 2661case TK_PAD6 :return VK_NUMPAD6 ; 2662case TK_PAD7 :return VK_NUMPAD7 ; 2663case TK_PAD8 :return VK_NUMPAD8 ; 2664case TK_PAD9 :return VK_NUMPAD9 ; 2665case TK_PADMUL :return VK_MULTIPLY ; 2666case TK_PADADD :return VK_ADD ; 2667case TK_PADENTER :return VK_SEPARATOR ; 2668case TK_PADSUB :return VK_SUBTRACT ; 2669case TK_PADDOT :return VK_DECIMAL ; 2670case TK_PADDIV :return VK_DIVIDE ; 2671case TK_F1 :return VK_F1 ; 2672case TK_F2 :return VK_F2 ; 2673case TK_F3 :return VK_F3 ; 2674case TK_F4 :return VK_F4 ; 2675case TK_F5 :return VK_F5 ; 2676case TK_F6 :return VK_F6 ; 2677case TK_F7 :return VK_F7 ; 2678case TK_F8 :return VK_F8 ; 2679case TK_F9 :return VK_F9 ; 2680case TK_F10 :return VK_F10 ; 2681case TK_F11 :return VK_F11 ; 2682case TK_F12 :return VK_F12 ; 2683case TK_NUMLOCK :return VK_NUMLOCK ; 2684case TK_SCROLL :return VK_SCROLL ; 2685case TK_LSHIFT :return VK_LSHIFT ; 2686case TK_RSHIFT :return VK_RSHIFT ; 2687case TK_LCONTROL :return VK_LCONTROL ; 2688case TK_RCONTROL :return VK_RCONTROL ; 2689case TK_LALT :return VK_LMENU ; 2690case TK_RALT :return VK_RMENU ; 2691case TK_SEMICOLON :return VK_OEM_1 ; 2692case TK_EQUALS :return VK_OEM_PLUS ; 2693case TK_COMMA :return VK_OEM_COMMA ; 2694case TK_MINUS :return VK_OEM_MINUS ; 2695case TK_DOT :return VK_OEM_PERIOD ; 2696case TK_SLASH :return VK_OEM_2 ; 2697case TK_BACKTICK :return VK_OEM_3 ; 2698case TK_LSQUARE :return VK_OEM_4 ; 2699case TK_BACKSLASH :return VK_OEM_5 ; 2700case TK_RSQUARE :return VK_OEM_6 ; 2701case TK_TICK :return VK_OEM_7 ; 2702 } 2703return 0 ; 2704} 2705 2706int tigrKeyDown (Tigr * bmp ,int key ) 2707{ 2708TigrInternal * win ; 2709int k = tigrWinVK (key ); 2710if (GetFocus ()!= bmp -> handle ) 2711return 0 ; 2712win = tigrInternal (bmp ); 2713return win -> keys [k ]&& !win -> prev [k ]; 2714} 2715 2716int tigrKeyHeld (Tigr * bmp ,int key ) 2717{ 2718TigrInternal * win ; 2719int k = tigrWinVK (key ); 2720if (GetFocus ()!= bmp -> handle ) 2721return 0 ; 2722win = tigrInternal (bmp ); 2723return win -> keys [k ]; 2724} 2725 2726int tigrReadChar (Tigr * bmp ) 2727{ 2728TigrInternal * win = tigrInternal (bmp ); 2729int c = win -> lastChar ; 2730win -> lastChar = 0 ; 2731return c ; 2732} 2733 2734// We supply our own WinMain and just chain through to the user's 2735// real entry point. 2736#ifdef UNICODE 2737int CALLBACK wWinMain (HINSTANCE hInstance ,HINSTANCE hPrevInstance ,LPWSTR lpCmdLine ,int nCmdShow ) 2738#else 2739int CALLBACK WinMain (HINSTANCE hInstance ,HINSTANCE hPrevInstance ,LPSTR lpCmdLine ,int nCmdShow ) 2740#endif 2741{ 2742int n ,argc ; 2743LPWSTR * wargv = CommandLineToArgvW (GetCommandLineW (),& argc ); 2744char ** argv = (char ** )calloc (argc + 1 ,sizeof (int )); 2745 2746 (void )hInstance ; (void )hPrevInstance ; (void )lpCmdLine ; (void )nCmdShow ; 2747 2748for (n = 0 ;n < argc ;n ++ ) 2749 { 2750int len = WideCharToMultiByte (CP_UTF8 ,0 ,wargv [n ],-1 ,0 ,0 ,NULL ,NULL ); 2751argv [n ]= (char * )malloc (len ); 2752WideCharToMultiByte (CP_UTF8 ,0 ,wargv [n ],-1 ,argv [n ],len ,NULL ,NULL ); 2753 } 2754return main (argc ,argv ); 2755} 2756#endif 2757 2758//////// End of inlined file: tigr_win.c //////// 2759 2760//////// Start of inlined file: tigr_osx.c //////// 2761 2762// this one is based on https://github.com/jimon/osx_app_in_plain_c 2763 2764//#include "tigr_internal.h" 2765 2766#ifdef __APPLE__ 2767#include <TargetConditionals.h> 2768#ifdef TARGET_OS_MAC 2769 2770#include <stdlib.h> 2771#include <stdbool.h> 2772#include <stdint.h> 2773#include <stdio.h> 2774#include <stdarg.h> 2775#include <limits.h> 2776#include <math.h> 2777#include <assert.h> 2778 2779#include <CoreFoundation/CoreFoundation.h> 2780#include <CoreGraphics/CoreGraphics.h> 2781#include <objc/objc.h> 2782#include <objc/runtime.h> 2783#include <objc/message.h> 2784#include <objc/NSObjCRuntime.h> 2785#include <mach/mach_time.h> 2786 2787// maybe this is available somewhere in objc runtime? 2788#if __LP64__ || (TARGET_OS_EMBEDDED && !TARGET_OS_IPHONE )|| TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64 2789#define NSIntegerEncoding "q" 2790#define NSUIntegerEncoding "L" 2791#else 2792#define NSIntegerEncoding "i" 2793#define NSUIntegerEncoding "I" 2794#endif 2795 2796#ifdef __OBJC__ 2797#import <Cocoa/Cocoa.h> 2798#else 2799// this is how they are defined originally 2800#include <CoreGraphics/CGBase.h> 2801#include <CoreGraphics/CGGeometry.h> 2802typedef CGPoint NSPoint ; 2803typedef CGSize NSSize ; 2804typedef CGRect NSRect ; 2805 2806extern id NSApp ; 2807extern id const NSDefaultRunLoopMode ; 2808#endif 2809 2810#if defined(__OBJC__ )&& __has_feature (objc_arc ) 2811//#define ARC_AVAILABLE 2812#error "Can't compile as objective-c code just yet! (see autorelease pool todo below)" 2813#endif 2814 2815// ABI is a bit different between platforms 2816#ifdef __arm64__ 2817#define abi_objc_msgSend_stret objc_msgSend 2818#else 2819#define abi_objc_msgSend_stret objc_msgSend_stret 2820#endif 2821#ifdef __i386__ 2822#define abi_objc_msgSend_fpret objc_msgSend_fpret 2823#else 2824#define abi_objc_msgSend_fpret objc_msgSend 2825#endif 2826 2827#define objc_msgSend_id ((id (*)(id, SEL))objc_msgSend) 2828#define objc_msgSend_void ((void (*)(id, SEL))objc_msgSend) 2829#define objc_msgSend_void_id ((void (*)(id, SEL, id))objc_msgSend) 2830#define objc_msgSend_void_bool ((void (*)(id, SEL, BOOL))objc_msgSend) 2831#define objc_msgSend_id_const_char ((id (*)(id, SEL, const char*))objc_msgSend) 2832 2833bool terminated = false; 2834 2835// we gonna construct objective-c class by hand in runtime, so wow, so hacker! 2836NSUInteger applicationShouldTerminate (id self ,SEL _sel ,id sender ) 2837{ 2838terminated = true; 2839return 0 ; 2840} 2841 2842void windowWillClose (id self ,SEL _sel ,id notification ) 2843{ 2844NSUInteger value = true; 2845object_setInstanceVariable (self ,"closed" , (void * )value ); 2846} 2847 2848void windowDidBecomeKey (id self ,SEL _sel ,id notification ) 2849{ 2850TigrInternal * win ; 2851Tigr * bmp = 0 ; 2852object_getInstanceVariable (self ,"tigrHandle" , (void ** )& bmp ); 2853win = bmp ?tigrInternal (bmp ) :NULL ; 2854 2855if (win ) 2856 { 2857memset (win -> keys ,0 ,256 ); 2858memset (win -> prev ,0 ,256 ); 2859win -> lastChar = 0 ; 2860win -> mouseButtons = 0 ; 2861 } 2862} 2863 2864bool _tigrCocoaIsWindowClosed (id window ) 2865{ 2866id wdg = objc_msgSend_id (window ,sel_registerName ("delegate" )); 2867if (!wdg ) 2868return false; 2869NSUInteger value = 0 ; 2870object_getInstanceVariable (wdg ,"closed" , (void ** )& value ); 2871return value ? true : false; 2872} 2873 2874static bool tigrOSXInited = false; 2875static id autoreleasePool = NULL ; 2876 2877void _tigrCleanupOSX () 2878{ 2879#ifdef ARC_AVAILABLE 2880// TODO autorelease pool id:2 gh:3 2881#else 2882objc_msgSend_void (autoreleasePool ,sel_registerName ("drain" )); 2883#endif 2884} 2885 2886void tigrInitOSX () 2887{ 2888if (tigrOSXInited ) 2889return ; 2890 2891#ifdef ARC_AVAILABLE 2892// TODO and what do we do now? it's a bit too tricky to use @autoreleasepool here id:5 gh:6 2893#error TODO this code should be compiled as C for now 2894#else 2895//would be nice to use objc_autoreleasePoolPush instead, but it's not publically available in the headers 2896id poolAlloc = objc_msgSend_id ((id )objc_getClass ("NSAutoreleasePool" ),sel_registerName ("alloc" )); 2897autoreleasePool = objc_msgSend_id (poolAlloc ,sel_registerName ("init" )); 2898atexit (& _tigrCleanupOSX ); 2899#endif 2900 2901objc_msgSend_id ((id )objc_getClass ("NSApplication" ),sel_registerName ("sharedApplication" )); 2902 ((void (* )(id ,SEL ,NSInteger ))objc_msgSend )(NSApp ,sel_registerName ("setActivationPolicy:" ),0 ); 2903 2904Class appDelegateClass = objc_allocateClassPair ((Class )objc_getClass ("NSObject" ),"AppDelegate" ,0 ); 2905bool resultAddProtoc = class_addProtocol (appDelegateClass ,objc_getProtocol ("NSApplicationDelegate" )); 2906assert (resultAddProtoc ); 2907bool resultAddMethod = class_addMethod (appDelegateClass ,sel_registerName ("applicationShouldTerminate:" ), (IMP )applicationShouldTerminate ,NSUIntegerEncoding "@:@" ); 2908assert (resultAddMethod ); 2909id dgAlloc = objc_msgSend_id ((id )appDelegateClass ,sel_registerName ("alloc" )); 2910id dg = objc_msgSend_id (dgAlloc ,sel_registerName ("init" )); 2911#ifndef ARC_AVAILABLE 2912objc_msgSend_void (dg ,sel_registerName ("autorelease" )); 2913#endif 2914 2915objc_msgSend_void_id (NSApp ,sel_registerName ("setDelegate:" ),dg ); 2916objc_msgSend_void (NSApp ,sel_registerName ("finishLaunching" )); 2917 2918id menubarAlloc = objc_msgSend_id ((id )objc_getClass ("NSMenu" ),sel_registerName ("alloc" )); 2919id menubar = objc_msgSend_id (menubarAlloc ,sel_registerName ("init" )); 2920#ifndef ARC_AVAILABLE 2921objc_msgSend_void (menubar ,sel_registerName ("autorelease" )); 2922#endif 2923 2924id appMenuItemAlloc = objc_msgSend_id ((id )objc_getClass ("NSMenuItem" ),sel_registerName ("alloc" )); 2925id appMenuItem = objc_msgSend_id (appMenuItemAlloc ,sel_registerName ("init" )); 2926#ifndef ARC_AVAILABLE 2927objc_msgSend_void (appMenuItem ,sel_registerName ("autorelease" )); 2928#endif 2929 2930objc_msgSend_void_id (menubar ,sel_registerName ("addItem:" ),appMenuItem ); 2931 ((id (* )(id ,SEL ,id ))objc_msgSend )(NSApp ,sel_registerName ("setMainMenu:" ),menubar ); 2932 2933id appMenuAlloc = objc_msgSend_id ((id )objc_getClass ("NSMenu" ),sel_registerName ("alloc" )); 2934id appMenu = objc_msgSend_id (appMenuAlloc ,sel_registerName ("init" )); 2935#ifndef ARC_AVAILABLE 2936objc_msgSend_void (appMenu ,sel_registerName ("autorelease" )); 2937#endif 2938 2939id processInfo = objc_msgSend_id ((id )objc_getClass ("NSProcessInfo" ),sel_registerName ("processInfo" )); 2940id appName = objc_msgSend_id (processInfo ,sel_registerName ("processName" )); 2941 2942id quitTitlePrefixString = objc_msgSend_id_const_char ((id )objc_getClass ("NSString" ),sel_registerName ("stringWithUTF8String:" ),"Quit " ); 2943id quitTitle = ((id (* )(id ,SEL ,id ))objc_msgSend )(quitTitlePrefixString ,sel_registerName ("stringByAppendingString:" ),appName ); 2944 2945id quitMenuItemKey = objc_msgSend_id_const_char ((id )objc_getClass ("NSString" ),sel_registerName ("stringWithUTF8String:" ),"q" ); 2946id quitMenuItemAlloc = objc_msgSend_id ((id )objc_getClass ("NSMenuItem" ),sel_registerName ("alloc" )); 2947id quitMenuItem = ((id (* )(id ,SEL ,id ,SEL ,id ))objc_msgSend )(quitMenuItemAlloc ,sel_registerName ("initWithTitle:action:keyEquivalent:" ),quitTitle ,sel_registerName ("terminate:" ),quitMenuItemKey ); 2948#ifndef ARC_AVAILABLE 2949objc_msgSend_void (quitMenuItem ,sel_registerName ("autorelease" )); 2950#endif 2951 2952objc_msgSend_void_id (appMenu ,sel_registerName ("addItem:" ),quitMenuItem ); 2953objc_msgSend_void_id (appMenuItem ,sel_registerName ("setSubmenu:" ),appMenu ); 2954 2955tigrOSXInited = true; 2956} 2957 2958void tigrError (Tigr * bmp ,const char * message , ...) 2959{ 2960char tmp [1024 ]; 2961 2962va_list args ; 2963va_start (args ,message ); 2964vsnprintf (tmp ,sizeof (tmp ),message ,args ); 2965tmp [sizeof (tmp )- 1 ]= 0 ; 2966va_end (args ); 2967 2968CFStringRef header = CFStringCreateWithCString (NULL ,"Error" ,kCFStringEncodingUTF8 ); 2969CFStringRef msg = CFStringCreateWithCString (NULL ,tmp ,kCFStringEncodingUTF8 ); 2970CFUserNotificationDisplayNotice (0.0 ,kCFUserNotificationStopAlertLevel ,NULL ,NULL ,NULL ,header ,msg ,NULL ); 2971CFRelease (header ); 2972CFRelease (msg ); 2973exit (1 ); 2974} 2975 2976NSSize _tigrCocoaWindowSize (id window ) 2977{ 2978id contentView = objc_msgSend_id (window ,sel_registerName ("contentView" )); 2979NSRect rect = ((NSRect (* )(id ,SEL ))abi_objc_msgSend_stret )(contentView ,sel_registerName ("frame" )); 2980rect = ((NSRect (* )(id ,SEL ,NSRect ))abi_objc_msgSend_stret )(contentView ,sel_registerName ("convertRectToBacking:" ),rect ); 2981 2982return rect .size ; 2983} 2984 2985TigrInternal * _tigrInternalCocoa (id window ) 2986{ 2987if (!window ) 2988return NULL ; 2989 2990id wdg = objc_msgSend_id (window ,sel_registerName ("delegate" )); 2991if (!wdg ) 2992return NULL ; 2993 2994Tigr * bmp = 0 ; 2995object_getInstanceVariable (wdg ,"tigrHandle" , (void ** )& bmp ); 2996return bmp ?tigrInternal (bmp ) :NULL ; 2997} 2998 2999Tigr * tigrWindow (int w ,int h ,const char * title ,int flags ) 3000{ 3001int scale ; 3002Tigr * bmp ; 3003TigrInternal * win ; 3004 3005tigrInitOSX (); 3006 3007if (flags & TIGR_AUTO ) 3008 { 3009// Always use a 1:1 pixel size. 3010scale = 1 ; 3011 }else { 3012// See how big we can make it and still fit on-screen. 3013CGRect mainMonitor = CGDisplayBounds (CGMainDisplayID ()); 3014int maxW = CGRectGetHeight (mainMonitor )* 3 /4 ; 3015int maxH = CGRectGetWidth (mainMonitor )* 3 /4 ; 3016scale = tigrCalcScale (w ,h ,maxW ,maxH ); 3017 } 3018 3019scale = tigrEnforceScale (scale ,flags ); 3020 3021NSRect rect = {{0 ,0 }, {w * scale ,h * scale }}; 3022id windowAlloc = objc_msgSend_id ((id )objc_getClass ("NSWindow" ),sel_registerName ("alloc" )); 3023id window = ((id (* )(id ,SEL ,NSRect ,NSUInteger ,NSUInteger ,BOOL ))objc_msgSend )(windowAlloc ,sel_registerName ("initWithContentRect:styleMask:backing:defer:" ),rect ,15 ,2 ,NO ); 3024#ifndef ARC_AVAILABLE 3025objc_msgSend_void (window ,sel_registerName ("autorelease" )); 3026#endif 3027 3028// when we are not using ARC, than window will be added to autorelease pool 3029// so if we close it by hand (pressing red button), we don't want it to be released for us 3030// so it will be released by autorelease pool later 3031objc_msgSend_void_bool (window ,sel_registerName ("setReleasedWhenClosed:" ),NO ); 3032 3033Class WindowDelegateClass = objc_allocateClassPair ((Class )objc_getClass ("NSObject" ),"WindowDelegate" ,0 ); 3034bool resultAddProtoc = class_addProtocol (WindowDelegateClass ,objc_getProtocol ("NSWindowDelegate" )); 3035assert (resultAddProtoc ); 3036bool resultAddIvar = class_addIvar (WindowDelegateClass ,"closed" ,sizeof (NSUInteger ),rint (log2 (sizeof (NSUInteger ))),NSUIntegerEncoding ); 3037assert (resultAddIvar ); 3038resultAddIvar = class_addIvar (WindowDelegateClass ,"tigrHandle" ,sizeof (void * ),rint (log2 (sizeof (void * ))),"ˆv" ); 3039assert (resultAddIvar ); 3040bool resultAddMethod = class_addMethod (WindowDelegateClass ,sel_registerName ("windowWillClose:" ), (IMP )windowWillClose ,"v@:@" ); 3041assert (resultAddMethod ); 3042resultAddMethod = class_addMethod (WindowDelegateClass ,sel_registerName ("windowDidBecomeKey:" ), (IMP )windowDidBecomeKey ,"v@:@" ); 3043assert (resultAddMethod ); 3044id wdgAlloc = objc_msgSend_id ((id )WindowDelegateClass ,sel_registerName ("alloc" )); 3045id wdg = objc_msgSend_id (wdgAlloc ,sel_registerName ("init" )); 3046#ifndef ARC_AVAILABLE 3047objc_msgSend_void (wdg ,sel_registerName ("autorelease" )); 3048#endif 3049 3050objc_msgSend_void_id (window ,sel_registerName ("setDelegate:" ),wdg ); 3051 3052id contentView = objc_msgSend_id (window ,sel_registerName ("contentView" )); 3053 3054if (flags & TIGR_RETINA ) 3055objc_msgSend_void_bool (contentView ,sel_registerName ("setWantsBestResolutionOpenGLSurface:" ),YES ); 3056 3057NSPoint point = {20 ,20 }; 3058 ((void (* )(id ,SEL ,NSPoint ))objc_msgSend )(window ,sel_registerName ("cascadeTopLeftFromPoint:" ),point ); 3059 3060id titleString = objc_msgSend_id_const_char ((id )objc_getClass ("NSString" ),sel_registerName ("stringWithUTF8String:" ),title ); 3061objc_msgSend_void_id (window ,sel_registerName ("setTitle:" ),titleString ); 3062 3063uint32_t glAttributes []= 3064 { 30658 ,24 ,// NSOpenGLPFAColorSize, 24, 306611 ,8 ,// NSOpenGLPFAAlphaSize, 8, 30675 ,// NSOpenGLPFADoubleBuffer, 306873 ,// NSOpenGLPFAAccelerated, 3069//72, // NSOpenGLPFANoRecovery, 3070//55, 1, // NSOpenGLPFASampleBuffers, 1, 3071//56, 4, // NSOpenGLPFASamples, 4, 307299 ,0x3200 ,// NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core, 30730 3074 }; 3075 3076id pixelFormatAlloc = objc_msgSend_id ((id )objc_getClass ("NSOpenGLPixelFormat" ),sel_registerName ("alloc" )); 3077id pixelFormat = ((id (* )(id ,SEL ,const uint32_t * ))objc_msgSend )(pixelFormatAlloc ,sel_registerName ("initWithAttributes:" ),glAttributes ); 3078#ifndef ARC_AVAILABLE 3079objc_msgSend_void (pixelFormat ,sel_registerName ("autorelease" )); 3080#endif 3081 3082id openGLContextAlloc = objc_msgSend_id ((id )objc_getClass ("NSOpenGLContext" ),sel_registerName ("alloc" )); 3083id openGLContext = ((id (* )(id ,SEL ,id ,id ))objc_msgSend )(openGLContextAlloc ,sel_registerName ("initWithFormat:shareContext:" ),pixelFormat ,nil ); 3084#ifndef ARC_AVAILABLE 3085objc_msgSend_void (openGLContext ,sel_registerName ("autorelease" )); 3086#endif 3087 3088objc_msgSend_void_id (openGLContext ,sel_registerName ("setView:" ),contentView ); 3089objc_msgSend_void_id (window ,sel_registerName ("makeKeyAndOrderFront:" ),window ); 3090objc_msgSend_void_bool (window ,sel_registerName ("setAcceptsMouseMovedEvents:" ),YES ); 3091 3092id blackColor = objc_msgSend_id ((id )objc_getClass ("NSColor" ),sel_registerName ("blackColor" )); 3093objc_msgSend_void_id (window ,sel_registerName ("setBackgroundColor:" ),blackColor ); 3094 3095// TODO do we really need this? id:6 gh:7 3096objc_msgSend_void_bool (NSApp ,sel_registerName ("activateIgnoringOtherApps:" ),YES ); 3097 3098// Wrap a bitmap around it. 3099NSSize windowSize = _tigrCocoaWindowSize (window ); 3100bmp = tigrBitmap2 (windowSize .width /scale ,windowSize .height /scale ,sizeof (TigrInternal )); 3101bmp -> handle = window ; 3102 3103// Set the handle 3104object_setInstanceVariable (wdg ,"tigrHandle" , (void * )bmp ); 3105 3106// Set up the Windows parts. 3107win = tigrInternal (bmp ); 3108win -> glContext = openGLContext ; 3109win -> shown = 0 ; 3110win -> closed = 0 ; 3111win -> scale = scale ; 3112win -> lastChar = 0 ; 3113win -> flags = flags ; 3114win -> hblur = win -> vblur = 0 ; 3115win -> scanlines = 0.0f ; 3116win -> contrast = 1.0f ; 3117win -> widgetsWanted = 0 ; 3118win -> widgetAlpha = 0 ; 3119win -> widgetsScale = 0 ; 3120win -> widgets = tigrBitmap (40 ,14 ); 3121win -> gl .gl_legacy = 0 ; 3122win -> mouseButtons = 0 ; 3123 3124tigrPosition (bmp ,win -> scale ,bmp -> w ,bmp -> h ,win -> pos ); 3125 3126objc_msgSend_void (openGLContext ,sel_registerName ("makeCurrentContext" )); 3127tigrGAPICreate (bmp ); 3128tigrGAPIBegin (bmp ); 3129tigrGAPIResize (bmp ,bmp -> w ,bmp -> h ); 3130 3131return bmp ; 3132} 3133 3134void tigrFree (Tigr * bmp ) 3135{ 3136if (bmp -> handle ) 3137 { 3138TigrInternal * win = tigrInternal (bmp ); 3139objc_msgSend_void ((id )win -> glContext ,sel_registerName ("makeCurrentContext" )); 3140tigrGAPIEnd (bmp ); 3141tigrGAPIDestroy (bmp ); 3142tigrFree (win -> widgets ); 3143 3144id window = (id )bmp -> handle ; 3145if (!_tigrCocoaIsWindowClosed (window )&& !terminated ) 3146objc_msgSend_void (window ,sel_registerName ("close" )); 3147 } 3148free (bmp -> pix ); 3149free (bmp ); 3150} 3151 3152uint8_t _tigrKeyFromOSX (uint16_t key ) 3153{ 3154// from Carbon HIToolbox/Events.h 3155enum 3156 { 3157kVK_ANSI_A = 0x00 , 3158kVK_ANSI_S = 0x01 , 3159kVK_ANSI_D = 0x02 , 3160kVK_ANSI_F = 0x03 , 3161kVK_ANSI_H = 0x04 , 3162kVK_ANSI_G = 0x05 , 3163kVK_ANSI_Z = 0x06 , 3164kVK_ANSI_X = 0x07 , 3165kVK_ANSI_C = 0x08 , 3166kVK_ANSI_V = 0x09 , 3167kVK_ANSI_B = 0x0B , 3168kVK_ANSI_Q = 0x0C , 3169kVK_ANSI_W = 0x0D , 3170kVK_ANSI_E = 0x0E , 3171kVK_ANSI_R = 0x0F , 3172kVK_ANSI_Y = 0x10 , 3173kVK_ANSI_T = 0x11 , 3174kVK_ANSI_1 = 0x12 , 3175kVK_ANSI_2 = 0x13 , 3176kVK_ANSI_3 = 0x14 , 3177kVK_ANSI_4 = 0x15 , 3178kVK_ANSI_6 = 0x16 , 3179kVK_ANSI_5 = 0x17 , 3180kVK_ANSI_Equal = 0x18 , 3181kVK_ANSI_9 = 0x19 , 3182kVK_ANSI_7 = 0x1A , 3183kVK_ANSI_Minus = 0x1B , 3184kVK_ANSI_8 = 0x1C , 3185kVK_ANSI_0 = 0x1D , 3186kVK_ANSI_RightBracket = 0x1E , 3187kVK_ANSI_O = 0x1F , 3188kVK_ANSI_U = 0x20 , 3189kVK_ANSI_LeftBracket = 0x21 , 3190kVK_ANSI_I = 0x22 , 3191kVK_ANSI_P = 0x23 , 3192kVK_ANSI_L = 0x25 , 3193kVK_ANSI_J = 0x26 , 3194kVK_ANSI_Quote = 0x27 , 3195kVK_ANSI_K = 0x28 , 3196kVK_ANSI_Semicolon = 0x29 , 3197kVK_ANSI_Backslash = 0x2A , 3198kVK_ANSI_Comma = 0x2B , 3199kVK_ANSI_Slash = 0x2C , 3200kVK_ANSI_N = 0x2D , 3201kVK_ANSI_M = 0x2E , 3202kVK_ANSI_Period = 0x2F , 3203kVK_ANSI_Grave = 0x32 , 3204kVK_ANSI_KeypadDecimal = 0x41 , 3205kVK_ANSI_KeypadMultiply = 0x43 , 3206kVK_ANSI_KeypadPlus = 0x45 , 3207kVK_ANSI_KeypadClear = 0x47 , 3208kVK_ANSI_KeypadDivide = 0x4B , 3209kVK_ANSI_KeypadEnter = 0x4C , 3210kVK_ANSI_KeypadMinus = 0x4E , 3211kVK_ANSI_KeypadEquals = 0x51 , 3212kVK_ANSI_Keypad0 = 0x52 , 3213kVK_ANSI_Keypad1 = 0x53 , 3214kVK_ANSI_Keypad2 = 0x54 , 3215kVK_ANSI_Keypad3 = 0x55 , 3216kVK_ANSI_Keypad4 = 0x56 , 3217kVK_ANSI_Keypad5 = 0x57 , 3218kVK_ANSI_Keypad6 = 0x58 , 3219kVK_ANSI_Keypad7 = 0x59 , 3220kVK_ANSI_Keypad8 = 0x5B , 3221kVK_ANSI_Keypad9 = 0x5C , 3222kVK_Return = 0x24 , 3223kVK_Tab = 0x30 , 3224kVK_Space = 0x31 , 3225kVK_Delete = 0x33 , 3226kVK_Escape = 0x35 , 3227kVK_Command = 0x37 , 3228kVK_Shift = 0x38 , 3229kVK_CapsLock = 0x39 , 3230kVK_Option = 0x3A , 3231kVK_Control = 0x3B , 3232kVK_RightShift = 0x3C , 3233kVK_RightOption = 0x3D , 3234kVK_RightControl = 0x3E , 3235kVK_Function = 0x3F , 3236kVK_F17 = 0x40 , 3237kVK_VolumeUp = 0x48 , 3238kVK_VolumeDown = 0x49 , 3239kVK_Mute = 0x4A , 3240kVK_F18 = 0x4F , 3241kVK_F19 = 0x50 , 3242kVK_F20 = 0x5A , 3243kVK_F5 = 0x60 , 3244kVK_F6 = 0x61 , 3245kVK_F7 = 0x62 , 3246kVK_F3 = 0x63 , 3247kVK_F8 = 0x64 , 3248kVK_F9 = 0x65 , 3249kVK_F11 = 0x67 , 3250kVK_F13 = 0x69 , 3251kVK_F16 = 0x6A , 3252kVK_F14 = 0x6B , 3253kVK_F10 = 0x6D , 3254kVK_F12 = 0x6F , 3255kVK_F15 = 0x71 , 3256kVK_Help = 0x72 , 3257kVK_Home = 0x73 , 3258kVK_PageUp = 0x74 , 3259kVK_ForwardDelete = 0x75 , 3260kVK_F4 = 0x76 , 3261kVK_End = 0x77 , 3262kVK_F2 = 0x78 , 3263kVK_PageDown = 0x79 , 3264kVK_F1 = 0x7A , 3265kVK_LeftArrow = 0x7B , 3266kVK_RightArrow = 0x7C , 3267kVK_DownArrow = 0x7D , 3268kVK_UpArrow = 0x7E 3269 }; 3270 3271switch (key ) 3272 { 3273case kVK_ANSI_Q :return 'Q' ; 3274case kVK_ANSI_W :return 'W' ; 3275case kVK_ANSI_E :return 'E' ; 3276case kVK_ANSI_R :return 'R' ; 3277case kVK_ANSI_T :return 'T' ; 3278case kVK_ANSI_Y :return 'Y' ; 3279case kVK_ANSI_U :return 'U' ; 3280case kVK_ANSI_I :return 'I' ; 3281case kVK_ANSI_O :return 'O' ; 3282case kVK_ANSI_P :return 'P' ; 3283case kVK_ANSI_A :return 'A' ; 3284case kVK_ANSI_S :return 'S' ; 3285case kVK_ANSI_D :return 'D' ; 3286case kVK_ANSI_F :return 'F' ; 3287case kVK_ANSI_G :return 'G' ; 3288case kVK_ANSI_H :return 'H' ; 3289case kVK_ANSI_J :return 'J' ; 3290case kVK_ANSI_K :return 'K' ; 3291case kVK_ANSI_L :return 'L' ; 3292case kVK_ANSI_Z :return 'Z' ; 3293case kVK_ANSI_X :return 'X' ; 3294case kVK_ANSI_C :return 'C' ; 3295case kVK_ANSI_V :return 'V' ; 3296case kVK_ANSI_B :return 'B' ; 3297case kVK_ANSI_N :return 'N' ; 3298case kVK_ANSI_M :return 'M' ; 3299case kVK_ANSI_0 :return '0' ; 3300case kVK_ANSI_1 :return '1' ; 3301case kVK_ANSI_2 :return '2' ; 3302case kVK_ANSI_3 :return '3' ; 3303case kVK_ANSI_4 :return '4' ; 3304case kVK_ANSI_5 :return '5' ; 3305case kVK_ANSI_6 :return '6' ; 3306case kVK_ANSI_7 :return '7' ; 3307case kVK_ANSI_8 :return '8' ; 3308case kVK_ANSI_9 :return '9' ; 3309case kVK_ANSI_Keypad0 :return TK_PAD0 ; 3310case kVK_ANSI_Keypad1 :return TK_PAD1 ; 3311case kVK_ANSI_Keypad2 :return TK_PAD2 ; 3312case kVK_ANSI_Keypad3 :return TK_PAD3 ; 3313case kVK_ANSI_Keypad4 :return TK_PAD4 ; 3314case kVK_ANSI_Keypad5 :return TK_PAD5 ; 3315case kVK_ANSI_Keypad6 :return TK_PAD6 ; 3316case kVK_ANSI_Keypad7 :return TK_PAD7 ; 3317case kVK_ANSI_Keypad8 :return TK_PAD8 ; 3318case kVK_ANSI_Keypad9 :return TK_PAD9 ; 3319case kVK_ANSI_KeypadMultiply :return TK_PADMUL ; 3320case kVK_ANSI_KeypadPlus :return TK_PADADD ; 3321case kVK_ANSI_KeypadEnter :return TK_PADENTER ; 3322case kVK_ANSI_KeypadMinus :return TK_PADSUB ; 3323case kVK_ANSI_KeypadDecimal :return TK_PADDOT ; 3324case kVK_ANSI_KeypadDivide :return TK_PADDIV ; 3325case kVK_F1 :return TK_F1 ; 3326case kVK_F2 :return TK_F2 ; 3327case kVK_F3 :return TK_F3 ; 3328case kVK_F4 :return TK_F4 ; 3329case kVK_F5 :return TK_F5 ; 3330case kVK_F6 :return TK_F6 ; 3331case kVK_F7 :return TK_F7 ; 3332case kVK_F8 :return TK_F8 ; 3333case kVK_F9 :return TK_F9 ; 3334case kVK_F10 :return TK_F10 ; 3335case kVK_F11 :return TK_F11 ; 3336case kVK_F12 :return TK_F12 ; 3337case kVK_Shift :return TK_LSHIFT ; 3338case kVK_Control :return TK_LCONTROL ; 3339case kVK_Option :return TK_LALT ; 3340case kVK_CapsLock :return TK_CAPSLOCK ; 3341case kVK_Command :return TK_LWIN ; 3342case kVK_Command - 1 :return TK_RWIN ; 3343case kVK_RightShift :return TK_RSHIFT ; 3344case kVK_RightControl :return TK_RCONTROL ; 3345case kVK_RightOption :return TK_RALT ; 3346case kVK_Delete :return TK_BACKSPACE ; 3347case kVK_Tab :return TK_TAB ; 3348case kVK_Return :return TK_RETURN ; 3349case kVK_Escape :return TK_ESCAPE ; 3350case kVK_Space :return TK_SPACE ; 3351case kVK_PageUp :return TK_PAGEUP ; 3352case kVK_PageDown :return TK_PAGEDN ; 3353case kVK_End :return TK_END ; 3354case kVK_Home :return TK_HOME ; 3355case kVK_LeftArrow :return TK_LEFT ; 3356case kVK_UpArrow :return TK_UP ; 3357case kVK_RightArrow :return TK_RIGHT ; 3358case kVK_DownArrow :return TK_DOWN ; 3359case kVK_Help :return TK_INSERT ; 3360case kVK_ForwardDelete :return TK_DELETE ; 3361case kVK_F14 :return TK_SCROLL ; 3362case kVK_F15 :return TK_PAUSE ; 3363case kVK_ANSI_KeypadClear :return TK_NUMLOCK ; 3364case kVK_ANSI_Semicolon :return TK_SEMICOLON ; 3365case kVK_ANSI_Equal :return TK_EQUALS ; 3366case kVK_ANSI_Comma :return TK_COMMA ; 3367case kVK_ANSI_Minus :return TK_MINUS ; 3368case kVK_ANSI_Slash :return TK_SLASH ; 3369case kVK_ANSI_Backslash :return TK_BACKSLASH ; 3370case kVK_ANSI_Grave :return TK_BACKTICK ; 3371case kVK_ANSI_Quote :return TK_TICK ; 3372case kVK_ANSI_LeftBracket :return TK_LSQUARE ; 3373case kVK_ANSI_RightBracket :return TK_RSQUARE ; 3374case kVK_ANSI_Period :return TK_DOT ; 3375default :return 0 ; 3376 } 3377} 3378 3379void _tigrOnCocoaEvent (id event ,id window ) 3380{ 3381if (!event ) 3382return ; 3383 3384TigrInternal * win = _tigrInternalCocoa (window ); 3385if (!win )// just pipe the event 3386 { 3387objc_msgSend_void_id (NSApp ,sel_registerName ("sendEvent:" ),event ); 3388return ; 3389 } 3390 3391NSUInteger eventType = ((NSUInteger (* )(id ,SEL ))objc_msgSend )(event ,sel_registerName ("type" )); 3392switch (eventType ) 3393 { 3394case 1 :// NSLeftMouseDown 3395win -> mouseButtons |=1 ; 3396break ; 3397case 2 :// NSLeftMouseUp 3398win -> mouseButtons &= ~1 ; 3399break ; 3400case 3 :// NSRightMouseDown 3401win -> mouseButtons |=2 ; 3402break ; 3403case 4 :// NSRightMouseUp 3404win -> mouseButtons &= ~2 ; 3405break ; 3406case 25 :// NSOtherMouseDown 3407 { 3408// number == 2 is a middle button 3409NSInteger number = ((NSInteger (* )(id ,SEL ))objc_msgSend )(event ,sel_registerName ("buttonNumber" )); 3410if (number == 2 ) 3411win -> mouseButtons |=4 ; 3412break ; 3413 } 3414case 26 :// NSOtherMouseUp 3415 { 3416NSInteger number = ((NSInteger (* )(id ,SEL ))objc_msgSend )(event ,sel_registerName ("buttonNumber" )); 3417if (number == 2 ) 3418win -> mouseButtons &= ~4 ; 3419break ; 3420 } 3421//case 22: // NSScrollWheel 3422//{ 3423// CGFloat deltaX = ((CGFloat (*)(id, SEL))abi_objc_msgSend_fpret)(event, sel_registerName("scrollingDeltaX")); 3424// CGFloat deltaY = ((CGFloat (*)(id, SEL))abi_objc_msgSend_fpret)(event, sel_registerName("scrollingDeltaY")); 3425// BOOL precisionScrolling = ((BOOL (*)(id, SEL))objc_msgSend)(event, sel_registerName("hasPreciseScrollingDeltas")); 3426// 3427// if(precisionScrolling) 3428// { 3429// deltaX *= 0.1f; // similar to glfw 3430// deltaY *= 0.1f; 3431// } 3432// 3433// if(fabs(deltaX) > 0.0f || fabs(deltaY) > 0.0f) 3434// printf("mouse scroll wheel delta %f %f\n", deltaX, deltaY); 3435// break; 3436//} 3437case 12 :// NSFlagsChanged 3438 { 3439NSUInteger modifiers = ((NSUInteger (* )(id ,SEL ))objc_msgSend )(event ,sel_registerName ("modifierFlags" )); 3440 3441// based on NSEventModifierFlags and NSDeviceIndependentModifierFlagsMask 3442struct 3443 { 3444union 3445 { 3446struct 3447 { 3448uint8_t alpha_shift :1 ; 3449uint8_t shift :1 ; 3450uint8_t control :1 ; 3451uint8_t alternate :1 ; 3452uint8_t command :1 ; 3453uint8_t numeric_pad :1 ; 3454uint8_t help :1 ; 3455uint8_t function :1 ; 3456 }; 3457uint8_t mask ; 3458 }; 3459 }keys ; 3460 3461keys .mask = (modifiers & 0xffff0000UL ) >>16 ; 3462 3463// TODO L,R variation of keys? id:1 gh:2 3464win -> keys [TK_CONTROL ]= keys .alpha_shift ; 3465win -> keys [TK_SHIFT ]= keys .shift ; 3466win -> keys [TK_CONTROL ]= keys .control ; 3467win -> keys [TK_ALT ]= keys .alternate ; 3468win -> keys [TK_LWIN ]= keys .command ; 3469win -> keys [TK_RWIN ]= keys .command ; 3470break ; 3471 } 3472case 10 :// NSKeyDown 3473 { 3474id inputText = objc_msgSend_id (event ,sel_registerName ("characters" )); 3475const char * inputTextUTF8 = ((const char * (* )(id ,SEL ))objc_msgSend )(inputText ,sel_registerName ("UTF8String" )); 3476 3477tigrDecodeUTF8 (inputTextUTF8 ,& win -> lastChar ); 3478 3479uint16_t keyCode = ((unsigned short (* )(id ,SEL ))objc_msgSend )(event ,sel_registerName ("keyCode" )); 3480win -> keys [_tigrKeyFromOSX (keyCode )]= 1 ; 3481break ; 3482 } 3483case 11 :// NSKeyUp 3484 { 3485uint16_t keyCode = ((unsigned short (* )(id ,SEL ))objc_msgSend )(event ,sel_registerName ("keyCode" )); 3486win -> keys [_tigrKeyFromOSX (keyCode )]= 0 ; 3487break ; 3488 } 3489default : 3490break ; 3491 } 3492 3493objc_msgSend_void_id (NSApp ,sel_registerName ("sendEvent:" ),event ); 3494} 3495 3496void tigrUpdate (Tigr * bmp ) 3497{ 3498TigrInternal * win ; 3499id openGLContext ; 3500id window ; 3501win = tigrInternal (bmp ); 3502window = (id )bmp -> handle ; 3503openGLContext = (id )win -> glContext ; 3504 3505id keyWindow = objc_msgSend_id (NSApp ,sel_registerName ("keyWindow" )); 3506 3507if (keyWindow == window ) 3508memcpy (win -> prev ,win -> keys ,256 ); 3509 3510id distantPast = objc_msgSend_id ((id )objc_getClass ("NSDate" ),sel_registerName ("distantPast" )); 3511id event = ((id (* )(id ,SEL ,NSUInteger ,id ,id ,BOOL ))objc_msgSend )(NSApp ,sel_registerName ("nextEventMatchingMask:untilDate:inMode:dequeue:" ),NSUIntegerMax ,distantPast ,NSDefaultRunLoopMode ,YES ); 3512_tigrOnCocoaEvent (event ,keyWindow ); 3513if (terminated || _tigrCocoaIsWindowClosed (window )) 3514return ; 3515 3516// do runloop stuff 3517objc_msgSend_void (NSApp ,sel_registerName ("updateWindows" )); 3518objc_msgSend_void (openGLContext ,sel_registerName ("update" )); 3519objc_msgSend_void (openGLContext ,sel_registerName ("makeCurrentContext" )); 3520 3521NSSize windowSize = _tigrCocoaWindowSize (window ); 3522 3523if (win -> flags & TIGR_AUTO ) 3524tigrResize (bmp ,windowSize .width /win -> scale ,windowSize .height /win -> scale ); 3525else 3526win -> scale = tigrEnforceScale (tigrCalcScale (bmp -> w ,bmp -> h ,windowSize .width ,windowSize .height ),win -> flags ); 3527 3528tigrPosition (bmp ,win -> scale ,windowSize .width ,windowSize .height ,win -> pos ); 3529tigrGAPIResize (bmp ,windowSize .width ,windowSize .height ); 3530tigrGAPIPresent (bmp ,windowSize .width ,windowSize .height ); 3531objc_msgSend_void (openGLContext ,sel_registerName ("flushBuffer" )); 3532} 3533 3534int tigrClosed (Tigr * bmp ) 3535{ 3536return (terminated || _tigrCocoaIsWindowClosed ((id )bmp -> handle )) ?1 :0 ; 3537} 3538 3539void tigrMouse (Tigr * bmp ,int * x ,int * y ,int * buttons ) 3540{ 3541TigrInternal * win ; 3542id window ; 3543win = tigrInternal (bmp ); 3544window = (id )bmp -> handle ; 3545 3546id windowContentView = objc_msgSend_id (window ,sel_registerName ("contentView" )); 3547NSRect adjustFrame = ((NSRect (* )(id ,SEL ))abi_objc_msgSend_stret )(windowContentView ,sel_registerName ("frame" )); 3548 3549// NSPoint is small enough to fit a register, so no need for objc_msgSend_stret 3550NSPoint p = ((NSPoint (* )(id ,SEL ))objc_msgSend )(window ,sel_registerName ("mouseLocationOutsideOfEventStream" )); 3551 3552// map input to content view rect 3553if (p .x < 0 )p .x = 0 ; 3554else if (p .x > adjustFrame .size .width )p .x = adjustFrame .size .width ; 3555if (p .y < 0 )p .y = 0 ; 3556else if (p .y > adjustFrame .size .height )p .y = adjustFrame .size .height ; 3557 3558// map input to pixels 3559NSRect r = {p .x ,p .y ,0 ,0 }; 3560r = ((NSRect (* )(id ,SEL ,NSRect ))abi_objc_msgSend_stret )(windowContentView ,sel_registerName ("convertRectToBacking:" ),r ); 3561p = r .origin ; 3562 3563p .x = (p .x - win -> pos [0 ]) /win -> scale ; 3564p .y = (adjustFrame .size .height - p .y - win -> pos [1 ]) /win -> scale ; 3565 3566if (x ) 3567* x = p .x ; 3568if (y ) 3569* y = p .y ; 3570 3571if (buttons ) 3572 { 3573id keyWindow = objc_msgSend_id (NSApp ,sel_registerName ("keyWindow" )); 3574* buttons = keyWindow != bmp -> handle ?0 :win -> mouseButtons ; 3575 } 3576} 3577 3578int tigrKeyDown (Tigr * bmp ,int key ) 3579{ 3580TigrInternal * win ; 3581assert (key < 256 ); 3582id keyWindow = objc_msgSend_id (NSApp ,sel_registerName ("keyWindow" )); 3583if (keyWindow != bmp -> handle ) 3584return 0 ; 3585win = tigrInternal (bmp ); 3586return win -> keys [key ]&& !win -> prev [key ]; 3587} 3588 3589int tigrKeyHeld (Tigr * bmp ,int key ) 3590{ 3591TigrInternal * win ; 3592assert (key < 256 ); 3593id keyWindow = objc_msgSend_id (NSApp ,sel_registerName ("keyWindow" )); 3594if (keyWindow != bmp -> handle ) 3595return 0 ; 3596win = tigrInternal (bmp ); 3597return win -> keys [key ]; 3598} 3599 3600int tigrReadChar (Tigr * bmp ) 3601{ 3602TigrInternal * win = tigrInternal (bmp ); 3603int c = win -> lastChar ; 3604win -> lastChar = 0 ; 3605return c ; 3606} 3607 3608float tigrTime () 3609{ 3610static uint64_t time = 0 ; 3611static mach_timebase_info_data_t timebaseInfo ; 3612 3613if (timebaseInfo .denom == 0 ) 3614 { 3615mach_timebase_info (& timebaseInfo ); 3616time = mach_absolute_time (); 3617return 0.0f ; 3618 } 3619 3620uint64_t current_time = mach_absolute_time (); 3621double elapsed = (double )(current_time - time )* timebaseInfo .numer / (timebaseInfo .denom * 1000000000.0 ); 3622time = current_time ; 3623return (float )elapsed ; 3624} 3625 3626#endif 3627#endif 3628 3629//////// End of inlined file: tigr_osx.c //////// 3630 3631//////// Start of inlined file: tigr_gl.c //////// 3632 3633//#include "tigr_internal.h" 3634#include <stdio.h> // TODO can we remove this and printf's later? id:4 gh:5 3635 3636#ifdef TIGR_GAPI_GL 3637#ifndef __APPLE__ 3638// please provide you own glext.h, you can download latest at https://www.opengl.org/registry/api/GL/glext.h 3639#include <glext.h> 3640#endif 3641#ifdef _WIN32 3642// please provide you own wglext.h, you can download latest at https://www.opengl.org/registry/api/GL/wglext.h 3643#include <wglext.h> 3644#endif 3645 3646extern const unsigned char tigr_upscale_gl_vs [],tigr_upscale_gl_fs []; 3647extern int tigr_upscale_gl_vs_size ,tigr_upscale_gl_fs_size ; 3648 3649#ifdef _WIN32 3650PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormat ; 3651PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs ; 3652PFNGLGENVERTEXARRAYSPROC glGenVertexArrays ; 3653PFNGLGENBUFFERSARBPROC glGenBuffers ; 3654PFNGLBINDBUFFERPROC glBindBuffer ; 3655PFNGLBUFFERDATAPROC glBufferData ; 3656PFNGLBINDVERTEXARRAYPROC glBindVertexArray ; 3657PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray ; 3658PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer ; 3659PFNGLCREATESHADERPROC glCreateShader ; 3660PFNGLSHADERSOURCEPROC glShaderSource ; 3661PFNGLCOMPILESHADERPROC glCompileShader ; 3662PFNGLCREATEPROGRAMPROC glCreateProgram ; 3663PFNGLATTACHSHADERPROC glAttachShader ; 3664PFNGLLINKPROGRAMPROC glLinkProgram ; 3665PFNGLDELETESHADERPROC glDeleteShader ; 3666PFNGLDELETEPROGRAMPROC glDeleteProgram ; 3667PFNGLGETSHADERIVPROC glGetShaderiv ; 3668PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog ; 3669PFNGLGETPROGRAMIVPROC glGetProgramiv ; 3670PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog ; 3671PFNGLUSEPROGRAMPROC glUseProgram ; 3672PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation ; 3673PFNGLUNIFORM4FPROC glUniform4f ; 3674PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv ; 3675PFNGLACTIVETEXTUREPROC glActiveTexture ; 3676int tigrGL11Init (Tigr * bmp ) 3677{ 3678int pixel_format ; 3679TigrInternal * win = tigrInternal (bmp ); 3680GLStuff * gl = & win -> gl ; 3681PIXELFORMATDESCRIPTOR pfd = 3682 { 3683sizeof (PIXELFORMATDESCRIPTOR ), 36841 , 3685PFD_DRAW_TO_WINDOW |PFD_SUPPORT_OPENGL |PFD_DOUBLEBUFFER |PFD_SWAP_EXCHANGE , 3686PFD_TYPE_RGBA , 368732 ,// color bits 36880 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , 36890 ,0 ,0 ,0 ,0 , 369024 ,// depth 36918 ,// stencil 36920 , 3693PFD_MAIN_PLANE ,// is it ignored ? 36940 , 36950 ,0 ,0 3696 }; 3697if (!(gl -> dc = GetDC ((HWND )bmp -> handle ))) {tigrError (bmp ,"Cannot create OpenGL device context.\n" );return -1 ;} 3698if (!(pixel_format = ChoosePixelFormat (gl -> dc ,& pfd ))) {tigrError (bmp ,"Cannot choose OpenGL pixel format.\n" );return -1 ;} 3699if (!SetPixelFormat (gl -> dc ,pixel_format ,& pfd )) {tigrError (bmp ,"Cannot set OpenGL pixel format.\n" );return -1 ;} 3700if (!(gl -> hglrc = wglCreateContext (gl -> dc ))) {tigrError (bmp ,"Cannot create OpenGL context.\n" );return -1 ;} 3701if (!wglMakeCurrent (gl -> dc ,gl -> hglrc )) {tigrError (bmp ,"Cannot activate OpenGL context.\n" );return -1 ;} 3702gl -> gl_legacy = 1 ; 3703return 0 ; 3704} 3705int tigrGL33Init (Tigr * bmp ) 3706{ 3707int pixel_format ; 3708UINT num_formats ; 3709TigrInternal * win = tigrInternal (bmp ); 3710GLStuff * gl = & win -> gl ; 3711 3712wglChoosePixelFormat = (PFNWGLCHOOSEPIXELFORMATARBPROC )wglGetProcAddress ("wglChoosePixelFormatARB" ); 3713wglCreateContextAttribs = (PFNWGLCREATECONTEXTATTRIBSARBPROC )wglGetProcAddress ("wglCreateContextAttribsARB" ); 3714glGenVertexArrays = (PFNGLGENVERTEXARRAYSPROC )wglGetProcAddress ("glGenVertexArrays" ); 3715glGenBuffers = (PFNGLGENBUFFERSARBPROC )wglGetProcAddress ("glGenBuffers" ); 3716glBindBuffer = (PFNGLBINDBUFFERPROC )wglGetProcAddress ("glBindBuffer" ); 3717glBufferData = (PFNGLBUFFERDATAPROC )wglGetProcAddress ("glBufferData" ); 3718glBindVertexArray = (PFNGLBINDVERTEXARRAYPROC )wglGetProcAddress ("glBindVertexArray" ); 3719glEnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC )wglGetProcAddress ("glEnableVertexAttribArray" ); 3720glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC )wglGetProcAddress ("glVertexAttribPointer" ); 3721glCreateShader = (PFNGLCREATESHADERPROC )wglGetProcAddress ("glCreateShader" ); 3722glShaderSource = (PFNGLSHADERSOURCEPROC )wglGetProcAddress ("glShaderSource" ); 3723glCompileShader = (PFNGLCOMPILESHADERPROC )wglGetProcAddress ("glCompileShader" ); 3724glCreateProgram = (PFNGLCREATEPROGRAMPROC )wglGetProcAddress ("glCreateProgram" ); 3725glAttachShader = (PFNGLATTACHSHADERPROC )wglGetProcAddress ("glAttachShader" ); 3726glLinkProgram = (PFNGLLINKPROGRAMPROC )wglGetProcAddress ("glLinkProgram" ); 3727glDeleteShader = (PFNGLDELETESHADERPROC )wglGetProcAddress ("glDeleteShader" ); 3728glDeleteProgram = (PFNGLDELETEPROGRAMPROC )wglGetProcAddress ("glDeleteProgram" ); 3729glGetShaderiv = (PFNGLGETSHADERIVPROC )wglGetProcAddress ("glGetShaderiv" ); 3730glGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC )wglGetProcAddress ("glGetShaderInfoLog" ); 3731glGetProgramiv = (PFNGLGETPROGRAMIVPROC )wglGetProcAddress ("glGetProgramiv" ); 3732glGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC )wglGetProcAddress ("glGetProgramInfoLog" ); 3733glUseProgram = (PFNGLUSEPROGRAMPROC )wglGetProcAddress ("glUseProgram" ); 3734glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC )wglGetProcAddress ("glGetUniformLocation" ); 3735glUniform4f = (PFNGLUNIFORM4FPROC )wglGetProcAddress ("glUniform4f" ); 3736glUniformMatrix4fv = (PFNGLUNIFORMMATRIX4FVPROC )wglGetProcAddress ("glUniformMatrix4fv" ); 3737glActiveTexture = (PFNGLACTIVETEXTUREPROC )wglGetProcAddress ("glActiveTexture" ); 3738 3739if (!wglChoosePixelFormat || !wglCreateContextAttribs ) {tigrError (bmp ,"Cannot create OpenGL context.\n" );return -1 ;} 3740const int attribList []= 3741 { 3742WGL_DRAW_TO_WINDOW_ARB ,GL_TRUE , 3743WGL_SUPPORT_OPENGL_ARB ,GL_TRUE , 3744WGL_DOUBLE_BUFFER_ARB ,GL_TRUE , 3745WGL_PIXEL_TYPE_ARB ,WGL_TYPE_RGBA_ARB , 3746WGL_COLOR_BITS_ARB ,32 , 3747WGL_DEPTH_BITS_ARB ,24 , 3748WGL_STENCIL_BITS_ARB ,8 , 37490 3750 }; 3751int attribs []= { 3752WGL_CONTEXT_MAJOR_VERSION_ARB ,3 , 3753WGL_CONTEXT_MINOR_VERSION_ARB ,3 , 37540 3755 }; 3756if (!wglChoosePixelFormat (gl -> dc ,attribList ,NULL ,1 ,& pixel_format ,& num_formats )) {tigrError (bmp ,"Cannot choose OpenGL pixel format.\n" );return -1 ;} 3757if (!(gl -> hglrc = wglCreateContextAttribs (gl -> dc ,gl -> hglrc ,attribs ))) {tigrError (bmp ,"Cannot create OpenGL context attribs.\n" );return -1 ;} 3758if (!wglMakeCurrent (gl -> dc ,gl -> hglrc )) {tigrError (bmp ,"Cannot activate OpenGL context.\n" );return -1 ;} 3759gl -> gl_legacy = 0 ; 3760return 0 ; 3761} 3762#endif 3763 3764void tigrCheckGLError (const char * state ) 3765{ 3766GLenum err = glGetError (); 3767if (err != GL_NO_ERROR ) 3768printf ("got gl error %x when was doing %s\n" ,err ,state ); 3769} 3770 3771void tigrCheckShaderErrors (GLuint object ) 3772{ 3773GLint success ; 3774GLchar info [2048 ]; 3775glGetShaderiv (object ,GL_COMPILE_STATUS ,& success ); 3776if (!success ) 3777 { 3778glGetShaderInfoLog (object ,sizeof (info ),NULL ,info ); 3779printf ("shader compile error : %s\n" ,info ); 3780 } 3781} 3782 3783void tigrCheckProgramErrors (GLuint object ) 3784{ 3785GLint success ; 3786GLchar info [2048 ]; 3787glGetProgramiv (object ,GL_LINK_STATUS ,& success ); 3788if (!success ) 3789 { 3790glGetProgramInfoLog (object ,sizeof (info ),NULL ,info ); 3791printf ("shader link error : %s\n" ,info ); 3792 } 3793} 3794 3795void tigrGAPICreate (Tigr * bmp ) 3796{ 3797GLuint vs ,fs ; 3798TigrInternal * win = tigrInternal (bmp ); 3799GLStuff * gl = & win -> gl ; 3800GLuint VBO ; 3801GLfloat vertices []= { 3802// pos uv 38030.0f ,1.0f ,0.0f ,1.0f , 38041.0f ,0.0f ,1.0f ,0.0f , 38050.0f ,0.0f ,0.0f ,0.0f , 38060.0f ,1.0f ,0.0f ,1.0f , 38071.0f ,1.0f ,1.0f ,1.0f , 38081.0f ,0.0f ,1.0f ,0.0f 3809 }; 3810 3811#ifdef _WIN32 3812if (tigrGL11Init (bmp )) 3813return ; 3814tigrGL33Init (bmp ); 3815#endif 3816 3817//printf("ogl version %s\n", glGetString(GL_VERSION)); 3818 3819if (!gl -> gl_legacy ) 3820 { 3821// create vao 3822glGenVertexArrays (1 ,& gl -> vao ); 3823glGenBuffers (1 ,& VBO ); 3824glBindBuffer (GL_ARRAY_BUFFER ,VBO ); 3825glBufferData (GL_ARRAY_BUFFER ,sizeof (vertices ),vertices ,GL_STATIC_DRAW ); 3826glBindVertexArray (gl -> vao ); 3827glEnableVertexAttribArray (0 ); 3828glEnableVertexAttribArray (1 ); 3829glVertexAttribPointer (0 ,2 ,GL_FLOAT ,GL_FALSE ,4 * sizeof (GLfloat ),NULL ); 3830glVertexAttribPointer (1 ,2 ,GL_FLOAT ,GL_FALSE ,4 * sizeof (GLfloat ),NULL ); 3831 3832// create program 3833vs = glCreateShader (GL_VERTEX_SHADER ); 3834const char * vs_source = (const char * )& tigr_upscale_gl_vs ; 3835glShaderSource (vs ,1 ,& vs_source ,& tigr_upscale_gl_vs_size ); 3836glCompileShader (vs ); 3837tigrCheckShaderErrors (vs ); 3838fs = glCreateShader (GL_FRAGMENT_SHADER ); 3839const char * fs_source = (const char * )& tigr_upscale_gl_fs ; 3840glShaderSource (fs ,1 ,& fs_source ,& tigr_upscale_gl_fs_size ); 3841glCompileShader (fs ); 3842tigrCheckShaderErrors (fs ); 3843gl -> program = glCreateProgram (); 3844glAttachShader (gl -> program ,vs ); 3845glAttachShader (gl -> program ,fs ); 3846glLinkProgram (gl -> program ); 3847tigrCheckProgramErrors (gl -> program ); 3848glDeleteShader (vs ); 3849glDeleteShader (fs ); 3850gl -> uniform_projection = glGetUniformLocation (gl -> program ,"projection" ); 3851gl -> uniform_model = glGetUniformLocation (gl -> program ,"model" ); 3852gl -> uniform_parameters = glGetUniformLocation (gl -> program ,"parameters" ); 3853 } 3854 3855// create textures 3856if (gl -> gl_legacy ) 3857glEnable (GL_TEXTURE_2D ); 3858glGenTextures (2 ,gl -> tex ); 3859for (int i = 0 ;i < 2 ;++ i ) { 3860glBindTexture (GL_TEXTURE_2D ,gl -> tex [i ]); 3861glTexParameteri (GL_TEXTURE_2D ,GL_TEXTURE_MIN_FILTER ,gl -> gl_legacy ?GL_NEAREST :GL_LINEAR ); 3862glTexParameteri (GL_TEXTURE_2D ,GL_TEXTURE_MAG_FILTER ,gl -> gl_legacy ?GL_NEAREST :GL_LINEAR ); 3863glPixelStorei (GL_UNPACK_ROW_LENGTH ,0 ); 3864glPixelStorei (GL_UNPACK_ALIGNMENT ,1 ); 3865 } 3866 3867tigrCheckGLError ("initialization" ); 3868} 3869 3870void tigrGAPIBegin (Tigr * bmp ) 3871{ 3872} 3873 3874void tigrGAPIEnd (Tigr * bmp ) 3875{ 3876} 3877 3878void tigrGAPIDestroy (Tigr * bmp ) 3879{ 3880TigrInternal * win = tigrInternal (bmp ); 3881GLStuff * gl = & win -> gl ; 3882 3883if (!gl -> gl_legacy ) 3884 { 3885glDeleteTextures (2 ,gl -> tex ); 3886glDeleteProgram (gl -> program ); 3887 } 3888 3889tigrCheckGLError ("destroy" ); 3890 3891#ifdef _WIN32 3892if (!wglMakeCurrent (NULL ,NULL )) {tigrError (bmp ,"Cannot deactivate OpenGL context.\n" );return ;} 3893if (gl -> hglrc && !wglDeleteContext (gl -> hglrc )) {tigrError (bmp ,"Cannot delete OpenGL context.\n" );return ;} 3894gl -> hglrc = NULL ; 3895 3896if (gl -> dc && !ReleaseDC ((HWND )bmp -> handle ,gl -> dc )) {tigrError (bmp ,"Cannot release OpenGL device context.\n" );return ;} 3897gl -> dc = NULL ; 3898#endif 3899} 3900 3901void tigrGAPIResize (Tigr * bmp ,int width ,int height ) 3902{ 3903// no-op 3904 (void )bmp ; 3905 (void )width ; 3906 (void )height ; 3907} 3908 3909void tigrGAPIDraw (int legacy ,GLuint uniform_model ,GLuint tex ,Tigr * bmp ,int x1 ,int y1 ,int x2 ,int y2 ) 3910{ 3911glBindTexture (GL_TEXTURE_2D ,tex ); 3912glTexImage2D (GL_TEXTURE_2D ,0 ,GL_RGBA8 ,bmp -> w ,bmp -> h ,0 ,GL_BGRA ,GL_UNSIGNED_BYTE ,bmp -> pix ); 3913 3914if (!legacy ) 3915 { 3916float sx = (float )(x2 - x1 ); 3917float sy = (float )(y2 - y1 ); 3918float tx = (float )x1 ; 3919float ty = (float )y1 ; 3920 3921float model [16 ]= 3922 { 3923sx ,0.0f ,0.0f ,0.0f , 39240.0f ,sy ,0.0f ,0.0f , 39250.0f ,0.0f ,1.0f ,0.0f , 3926tx ,ty ,0.0f ,1.0f 3927 }; 3928 3929glUniformMatrix4fv (uniform_model ,1 ,GL_FALSE ,model ); 3930glDrawArrays (GL_TRIANGLES ,0 ,6 ); 3931 } 3932else 3933 { 3934#ifndef __APPLE__ 3935glBegin (GL_QUADS ); 3936glTexCoord2f (1.0f ,0.0f );glVertex2i (x2 ,y1 ); 3937glTexCoord2f (0.0f ,0.0f );glVertex2i (x1 ,y1 ); 3938glTexCoord2f (0.0f ,1.0f );glVertex2i (x1 ,y2 ); 3939glTexCoord2f (1.0f ,1.0f );glVertex2i (x2 ,y2 ); 3940glEnd (); 3941#else 3942assert (0 ); 3943#endif 3944 } 3945} 3946 3947void tigrGAPIPresent (Tigr * bmp ,int w ,int h ) 3948{ 3949TigrInternal * win = tigrInternal (bmp ); 3950GLStuff * gl = & win -> gl ; 3951 3952#ifdef _WIN32 3953wglMakeCurrent (gl -> dc ,gl -> hglrc ); 3954#endif 3955glViewport (0 ,0 ,w ,h ); 3956glClearColor (0 ,0 ,0 ,1 ); 3957glClear (GL_COLOR_BUFFER_BIT ); 3958 3959if (!gl -> gl_legacy ) 3960 { 3961float projection [16 ]= 3962 { 39632.0f /w ,0.0f ,0.0f ,0.0f , 39640.0f ,-2.0f /h ,0.0f ,0.0f , 39650.0f ,0.0f ,1.0f ,0.0f , 3966-1.0f ,1.0f ,0.0f ,1.0f 3967 }; 3968 3969glActiveTexture (GL_TEXTURE0 ); 3970glBindVertexArray (gl -> vao ); 3971glUseProgram (gl -> program ); 3972glUniformMatrix4fv (gl -> uniform_projection ,1 ,GL_FALSE ,projection ); 3973glUniform4f (gl -> uniform_parameters ,win -> hblur ?1.0f :0.0f ,win -> vblur ?1.0f :0.0f ,win -> scanlines ,win -> contrast ); 3974 } 3975else 3976 { 3977#ifndef __APPLE__ 3978glMatrixMode (GL_PROJECTION ); 3979glLoadIdentity (); 3980glOrtho (0 ,w ,h ,0 ,-1.0f ,1.0f ); 3981glEnable (GL_TEXTURE_2D ); 3982#else 3983assert (0 ); 3984#endif 3985 } 3986 3987glDisable (GL_BLEND ); 3988tigrGAPIDraw (gl -> gl_legacy ,gl -> uniform_model ,gl -> tex [0 ],bmp ,win -> pos [0 ],win -> pos [1 ],win -> pos [2 ],win -> pos [3 ]); 3989 3990if (win -> widgetsScale > 0 ) 3991 { 3992glEnable (GL_BLEND ); 3993glBlendFunc (GL_SRC_ALPHA ,GL_ONE_MINUS_SRC_ALPHA ); 3994tigrGAPIDraw (gl -> gl_legacy ,gl -> uniform_model ,gl -> tex [1 ],win -> widgets , 3995 (int )(w - win -> widgets -> w * win -> widgetsScale ),0 , 3996w , (int )(win -> widgets -> h * win -> widgetsScale )); 3997 } 3998 3999tigrCheckGLError ("present" ); 4000 4001#ifdef _WIN32 4002if (!SwapBuffers (gl -> dc )) {tigrError (bmp ,"Cannot swap OpenGL buffers.\n" );return ;} 4003#endif 4004} 4005 4006#endif 4007 4008//////// End of inlined file: tigr_gl.c //////// 4009 4010 4011//////// End of inlined file: tigr_amalgamated.c //////// 4012