@@ -87,7 +87,7 @@ const unsigned char icon[] = { // 16, 16, 4
87
87
// globals
88
88
//*************************************
89
89
const char appTitle [] = "Voxel Paint" ;
90
- const char appVersion [] = "v2.2 " ;
90
+ const char appVersion [] = "v2.3 " ;
91
91
char * basedir , * appdir ;
92
92
SDL_Window * wnd ;
93
93
SDL_GLContext glc ;
@@ -96,6 +96,8 @@ int winw = 1024, winh = 768;
96
96
int winw2 = 512 , winh2 = 384 ;
97
97
float ww , wh ;
98
98
float aspect , t = 0.f ;
99
+ uint drag = 0 ,size = 0 ,dsx = 0 ,dsy = 0 ;
100
+ int mx = 0 , my = 0 , xd = 0 , yd = 0 , md = 0 ;
99
101
uint g_fps = 0 ;
100
102
uint ks [10 ] = {0 }; // keystate
101
103
uint focus_mouse = 0 ; // mouse lock
@@ -979,6 +981,26 @@ int lenText(const char* s)
979
981
//*************************************
980
982
// update & render
981
983
//*************************************
984
+ void WOX_QUIT ()
985
+ {
986
+ SDL_HideWindow (wnd );
987
+ saveState ("" );
988
+ drawText (NULL , "*K" , 0 , 0 , 0 );
989
+ SDL_FreeSurface (s_icon );
990
+ SDL_FreeSurface (sHud );
991
+ SDL_GL_DeleteContext (glc );
992
+ SDL_DestroyWindow (wnd );
993
+ SDL_Quit ();
994
+ exit (0 );
995
+ }
996
+ void WOX_POP (const int w , const int h )
997
+ {
998
+ winw = w ;
999
+ winh = h ;
1000
+ winw2 = winw /2 ;
1001
+ winh2 = winh /2 ;
1002
+ doPerspective ();
1003
+ }
982
1004
void main_loop ()
983
1005
{
984
1006
//*************************************
@@ -992,10 +1014,9 @@ void main_loop()
992
1014
//*************************************
993
1015
// input handling
994
1016
//*************************************
995
- static int mx = 0 , my = 0 , lx = 0 , ly = 0 , md = 0 ;
996
- static float idle = 0.f ;
997
-
1017
+
998
1018
// if user is idle for 3 minutes, save.
1019
+ static float idle = 0.f ;
999
1020
if (idle != 0.f && t - idle > 180.f )
1000
1021
{
1001
1022
// char tmp[32];
@@ -1012,6 +1033,45 @@ void main_loop()
1012
1033
// on input a new idle is set, and a
1013
1034
// count-down for a new save begins.
1014
1035
}
1036
+
1037
+ // window decor stuff
1038
+ if (drag == 1 )
1039
+ {
1040
+ static int lx = 0 , ly = 0 ;
1041
+ static float lt = 0 ;
1042
+ if (t > lt )
1043
+ {
1044
+ if (lx != mx || ly != my )
1045
+ {
1046
+ int x ,y ;
1047
+ SDL_GetWindowPosition (wnd , & x , & y );
1048
+ SDL_SetWindowPosition (wnd , x + (mx - dsx ), y + (my - dsy ));
1049
+ lx = mx , ly = my ;
1050
+ }
1051
+ lt = t + 0.03f ;
1052
+ }
1053
+ }
1054
+ if (size == 1 )
1055
+ {
1056
+ static float lt = 0 ;
1057
+ if (t > lt )
1058
+ {
1059
+ int w ,h ;
1060
+ SDL_GetWindowSize (wnd , & w , & h );
1061
+ winw = w + (mx - dsx );
1062
+ winh = h + (my - dsy );
1063
+ dsx = mx ;
1064
+ dsy = my ;
1065
+ if (winw > 380 && winh > 380 )
1066
+ {
1067
+ SDL_SetWindowSize (wnd , winw , winh );
1068
+ winw2 = winw /2 ;
1069
+ winh2 = winh /2 ;
1070
+ doPerspective ();
1071
+ }
1072
+ lt = t + 0.03f ;
1073
+ }
1074
+ }
1015
1075
1016
1076
SDL_Event event ;
1017
1077
while (SDL_PollEvent (& event ))
@@ -1020,6 +1080,21 @@ void main_loop()
1020
1080
{
1021
1081
case SDL_KEYDOWN :
1022
1082
{
1083
+ if (event .key .keysym .sym == SDLK_ESCAPE || event .key .keysym .sym == SDLK_TAB ) // unlock mouse focus
1084
+ {
1085
+ focus_mouse = 1 - focus_mouse ;
1086
+ SDL_ShowCursor (1 - focus_mouse );
1087
+ if (focus_mouse == 1 )
1088
+ {
1089
+ SDL_GetRelativeMouseState (& xd , & yd );
1090
+ SDL_SetRelativeMouseMode (SDL_TRUE );
1091
+ }
1092
+ else
1093
+ {
1094
+ SDL_GetRelativeMouseState (& xd , & yd );
1095
+ SDL_SetRelativeMouseMode (SDL_FALSE );
1096
+ }
1097
+ }
1023
1098
if (focus_mouse == 0 ){break ;}
1024
1099
if (event .key .keysym .sym == SDLK_w ){ks [0 ] = 1 ;}
1025
1100
else if (event .key .keysym .sym == SDLK_a ){ks [1 ] = 1 ;}
@@ -1031,11 +1106,6 @@ void main_loop()
1031
1106
else if (event .key .keysym .sym == SDLK_UP ){ks [7 ] = 1 ;}
1032
1107
else if (event .key .keysym .sym == SDLK_DOWN ){ks [8 ] = 1 ;}
1033
1108
else if (event .key .keysym .sym == SDLK_SPACE ){ks [9 ] = 1 ;} // move up Z
1034
- else if (event .key .keysym .sym == SDLK_ESCAPE ) // unlock mouse focus
1035
- {
1036
- focus_mouse = 0 ;
1037
- SDL_ShowCursor (1 );
1038
- }
1039
1109
else if (event .key .keysym .sym == SDLK_q ) // clone pointed voxel texture
1040
1110
{
1041
1111
if (ise == 0 )
@@ -1434,9 +1504,9 @@ void main_loop()
1434
1504
1435
1505
case SDL_MOUSEMOTION :
1436
1506
{
1437
- if (focus_mouse == 0 ){break ;}
1438
1507
mx = event .motion .x ;
1439
1508
my = event .motion .y ;
1509
+ if (focus_mouse == 0 ){break ;}
1440
1510
1441
1511
if (ise == 1 )
1442
1512
{
@@ -1471,7 +1541,18 @@ void main_loop()
1471
1541
1472
1542
case SDL_MOUSEBUTTONUP :
1473
1543
{
1474
- if (event .button .button == SDL_BUTTON_LEFT ){ptt = 0.f ;}
1544
+ if (event .button .button == SDL_BUTTON_LEFT )
1545
+ {
1546
+ if (drag == 1 || size == 1 )
1547
+ {
1548
+ drag = 0 ;
1549
+ size = 0 ;
1550
+ SDL_GetWindowSize (wnd , & winw , & winh );
1551
+ WOX_POP (winw , winh );
1552
+ SDL_CaptureMouse (SDL_FALSE );
1553
+ }
1554
+ ptt = 0.f ;
1555
+ }
1475
1556
else if (event .button .button == SDL_BUTTON_RIGHT ){dtt = 0.f ;}
1476
1557
else if (event .button .button == SDL_BUTTON_MIDDLE ) // clone pointed voxel
1477
1558
{
@@ -1508,15 +1589,82 @@ void main_loop()
1508
1589
1509
1590
case SDL_MOUSEBUTTONDOWN :
1510
1591
{
1511
- lx = event .button .x ;
1512
- ly = event .button .y ;
1513
1592
mx = event .button .x ;
1514
1593
my = event .button .y ;
1515
1594
1595
+ static float llct = 0.f ;
1596
+ static uint maxed = 0 ;
1597
+
1598
+ if (event .button .button == SDL_BUTTON_LEFT ) // check window decor stuff
1599
+ {
1600
+ if (focus_mouse == 0 )
1601
+ {
1602
+ if (llct != 0.f && t - llct < 0.3f )
1603
+ {
1604
+ if (maxed == 0 )
1605
+ {
1606
+ SDL_MaximizeWindow (wnd );
1607
+ maxed = 1 ;
1608
+ drag = 0 ;
1609
+ size = 0 ;
1610
+ llct = t ;
1611
+ break ;
1612
+ }
1613
+ else
1614
+ {
1615
+ SDL_RestoreWindow (wnd );
1616
+ maxed = 0 ;
1617
+ drag = 0 ;
1618
+ size = 0 ;
1619
+ llct = t ;
1620
+ break ;
1621
+ }
1622
+ }
1623
+ llct = t ;
1624
+ if (my < 22 )
1625
+ {
1626
+ if (mx < 14 )
1627
+ {
1628
+ WOX_QUIT ();
1629
+ break ;
1630
+ }
1631
+ else if (mx < 28 )
1632
+ {
1633
+ SDL_MinimizeWindow (wnd );
1634
+ break ;
1635
+ }
1636
+ else if (mx > winw - 14 )
1637
+ {
1638
+ WOX_QUIT ();
1639
+ break ;
1640
+ }
1641
+ else if (mx > winw - 28 )
1642
+ {
1643
+ SDL_MinimizeWindow (wnd );
1644
+ break ;
1645
+ }
1646
+
1647
+ dsx = mx , dsy = my ;
1648
+ drag = 1 ;
1649
+ SDL_CaptureMouse (SDL_TRUE );
1650
+ break ;
1651
+ }
1652
+ else if (mx > winw - 15 && my > winh - 15 )
1653
+ {
1654
+ size = 1 ;
1655
+ dsx = mx , dsy = my ;
1656
+ SDL_CaptureMouse (SDL_TRUE );
1657
+ break ;
1658
+ }
1659
+ }
1660
+ }
1661
+
1516
1662
if (focus_mouse == 0 ) // lock mouse focus on every mouse input to the window
1517
1663
{
1518
1664
SDL_ShowCursor (0 );
1519
1665
focus_mouse = 1 ;
1666
+ SDL_GetRelativeMouseState (& xd , & yd );
1667
+ SDL_SetRelativeMouseMode (SDL_TRUE );
1520
1668
break ;
1521
1669
}
1522
1670
@@ -1563,14 +1711,7 @@ void main_loop()
1563
1711
1564
1712
case SDL_QUIT :
1565
1713
{
1566
- SDL_HideWindow (wnd );
1567
- saveState ("" );
1568
- SDL_FreeSurface (s_icon );
1569
- SDL_FreeSurface (sHud );
1570
- SDL_GL_DeleteContext (glc );
1571
- SDL_DestroyWindow (wnd );
1572
- SDL_Quit ();
1573
- exit (0 );
1714
+ WOX_QUIT ();
1574
1715
}
1575
1716
break ;
1576
1717
}
@@ -1709,12 +1850,11 @@ void main_loop()
1709
1850
//*************************************
1710
1851
// camera/mouse control
1711
1852
//*************************************
1712
- const float xd = lx - mx ;
1713
- const float yd = ly - my ;
1853
+ SDL_GetRelativeMouseState (& xd , & yd );
1714
1854
if (xd != 0 || yd != 0 )
1715
1855
{
1716
- g .xrot + = xd * g .sens ;
1717
- g .yrot + = yd * g .sens ;
1856
+ g .xrot - = xd * g .sens ;
1857
+ g .yrot - = yd * g .sens ;
1718
1858
1719
1859
if (g .plock == 1 )
1720
1860
{
@@ -1730,9 +1870,6 @@ void main_loop()
1730
1870
if (g .yrot < 0.1f )
1731
1871
g .yrot = 0.1f ;
1732
1872
}
1733
-
1734
- lx = winw2 , ly = winh2 ;
1735
- SDL_WarpMouseInWindow (wnd , lx , ly );
1736
1873
}
1737
1874
}
1738
1875
@@ -1741,6 +1878,8 @@ void main_loop()
1741
1878
mRotate (& view , g .xrot , 0.f , 0.f , 1.f );
1742
1879
mTranslate (& view , g .pp .x , g .pp .y , g .pp .z );
1743
1880
1881
+ mGetViewZ (& look_dir , view ); // refresh
1882
+
1744
1883
//*************************************
1745
1884
// begin render
1746
1885
//*************************************
@@ -1861,6 +2000,23 @@ void drawHud()
1861
2000
// clear cpu hud before rendering to it
1862
2001
SDL_FillRect (sHud , & sHud -> clip_rect , 0x00000000 );
1863
2002
2003
+ // window title
2004
+ SDL_FillRect (sHud , & (SDL_Rect ){0 , 0 , winw , 19 }, 0xDDd0e040 );
2005
+ SDL_FillRect (sHud , & (SDL_Rect ){1 , 1 , winw - 2 , 17 }, 0xBBa0b010 );
2006
+ const uint len = lenText ("Voxel Paint" );
2007
+ drawText (sHud , "Voxel Paint" , winw2 - 24 , 3 , 2 );
2008
+ drawText (sHud , "Voxel Paint" , winw2 - 26 , 3 , 2 );
2009
+ drawText (sHud , "Voxel Paint" , winw2 - 25 , 5 , 2 );
2010
+ drawText (sHud , "Voxel Paint" , winw2 - 25 , 4 , 0 );
2011
+ drawText (sHud , "X -" , 5 , 3 , 3 );
2012
+ drawText (sHud , "X -" , 4 , 4 , 0 );
2013
+ drawText (sHud , "- X" , winw - 23 , 3 , 3 );
2014
+ drawText (sHud , "- X" , winw - 22 , 4 , 0 );
2015
+ SDL_FillRect (sHud , & (SDL_Rect ){winw - 15 , winh - 15 , 15 , 15 }, 0xDDd0e040 );
2016
+ SDL_FillRect (sHud , & (SDL_Rect ){winw - 14 , winh - 14 , 13 , 13 }, 0xBBa0b010 );
2017
+ drawText (sHud , "r" , winw - 8 , winh - 12 , 3 );
2018
+ drawText (sHud , "r" , winw - 9 , winh - 13 , 0 );
2019
+
1864
2020
// pixel crosshair
1865
2021
// setpixel(sHud, winw2, winh2, 0xFFFFFF00);
1866
2022
// setpixel(sHud, winw2+1, winh2, 0xFFFFFF00);
@@ -1879,11 +2035,12 @@ void drawHud()
1879
2035
// fps
1880
2036
char tmp [16 ];
1881
2037
sprintf (tmp , "%u" , g_fps );
1882
- SDL_FillRect (sHud , & (SDL_Rect ){0 , 0 , lenText (tmp )+ 8 , 19 }, 0xCC000000 );
1883
- drawText (sHud , tmp , 4 , 4 , 2 );
2038
+ SDL_FillRect (sHud , & (SDL_Rect ){0 , 19 , lenText (tmp )+ 8 , 19 }, 0xCC000000 );
2039
+ drawText (sHud , tmp , 4 , 23 , 2 );
1884
2040
// center hud
1885
2041
const int top = winh2 - (11 * 12 );
1886
2042
const int left = winw2 - 239 ;
2043
+ SDL_FillRect (sHud , & (SDL_Rect ){winw2 - 255 , top - 5 , 510 , 280 }, 0xBBa0b010 );
1887
2044
SDL_FillRect (sHud , & (SDL_Rect ){winw2 - 250 , top , 500 , 270 }, 0xCC000000 );
1888
2045
int a = drawText (sHud , "Voxel Paint" , winw2 - 27 , top + 11 , 3 );
1889
2046
a = drawText (sHud , appVersion , left + 455 , top + 11 , 4 );
@@ -1978,7 +2135,7 @@ int main(int argc, char** argv)
1978
2135
SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION , 2 );
1979
2136
SDL_GL_SetAttribute (SDL_GL_CONTEXT_MINOR_VERSION , 0 );
1980
2137
SDL_GL_SetAttribute (SDL_GL_CONTEXT_PROFILE_MASK , SDL_GL_CONTEXT_PROFILE_ES );
1981
- wnd = SDL_CreateWindow (appTitle , SDL_WINDOWPOS_CENTERED , SDL_WINDOWPOS_CENTERED , winw , winh , SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN );
2138
+ wnd = SDL_CreateWindow (appTitle , SDL_WINDOWPOS_CENTERED , SDL_WINDOWPOS_CENTERED , winw , winh , SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_BORDERLESS );
1982
2139
if (wnd == NULL )
1983
2140
{
1984
2141
printf ("ERROR: SDL_CreateWindow(): %s\n" , SDL_GetError ());
@@ -2047,7 +2204,7 @@ int main(int argc, char** argv)
2047
2204
printf ("----\n" );
2048
2205
printf ("James William Fletcher (github.com/mrbid)\n" );
2049
2206
printf ("----\n\n" );
2050
- printf ("Mouse locks when you click on the game window, press ESCAPE to unlock the mouse.\n\n" );
2207
+ printf ("Mouse locks when you click on the game window, press ESCAPE or TAB to unlock the mouse.\n\n" );
2051
2208
printf ("W,A,S,D = Move around based on relative orientation to X and Y.\n" );
2052
2209
printf ("SPACE + L-SHIFT = Move up and down relative Z.\n" );
2053
2210
printf ("Left Click / R-SHIFT = Place node.\n" );
0 commit comments