Added basic char injection and editbox
keyCodetable.h
#ifndef KEYCODETABLE_H
#define KEYCODETABLE_H
// Simple hardcoded and dirty GDK --> Unicode convertion
// The map pair Key is the GDK code (dbScanCode(),dbKeystate())
// the value is the unicode.
//
// TODO:
// - Add more keycode for /,; and the rest characters
// - Add CEGUI::Key code support
// - Check for mod keys (Caps lock,Shift,etc)
// - TEST IT! I havent tested it yet.
// - Change syntax to match Matty's
// - Key press
#include <map>
typedef struct gdkKey
{
int m_unicode;
bool m_pressed;
gdkKey()
{
}
gdkKey(int unicode,bool pressed = false) : m_unicode(unicode),m_pressed(pressed)
{
}
} gdkKey;
class keycodeTable
{
public:
keycodeTable()
{
//0 - 9
m_keys[11]=gdkKey(0x30); //0
m_keys[2]=gdkKey(0x31); //1
m_keys[3]=gdkKey(0x32); //2
m_keys[4]=gdkKey(0x33); //3
m_keys[5]=gdkKey(0x34); //4
m_keys[6]=gdkKey(0x35); //5
m_keys[7]=gdkKey(0x36); //6
m_keys[8]=gdkKey(0x37); //7
m_keys[9]=gdkKey(0x38); //8
m_keys[10]=gdkKey(0x39); //9
//A - Z
m_keys[30]=gdkKey(0x41); //A
m_keys[48]=gdkKey(0x42); //B
m_keys[46]=gdkKey(0x43); //C
m_keys[32]=gdkKey(0x44); //D
m_keys[18]=gdkKey(0x45); //E
m_keys[33]=gdkKey(0x46); //F
m_keys[34]=gdkKey(0x47); //G
m_keys[35]=gdkKey(0x48); //H
m_keys[23]=gdkKey(0x49); //I
m_keys[36]=gdkKey(0x4a); //J
m_keys[37]=gdkKey(0x4b); //K
m_keys[38]=gdkKey(0x4c); //L
m_keys[49]=gdkKey(0x4d); //M
m_keys[50]=gdkKey(0x4e); //N
m_keys[24]=gdkKey(0x4f); //O
m_keys[25]=gdkKey(0x50); //P
m_keys[16]=gdkKey(0x51); //Q
m_keys[19]=gdkKey(0x52); //R
m_keys[31]=gdkKey(0x53); //S
m_keys[20]=gdkKey(0x54); //T
m_keys[22]=gdkKey(0x55); //U
m_keys[47]=gdkKey(0x56); //V
m_keys[17]=gdkKey(0x57); //W
m_keys[45]=gdkKey(0x58); //X
m_keys[21]=gdkKey(0x59); //Y
m_keys[44]=gdkKey(0x5a); //Z
}
int getUnicode(int gdkCode)
{
return m_keys[gdkCode].m_unicode;
}
void setPressed(int gdkCode,bool pressed)
{
m_keys[gdkCode].m_pressed = pressed;
}
bool getPressed(int gdkCode)
{
return m_keys[gdkCode].m_pressed;
}
private:
std::map<int,gdkKey> m_keys;
};
#endif //KEYCODETABLE_H
CEGUI_GDK.h
#pragma once
#include "CEGUI.h"
#include "DarkGDK.h"
#include "RendererModules/Direct3D9/CEGUIDirect3D9Renderer.h"
#include <CEGUIDefaultResourceProvider.h>
#include <string>
#pragma comment(lib, "CEGUIBase.lib")
#pragma comment(lib, "CEGUIDirect3D9Renderer.lib")
//******
//ADDED
#include "keycodeTable.h"
//******/
class CEGUI_GDK
{
public:
CEGUI_GDK(void);
~CEGUI_GDK(void);
//-- Initialise DirectX and resources
void start();
//-- Initialise and set defaults for given scheme
void setScheme(int scheme);
void pollMouse();
//******
//ADDED
//******/
void pollKeyboard();
//*********
//END ADDED
//*********/
CEGUI::Window* makeRootWindow(std::string name);
CEGUI::Window* makeButton(std::string name, CEGUI::UDim sizeX, CEGUI::UDim sizeY, CEGUI::UDim posX, CEGUI::UDim posY);
CEGUI::Menubar* makeMenubar(std::string name, CEGUI::UDim sizeX, CEGUI::UDim sizeY, CEGUI::UDim posX, CEGUI::UDim posY);
CEGUI::MenuItem* makeMenuItem(std::string name);
CEGUI::PopupMenu* makePopupMenu(std::string name);
enum{WINDOWS_LOOK, TAHEREZ_LOOK, VANILLA_SKIN, OGRE_TRAY};
//******
//ADDED
//******/
CEGUI::Checkbox* makeCheckbox(std::string name, CEGUI::UDim sizeX, CEGUI::UDim sizeY, CEGUI::UDim posX, CEGUI::UDim posY,bool selected = false);
CEGUI::Combobox* makeCombobox(std::string name, CEGUI::UDim sizeX, CEGUI::UDim sizeY, CEGUI::UDim posX, CEGUI::UDim posY);
CEGUI::Listbox* makeListbox(std::string name, CEGUI::UDim sizeX, CEGUI::UDim sizeY, CEGUI::UDim posX, CEGUI::UDim posY);
CEGUI::MultiColumnList* makeMultiColumnList(std::string name, CEGUI::UDim sizeX, CEGUI::UDim sizeY, CEGUI::UDim posX, CEGUI::UDim posY);
CEGUI::ListboxTextItem* makeListboxTextItem(std::string text,int id,void* data = NULL,bool disabled = false);
CEGUI::Editbox* makeEditbox(std::string name, CEGUI::UDim sizeX, CEGUI::UDim sizeY, CEGUI::UDim posX, CEGUI::UDim posY);
//*********
//END ADDED
//*********/
protected:
std::string scheme_;
bool mouseDown_;
CEGUI::Direct3D9Renderer* renderer_;
CEGUI::DefaultResourceProvider* rp_;
keycodeTable keyTable;
};
CEGUI_GDK.cpp
#include "CEGUI_GDK.h"
CEGUI_GDK::CEGUI_GDK(void)
{
renderer_ = 0;
rp_ = 0;
mouseDown_ = false;
}
CEGUI_GDK::~CEGUI_GDK(void)
{
}
void CEGUI_GDK::start(){
try{
renderer_ = &CEGUI::Direct3D9Renderer::bootstrapSystem(dbGetDirect3DDevice());
rp_ = static_cast<CEGUI::DefaultResourceProvider*>(CEGUI::System::getSingleton().getResourceProvider());
rp_->setResourceGroupDirectory("schemes", "../datafiles/schemes/");
rp_->setResourceGroupDirectory("imagesets", "../datafiles/imagesets/");
rp_->setResourceGroupDirectory("fonts", "../datafiles/fonts/");
rp_->setResourceGroupDirectory("layouts", "../datafiles/layouts/");
rp_->setResourceGroupDirectory("looknfeels", "../datafiles/looknfeel/");
rp_->setResourceGroupDirectory("lua_scripts", "../datafiles/lua_scripts/");
// set the default resource groups to be used
CEGUI::Imageset::setDefaultResourceGroup("imagesets");
CEGUI::Font::setDefaultResourceGroup("fonts");
CEGUI::Scheme::setDefaultResourceGroup("schemes");
CEGUI::WidgetLookManager::setDefaultResourceGroup("looknfeels");
CEGUI::WindowManager::setDefaultResourceGroup("layouts");
CEGUI::ScriptModule::setDefaultResourceGroup("lua_scripts");
}
catch(CEGUI::Exception &e){
MessageBox(0, e.getMessage().c_str(), "CEGUI_GDK::start()", MB_OK);
}
}
void CEGUI_GDK::setScheme(int scheme){
try{
switch(scheme){
case WINDOWS_LOOK:
CEGUI::SchemeManager::getSingleton().create( "WindowsLook.scheme" );
CEGUI::System::getSingleton().setDefaultMouseCursor( "WindowsLook", "MouseArrow" );
CEGUI::System::getSingleton().setDefaultTooltip( "WindowsLook/Tooltip" );
scheme_ = std::string("WindowsLook");
break;
case TAHEREZ_LOOK:
CEGUI::SchemeManager::getSingleton().create( "TaharezLook.scheme" );
CEGUI::System::getSingleton().setDefaultMouseCursor( "TaharezLook", "MouseArrow" );
CEGUI::System::getSingleton().setDefaultTooltip( "TaharezLook/Tooltip" );
scheme_ = std::string("TaharezLook");
break;
case VANILLA_SKIN:
CEGUI::SchemeManager::getSingleton().create( "WindowsLook.scheme" );
CEGUI::System::getSingleton().setDefaultMouseCursor( "WindowsLook", "MouseArrow" );
CEGUI::System::getSingleton().setDefaultTooltip( "WindowsLook/Tooltip" );
CEGUI::SchemeManager::getSingleton().create( "VanillaSkin.scheme" );
scheme_ = std::string("Vanilla");
break;
case OGRE_TRAY:
CEGUI::SchemeManager::getSingleton().create( "WindowsLook.scheme" );
CEGUI::System::getSingleton().setDefaultMouseCursor( "WindowsLook", "MouseArrow" );
CEGUI::System::getSingleton().setDefaultTooltip( "WindowsLook/Tooltip" );
CEGUI::SchemeManager::getSingleton().create( "OgreTray.scheme" );
scheme_ = std::string("OgreTray");
break;
}
CEGUI::FontManager::getSingleton().create( "DejaVuSans-10.font" );
CEGUI::System::getSingleton().setDefaultFont( "DejaVuSans-10" );
}
catch(CEGUI::Exception &e){
MessageBox(0, e.getMessage().c_str(), "CEGUI_GDK::setScheme()", MB_OK);
}
}
void CEGUI_GDK::pollMouse(){
CEGUI::System::getSingleton().injectMousePosition(dbMouseX(), dbMouseY());
if(dbMouseClick()){
if(!mouseDown_){
CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton);
mouseDown_ = true;
}
}
else{
if(mouseDown_){
CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::LeftButton);
mouseDown_ = false;
}
}
}
CEGUI::Window* CEGUI_GDK::makeRootWindow(std::string name){
//--Creates our default window, you can't see this window, it is the root
//--GUI sheet that we build on.
CEGUI::WindowManager &wmgr = CEGUI::WindowManager::getSingleton();
CEGUI::Window* root = wmgr.createWindow( "DefaultWindow", name );
CEGUI::System::getSingleton().setGUISheet( root );
return root;
}
CEGUI::Window* CEGUI_GDK::makeButton(std::string name, CEGUI::UDim sizeX, CEGUI::UDim sizeY, CEGUI::UDim posX, CEGUI::UDim posY){
std::string str(scheme_);
std::string buttonStr("/Button");
str.append(buttonStr);
CEGUI::Window* btnWindow = 0;
try{
btnWindow = CEGUI::WindowManager::getSingleton().createWindow(str, name); // Create Window
btnWindow->setPosition(CEGUI::UVector2(posX, posY));
btnWindow->setSize(CEGUI::UVector2(sizeX, sizeY));
}
catch(CEGUI::Exception &e){
MessageBox(0, e.getMessage().c_str(), "CEGUI_GDK::makeButton()", MB_OK);
}
return btnWindow;
}
CEGUI::Menubar* CEGUI_GDK::makeMenubar(std::string name, CEGUI::UDim sizeX, CEGUI::UDim sizeY, CEGUI::UDim posX, CEGUI::UDim posY){
std::string str(scheme_);
std::string buttonStr("/Menubar");
str.append(buttonStr);
CEGUI::Menubar* mBar = 0;
try{
mBar = static_cast<CEGUI::Menubar *>(CEGUI::WindowManager::getSingleton().createWindow(str, name));
mBar->setPosition(CEGUI::UVector2(posX, posY));
mBar->setSize(CEGUI::UVector2(sizeX, sizeY));
}
catch(CEGUI::Exception &e){
MessageBox(0, e.getMessage().c_str(), "CEGUI_GDK::makeMenubar()", MB_OK);
}
return mBar;
}
CEGUI::MenuItem* CEGUI_GDK::makeMenuItem(std::string name){
std::string str(scheme_);
std::string buttonStr("/MenuItem");
str.append(buttonStr);
CEGUI::MenuItem* mItem = 0;
try{
mItem = static_cast<CEGUI::MenuItem *>(CEGUI::WindowManager::getSingleton().createWindow(str, name));
}
catch(CEGUI::Exception &e){
MessageBox(0, e.getMessage().c_str(), "CEGUI_GDK::makeMenuItem()", MB_OK);
}
return mItem;
}
CEGUI::PopupMenu* CEGUI_GDK::makePopupMenu(std::string name){
std::string str(scheme_);
std::string buttonStr("/PopupMenu");
str.append(buttonStr);
CEGUI::PopupMenu* pMenu = 0;
try{
pMenu = static_cast<CEGUI::PopupMenu *>(CEGUI::WindowManager::getSingleton().createWindow(str, name));
}
catch(CEGUI::Exception &e){
MessageBox(0, e.getMessage().c_str(), "CEGUI_GDK::makePopupMenu()", MB_OK);
}
return pMenu;
}
//******
//ADDED
//******/
CEGUI::Checkbox* CEGUI_GDK::makeCheckbox(std::string name, CEGUI::UDim sizeX, CEGUI::UDim sizeY, CEGUI::UDim posX, CEGUI::UDim posY,bool selected)
{
std::string str(scheme_);
std::string factoryStr("/Checkbox");
str.append(factoryStr);
CEGUI::Checkbox* pCheckbox = NULL;
try
{
pCheckbox = static_cast<CEGUI::Checkbox *>(CEGUI::WindowManager::getSingleton().createWindow(str, name));
pCheckbox->setPosition(CEGUI::UVector2(posX, posY));
pCheckbox->setSize(CEGUI::UVector2(sizeX, sizeY));
pCheckbox->setSelected(selected);
}
catch(CEGUI::Exception &e)
{
MessageBox(0, e.getMessage().c_str(), "CEGUI_GDK::makeCheckbox()", MB_OK);
}
return pCheckbox;
}
CEGUI::Combobox* CEGUI_GDK::makeCombobox(std::string name, CEGUI::UDim sizeX, CEGUI::UDim sizeY, CEGUI::UDim posX, CEGUI::UDim posY)
{
std::string str(scheme_);
std::string factoryStr("/Combobox");
str.append(factoryStr);
CEGUI::Combobox* pCombobox = NULL;
try
{
pCombobox = static_cast<CEGUI::Combobox *>(CEGUI::WindowManager::getSingleton().createWindow(str, name));
pCombobox->setPosition(CEGUI::UVector2(posX, posY));
pCombobox->setSize(CEGUI::UVector2(sizeX, sizeY));
}
catch(CEGUI::Exception &e)
{
MessageBox(0, e.getMessage().c_str(), "CEGUI_GDK::makeCombobox()", MB_OK);
}
return pCombobox;
}
CEGUI::Listbox* CEGUI_GDK::makeListbox(std::string name, CEGUI::UDim sizeX, CEGUI::UDim sizeY, CEGUI::UDim posX, CEGUI::UDim posY)
{
std::string str(scheme_);
std::string factoryStr("/Listbox");
str.append(factoryStr);
CEGUI::Listbox* pItemListBox = NULL;
try
{
pItemListBox = static_cast<CEGUI::Listbox *>(CEGUI::WindowManager::getSingleton().createWindow(str, name));
pItemListBox->setPosition(CEGUI::UVector2(posX, posY));
pItemListBox->setSize(CEGUI::UVector2(sizeX, sizeY));
}
catch(CEGUI::Exception &e)
{
MessageBox(0, e.getMessage().c_str(), "CEGUI_GDK::makeListBox()", MB_OK);
}
return pItemListBox;
}
//Last time i checked (Half a year ago) the multicolumn lists were very buggy.
//Dunno its current state.
CEGUI::MultiColumnList* CEGUI_GDK::makeMultiColumnList(std::string name, CEGUI::UDim sizeX, CEGUI::UDim sizeY, CEGUI::UDim posX, CEGUI::UDim posY)
{
std::string str(scheme_);
std::string factoryStr("/MultiColumnList");
str.append(factoryStr);
CEGUI::MultiColumnList* pMultiColumnList = NULL;
try
{
pMultiColumnList = static_cast<CEGUI::MultiColumnList *>(CEGUI::WindowManager::getSingleton().createWindow(str, name));
pMultiColumnList->setPosition(CEGUI::UVector2(posX, posY));
pMultiColumnList->setSize(CEGUI::UVector2(sizeX, sizeY));
}
catch(CEGUI::Exception &e)
{
MessageBox(0, e.getMessage().c_str(), "CEGUI_GDK::makeMultiColumnList()", MB_OK);
}
return pMultiColumnList;
}
CEGUI::ListboxTextItem* CEGUI_GDK::makeListboxTextItem(std::string text,int id,void* data,bool disabled)
{
CEGUI::ListboxTextItem* pListboxTextItem = new CEGUI::ListboxTextItem(text,id,data,disabled);
pListboxTextItem->setSelectionBrushImage(scheme_, "MultiListSelectionBrush");
return pListboxTextItem;
}
CEGUI::Editbox* CEGUI_GDK::makeEditbox(std::string name, CEGUI::UDim sizeX, CEGUI::UDim sizeY, CEGUI::UDim posX, CEGUI::UDim posY)
{
std::string str(scheme_);
std::string factoryStr("/Editbox");
str.append(factoryStr);
CEGUI::Editbox* pEditbox = NULL;
try
{
pEditbox = static_cast<CEGUI::Editbox *>(CEGUI::WindowManager::getSingleton().createWindow(str, name));
pEditbox->setPosition(CEGUI::UVector2(posX, posY));
pEditbox->setSize(CEGUI::UVector2(sizeX, sizeY));
}
catch(CEGUI::Exception &e)
{
MessageBox(0, e.getMessage().c_str(), "CEGUI_GDK::makeEditbox()", MB_OK);
}
return pEditbox;
}
void CEGUI_GDK::pollKeyboard()
{
CEGUI::System::getSingleton().injectChar(keyTable.getUnicode( dbScanCode()) );
}
/**********
//END ADDED
**********/
Main.cpp
//****************************************************************************//
//************************** CEGUI_GDK Example *****************************//
//****************************************************************************//
//-- CEGUI_GDK is a light wrapper to CEGUI which will make the process
//-- of setting up and handling input with CEGUI with GDK a little easier.
//-- The CEGUI_GDK object will just setup CEGUI for you with some common
//-- default behavior, it will also handle basic input for you so you
//-- can get started quickly, you may want to re-write alot of this yourself
//-- if you decide to use CEGUI for a game/app.
//-- After setup you will access CEGUI through the CEGUI namespace just as
//-- you would without the CEGUI_GDK wrapper.
//-- For any project you use with CEGUI_GDK you will need to change the
//-- following compiler settings:
//-- Project->(project name)Properties->C/C++->Code Generation->Runtime Library
//-- Change to Multi-threaded(/MT).
//-- Project->(project name)Properties->Debugging->Working Directory
//-- Change to the 'bin' folder containing your dll's.
//-- The 'bin' and 'datafiles' folders should be in the same directory.
#include "DarkGDK.h"
#include "CEGUI_GDK.h"
#include "keycodeTable.h"
//-- Create our helper object for setup and input polling.
CEGUI_GDK uiHelper;
bool makeBox(const CEGUI::EventArgs& /*e*/){
int object = 1;
while(dbObjectExist(object)){
object++;
}
dbMakeObjectBox(object, 1, 1, 1);
dbColorObject(object, dbRGB(dbRND(255), dbRND(255), dbRND(255)));
dbPositionObject(object, dbRND(20) - 10, dbRND(20) - 10, dbRND(20) - 10);
return true;
}
void DarkGDK ( void )
{
uiHelper.start();
uiHelper.setScheme(1); // 0 - Windows Scheme, 1 - Taherez Scheme, 2 - Vanilla Scheme, 3 - Ogre Scheme
//--CREATE ROOT WINDOW--//
CEGUI::Window *rootWindow = uiHelper.makeRootWindow("root");
//--BUTTON--//
//--Positions and sizes are set with a scale value using the parent window, then an offset value.
//--To set a position or size without a relation to the parent window then set the scale value
//--to 0 and just use the offset value.
//--This button is positioned halfway across the screen(0.5) minus half the button width(100/2).
CEGUI::Window *button1 = uiHelper.makeButton("button1", CEGUI::UDim(0, 100), CEGUI::UDim(0, 30), CEGUI::UDim(0.5, -50), CEGUI::UDim(0.8, 0));
button1->setText("Create Object");
button1->subscribeEvent(CEGUI::PushButton::EventMouseClick, CEGUI::Event::Subscriber(&makeBox));
//*****
//ADDED
/******/
CEGUI::Checkbox* checkbox1 = uiHelper.makeCheckbox("checkbox1",CEGUI::UDim(0, 100),CEGUI::UDim(0, 50),CEGUI::UDim(0,10),CEGUI::UDim(0,10),true);
checkbox1->setText("Checkbox1");
CEGUI::Combobox* combobox1 = uiHelper.makeCombobox("combobox1",CEGUI::UDim(0, 100),CEGUI::UDim(0, 200),CEGUI::UDim(0,10),CEGUI::UDim(0,50));
combobox1->setText("Combobox1");
combobox1->getDropList()->addItem( uiHelper.makeListboxTextItem("Item1",1,NULL) );
combobox1->getDropList()->addItem( uiHelper.makeListboxTextItem("Item2",2,NULL) );
CEGUI::Listbox* listBox1 = uiHelper.makeListbox("listBox1",CEGUI::UDim(0, 100),CEGUI::UDim(0, 50),CEGUI::UDim(0,10),CEGUI::UDim(0,100));
listBox1->addItem( uiHelper.makeListboxTextItem("Item1",1,NULL) );
listBox1->addItem( uiHelper.makeListboxTextItem("Item2",2,NULL) );
CEGUI::MultiColumnList* multiColumnList1 = uiHelper.makeMultiColumnList("multiColumnList1",CEGUI::UDim(0, 300),CEGUI::UDim(0, 100),CEGUI::UDim(0,10),CEGUI::UDim(0,200));
multiColumnList1->addColumn("COL1",0,CEGUI::UDim(0.5,0) );
multiColumnList1->addColumn("COL2",1,CEGUI::UDim(0.5,0) );
multiColumnList1->setSelectionMode(CEGUI::MultiColumnList::RowSingle);
multiColumnList1->addRow();
multiColumnList1->setItem( uiHelper.makeListboxTextItem("Col1Item1",1,NULL) ,0,0);
multiColumnList1->setItem( uiHelper.makeListboxTextItem("Col2Item1",2,NULL) ,1,0);
CEGUI::Editbox* editbox1 = uiHelper.makeEditbox("editbox1",CEGUI::UDim(0,100), CEGUI::UDim(0,30),CEGUI::UDim(0,10), CEGUI::UDim(0,350));
rootWindow->addChildWindow(checkbox1);
rootWindow->addChildWindow(combobox1);
rootWindow->addChildWindow(listBox1);
rootWindow->addChildWindow(multiColumnList1);
rootWindow->addChildWindow(editbox1);
//*********
//END ADDED
/**********/
//--Add button to root sheet
rootWindow->addChildWindow(button1);
dbSyncOn ( );
dbSyncRate ( 60 );
dbBackdropOn();
dbAutoCamOff();
dbPositionCamera(0, 0, -50);
while ( LoopGDK ( ) )
{
uiHelper.pollMouse();
//******
//ADDED
//******/
uiHelper.pollKeyboard();
//*********
//END ADDED
//*********/
dbSync();
CEGUI::System::getSingleton().renderGUI();
}
return;
}
It translates 0-9 and A-Z DarkGDK scancodes to Unicode for CEGUI.