@@ -91,7 +91,7 @@ const unsigned char icon[] = { // 16, 16, 4
9191// globals
9292//*************************************
9393const char appTitle [] = "Voxel Paint Pro" ;
94- const char appVersion [] = "v1.1 " ;
94+ const char appVersion [] = "v1.2 " ;
9595char * basedir , * appdir ;
9696SDL_Window * wnd ;
9797SDL_GLContext glc ;
@@ -100,6 +100,8 @@ int winw = 1024, winh = 768;
100100int winw2 = 512 , winh2 = 384 ;
101101float ww , wh ;
102102float aspect , t = 0.f ;
103+ uint drag = 0 ,size = 0 ,dsx = 0 ,dsy = 0 ;
104+ int mx = 0 , my = 0 , xd = 0 , yd = 0 , md = 0 ;
103105uint g_fps = 0 ;
104106uint ks [10 ] = {0 }; // keystate
105107uint focus_mouse = 0 ; // mouse lock
@@ -945,6 +947,26 @@ int lenText(const char* s)
945947//*************************************
946948// update & render
947949//*************************************
950+ void WOX_QUIT ()
951+ {
952+ SDL_HideWindow (wnd );
953+ saveState ("" );
954+ drawText (NULL , "*K" , 0 , 0 , 0 );
955+ SDL_FreeSurface (s_icon );
956+ SDL_FreeSurface (sHud );
957+ SDL_GL_DeleteContext (glc );
958+ SDL_DestroyWindow (wnd );
959+ SDL_Quit ();
960+ exit (0 );
961+ }
962+ void WOX_POP (const int w , const int h )
963+ {
964+ winw = w ;
965+ winh = h ;
966+ winw2 = winw /2 ;
967+ winh2 = winh /2 ;
968+ doPerspective ();
969+ }
948970void main_loop ()
949971{
950972//*************************************
@@ -958,10 +980,9 @@ void main_loop()
958980//*************************************
959981// input handling
960982//*************************************
961- static int mx = 0 , my = 0 , lx = 0 , ly = 0 , md = 0 ;
962- static float idle = 0.f ;
963-
983+
964984 // if user is idle for 3 minutes, save.
985+ static float idle = 0.f ;
965986 if (idle != 0.f && t - idle > 180.f )
966987 {
967988 // char tmp[32];
@@ -978,6 +999,45 @@ void main_loop()
978999 // on input a new idle is set, and a
9791000 // count-down for a new save begins.
9801001 }
1002+
1003+ // window decor stuff
1004+ if (drag == 1 )
1005+ {
1006+ static int lx = 0 , ly = 0 ;
1007+ static float lt = 0 ;
1008+ if (t > lt )
1009+ {
1010+ if (lx != mx || ly != my )
1011+ {
1012+ int x ,y ;
1013+ SDL_GetWindowPosition (wnd , & x , & y );
1014+ SDL_SetWindowPosition (wnd , x + (mx - dsx ), y + (my - dsy ));
1015+ lx = mx , ly = my ;
1016+ }
1017+ lt = t + 0.03f ;
1018+ }
1019+ }
1020+ if (size == 1 )
1021+ {
1022+ static float lt = 0 ;
1023+ if (t > lt )
1024+ {
1025+ int w ,h ;
1026+ SDL_GetWindowSize (wnd , & w , & h );
1027+ winw = w + (mx - dsx );
1028+ winh = h + (my - dsy );
1029+ dsx = mx ;
1030+ dsy = my ;
1031+ if (winw > 380 && winh > 380 )
1032+ {
1033+ SDL_SetWindowSize (wnd , winw , winh );
1034+ winw2 = winw /2 ;
1035+ winh2 = winh /2 ;
1036+ doPerspective ();
1037+ }
1038+ lt = t + 0.03f ;
1039+ }
1040+ }
9811041
9821042 SDL_Event event ;
9831043 while (SDL_PollEvent (& event ))
@@ -986,6 +1046,21 @@ void main_loop()
9861046 {
9871047 case SDL_KEYDOWN :
9881048 {
1049+ if (event .key .keysym .sym == SDLK_ESCAPE ) // unlock mouse focus
1050+ {
1051+ focus_mouse = 1 - focus_mouse ;
1052+ SDL_ShowCursor (1 - focus_mouse );
1053+ if (focus_mouse == 1 )
1054+ {
1055+ SDL_GetRelativeMouseState (& xd , & yd );
1056+ SDL_SetRelativeMouseMode (SDL_TRUE );
1057+ }
1058+ else
1059+ {
1060+ SDL_GetRelativeMouseState (& xd , & yd );
1061+ SDL_SetRelativeMouseMode (SDL_FALSE );
1062+ }
1063+ }
9891064 if (focus_mouse == 0 ){break ;}
9901065 if (event .key .keysym .sym == SDLK_w ){ks [0 ] = 1 ;}
9911066 else if (event .key .keysym .sym == SDLK_a ){ks [1 ] = 1 ;}
@@ -997,11 +1072,6 @@ void main_loop()
9971072 else if (event .key .keysym .sym == SDLK_UP ){ks [7 ] = 1 ;}
9981073 else if (event .key .keysym .sym == SDLK_DOWN ){ks [8 ] = 1 ;}
9991074 else if (event .key .keysym .sym == SDLK_SPACE ){ks [9 ] = 1 ;} // move up Z
1000- else if (event .key .keysym .sym == SDLK_ESCAPE ) // unlock mouse focus
1001- {
1002- focus_mouse = 0 ;
1003- SDL_ShowCursor (1 );
1004- }
10051075 else if (event .key .keysym .sym == SDLK_q ) // clone pointed voxel color
10061076 {
10071077 if (ise == 0 )
@@ -1481,9 +1551,9 @@ void main_loop()
14811551
14821552 case SDL_MOUSEMOTION :
14831553 {
1484- if (focus_mouse == 0 ){break ;}
14851554 mx = event .motion .x ;
14861555 my = event .motion .y ;
1556+ if (focus_mouse == 0 ){break ;}
14871557
14881558 if (ise == 1 )
14891559 {
@@ -1516,7 +1586,18 @@ void main_loop()
15161586
15171587 case SDL_MOUSEBUTTONUP :
15181588 {
1519- if (event .button .button == SDL_BUTTON_LEFT ){ptt = 0.f ;}
1589+ if (event .button .button == SDL_BUTTON_LEFT )
1590+ {
1591+ if (drag == 1 || size == 1 )
1592+ {
1593+ drag = 0 ;
1594+ size = 0 ;
1595+ SDL_GetWindowSize (wnd , & winw , & winh );
1596+ WOX_POP (winw , winh );
1597+ SDL_CaptureMouse (SDL_FALSE );
1598+ }
1599+ ptt = 0.f ;
1600+ }
15201601 else if (event .button .button == SDL_BUTTON_RIGHT ){dtt = 0.f ;}
15211602 else if (event .button .button == SDL_BUTTON_X2 ){rtt = 0.f ;}
15221603 else if (event .button .button == SDL_BUTTON_MIDDLE || event .button .button == SDL_BUTTON_X1 ) // clone pointed voxel
@@ -1554,15 +1635,82 @@ void main_loop()
15541635
15551636 case SDL_MOUSEBUTTONDOWN :
15561637 {
1557- lx = event .button .x ;
1558- ly = event .button .y ;
15591638 mx = event .button .x ;
15601639 my = event .button .y ;
15611640
1641+ static float llct = 0.f ;
1642+ static uint maxed = 0 ;
1643+
1644+ if (event .button .button == SDL_BUTTON_LEFT ) // check window decor stuff
1645+ {
1646+ if (focus_mouse == 0 )
1647+ {
1648+ if (llct != 0.f && t - llct < 0.3f )
1649+ {
1650+ if (maxed == 0 )
1651+ {
1652+ SDL_MaximizeWindow (wnd );
1653+ maxed = 1 ;
1654+ drag = 0 ;
1655+ size = 0 ;
1656+ llct = t ;
1657+ break ;
1658+ }
1659+ else
1660+ {
1661+ SDL_RestoreWindow (wnd );
1662+ maxed = 0 ;
1663+ drag = 0 ;
1664+ size = 0 ;
1665+ llct = t ;
1666+ break ;
1667+ }
1668+ }
1669+ llct = t ;
1670+ if (my < 22 )
1671+ {
1672+ if (mx < 14 )
1673+ {
1674+ WOX_QUIT ();
1675+ break ;
1676+ }
1677+ else if (mx < 28 )
1678+ {
1679+ SDL_MinimizeWindow (wnd );
1680+ break ;
1681+ }
1682+ else if (mx > winw - 14 )
1683+ {
1684+ WOX_QUIT ();
1685+ break ;
1686+ }
1687+ else if (mx > winw - 28 )
1688+ {
1689+ SDL_MinimizeWindow (wnd );
1690+ break ;
1691+ }
1692+
1693+ dsx = mx , dsy = my ;
1694+ drag = 1 ;
1695+ SDL_CaptureMouse (SDL_TRUE );
1696+ break ;
1697+ }
1698+ else if (mx > winw - 15 && my > winh - 15 )
1699+ {
1700+ size = 1 ;
1701+ dsx = mx , dsy = my ;
1702+ SDL_CaptureMouse (SDL_TRUE );
1703+ break ;
1704+ }
1705+ }
1706+ }
1707+
15621708 if (focus_mouse == 0 ) // lock mouse focus on every mouse input to the window
15631709 {
15641710 SDL_ShowCursor (0 );
15651711 focus_mouse = 1 ;
1712+ SDL_GetRelativeMouseState (& xd , & yd );
1713+ SDL_SetRelativeMouseMode (SDL_TRUE );
15661714 break ;
15671715 }
15681716
@@ -1641,6 +1789,7 @@ void main_loop()
16411789 {
16421790 SDL_HideWindow (wnd );
16431791 saveState ("" );
1792+ drawText (NULL , "*K" , 0 , 0 , 0 );
16441793 SDL_FreeSurface (s_icon );
16451794 SDL_FreeSurface (sHud );
16461795 SDL_GL_DeleteContext (glc );
@@ -1792,12 +1941,11 @@ void main_loop()
17921941 //*************************************
17931942 // camera/mouse control
17941943 //*************************************
1795- const float xd = lx - mx ;
1796- const float yd = ly - my ;
1944+ SDL_GetRelativeMouseState (& xd , & yd );
17971945 if (xd != 0 || yd != 0 )
17981946 {
1799- g .xrot + = xd * g .sens ;
1800- g .yrot + = yd * g .sens ;
1947+ g .xrot - = xd * g .sens ;
1948+ g .yrot - = yd * g .sens ;
18011949
18021950 if (g .plock == 1 )
18031951 {
@@ -1813,9 +1961,6 @@ void main_loop()
18131961 if (g .yrot < 0.1f )
18141962 g .yrot = 0.1f ;
18151963 }
1816-
1817- lx = winw2 , ly = winh2 ;
1818- SDL_WarpMouseInWindow (wnd , lx , ly );
18191964 }
18201965 }
18211966
@@ -1933,13 +2078,43 @@ void main_loop()
19332078}
19342079void drawHud ()
19352080{
1936- // clear cpu hud before rendering to it
1937- SDL_FillRect (sHud , & sHud -> clip_rect , 0x00000000 );
2081+ // window title
2082+ SDL_FillRect (sHud , & (SDL_Rect ){0 , 0 , winw , 19 }, 0xDDFFFF00 );
2083+ SDL_FillRect (sHud , & (SDL_Rect ){1 , 1 , winw - 2 , 17 }, 0xBB777700 );
2084+ const uint len = lenText ("Voxel Paint Pro" );
2085+ drawText (sHud , "Voxel Paint Pro" , winw2 - 24 , 3 , 3 );
2086+ drawText (sHud , "Voxel Paint Pro" , winw2 - 26 , 3 , 3 );
2087+ drawText (sHud , "Voxel Paint Pro" , winw2 - 25 , 5 , 3 );
2088+ drawText (sHud , "Voxel Paint Pro" , winw2 - 25 , 4 , 0 );
2089+ drawText (sHud , "X -" , 5 , 3 , 3 );
2090+ drawText (sHud , "X -" , 4 , 4 , 0 );
2091+ drawText (sHud , "- X" , winw - 23 , 3 , 3 );
2092+ drawText (sHud , "- X" , winw - 22 , 4 , 0 );
2093+ SDL_FillRect (sHud , & (SDL_Rect ){winw - 15 , winh - 15 , 15 , 15 }, 0xDDFFFF00 );
2094+ SDL_FillRect (sHud , & (SDL_Rect ){winw - 14 , winh - 14 , 13 , 13 }, 0xBB777700 );
2095+ drawText (sHud , "r" , winw - 9 , winh - 14 , 3 );
2096+ drawText (sHud , "r" , winw - 8 , winh - 13 , 0 );
2097+
2098+ // pixel crosshair
2099+ // setpixel(sHud, winw2, winh2, 0xFFFFFF00);
2100+ // setpixel(sHud, winw2+1, winh2, 0xFFFFFF00);
2101+ // setpixel(sHud, winw2-1, winh2, 0xFFFFFF00);
2102+ // setpixel(sHud, winw2, winh2+1, 0xFFFFFF00);
2103+ // setpixel(sHud, winw2, winh2-1, 0xFFFFFF00);
2104+ // setpixel(sHud, winw2+2, winh2, 0xFFFFFF00);
2105+ // setpixel(sHud, winw2-2, winh2, 0xFFFFFF00);
2106+ // setpixel(sHud, winw2, winh2+2, 0xFFFFFF00);
2107+ // setpixel(sHud, winw2, winh2-2, 0xFFFFFF00);
2108+ // setpixel(sHud, winw2+3, winh2, 0xFFFFFF00);
2109+ // setpixel(sHud, winw2-3, winh2, 0xFFFFFF00);
2110+ // setpixel(sHud, winw2, winh2+3, 0xFFFFFF00);
2111+ // setpixel(sHud, winw2, winh2-3, 0xFFFFFF00);
2112+
19382113 // fps
19392114 char tmp [16 ];
19402115 sprintf (tmp , "%u" , g_fps );
1941- SDL_FillRect (sHud , & (SDL_Rect ){0 , 0 , lenText (tmp )+ 8 , 19 }, 0xCC000000 );
1942- drawText (sHud , tmp , 4 , 4 , 2 );
2116+ SDL_FillRect (sHud , & (SDL_Rect ){0 , 19 , lenText (tmp )+ 8 , 19 }, 0xCC000000 );
2117+ drawText (sHud , tmp , 4 , 23 , 2 );
19432118 // center hud
19442119 const int top = winh2 - (11 * 19 );
19452120 const int left = winw2 - 239 ;
@@ -2072,7 +2247,7 @@ int main(int argc, char** argv)
20722247 SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION , 2 );
20732248 SDL_GL_SetAttribute (SDL_GL_CONTEXT_MINOR_VERSION , 0 );
20742249 SDL_GL_SetAttribute (SDL_GL_CONTEXT_PROFILE_MASK , SDL_GL_CONTEXT_PROFILE_ES );
2075- wnd = SDL_CreateWindow (appTitle , SDL_WINDOWPOS_CENTERED , SDL_WINDOWPOS_CENTERED , winw , winh , SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN );
2250+ wnd = SDL_CreateWindow (appTitle , SDL_WINDOWPOS_CENTERED , SDL_WINDOWPOS_CENTERED , winw , winh , SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_BORDERLESS );
20762251 while (wnd == NULL )
20772252 {
20782253 if (msaa == 0 )
@@ -2081,7 +2256,7 @@ int main(int argc, char** argv)
20812256 return 1 ;
20822257 }
20832258 SDL_GL_SetAttribute (SDL_GL_MULTISAMPLESAMPLES , msaa /2 );
2084- wnd = SDL_CreateWindow (appTitle , SDL_WINDOWPOS_CENTERED , SDL_WINDOWPOS_CENTERED , winw , winh , SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN );
2259+ wnd = SDL_CreateWindow (appTitle , SDL_WINDOWPOS_CENTERED , SDL_WINDOWPOS_CENTERED , winw , winh , SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_BORDERLESS );
20852260 }
20862261 SDL_GL_SetSwapInterval (1 );
20872262 glc = SDL_GL_CreateContext (wnd );
0 commit comments