Merge branch 'master' into tables
commit
f4c9897bbd
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,116 @@
|
||||
#include "debugwindow.hpp"
|
||||
|
||||
|
||||
#include <LinearMath/btQuickprof.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
void bulletDumpRecursive(CProfileIterator* pit, int spacing, std::stringstream& os)
|
||||
{
|
||||
pit->First();
|
||||
if (pit->Is_Done())
|
||||
return;
|
||||
|
||||
float accumulated_time=0,parent_time = pit->Is_Root() ? CProfileManager::Get_Time_Since_Reset() : pit->Get_Current_Parent_Total_Time();
|
||||
int i,j;
|
||||
int frames_since_reset = CProfileManager::Get_Frame_Count_Since_Reset();
|
||||
for (i=0;i<spacing;i++) os << ".";
|
||||
os << "----------------------------------\n";
|
||||
for (i=0;i<spacing;i++) os << ".";
|
||||
std::string s = "Profiling: "+
|
||||
std::string(pit->Get_Current_Parent_Name())+" (total running time: "+MyGUI::utility::toString(parent_time,3)+" ms) ---\n";
|
||||
os << s;
|
||||
//float totalTime = 0.f;
|
||||
|
||||
int numChildren = 0;
|
||||
|
||||
for (i = 0; !pit->Is_Done(); i++,pit->Next())
|
||||
{
|
||||
numChildren++;
|
||||
float current_total_time = pit->Get_Current_Total_Time();
|
||||
accumulated_time += current_total_time;
|
||||
float fraction = parent_time > SIMD_EPSILON ? (current_total_time / parent_time) * 100 : 0.f;
|
||||
|
||||
for (j=0;j<spacing;j++) os << ".";
|
||||
double ms = (current_total_time / (double)frames_since_reset);
|
||||
s = MyGUI::utility::toString(i)+" -- "+pit->Get_Current_Name()+" ("+MyGUI::utility::toString(fraction,2)+" %) :: "+MyGUI::utility::toString(ms,3)+" ms / frame ("+MyGUI::utility::toString(pit->Get_Current_Total_Calls())+" calls)\n";
|
||||
os << s;
|
||||
//totalTime += current_total_time;
|
||||
//recurse into children
|
||||
}
|
||||
|
||||
if (parent_time < accumulated_time)
|
||||
{
|
||||
os << "what's wrong\n";
|
||||
}
|
||||
for (i=0;i<spacing;i++) os << ".";
|
||||
double unaccounted= parent_time > SIMD_EPSILON ? ((parent_time - accumulated_time) / parent_time) * 100 : 0.f;
|
||||
s = "Unaccounted: ("+MyGUI::utility::toString(unaccounted,3)+" %) :: "+MyGUI::utility::toString(parent_time - accumulated_time,3)+" ms\n";
|
||||
os << s;
|
||||
|
||||
for (i=0;i<numChildren;i++)
|
||||
{
|
||||
pit->Enter_Child(i);
|
||||
bulletDumpRecursive(pit, spacing+3, os);
|
||||
pit->Enter_Parent();
|
||||
}
|
||||
}
|
||||
|
||||
void bulletDumpAll(std::stringstream& os)
|
||||
{
|
||||
CProfileIterator* profileIterator = 0;
|
||||
profileIterator = CProfileManager::Get_Iterator();
|
||||
|
||||
bulletDumpRecursive(profileIterator, 0, os);
|
||||
|
||||
CProfileManager::Release_Iterator(profileIterator);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
||||
DebugWindow::DebugWindow()
|
||||
: WindowBase("openmw_debug_window.layout")
|
||||
{
|
||||
getWidget(mTabControl, "TabControl");
|
||||
|
||||
// Ideas for other tabs:
|
||||
// - Texture / compositor texture viewer
|
||||
// - Log viewer
|
||||
// - Material editor
|
||||
// - Shader editor
|
||||
|
||||
MyGUI::TabItem* item = mTabControl->addItem("Physics Profiler");
|
||||
mBulletProfilerEdit = item->createWidgetReal<MyGUI::EditBox>
|
||||
("LogEdit", MyGUI::FloatCoord(0,0,1,1), MyGUI::Align::Stretch);
|
||||
|
||||
MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize();
|
||||
mMainWidget->setSize(viewSize);
|
||||
}
|
||||
|
||||
void DebugWindow::onFrame(float dt)
|
||||
{
|
||||
if (!isVisible())
|
||||
return;
|
||||
|
||||
static float timer = 0;
|
||||
timer -= dt;
|
||||
|
||||
if (timer > 0)
|
||||
return;
|
||||
timer = 1;
|
||||
|
||||
std::stringstream stream;
|
||||
bulletDumpAll(stream);
|
||||
|
||||
if (mBulletProfilerEdit->isTextSelection()) // pause updating while user is trying to copy text
|
||||
return;
|
||||
|
||||
size_t previousPos = mBulletProfilerEdit->getVScrollPosition();
|
||||
mBulletProfilerEdit->setCaption(stream.str());
|
||||
mBulletProfilerEdit->setVScrollPosition(std::min(previousPos, mBulletProfilerEdit->getVScrollRange()-1));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
#ifndef OPENMW_MWGUI_DEBUGWINDOW_H
|
||||
#define OPENMW_MWGUI_DEBUGWINDOW_H
|
||||
|
||||
#include "windowbase.hpp"
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
||||
class DebugWindow : public WindowBase
|
||||
{
|
||||
public:
|
||||
DebugWindow();
|
||||
|
||||
void onFrame(float dt);
|
||||
|
||||
private:
|
||||
MyGUI::TabControl* mTabControl;
|
||||
|
||||
MyGUI::EditBox* mBulletProfilerEdit;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,169 +0,0 @@
|
||||
#include "list.hpp"
|
||||
|
||||
#include <MyGUI_Gui.h>
|
||||
#include <MyGUI_Button.h>
|
||||
#include <MyGUI_ImageBox.h>
|
||||
#include <MyGUI_ScrollBar.h>
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
||||
namespace Widgets
|
||||
{
|
||||
|
||||
MWList::MWList() :
|
||||
mClient(0)
|
||||
, mScrollView(0)
|
||||
, mItemHeight(0)
|
||||
{
|
||||
}
|
||||
|
||||
void MWList::initialiseOverride()
|
||||
{
|
||||
Base::initialiseOverride();
|
||||
|
||||
assignWidget(mClient, "Client");
|
||||
if (mClient == 0)
|
||||
mClient = this;
|
||||
|
||||
mScrollView = mClient->createWidgetReal<MyGUI::ScrollView>(
|
||||
"MW_ScrollView", MyGUI::FloatCoord(0.0, 0.0, 1.0, 1.0),
|
||||
MyGUI::Align::Top | MyGUI::Align::Left | MyGUI::Align::Stretch, getName() + "_ScrollView");
|
||||
}
|
||||
|
||||
void MWList::addItem(const std::string& name)
|
||||
{
|
||||
mItems.push_back(name);
|
||||
}
|
||||
|
||||
void MWList::addSeparator()
|
||||
{
|
||||
mItems.push_back("");
|
||||
}
|
||||
|
||||
void MWList::adjustSize()
|
||||
{
|
||||
redraw();
|
||||
}
|
||||
|
||||
void MWList::redraw(bool scrollbarShown)
|
||||
{
|
||||
const int _scrollBarWidth = 20; // fetch this from skin?
|
||||
const int scrollBarWidth = scrollbarShown ? _scrollBarWidth : 0;
|
||||
const int spacing = 3;
|
||||
size_t viewPosition = -mScrollView->getViewOffset().top;
|
||||
|
||||
while (mScrollView->getChildCount())
|
||||
{
|
||||
MyGUI::Gui::getInstance().destroyWidget(mScrollView->getChildAt(0));
|
||||
}
|
||||
|
||||
mItemHeight = 0;
|
||||
int i=0;
|
||||
for (std::vector<std::string>::const_iterator it=mItems.begin();
|
||||
it!=mItems.end(); ++it)
|
||||
{
|
||||
if (*it != "")
|
||||
{
|
||||
if (mListItemSkin.empty())
|
||||
throw std::runtime_error("MWList needs a ListItemSkin property");
|
||||
MyGUI::Button* button = mScrollView->createWidget<MyGUI::Button>(
|
||||
mListItemSkin, MyGUI::IntCoord(0, mItemHeight, mScrollView->getSize().width - scrollBarWidth - 2, 24),
|
||||
MyGUI::Align::Left | MyGUI::Align::Top, getName() + "_item_" + (*it));
|
||||
button->setCaption((*it));
|
||||
button->getSubWidgetText()->setWordWrap(true);
|
||||
button->getSubWidgetText()->setTextAlign(MyGUI::Align::Left);
|
||||
button->eventMouseWheel += MyGUI::newDelegate(this, &MWList::onMouseWheel);
|
||||
button->eventMouseButtonClick += MyGUI::newDelegate(this, &MWList::onItemSelected);
|
||||
|
||||
int height = button->getTextSize().height;
|
||||
button->setSize(MyGUI::IntSize(button->getSize().width, height));
|
||||
button->setUserData(i);
|
||||
|
||||
mItemHeight += height + spacing;
|
||||
}
|
||||
else
|
||||
{
|
||||
MyGUI::ImageBox* separator = mScrollView->createWidget<MyGUI::ImageBox>("MW_HLine",
|
||||
MyGUI::IntCoord(2, mItemHeight, mScrollView->getWidth() - scrollBarWidth - 4, 18),
|
||||
MyGUI::Align::Left | MyGUI::Align::Top | MyGUI::Align::HStretch);
|
||||
separator->setNeedMouseFocus(false);
|
||||
|
||||
mItemHeight += 18 + spacing;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
// Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the scrollbar is hidden
|
||||
mScrollView->setVisibleVScroll(false);
|
||||
mScrollView->setCanvasSize(mClient->getSize().width, std::max(mItemHeight, mClient->getSize().height));
|
||||
mScrollView->setVisibleVScroll(true);
|
||||
|
||||
if (!scrollbarShown && mItemHeight > mClient->getSize().height)
|
||||
redraw(true);
|
||||
|
||||
size_t viewRange = mScrollView->getCanvasSize().height;
|
||||
if(viewPosition > viewRange)
|
||||
viewPosition = viewRange;
|
||||
mScrollView->setViewOffset(MyGUI::IntPoint(0, viewPosition * -1));
|
||||
}
|
||||
|
||||
void MWList::setPropertyOverride(const std::string &_key, const std::string &_value)
|
||||
{
|
||||
if (_key == "ListItemSkin")
|
||||
mListItemSkin = _value;
|
||||
else
|
||||
Base::setPropertyOverride(_key, _value);
|
||||
}
|
||||
|
||||
bool MWList::hasItem(const std::string& name)
|
||||
{
|
||||
return (std::find(mItems.begin(), mItems.end(), name) != mItems.end());
|
||||
}
|
||||
|
||||
unsigned int MWList::getItemCount()
|
||||
{
|
||||
return mItems.size();
|
||||
}
|
||||
|
||||
std::string MWList::getItemNameAt(unsigned int at)
|
||||
{
|
||||
assert(at < mItems.size() && "List item out of bounds");
|
||||
return mItems[at];
|
||||
}
|
||||
|
||||
void MWList::removeItem(const std::string& name)
|
||||
{
|
||||
assert( std::find(mItems.begin(), mItems.end(), name) != mItems.end() );
|
||||
mItems.erase( std::find(mItems.begin(), mItems.end(), name) );
|
||||
}
|
||||
|
||||
void MWList::clear()
|
||||
{
|
||||
mItems.clear();
|
||||
}
|
||||
|
||||
void MWList::onMouseWheel(MyGUI::Widget* _sender, int _rel)
|
||||
{
|
||||
//NB view offset is negative
|
||||
if (mScrollView->getViewOffset().top + _rel*0.3 > 0)
|
||||
mScrollView->setViewOffset(MyGUI::IntPoint(0, 0));
|
||||
else
|
||||
mScrollView->setViewOffset(MyGUI::IntPoint(0, mScrollView->getViewOffset().top + _rel*0.3));
|
||||
}
|
||||
|
||||
void MWList::onItemSelected(MyGUI::Widget* _sender)
|
||||
{
|
||||
std::string name = _sender->castType<MyGUI::Button>()->getCaption();
|
||||
int id = *_sender->getUserData<int>();
|
||||
eventItemSelected(name, id);
|
||||
eventWidgetSelected(_sender);
|
||||
}
|
||||
|
||||
MyGUI::Widget* MWList::getItemWidget(const std::string& name)
|
||||
{
|
||||
return mScrollView->findWidget (getName() + "_item_" + name);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
#ifndef MWGUI_LIST_HPP
|
||||
#define MWGUI_LIST_HPP
|
||||
|
||||
#include <MyGUI_ScrollView.h>
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
namespace Widgets
|
||||
{
|
||||
/**
|
||||
* \brief a very simple list widget that supports word-wrapping entries
|
||||
* \note if the width or height of the list changes, you must call adjustSize() method
|
||||
*/
|
||||
class MWList : public MyGUI::Widget
|
||||
{
|
||||
MYGUI_RTTI_DERIVED(MWList)
|
||||
public:
|
||||
MWList();
|
||||
|
||||
typedef MyGUI::delegates::CMultiDelegate2<const std::string&, int> EventHandle_StringInt;
|
||||
typedef MyGUI::delegates::CMultiDelegate1<MyGUI::Widget*> EventHandle_Widget;
|
||||
|
||||
/**
|
||||
* Event: Item selected with the mouse.
|
||||
* signature: void method(std::string itemName, int index)
|
||||
*/
|
||||
EventHandle_StringInt eventItemSelected;
|
||||
|
||||
/**
|
||||
* Event: Item selected with the mouse.
|
||||
* signature: void method(MyGUI::Widget* sender)
|
||||
*/
|
||||
EventHandle_Widget eventWidgetSelected;
|
||||
|
||||
|
||||
/**
|
||||
* Call after the size of the list changed, or items were inserted/removed
|
||||
*/
|
||||
void adjustSize();
|
||||
|
||||
void addItem(const std::string& name);
|
||||
void addSeparator(); ///< add a seperator between the current and the next item.
|
||||
void removeItem(const std::string& name);
|
||||
bool hasItem(const std::string& name);
|
||||
unsigned int getItemCount();
|
||||
std::string getItemNameAt(unsigned int at); ///< \attention if there are separators, this method will return "" at the place where the separator is
|
||||
void clear();
|
||||
|
||||
MyGUI::Widget* getItemWidget(const std::string& name);
|
||||
///< get widget for an item name, useful to set up tooltip
|
||||
|
||||
virtual void setPropertyOverride(const std::string& _key, const std::string& _value);
|
||||
|
||||
protected:
|
||||
void initialiseOverride();
|
||||
|
||||
void redraw(bool scrollbarShown = false);
|
||||
|
||||
void onMouseWheel(MyGUI::Widget* _sender, int _rel);
|
||||
void onItemSelected(MyGUI::Widget* _sender);
|
||||
|
||||
private:
|
||||
MyGUI::ScrollView* mScrollView;
|
||||
MyGUI::Widget* mClient;
|
||||
std::string mListItemSkin;
|
||||
|
||||
std::vector<std::string> mItems;
|
||||
|
||||
int mItemHeight; // height of all items
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue