Added simple file browser. Needs directory browsing and forced file extension.

This commit is contained in:
grimfang4
2011-02-25 23:56:45 +00:00
parent f72816b2a0
commit 6f71bbf292
7 changed files with 675 additions and 712 deletions

View File

@@ -1,10 +1,10 @@
AUTOMAKE_OPTIONS = foreign AUTOMAKE_OPTIONS = foreign
CFLAGS = --pedantic -Wall -O2 CFLAGS = --pedantic -Wall -O2
CXXFLAGS=$(CFLAGS) `sdl-config --cflags` `pkg-config gtk+-2.0 --cflags` CXXFLAGS=$(CFLAGS) `sdl-config --cflags`
CPPFLAGS=-DDATADIR='$(pkgdatadir)' CPPFLAGS=-DDATADIR='$(pkgdatadir)'
LDFLAGS=`sdl-config --libs` `pkg-config gtk+-2.0 --libs` LDFLAGS=`sdl-config --libs`
bin_PROGRAMS = sfxr bin_PROGRAMS = sfxr
sfxr_SOURCES := main.cpp ddrawkit.h sdlkit.h tools.h sfxr_SOURCES := main.cpp sdlkit.cpp tools.cpp sdlkit.h tools.h

View File

@@ -1,390 +0,0 @@
/*
Copyright (c) 2007 Tomas Pettersson <drpetter@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Porting notes
-------------
Need to provide window/framebuffer setup at program start
ddkUnlock() is called when the window should be redrawn
WinMain() at the bottom of this file is the entry point and main loop
which handles messages and calling the app update function ddkCalcFrame()
ddkscreen32 = pointer to 640x480 DWORD pixel buffer
mouse_* = mouse info, only need x/y/px/py/left/right/leftclick/rightclick
*/
#define _WIN32_WINDOWS 0xBAD
#include <windows.h>
extern "C" long _ftol( double ); //defined by VC6 C libs
extern "C" long _ftol2( double dblSource ) { return _ftol( dblSource ); }
void ddkInit(); // Will be called on startup
bool ddkCalcFrame(); // Will be called every frame, return true to continue running or false to quit
void ddkFree(); // Will be called on shutdown
bool ddkLock(); // Call immediately before drawing (once per frame)
void ddkUnlock(); // Call immediately after drawing (once per frame)
void ddkDrawPixel(int x, int y, int red, int green, int blue); // Draw a pixel
void ddkSetMode(int width, int height, int bpp, int refreshrate, int fullscreen, char *title);
#define DDK_WINDOW 0 // Run in a normal resizable window (stretch to fit)
#define DDK_FULLSCREEN 1 // Change display mode to the one specified, use vsync
#define DDK_STRETCH 2 // Run in a maximized window, looks like fullscreen
int ddkGetBpp(); // Use this to find out the current color depth
DWORD *ddkscreen32; // Use this for 32 bit modes
WORD *ddkscreen16; // Use this for 16 bit modes
int ddkpitch; // Offset in pixels from the start of one horizontal line to the start of the next
bool ddrawkit_initialised;
bool ddrawkit_released;
bool ddrawkit_fullscreen;
bool ddrawkit_fullwindow;
int ddrawkit_width;
int ddrawkit_height;
int ddrawkit_bpp;
int ddrawkit_refresh;
bool ddrawkit_timeravailable;
HWND hWndMain;
HINSTANCE hInstanceMain;
HCURSOR cursor_arrow;
int mouse_x, mouse_y, mouse_px, mouse_py;
bool mouse_left=false, mouse_right=false, mouse_middle=false;
bool mouse_leftclick=false, mouse_rightclick=false, mouse_middleclick=false;
bool mouse_doubleclick=false;
int mouse_wheel=0;
// --- DDB implementation
struct pBITMAPINFO
{
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[256];
} BMInfo;
HBITMAP hBM;
HDC hDC_comp;
DWORD* image_bitmap;
void InitImageBuffer()
{
HPALETTE PalHan;
HWND ActiveWindow;
HDC hDC;
image_bitmap=(DWORD*)malloc(ddrawkit_width*ddrawkit_height*sizeof(DWORD));
ActiveWindow=hWndMain;
hDC=GetDC(ActiveWindow);
BMInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
BMInfo.bmiHeader.biWidth=ddrawkit_width;
BMInfo.bmiHeader.biHeight=-abs(ddrawkit_height);
BMInfo.bmiHeader.biPlanes=1;
BMInfo.bmiHeader.biBitCount=32;
BMInfo.bmiHeader.biCompression=BI_RGB;
BMInfo.bmiHeader.biSizeImage=ddrawkit_width*ddrawkit_height*4;
BMInfo.bmiHeader.biXPelsPerMeter=0;
BMInfo.bmiHeader.biYPelsPerMeter=0;
hBM=CreateDIBSection(hDC, (BITMAPINFO*)&BMInfo, DIB_RGB_COLORS, (void**)&image_bitmap, 0, 0);
ReleaseDC(ActiveWindow, hDC);
ddkscreen32=image_bitmap;
ddkpitch=ddrawkit_width;
}
void DestroyImageBuffer()
{
free(image_bitmap);
}
void ddrawkit_BlitWindowDDB()
{
HDC hDC;
HBITMAP DefaultBitmap;
hDC=GetDC(hWndMain);
DefaultBitmap=(HBITMAP)SelectObject(hDC_comp, hBM);
// BitBlt(hDC, x1, y1, x2-x1, y2-y1, hDC_comp, x1, y1, SRCCOPY);
BitBlt(hDC, 0, 0, ddrawkit_width, ddrawkit_height, hDC_comp, 0, 0, SRCCOPY);
SelectObject(hDC_comp, DefaultBitmap);
DeleteDC(hDC);
}
// --- DDB implementation
void ddrawkit_SafeDestroy()
{
if(!ddrawkit_released)
{
ddrawkit_released=true;
ddkFree();
DestroyWindow(hWndMain);
DestroyImageBuffer();
}
}
LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_CLOSE:
ddrawkit_SafeDestroy();
return 0;
case WM_SETCURSOR:
if(ddrawkit_fullscreen || ddrawkit_fullwindow)
{
SetCursor(NULL);
return 0;
}
else
SetCursor(cursor_arrow);
break;
case WM_MOUSEMOVE:
int curwidth, curheight;
RECT rect;
GetClientRect(hWndMain, &rect);
curwidth=rect.right-rect.left;
curheight=rect.bottom-rect.top;
mouse_x=(int)((float)LOWORD(lParam)/curwidth*ddrawkit_width);
mouse_y=(int)((float)HIWORD(lParam)/curheight*ddrawkit_height);
return 0;
case WM_MOUSEWHEEL:
if((wParam>>16)&0x7FFF)
{
if((wParam>>16)&0x8000)
mouse_wheel=-1;
else
mouse_wheel=1;
}
return 0;
case WM_LBUTTONDBLCLK:
mouse_doubleclick=true;
return 0;
case WM_LBUTTONDOWN:
mouse_left=true;
mouse_leftclick=true;
return 0;
case WM_LBUTTONUP:
mouse_left=false;
return 0;
case WM_RBUTTONDOWN:
mouse_right=true;
mouse_rightclick=true;
return 0;
case WM_RBUTTONUP:
mouse_right=false;
return 0;
case WM_MBUTTONDOWN:
mouse_middle=true;
mouse_middleclick=true;
return 0;
case WM_MBUTTONUP:
mouse_middle=false;
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
void ddrawkit_RegisterWindowClass()
{
WNDCLASSEX wcx;
ZeroMemory(&wcx, sizeof(WNDCLASSEX));
wcx.cbSize=sizeof(WNDCLASSEX);
wcx.lpfnWndProc=MainWindowProc;
wcx.hInstance=GetModuleHandle(NULL);
wcx.hIcon=LoadIcon(NULL, IDI_APPLICATION);
wcx.hCursor=NULL;
// wcx.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wcx.hbrBackground=NULL;
wcx.lpszMenuName=NULL;
wcx.lpszClassName="DDrawKitClass";
RegisterClassEx(&wcx);
}
bool ddkLock()
{
return true;
}
void ddkUnlock()
{
ddrawkit_BlitWindowDDB();
}
void ddkDrawPixel(int x, int y, int red, int green, int blue)
{
if(x<0 || y<0 || x>=ddrawkit_width || y>=ddrawkit_height)
return;
if(ddrawkit_bpp==32)
{
DWORD color=(red<<16)|(green<<8)|blue;
ddkscreen32[y*ddkpitch+x]=color;
}
if(ddrawkit_bpp==16)
{
WORD color=((red>>3)<<11)|((green>>2)<<5)|(blue>>3);
ddkscreen16[y*ddkpitch+x]=color;
}
}
void ddkSetMode(int width, int height, int bpp, int refreshrate, int fullscreen, char *title)
{
if(!ddrawkit_initialised)
{
ddrawkit_width=width;
ddrawkit_height=height;
ddrawkit_bpp=bpp;
ddrawkit_refresh=refreshrate;
switch(fullscreen)
{
case 0:
ddrawkit_fullscreen=false;
ddrawkit_fullwindow=false;
break;
case 1:
ddrawkit_fullscreen=true;
ddrawkit_fullwindow=false;
break;
case 2:
ddrawkit_fullscreen=false;
ddrawkit_fullwindow=true;
break;
}
ddrawkit_RegisterWindowClass();
if(ddrawkit_fullscreen || ddrawkit_fullwindow)
{
// Screen sized window (possibly stretched)
hWndMain=CreateWindowEx(WS_EX_APPWINDOW,
"DDrawKitClass", title, WS_POPUP,
0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN),
NULL, NULL, hInstanceMain, NULL);
}
else
{
// Normal window
// hWndMain=CreateWindow("DDrawKitClass", title, WS_OVERLAPPEDWINDOW,
hWndMain=CreateWindow("DDrawKitClass", title, WS_OVERLAPPED|WS_BORDER|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX,
// 0, 0, ddrawkit_width+GetSystemMetrics(SM_CXSIZEFRAME)*2,
// ddrawkit_height+GetSystemMetrics(SM_CYSIZEFRAME)*2+GetSystemMetrics(SM_CYCAPTION),
GetSystemMetrics(SM_CXSCREEN)/2-320, GetSystemMetrics(SM_CYSCREEN)/2-300,
ddrawkit_width+GetSystemMetrics(SM_CXEDGE)*2,
ddrawkit_height+GetSystemMetrics(SM_CYEDGE)*2+GetSystemMetrics(SM_CYCAPTION),
NULL, NULL, hInstanceMain, NULL);
}
// init DDB implementation
hDC_comp=CreateCompatibleDC(NULL);
InitImageBuffer();
ShowWindow(hWndMain, SW_SHOW);
ddrawkit_initialised=true;
ddrawkit_released=false;
// Clear screen
ddkLock();
for(int y=0;y<ddrawkit_height;y++)
for(int x=0;x<ddrawkit_width;x++)
{
if(ddrawkit_bpp==32)
ddkscreen32[y*ddkpitch+x]=0;
else
ddkscreen16[y*ddkpitch+x]=0;
}
ddkUnlock();
}
}
int ddkGetBpp()
{
return ddrawkit_bpp;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
{
MSG msg;
hInstanceMain=hInstance;
cursor_arrow=LoadCursor(NULL, IDC_ARROW);
ddkInit();
LARGE_INTEGER startTime;
LARGE_INTEGER frequency;
if(!QueryPerformanceFrequency(&frequency))
ddrawkit_timeravailable=false;
else
{
ddrawkit_timeravailable=true;
QueryPerformanceCounter(&startTime);
}
for(;;)
{
while(PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
{
if(!GetMessage(&msg, NULL, 0, 0))
break;
DispatchMessage(&msg);
}
if(ddrawkit_released)
break;
if(!ddkCalcFrame())
{
ddrawkit_SafeDestroy();
break;
}
mouse_px=mouse_x;
mouse_py=mouse_y;
mouse_leftclick=false;
mouse_rightclick=false;
mouse_middleclick=false;
mouse_doubleclick=false;
}
return 0;
}

View File

@@ -19,16 +19,10 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
Porting notes
-------------
Search for WIN32 to find windows-specific code
snippets which need to be replaced or removed.
*/ */
#include "sdlkit.h" #include "sdlkit.h"
#include "tools.h"
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
@@ -47,13 +41,6 @@ float frnd(float range)
return (float)rnd(10000)/10000*range; return (float)rnd(10000)/10000*range;
} }
struct Spriteset
{
DWORD *data;
int width;
int height;
int pitch;
};
Spriteset font; Spriteset font;
Spriteset ld48; Spriteset ld48;
@@ -212,50 +199,51 @@ bool LoadSettings(char* filename)
if(!file) if(!file)
return false; return false;
size_t n;
int version=0; int version=0;
fread(&version, 1, sizeof(int), file); n = fread(&version, 1, sizeof(int), file);
if(version!=100 && version!=101 && version!=102) if(version!=100 && version!=101 && version!=102)
return false; return false;
fread(&wave_type, 1, sizeof(int), file); n = fread(&wave_type, 1, sizeof(int), file);
sound_vol=0.5f; sound_vol=0.5f;
if(version==102) if(version==102)
fread(&sound_vol, 1, sizeof(float), file); n = fread(&sound_vol, 1, sizeof(float), file);
fread(&p_base_freq, 1, sizeof(float), file); n = fread(&p_base_freq, 1, sizeof(float), file);
fread(&p_freq_limit, 1, sizeof(float), file); n = fread(&p_freq_limit, 1, sizeof(float), file);
fread(&p_freq_ramp, 1, sizeof(float), file); n = fread(&p_freq_ramp, 1, sizeof(float), file);
if(version>=101) if(version>=101)
fread(&p_freq_dramp, 1, sizeof(float), file); n = fread(&p_freq_dramp, 1, sizeof(float), file);
fread(&p_duty, 1, sizeof(float), file); n = fread(&p_duty, 1, sizeof(float), file);
fread(&p_duty_ramp, 1, sizeof(float), file); n = fread(&p_duty_ramp, 1, sizeof(float), file);
fread(&p_vib_strength, 1, sizeof(float), file); n = fread(&p_vib_strength, 1, sizeof(float), file);
fread(&p_vib_speed, 1, sizeof(float), file); n = fread(&p_vib_speed, 1, sizeof(float), file);
fread(&p_vib_delay, 1, sizeof(float), file); n = fread(&p_vib_delay, 1, sizeof(float), file);
fread(&p_env_attack, 1, sizeof(float), file); n = fread(&p_env_attack, 1, sizeof(float), file);
fread(&p_env_sustain, 1, sizeof(float), file); n = fread(&p_env_sustain, 1, sizeof(float), file);
fread(&p_env_decay, 1, sizeof(float), file); n = fread(&p_env_decay, 1, sizeof(float), file);
fread(&p_env_punch, 1, sizeof(float), file); n = fread(&p_env_punch, 1, sizeof(float), file);
fread(&filter_on, 1, sizeof(bool), file); n = fread(&filter_on, 1, sizeof(bool), file);
fread(&p_lpf_resonance, 1, sizeof(float), file); n = fread(&p_lpf_resonance, 1, sizeof(float), file);
fread(&p_lpf_freq, 1, sizeof(float), file); n = fread(&p_lpf_freq, 1, sizeof(float), file);
fread(&p_lpf_ramp, 1, sizeof(float), file); n = fread(&p_lpf_ramp, 1, sizeof(float), file);
fread(&p_hpf_freq, 1, sizeof(float), file); n = fread(&p_hpf_freq, 1, sizeof(float), file);
fread(&p_hpf_ramp, 1, sizeof(float), file); n = fread(&p_hpf_ramp, 1, sizeof(float), file);
fread(&p_pha_offset, 1, sizeof(float), file); n = fread(&p_pha_offset, 1, sizeof(float), file);
fread(&p_pha_ramp, 1, sizeof(float), file); n = fread(&p_pha_ramp, 1, sizeof(float), file);
fread(&p_repeat_speed, 1, sizeof(float), file); n = fread(&p_repeat_speed, 1, sizeof(float), file);
if(version>=101) if(version>=101)
{ {
fread(&p_arp_speed, 1, sizeof(float), file); n = fread(&p_arp_speed, 1, sizeof(float), file);
fread(&p_arp_mod, 1, sizeof(float), file); n = fread(&p_arp_mod, 1, sizeof(float), file);
} }
fclose(file); fclose(file);
@@ -687,7 +675,7 @@ bool Slider(int x, int y, float& value, bool bipolar, const char* text)
DWORD tcol=0x000000; DWORD tcol=0x000000;
if(wave_type!=0 && (&value==&p_duty || &value==&p_duty_ramp)) if(wave_type!=0 && (&value==&p_duty || &value==&p_duty_ramp))
tcol=0x808080; tcol=0x808080;
DrawText(x-4-strlen(text)*8, y+1, tcol, text); DrawText(font, x-4-strlen(text)*8, y+1, tcol, text);
return result; return result;
} }
@@ -714,7 +702,7 @@ bool Button(int x, int y, bool highlight, const char* text, int id)
} }
DrawBar(x-1, y-1, 102, 19, color1); DrawBar(x-1, y-1, 102, 19, color1);
DrawBar(x, y, 100, 17, color2); DrawBar(x, y, 100, 17, color2);
DrawText(x+5, y+5, color3, text); DrawText(font, x+5, y+5, color3, text);
if(current && hover && !mouse_left) if(current && hover && !mouse_left)
return true; return true;
return false; return false;
@@ -743,7 +731,7 @@ bool ButtonWH(int x, int y, int w, int h, bool highlight, const char* text, int
} }
DrawBar(x-1, y-1, w + 2, h + 2, color1); DrawBar(x-1, y-1, w + 2, h + 2, color1);
DrawBar(x, y, w, h, color2); DrawBar(x, y, w, h, color2);
DrawText(x+5, y+5, color3, text); DrawText(font, x+5, y+5, color3, text);
if(current && hover && !mouse_left) if(current && hover && !mouse_left)
return true; return true;
return false; return false;
@@ -789,7 +777,7 @@ void DrawScreen()
ClearScreen(0xC0B090); ClearScreen(0xC0B090);
DrawText(10, 10, 0x504030, "GENERATOR"); DrawText(font, 10, 10, 0x504030, "GENERATOR");
for(int i=0;i<7;i++) for(int i=0;i<7;i++)
{ {
if(Button(5, 35+i*30, false, categories[i].name, 300+i)) if(Button(5, 35+i*30, false, categories[i].name, 300+i))
@@ -959,7 +947,7 @@ void DrawScreen()
} }
} }
DrawBar(110, 0, 2, 480, 0x000000); DrawBar(110, 0, 2, 480, 0x000000);
DrawText(120, 10, 0x504030, "MANUAL SETTINGS"); DrawText(font, 120, 10, 0x504030, "MANUAL SETTINGS");
DrawSprite(ld48, 8, 440, 0, 0xB0A080); DrawSprite(ld48, 8, 440, 0, 0xB0A080);
@@ -995,7 +983,7 @@ void DrawScreen()
if(ButtonWH(490, 140, 17, 17, dragOnLeftClick, "", 101)) if(ButtonWH(490, 140, 17, 17, dragOnLeftClick, "", 101))
dragOnLeftClick = !dragOnLeftClick; dragOnLeftClick = !dragOnLeftClick;
} }
DrawText(515, 145, 0x000000, "DRAG BARS"); DrawText(font, 515, 145, 0x000000, "DRAG BARS");
DrawBar(5-1-1, 412-1-1, 102+2, 19+2, 0x000000); DrawBar(5-1-1, 412-1-1, 102+2, 19+2, 0x000000);
if(Button(5, 412, false, "RANDOMIZE", 40)) if(Button(5, 412, false, "RANDOMIZE", 40))
@@ -1071,7 +1059,7 @@ void DrawScreen()
do_play=true; do_play=true;
} }
DrawText(515, 170, 0x000000, "VOLUME"); DrawText(font, 515, 170, 0x000000, "VOLUME");
DrawBar(490-1-1+60, 180-1+5, 70, 2, 0x000000); DrawBar(490-1-1+60, 180-1+5, 70, 2, 0x000000);
DrawBar(490-1-1+60+68, 180-1+5, 2, 205, 0x000000); DrawBar(490-1-1+60+68, 180-1+5, 2, 205, 0x000000);
DrawBar(490-1-1+60, 180-1, 42+2, 10+2, 0xFF0000); DrawBar(490-1-1+60, 180-1, 42+2, 10+2, 0xFF0000);
@@ -1083,7 +1071,7 @@ void DrawScreen()
if(Button(490, 290, false, "LOAD SOUND", 14)) if(Button(490, 290, false, "LOAD SOUND", 14))
{ {
char filename[256]; char filename[256];
if(FileSelectorLoad(hWndMain, filename, 1)) // WIN32 if(FileSelectorLoad(filename, 1))
{ {
ResetParams(); ResetParams();
LoadSettings(filename); LoadSettings(filename);
@@ -1093,7 +1081,7 @@ void DrawScreen()
if(Button(490, 320, false, "SAVE SOUND", 15)) if(Button(490, 320, false, "SAVE SOUND", 15))
{ {
char filename[256]; char filename[256];
if(FileSelectorSave(hWndMain, filename, 1)) // WIN32 if(FileSelectorSave(filename, 1))
SaveSettings(filename); SaveSettings(filename);
} }
@@ -1102,7 +1090,7 @@ void DrawScreen()
if(Button(490, 380, false, "EXPORT .WAV", 16)) if(Button(490, 380, false, "EXPORT .WAV", 16))
{ {
char filename[256]; char filename[256];
if(FileSelectorSave(hWndMain, filename, 0)) // WIN32 if(FileSelectorSave(filename, 0))
ExportWAV(filename); ExportWAV(filename);
} }
char str[10]; char str[10];
@@ -1301,9 +1289,9 @@ bool keydown=false;
bool ddkCalcFrame() bool ddkCalcFrame()
{ {
input->Update(); // WIN32 (for keyboard input) input->Update(); // (for keyboard input)
if(input->KeyPressed(DIK_SPACE) || input->KeyPressed(DIK_RETURN)) // WIN32 (keyboard input only for convenience, ok to remove) if(input->KeyPressed(DIK_SPACE) || input->KeyPressed(DIK_RETURN)) // (keyboard input only for convenience, ok to remove)
{ {
if(!keydown) if(!keydown)
{ {
@@ -1321,7 +1309,7 @@ bool ddkCalcFrame()
DrawScreen(); DrawScreen();
Sleep(5); // WIN32 SDL_Delay(5);
return true; return true;
} }
@@ -1353,7 +1341,7 @@ void ddkInit()
ld48.width=ld48.pitch; ld48.width=ld48.pitch;
input=new DPInput(hWndMain, hInstanceMain); // WIN32 input=new DPInput;
strcpy(categories[0].name, "PICKUP/COIN"); strcpy(categories[0].name, "PICKUP/COIN");
strcpy(categories[1].name, "LASER/SHOOT"); strcpy(categories[1].name, "LASER/SHOOT");

422
sfxr/sdlkit.cpp Normal file
View File

@@ -0,0 +1,422 @@
/*
Copyright (c) 2007 mjau/GerryJJ
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "sdlkit.h"
#include <stdio.h>
#include <string.h>
void error (const char *file, unsigned int line, const char *msg)
{
fprintf(stderr, "[!] %s:%u %s\n", file, line, msg);
exit(1);
}
bool keys[SDLK_LAST];
bool DPInput::KeyPressed(SDLKey key)
{
bool r = keys[key];
keys[key] = false;
return r;
}
Uint32 *ddkscreen32;
Uint16 *ddkscreen16;
int ddkpitch;
int mouse_x, mouse_y, mouse_px, mouse_py;
bool mouse_left = false, mouse_right = false, mouse_middle = false;
bool mouse_leftclick = false, mouse_rightclick = false, mouse_middleclick = false;
SDL_Surface *sdlscreen = NULL;
void sdlupdate ()
{
mouse_px = mouse_x;
mouse_py = mouse_y;
Uint8 buttons = SDL_GetMouseState(&mouse_x, &mouse_y);
bool mouse_left_p = mouse_left;
bool mouse_right_p = mouse_right;
bool mouse_middle_p = mouse_middle;
mouse_left = buttons & SDL_BUTTON(1);
mouse_right = buttons & SDL_BUTTON(3);
mouse_middle = buttons & SDL_BUTTON(2);
mouse_leftclick = mouse_left && !mouse_left_p;
mouse_rightclick = mouse_right && !mouse_right_p;
mouse_middleclick = mouse_middle && !mouse_middle_p;
}
bool ddkLock ()
{
if(SDL_MUSTLOCK(sdlscreen))
{
if(SDL_LockSurface(sdlscreen) < 0)
return false;
}
ddkpitch = sdlscreen->pitch / (sdlscreen->format->BitsPerPixel == 32 ? 4 : 2);
ddkscreen16 = (Uint16*)(sdlscreen->pixels);
ddkscreen32 = (Uint32*)(sdlscreen->pixels);
return true;
}
void ddkUnlock ()
{
if(SDL_MUSTLOCK(sdlscreen))
{
SDL_UnlockSurface(sdlscreen);
}
}
void ddkSetMode (int width, int height, int bpp, int refreshrate, int fullscreen, const char *title)
{
VERIFY(sdlscreen = SDL_SetVideoMode(width, height, bpp, fullscreen ? SDL_FULLSCREEN : 0));
SDL_WM_SetCaption(title, title);
}
#include <string.h>
#include <malloc.h>
bool Button(int x, int y, bool highlight, const char* text, int id);
#include <string>
#include <list>
#include <sys/stat.h>
#include <dirent.h>
bool ioIsDir(const std::string& filename)
{
using namespace std;
struct stat status;
stat(filename.c_str(), &status);
return (status.st_mode & S_IFDIR);
}
std::list<std::string> ioList(const std::string& dirname, bool directories, bool files)
{
using namespace std;
list<string> dirList;
list<string> fileList;
DIR* dir = opendir(dirname.c_str());
dirent* entry;
while ((entry = readdir(dir)) != NULL)
{
#ifdef WIN32
if(ioIsDir(dirname + "/" + entry->d_name))
#else
if(entry->d_type == DT_DIR)
#endif
{
if(directories)
dirList.push_back(entry->d_name);
}
else if(files)
fileList.push_back(entry->d_name);
}
closedir(dir);
dirList.sort();
fileList.sort();
fileList.splice(fileList.begin(), dirList);
return fileList;
}
extern DPInput *input;
bool file_select_update()
{
input->Update(); // (for keyboard input)
//keydown=false;
return true;
}
std::string stoupper(const std::string& s)
{
std::string result = s;
std::string::iterator i = result.begin();
std::string::iterator end = result.end();
while(i != end)
{
*i = std::toupper((unsigned char)*i);
++i;
}
return result;
}
bool ioExists(const std::string& filename)
{
return (access(filename.c_str(), 0) == 0);
}
bool ioNew(const std::string& filename, bool readable, bool writeable)
{
if(ioExists(filename))
return false;
FILE* file = fopen(filename.c_str(), "wb");
if(file == NULL)
return false;
fclose(file);
return true;
}
void ClearScreen(DWORD color);
extern int vcurbutton;
#include "tools.h"
extern Spriteset font;
std::string new_file()
{
using namespace std;
SDL_EnableUNICODE(1);
SDL_EnableKeyRepeat(0, 0);
string result;
bool done = false;
SDL_Event e;
while (!done)
{
while(SDL_PollEvent(&e))
{
switch (e.type)
{
case SDL_QUIT:
exit(0);
case SDL_KEYDOWN:
if(e.key.keysym.sym == SDLK_ESCAPE)
{
return "";
}
if(e.key.keysym.sym == SDLK_RETURN)
{
done = true;
break;
}
{
char c = e.key.keysym.unicode;
if(0x21 <= c && c <= 0x7E)
result += c;
}
default: break;
}
}
sdlupdate();
ClearScreen(0xC0B090);
DrawText(font, 90, 150, 0x000000, "TYPE NEW FILE NAME:");
DrawText(font, 100, 200, 0x000000, "%s", stoupper(result).c_str());
SDL_Delay(5);
SDL_Flip(sdlscreen);
}
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
SDL_EnableUNICODE(0);
// FIXME: Force .sfxr
return result;
}
void DrawFileSelectScreen(std::list<std::string>& files, char* buf, bool& gotFile, bool& done)
{
using namespace std;
ddkLock();
ClearScreen(0xC0B090);
int i = 0, j = 0;
for(list<string>::iterator e = files.begin(); e != files.end(); e++)
{
if(40 + 20*i > sdlscreen->h - 50)
{
j++;
i = 0;
}
if(Button(30 + 150*j, 40 + 20*i, false, stoupper(*e).c_str(), 31 + i + j))
{
gotFile = true;
sprintf(buf, "%s", e->c_str());
done = true;
}
i++;
}
if(Button(10, 10, false, "CANCEL", 400))
{
gotFile = false;
done = true;
}
if(Button(10, 160, false, "NEW FILE", 401))
{
string s = new_file();
if(s != "")
{
ioNew(s, true, true);
files = ioList(".", false, true);
for(list<string>::iterator e = files.begin(); e != files.end();)
{
if(e->find(".sfxr") == string::npos)
{
e = files.erase(e);
continue;
}
e++;
}
}
}
ddkUnlock();
if(!mouse_left)
vcurbutton=-1;
}
bool select_file (char *buf)
{
// FIXME: Needs directory browsing
bool gotFile = false;
using namespace std;
list<string> files;
files = ioList(".", false, true);
for(list<string>::iterator e = files.begin(); e != files.end();)
{
if(e->find(".sfxr") == string::npos)
{
e = files.erase(e);
continue;
}
e++;
}
bool done = false;
SDL_Event e;
while (!done)
{
SDL_PollEvent(&e);
switch (e.type)
{
case SDL_QUIT:
exit(0);
case SDL_KEYDOWN:
keys[e.key.keysym.sym] = true;
default: break;
}
sdlupdate();
DrawFileSelectScreen(files, buf, gotFile, done);
SDL_Delay(5);
SDL_Flip(sdlscreen);
}
return gotFile;
}
#define FileSelectorLoad(file,y) select_file(file)
#define FileSelectorSave(file,y) select_file(file)
void sdlquit ()
{
ddkFree();
SDL_Quit();
}
void sdlinit ()
{
SDL_Surface *icon;
VERIFY(!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO));
icon = SDL_LoadBMP("/usr/share/sfxr/sfxr.bmp");
if (!icon)
icon = SDL_LoadBMP("sfxr.bmp");
if (icon)
SDL_WM_SetIcon(icon, NULL);
atexit(sdlquit);
memset(keys, 0, sizeof(keys));
ddkInit();
}
void loop (void)
{
SDL_Event e;
while (true)
{
SDL_PollEvent(&e);
switch (e.type)
{
case SDL_QUIT:
exit(0);
case SDL_KEYDOWN:
keys[e.key.keysym.sym] = true;
default: break;
}
sdlupdate();
if (!ddkCalcFrame())
return;
SDL_Flip(sdlscreen);
}
}
int main(int argc, char *argv[])
{
sdlinit();
loop();
return 0;
}

View File

@@ -24,16 +24,10 @@
#define SDLKIT_H #define SDLKIT_H
#include "SDL.h" #include "SDL.h"
#define ERROR(x) error(__FILE__, __LINE__, #x) #define ERROR(x) error(__FILE__, __LINE__, #x)
#define VERIFY(x) do { if (!(x)) ERROR(x); } while (0) #define VERIFY(x) do { if (!(x)) ERROR(x); } while (0)
#include <stdio.h>
#include <string.h>
static void error (const char *file, unsigned int line, const char *msg)
{
fprintf(stderr, "[!] %s:%u %s\n", file, line, msg);
exit(1);
}
typedef Uint32 DWORD; typedef Uint32 DWORD;
typedef Uint16 WORD; typedef Uint16 WORD;
@@ -43,12 +37,18 @@ typedef Uint16 WORD;
#define DIK_Z SDLK_z #define DIK_Z SDLK_z
#define DDK_WINDOW 0 #define DDK_WINDOW 0
#define hWndMain 0
#define hInstanceMain 0
#define Sleep(x) SDL_Delay(x) extern Uint32 *ddkscreen32;
extern Uint16 *ddkscreen16;
extern int ddkpitch;
static bool keys[SDLK_LAST];
extern int mouse_x, mouse_y, mouse_px, mouse_py;
extern bool mouse_left, mouse_right, mouse_middle;
extern bool mouse_leftclick, mouse_rightclick, mouse_middleclick;
void error (const char *file, unsigned int line, const char *msg);
void ddkInit(); // Will be called on startup void ddkInit(); // Will be called on startup
bool ddkCalcFrame(); // Will be called every frame, return true to continue running or false to quit bool ddkCalcFrame(); // Will be called every frame, return true to continue running or false to quit
@@ -56,149 +56,35 @@ void ddkFree(); // Will be called on shutdown
class DPInput { class DPInput {
public: public:
DPInput(int,int) {} DPInput() {}
~DPInput() {} ~DPInput() {}
static void Update () {} static void Update () {}
static bool KeyPressed(SDLKey key) static bool KeyPressed(SDLKey key);
{
bool r = keys[key];
keys[key] = false;
return r;
}
}; };
static Uint32 *ddkscreen32; void sdlupdate ();
static Uint16 *ddkscreen16;
static int ddkpitch;
static int mouse_x, mouse_y, mouse_px, mouse_py;
static bool mouse_left = false, mouse_right = false, mouse_middle = false;
static bool mouse_leftclick = false, mouse_rightclick = false, mouse_middleclick = false;
static SDL_Surface *sdlscreen = NULL; bool ddkLock ();
static void sdlupdate () void ddkUnlock ();
{
mouse_px = mouse_x;
mouse_py = mouse_y;
Uint8 buttons = SDL_GetMouseState(&mouse_x, &mouse_y);
bool mouse_left_p = mouse_left;
bool mouse_right_p = mouse_right;
bool mouse_middle_p = mouse_middle;
mouse_left = buttons & SDL_BUTTON(1);
mouse_right = buttons & SDL_BUTTON(3);
mouse_middle = buttons & SDL_BUTTON(2);
mouse_leftclick = mouse_left && !mouse_left_p;
mouse_rightclick = mouse_right && !mouse_right_p;
mouse_middleclick = mouse_middle && !mouse_middle_p;
}
static bool ddkLock () void ddkSetMode (int width, int height, int bpp, int refreshrate, int fullscreen, const char *title);
{
if(SDL_MUSTLOCK(sdlscreen))
{
if(SDL_LockSurface(sdlscreen) < 0)
return false;
}
ddkpitch = sdlscreen->pitch / (sdlscreen->format->BitsPerPixel == 32 ? 4 : 2);
ddkscreen16 = (Uint16*)(sdlscreen->pixels);
ddkscreen32 = (Uint32*)(sdlscreen->pixels);
return true;
}
static void ddkUnlock ()
{
if(SDL_MUSTLOCK(sdlscreen))
{
SDL_UnlockSurface(sdlscreen);
}
}
static void ddkSetMode (int width, int height, int bpp, int refreshrate, int fullscreen, const char *title) //void selected_file (GtkWidget *button, GtkFileSelection *fs);
{
VERIFY(sdlscreen = SDL_SetVideoMode(width, height, bpp, fullscreen ? SDL_FULLSCREEN : 0));
SDL_WM_SetCaption(title, title);
}
#include <gtk/gtk.h> bool select_file (char *buf);
#include <string.h>
#include <malloc.h>
static char *gtkfilename; #define FileSelectorLoad(file,y) select_file(file)
#define FileSelectorSave(file,y) select_file(file)
static void selected_file (GtkWidget *button, GtkFileSelection *fs) void sdlquit ();
{
strncpy(gtkfilename, gtk_file_selection_get_filename(fs), 255);
gtkfilename[255] = 0;
gtk_widget_destroy(GTK_WIDGET(fs));
gtk_main_quit();
}
static bool select_file (char *buf) void sdlinit ();
{
gtkfilename = buf;
GtkWidget *dialog = gtk_file_selection_new("It's file selection time!");
g_signal_connect(G_OBJECT(dialog), "destroy", G_CALLBACK(gtk_main_quit), NULL);
g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(dialog)->ok_button), "clicked", G_CALLBACK(selected_file), G_OBJECT(dialog));
g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(dialog)->cancel_button), "clicked", G_CALLBACK(gtk_widget_destroy), G_OBJECT(dialog));
gtk_widget_show(GTK_WIDGET(dialog));
gtk_main();
return *gtkfilename;
}
#define FileSelectorLoad(x,file,y) select_file(file) void loop ();
#define FileSelectorSave(x,file,y) select_file(file)
static void sdlquit ()
{
ddkFree();
SDL_Quit();
}
static void sdlinit ()
{
SDL_Surface *icon;
VERIFY(!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO));
icon = SDL_LoadBMP("/usr/share/sfxr/sfxr.bmp");
if (!icon)
icon = SDL_LoadBMP("sfxr.bmp");
if (icon)
SDL_WM_SetIcon(icon, NULL);
atexit(sdlquit);
memset(keys, 0, sizeof(keys));
ddkInit();
}
static void loop (void)
{
SDL_Event e;
while (true)
{
SDL_PollEvent(&e);
switch (e.type)
{
case SDL_QUIT:
return;
case SDL_KEYDOWN:
keys[e.key.keysym.sym] = true;
default: break;
}
sdlupdate();
if (!ddkCalcFrame())
return;
SDL_Flip(sdlscreen);
}
}
int main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
sdlinit();
loop();
return 0;
}
#endif #endif

161
sfxr/tools.cpp Normal file
View File

@@ -0,0 +1,161 @@
/*
Copyright (c) 2007 Tomas Pettersson <drpetter@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "sdlkit.h"
#include "tools.h"
int LoadTGA(Spriteset& tiles, const char *filename)
{
FILE *file;
unsigned char byte, crap[16], id_length;
int i, width, height, channels, x, y;
file=fopen(filename, "rb");
if (!file)
return -1;
int n;
n = fread(&id_length, 1, 1, file);
n = fread(crap, 1, 11, file);
width=0;
height=0;
n = fread(&width, 1, 2, file); // width
n = fread(&height, 1, 2, file); // height
n = fread(&byte, 1, 1, file); // bits
channels=byte/8;
n = fread(&byte, 1, 1, file); // image descriptor byte (per-bit info)
for(i=0;i<id_length;i++)
n = fread(&byte, 1, 1, file); // image description
tiles.data=(DWORD*)malloc(width*height*sizeof(DWORD));
for(y=height-1;y>=0;y--)
for(x=0;x<width;x++)
{
DWORD pixel=0;
n = fread(&byte, 1, 1, file);
pixel|=byte;
n = fread(&byte, 1, 1, file);
pixel|=byte<<8;
n = fread(&byte, 1, 1, file);
pixel|=byte<<16;
tiles.data[y*width+x]=pixel;
}
fclose(file);
tiles.height=height;
tiles.width=height;
tiles.pitch=width;
return 0;
}
void ClearScreen(DWORD color)
{
for(int y=0;y<480;y++)
{
int offset=y*ddkpitch;
for(int x=0;x<640;x+=8)
{
ddkscreen32[offset++]=color;
ddkscreen32[offset++]=color;
ddkscreen32[offset++]=color;
ddkscreen32[offset++]=color;
ddkscreen32[offset++]=color;
ddkscreen32[offset++]=color;
ddkscreen32[offset++]=color;
ddkscreen32[offset++]=color;
}
}
}
void DrawBar(int sx, int sy, int w, int h, DWORD color)
{
for(int y=sy;y<sy+h;y++)
{
int offset=y*ddkpitch+sx;
int x1=0;
if(w>8)
for(x1=0;x1<w-8;x1+=8)
{
ddkscreen32[offset++]=color;
ddkscreen32[offset++]=color;
ddkscreen32[offset++]=color;
ddkscreen32[offset++]=color;
ddkscreen32[offset++]=color;
ddkscreen32[offset++]=color;
ddkscreen32[offset++]=color;
ddkscreen32[offset++]=color;
}
for(int x=x1;x<w;x++)
ddkscreen32[offset++]=color;
}
}
void DrawBox(int sx, int sy, int w, int h, DWORD color)
{
DrawBar(sx, sy, w, 1, color);
DrawBar(sx, sy, 1, h, color);
DrawBar(sx+w, sy, 1, h, color);
DrawBar(sx, sy+h, w+1, 1, color);
}
void DrawSprite(Spriteset& sprites, int sx, int sy, int i, DWORD color)
{
for(int y=0;y<sprites.height;y++)
{
int offset=(sy+y)*ddkpitch+sx;
int spoffset=y*sprites.pitch+i*sprites.width;
if(color&0xFF000000)
for(int x=0;x<sprites.width;x++)
{
DWORD p=sprites.data[spoffset++];
if(p!=0x300030)
ddkscreen32[offset+x]=p;
}
else
for(int x=0;x<sprites.width;x++)
{
DWORD p=sprites.data[spoffset++];
if(p!=0x300030)
ddkscreen32[offset+x]=color;
}
}
}
void DrawText(Spriteset& font, int sx, int sy, DWORD color, const char *string, ...)
{
char string2[256];
va_list args;
va_start(args, string);
vsprintf(string2, string, args);
va_end(args);
int len=strlen(string2);
for(int i=0;i<len;i++)
DrawSprite(font, sx+i*8, sy, string2[i]-' ', color);
}
bool MouseInBox(int x, int y, int w, int h)
{
if(mouse_x>=x && mouse_x<x+w && mouse_y>=y && mouse_y<y+h)
return true;
return false;
}

View File

@@ -20,137 +20,33 @@
THE SOFTWARE. THE SOFTWARE.
*/ */
int LoadTGA(Spriteset& tiles, const char *filename) #ifndef _TOOLS_H__
#define _TOOLS_H__
typedef Uint32 DWORD;
typedef Uint16 WORD;
struct Spriteset
{ {
FILE *file; DWORD *data;
unsigned char byte, crap[16], id_length; int width;
int n, width, height, channels, x, y; int height;
file=fopen(filename, "rb"); int pitch;
if (!file) };
return -1;
fread(&id_length, 1, 1, file);
fread(crap, 1, 11, file);
width=0;
height=0;
fread(&width, 1, 2, file); // width
fread(&height, 1, 2, file); // height
fread(&byte, 1, 1, file); // bits
channels=byte/8;
fread(&byte, 1, 1, file); // image descriptor byte (per-bit info)
for(n=0;n<id_length;n++)
fread(&byte, 1, 1, file); // image description
tiles.data=(DWORD*)malloc(width*height*sizeof(DWORD));
for(y=height-1;y>=0;y--)
for(x=0;x<width;x++)
{
DWORD pixel=0;
fread(&byte, 1, 1, file);
pixel|=byte;
fread(&byte, 1, 1, file);
pixel|=byte<<8;
fread(&byte, 1, 1, file);
pixel|=byte<<16;
tiles.data[y*width+x]=pixel;
}
fclose(file);
tiles.height=height;
tiles.width=height;
tiles.pitch=width;
return 0; int LoadTGA(Spriteset& tiles, const char *filename);
}
void ClearScreen(DWORD color) void ClearScreen(DWORD color);
{
for(int y=0;y<480;y++)
{
int offset=y*ddkpitch;
for(int x=0;x<640;x+=8)
{
ddkscreen32[offset++]=color;
ddkscreen32[offset++]=color;
ddkscreen32[offset++]=color;
ddkscreen32[offset++]=color;
ddkscreen32[offset++]=color;
ddkscreen32[offset++]=color;
ddkscreen32[offset++]=color;
ddkscreen32[offset++]=color;
}
}
}
void DrawBar(int sx, int sy, int w, int h, DWORD color) void DrawBar(int sx, int sy, int w, int h, DWORD color);
{
for(int y=sy;y<sy+h;y++)
{
int offset=y*ddkpitch+sx;
int x1=0;
if(w>8)
for(x1=0;x1<w-8;x1+=8)
{
ddkscreen32[offset++]=color;
ddkscreen32[offset++]=color;
ddkscreen32[offset++]=color;
ddkscreen32[offset++]=color;
ddkscreen32[offset++]=color;
ddkscreen32[offset++]=color;
ddkscreen32[offset++]=color;
ddkscreen32[offset++]=color;
}
for(int x=x1;x<w;x++)
ddkscreen32[offset++]=color;
}
}
void DrawBox(int sx, int sy, int w, int h, DWORD color) void DrawBox(int sx, int sy, int w, int h, DWORD color);
{
DrawBar(sx, sy, w, 1, color);
DrawBar(sx, sy, 1, h, color);
DrawBar(sx+w, sy, 1, h, color);
DrawBar(sx, sy+h, w+1, 1, color);
}
void DrawSprite(Spriteset& sprites, int sx, int sy, int i, DWORD color) void DrawSprite(Spriteset& sprites, int sx, int sy, int i, DWORD color);
{
for(int y=0;y<sprites.height;y++)
{
int offset=(sy+y)*ddkpitch+sx;
int spoffset=y*sprites.pitch+i*sprites.width;
if(color&0xFF000000)
for(int x=0;x<sprites.width;x++)
{
DWORD p=sprites.data[spoffset++];
if(p!=0x300030)
ddkscreen32[offset+x]=p;
}
else
for(int x=0;x<sprites.width;x++)
{
DWORD p=sprites.data[spoffset++];
if(p!=0x300030)
ddkscreen32[offset+x]=color;
}
}
}
void DrawText(int sx, int sy, DWORD color, const char *string, ...) void DrawText(Spriteset& font, int sx, int sy, DWORD color, const char *string, ...);
{
char string2[256];
va_list args;
va_start(args, string); bool MouseInBox(int x, int y, int w, int h);
vsprintf(string2, string, args);
va_end(args);
int len=strlen(string2); #endif
for(int i=0;i<len;i++)
DrawSprite(font, sx+i*8, sy, string2[i]-' ', color);
}
bool MouseInBox(int x, int y, int w, int h)
{
if(mouse_x>=x && mouse_x<x+w && mouse_y>=y && mouse_y<y+h)
return true;
return false;
}