Mercurial > LightClone
view LightClone/Source/CodeSlot.cpp @ 51:efd2b1ca5b77
Clean up gui
author | koryspansel <koryspansel@bendbroadband.com> |
---|---|
date | Tue, 27 Sep 2011 09:42:01 -0700 |
parents | 58a16d529d95 |
children | 95677f648a2c |
line wrap: on
line source
/* * CodeSlot */ #include "CodeSlot.h" #include "GuiInterface.h" #include "InputManager.h" /* * ActionTextureName */ const char* ActionTextureName[] = { "Data\\Textures\\Forward.tga", "Data\\Textures\\RotateCW.tga", "Data\\Textures\\RotateCCW.tga", "Data\\Textures\\Jump.tga", "Data\\Textures\\Light.tga", "Data\\Textures\\Function1.tga", "Data\\Textures\\Function2.tga", }; /* * CodeSlot */ CodeSlot::CodeSlot() : GuiImage(), nAction(Action_Default), bPermanent(false) { SetFlag(GuiElementFlag_Pickable); } /* * Initialize */ ErrorCode CodeSlot::Initialize(ResourceManager* pManager) { ErrorCode eCode = GuiImage::Initialize(pManager); if(eCode == Error_Success) { SetTexture("Data\\Textures\\Slot.tga"); } return eCode; } /* * Terminate */ void CodeSlot::Terminate() { } /* * SetSlot */ void CodeSlot::SetSlot(uint32 nValue) { nSlot = nValue; } /* * GetSlot */ uint32 CodeSlot::GetSlot() const { return nSlot; } /* * SetAction */ void CodeSlot::SetAction(uint32 nValue) { nAction = nValue; SetTexture(nAction == Action_Default ? "Data\\Textures\\Slot.tga" : ActionTextureName[nAction - Action_Forward]); } /* * GetAction */ uint32 CodeSlot::GetAction() const { return nAction; } /* * SetPermanent */ void CodeSlot::SetPermanent(bool bValue) { bPermanent = bValue; } /* * OnMouseDown */ void CodeSlot::OnMouseDown(uint32 nButton, float fX, float fY) { if(nButton == MouseButton_Left) { pInterface->AcquireCursor(this); } } /* * OnMouseUp */ void CodeSlot::OnMouseUp(uint32 nButton, float fX, float fY) { if(pInterface->IsCursorAcquiredBy(this)) { pInterface->ReleaseCursor(); } } /* * OnMouseMove */ void CodeSlot::OnMouseMove(float fX, float fY) { if(pInterface->IsCursorAcquiredBy(this)) { pInterface->ReleaseCursor(); if(nAction != Action_Default) { //TODO: Figure out some other way of doing this // create a new element to represent the object being dragged CodeSlot* pInstance = new CodeSlot(); pInstance->Initialize(pResourceManager); pInstance->SetAction(nAction); pInstance->SetDimensions(kDimensions); pInstance->SetPosition(kPosition); pInstance->SetInterface(pInterface); // let the interface and cursor manage the drag object pInterface->BeginDrag(pInstance, MouseButton_Left); // if this slot is always suppose to have a valid action, do // not clear out the current action if(!bPermanent) { SetAction(Action_Default); } } } } /* * OnDrop */ void CodeSlot::OnDrop(GuiElement* pSource, float fX, float fY) { //TODO: Need to make sure pSource is actually a CodeSlot SetAction(((CodeSlot*)pSource)->nAction); GuiEventArguments kArguments(this); Fire(CodeSlot::EventDrop, kArguments); }