A short header I wrote, plus globstruct.h and windows.h.
The header, mapi.h, looks like this:
//MAPI: Simple and fast API/Form Element system for DarkGDK
//Developed by Mike Perron, copyright 2008 Feuerfuchs Studios
#define TBWCONTINUE 1
#define TBWYESNO 2
#define TBWENTRY 3
typedef struct apiWindow{
int x;
int y;
int w;
int h;
int active;
char *label;
} apiWinControl;
void apiFontSetup(void){
dbSetTextFont("Tahoma");
dbSetTextSize(16);
return;
}
bool apiWindow(int apiWindowX, int apiWindowY, int apiWindowW, int apiWindowH, char *apiWindowLabel){
bool apiWindowNeedsMove=false;
if ((dbMouseX()>apiWindowX)&&(dbMouseX()<apiWindowX+apiWindowW)&&(dbMouseY()>apiWindowY)&&(dbMouseY()<apiWindowY+20)){
if(dbMouseClick()!=0){apiWindowNeedsMove=true;}else{apiWindowNeedsMove=false;}
}
dbInk(dbRGB(255,255,255),dbRGB(0,0,0));
dbBox(apiWindowX,apiWindowY,apiWindowX+apiWindowW,apiWindowY+apiWindowH);
dbInk(dbRGB(50,50,50),dbRGB(0,0,0));
dbBox(apiWindowX+1,apiWindowY+1,apiWindowX+apiWindowW-1,apiWindowY+apiWindowH-1);
dbInk(dbRGB(200,200,100),dbRGB(0,0,0));
dbBox(apiWindowX+1,apiWindowY+1,apiWindowX+apiWindowW-1,apiWindowY+20);
dbInk(dbRGB(0,0,0),dbRGB(0,0,0));
dbCenterText(apiWindowX+(apiWindowW/2),apiWindowY+2,apiWindowLabel);
return apiWindowNeedsMove;
}
int apiButton(int apiButtonX,int apiButtonY, int apiButtonW, int apiButtonH, char *apiButtonLabel, int apiParentX, int apiParentY){
int apiButtonClicked=0;
int apiButtonHover=0;
//Check if the mouse is hovering
if ((dbMouseX()>apiParentX+apiButtonX)&&(dbMouseX()<apiParentX+apiButtonX+apiButtonW)&&(dbMouseY()>apiParentY+apiButtonY)&&(dbMouseY()<apiParentY+apiButtonY+apiButtonH)){apiButtonHover=1;}
//Draw
if (!apiButtonHover){
dbInk(dbRGB(255,255,255),dbRGB(0,0,0));
dbBox(apiParentX+apiButtonX, apiParentY+apiButtonY, apiParentX+apiButtonX+apiButtonW, apiParentY+apiButtonY+apiButtonH);
dbInk(dbRGB(0,0,0),dbRGB(0,0,0));
dbBox(apiParentX+apiButtonX+1, apiParentY+apiButtonY+1, apiParentX+apiButtonX+apiButtonW-1, apiParentY+apiButtonY+apiButtonH-1);
dbInk(dbRGB(255,255,255),dbRGB(0,0,0));
dbCenterText(apiParentX+apiButtonX+(apiButtonW/2),apiParentY+apiButtonY,apiButtonLabel);
}
if (apiButtonHover){
if (dbMouseClick()!=0){
dbInk(dbRGB(200,200,0),dbRGB(0,0,0));
}
else{
dbInk(dbRGB(255,255,255),dbRGB(0,0,0));
}
dbBox(apiParentX+apiButtonX, apiParentY+apiButtonY, apiParentX+apiButtonX+apiButtonW, apiParentY+apiButtonY+apiButtonH);
dbInk(dbRGB(0,99,204),dbRGB(0,0,0));
dbBox(apiParentX+apiButtonX+1, apiParentY+apiButtonY+1, apiParentX+apiButtonX+apiButtonW-1, apiParentY+apiButtonY+apiButtonH-1);
dbInk(dbRGB(255,255,255),dbRGB(0,0,0));
dbCenterText(apiParentX+apiButtonX+(apiButtonW/2),apiParentY+apiButtonY,apiButtonLabel);
apiButtonClicked=dbMouseClick();
}
return apiButtonClicked;
}
void apiLabel(int x, int y, int pX, int pY, char *text, int style){
switch(style){
case 1:
dbInk(dbRGB(255,255,255),dbRGB(0,0,0));
dbCenterText(pX+x,pY+y,text);
break;
case 2:
dbInk(dbRGB(255,255,255),dbRGB(0,0,0));
dbText(pX+x,pY+y,text);
break;
default:
dbPrint(text);
break;
}
return;
}
//Warning! This function will halt all other operations!
char *apiTextBlockWindow(int mode,char *textL1,char *textL2,char *textL3){
dbInk(dbRGB(255,255,255),dbRGB(0,0,0));dbBox(15,dbScreenHeight()-115,dbScreenWidth()-15,dbScreenHeight()-15);
dbInk(dbRGB(0,0,200),dbRGB(0,0,0));dbBox(17,dbScreenHeight()-113,dbScreenWidth()-17,dbScreenHeight()-17);
dbInk(dbRGB(255,255,255),dbRGB(0,0,200));
int tbwContinueButton;
bool tbwContinueButtonCatch=false;
int tbwYesButton;
bool tbwYesButtonCatch=false;
int tbwNoButton;
bool tbwNoButtonCatch=false;
bool tbwSpaceCatch=false;
bool tbwYCatch=false;
bool tbwNCatch=false;
dbText(20,dbScreenHeight()-105,textL1);
dbText(20,dbScreenHeight()-85,textL2);
dbText(20,dbScreenHeight()-65,textL3);
switch(mode){
case TBWCONTINUE:
while(LoopGDK()){
tbwContinueButton=apiButton(dbScreenWidth()-120,dbScreenHeight()-37,100,18,"Continue",0,0);
dbSync();
//Check for mouse clicks on the button
if((tbwContinueButton==1)&&(tbwContinueButtonCatch==false))tbwContinueButtonCatch=true;
if((tbwContinueButton!=1)&&(tbwContinueButtonCatch==true)&&(dbMouseClick()!=0))tbwContinueButtonCatch=false;
if((tbwContinueButton!=1)&&(tbwContinueButtonCatch==true)&&(dbMouseClick()==0)){
tbwContinueButtonCatch=false;
break;
}
//Check for space key
if((dbSpaceKey()==1)&&(tbwSpaceCatch==false))tbwSpaceCatch=true;
if((dbSpaceKey()==0)&&(tbwSpaceCatch==true)){
tbwSpaceCatch=false;
break;
}
}
break;
case TBWYESNO:
while(LoopGDK()){
tbwNoButton=apiButton(dbScreenWidth()-225,dbScreenHeight()-37,100,18,"No",0,0);
tbwYesButton=apiButton(dbScreenWidth()-120,dbScreenHeight()-37,100,18,"Yes",0,0);
dbSync();
if((tbwYesButton==1)&&(tbwYesButtonCatch==false))tbwYesButtonCatch=true;
if((tbwYesButton==0)&&(tbwYesButtonCatch==true)&&(dbMouseClick()!=0))tbwYesButtonCatch=false;
if((tbwYesButton==0)&&(tbwYesButtonCatch==true)&&(dbMouseClick()==0)){
tbwYesButtonCatch=false;
return "YES";
}
if((tbwNoButton==1)&&(tbwNoButtonCatch==false))tbwNoButtonCatch=true;
if((tbwNoButton==0)&&(tbwNoButtonCatch==true)&&(dbMouseClick()!=0))tbwNoButtonCatch=false;
if((tbwNoButton==0)&&(tbwNoButtonCatch==true)&&(dbMouseClick()==0)){
tbwNoButtonCatch=false;
return "NO";
}
if((dbSpaceKey()==1)&&(tbwSpaceCatch==false))tbwSpaceCatch=true;
if((dbSpaceKey()==0)&&(tbwSpaceCatch==true)){
tbwSpaceCatch=false;
return "YES";
}
//21=y and 49=n
if((dbKeyState(21)==1)&&(tbwYCatch==false))tbwYCatch=true;
if((dbKeyState(21)==0)&&(tbwYCatch==true)){
tbwYCatch=false;
return "YES";
}
if((dbKeyState(49)==1)&&(tbwNCatch==false))tbwNCatch=true;
if((dbKeyState(49)==0)&&(tbwNCatch==true)){
tbwNCatch=false;
return "NO";
}
}
break;
case TBWENTRY:
dbInk(dbRGB(255,255,255),dbRGB(0,0,0));
dbBox(dbScreenWidth()/2-70,dbScreenHeight()/2-40,dbScreenWidth()/2+70,dbScreenHeight()/2);
dbInk(dbRGB(100,100,100),dbRGB(255,255,255));
dbBox(dbScreenWidth()/2-68,dbScreenHeight()/2-38,dbScreenWidth()/2+68,dbScreenHeight()/2-2);
dbInk(dbRGB(255,255,255),dbRGB(100,100,100));
dbSetCursor(dbScreenWidth()/2-60,dbScreenHeight()/2-30);
return dbInput();
break;
default:
dbText(20,dbScreenHeight()-105,textL1);
dbText(20,dbScreenHeight()-85,textL2);
dbText(20,dbScreenHeight()-65,textL3);
break;
}
return "";
}
Note that this header has a few other functions, that aren't used in my little example. My apologies that it isn't commented, I never bother with that. You're welcome to use any of that if you can make sense of it.
My site, for various stuff that I make.