Enjoy.
#include <DarkGDK.h>
#include <string>
#include <list>
class SliderControl
{
public:
int X;
int Y;
int Width;
float percentage;
void Update();
};
void SliderControl::Update()
{
dbInk(dbRGB(150, 150, 150), 0);
dbBox(X, Y, X + 10, Y + 10);
dbBox(X + Width - 10, Y, X + Width, Y + 10);
dbLine(X, Y, X + Width, Y);
dbLine(X, Y + 10, X + Width, Y + 10);
int mx = dbMouseX() - (X + 10);
float mper = (float)mx / (float)(Width - 20);
if (mper > 1.0f)
mper = 1.0f;
if (mper < 0.0f)
mper = 0.0f;
if (dbMouseClick() && dbMouseY() > Y && dbMouseY() < Y + 10 && dbMouseX() > X && dbMouseX() < X + Width)
percentage = mper;
int sliderx = (Width - 30) * percentage;
sliderx += X + 10;
dbBox(sliderx, Y, sliderx + 10, Y + 10);
}
class Listbox
{
public:
std::list<std::string> items;
int selected;
int X;
int Y;
int Width;
int Rows;
void Update();
};
void Listbox::Update()
{
dbInk(dbRGB(150, 150, 150), 0);
int height = Rows * (dbTextHeight("|") + 2);
height -= 2;
dbLine(X, Y, X + Width, Y);
dbLine(X, Y, X, Y + height);
dbLine(X, Y + height, X + Width + 1, Y + height);
dbLine(X + Width, Y, X + Width, Y + height);
int scrollw = 0;
if (items.size() > Rows)
scrollw = 14;
if (selected != -1)
{
dbInk(dbRGB(75, 75, 75), 0);
dbBox(X + 1, Y + (selected * dbTextHeight("|") + 2), X + Width, Y + ((selected + 1) * dbTextHeight("|") + 2));
dbInk(dbRGB(150, 150, 150), 0);
}
int rmy = dbMouseY() - Y;
int select = rmy / (dbTextHeight("|"));
if (dbMouseClick() == 1 && dbMouseX() > X && dbMouseX() < X + (Width - scrollw) &&
dbMouseY() > Y && dbMouseY() < Y + height && items.size() > select) selected = select;
int ctr = 0;
for (std::list<std::string>::iterator i = items.begin(); i != items.end(); i++)
{
std::string disp = (*i);
std::string withending = disp + "..";
if (dbTextWidth((char*)disp.c_str()) > Width - scrollw)
{
while (dbTextWidth((char*)withending.c_str()) > Width - scrollw)
{
disp.replace(disp.length() - 1, 1, "");
withending = disp + "..";
}
disp += "..";
}
int y = Y + (ctr * dbTextHeight("|") + 2);
dbText(X + 2, y, (char*)disp.c_str());
ctr++;
}
}
void DarkGDK()
{
dbSyncOn();
dbSyncRate(60);
dbAutoCamOff();
dbMakeObjectBox(1, 10.0f, 1.0f, 10.0f);
dbPositionObject(1, 0, 0, 0);
dbPositionCamera(10, 10, 10);
dbPointCamera(0, 0, 0);
int ctr = 3;
dbMakeObjectSphere(60000, 1.0f, 12, 12);
dbSetCameraView(150, 0, dbScreenWidth(), dbScreenHeight());
dbSetCameraAspect((float)(dbScreenWidth() - 150)/(float)dbScreenHeight());
SliderControl slider;
slider.X = 5;
slider.Y = 38;
slider.Width = 120;
Listbox test;
test.X = 5;
test.Y = 74;
test.Width = 140;
test.Rows = 10;
test.items.push_back("test.x");
test.items.push_back("test2.x");
test.items.push_back("a really long name.x");
test.selected = 1;
int click = 0;
while (LoopGDK())
{
dbInk(0, 0);
dbBox(0, 0, 150, dbScreenHeight());
dbInk(dbRGB(150, 150, 150), 0);
dbLine(150, 0, 150, dbScreenHeight());
slider.Update();
test.Update();
dbSetTextToBold();
dbText(3, 2, "Tools");
dbSetTextToNormal();
dbText(5, 22, "Height Offset");
dbText(5, 58, "Loaded Models");
dbText(slider.X + slider.Width + 5, slider.Y - 2, dbStr((int)(slider.percentage * 5)));
if (dbMouseX() > 150)
{
dbShowObject(60000);
int pick = dbPickObject(dbMouseX(), dbMouseY(), 0, 10000);
float dist = dbGetPickDistance();
dbPickScreen(dbMouseX(), dbMouseY(), dist);
float px = dbGetPickVectorX() + dbCameraPositionX();
float py = dbGetPickVectorY()+ dbCameraPositionY();
float pz = dbGetPickVectorZ() + dbCameraPositionZ();
dbPositionObject(60000, px, py, pz);
if (dbMouseClick() && dbTimer() > click + 300 )
{
click = dbTimer();
dbMakeObjectCube(ctr, 1.0f);
dbPositionObject(ctr, px, py + 0.5f + (int)(slider.percentage * 5), pz);
ctr++;
}
if (dbMouseClick() == 2)
}
else
dbHideObject(60000);
dbSync();
}
}
It has a simple (unfinished) listbox, a slider bar, object placement...
So yeah, it's kinda easy to use the listbox and slider bar. Just enjoy. The listbox isn't done because it doesn't have scrolling yet.
I'm no longer using DGDK for anything now, so I thought I'd just let the community have this.