Skip to content

Commit

Permalink
Shell|libshell: Set up libshell as a sub-library of libdeng2
Browse files Browse the repository at this point in the history
As a sub-library, libshell uses the namespace de::shell, and the
public header folder "de/shell".

The classes TextCanvas, TextWidget, and TextRootWidget were moved to
libshell so they can be used also in shell-gui and other executables.
  • Loading branch information
skyjake committed Jan 25, 2013
1 parent 73f97c9 commit 42c7135
Show file tree
Hide file tree
Showing 20 changed files with 162 additions and 82 deletions.
23 changes: 23 additions & 0 deletions doomsday/dep_shell.pri
@@ -0,0 +1,23 @@
# Build configuration for using the libdeng_shell library.
shellDir = tools/shell/libshell
INCLUDEPATH += $$PWD/$$shellDir/include

# Use the appropriate library path.
!useLibDir($$OUT_PWD/../$$shellDir) {
!useLibDir($$OUT_PWD/../../$$shellDir) {
!useLibDir($$OUT_PWD/../../../$$shellDir) {
useLibDir($$OUT_PWD/../../builddir/$$shellDir)
}
}
}

LIBS += -ldeng_shell

macx {
defineTest(linkBinaryToBundledLibdengShell) {
fixInstallName($${1}, libdeng_shell.0.dylib, ..)
}
defineTest(linkToBundledLibdengShell) {
linkBinaryToBundledLibdengShell($${1}.bundle/$$1)
}
}
9 changes: 0 additions & 9 deletions doomsday/libdeng1/libdeng1.pro
Expand Up @@ -129,16 +129,7 @@ else:unix {
macx {
linkDylibToBundledLibdeng2(libdeng1)

defineTest(fixDengLinkage) {
doPostLink("install_name_tool -change $$1 @executable_path/../Frameworks/$$1 libdeng1.1.dylib")
doPostLink("install_name_tool -change $$(QTDIR)lib/$$1 @executable_path/../Frameworks/$$1 libdeng1.1.dylib")
doPostLink("install_name_tool -change $$(QTDIR)/lib/$$1 @executable_path/../Frameworks/$$1 libdeng1.1.dylib")
}
doPostLink("install_name_tool -id @executable_path/../Frameworks/libdeng1.1.dylib libdeng1.1.dylib")
fixDengLinkage("QtCore.framework/Versions/4/QtCore")
fixDengLinkage("QtNetwork.framework/Versions/4/QtNetwork")
fixDengLinkage("QtGui.framework/Versions/4/QtGui")
fixDengLinkage("QtOpenGL.framework/Versions/4/QtOpenGL")

# Update the library included in the main app bundle.
doPostLink("mkdir -p ../client/Doomsday.app/Contents/Frameworks")
Expand Down
1 change: 1 addition & 0 deletions doomsday/tools/shell/libshell/include/de/shell/TextCanvas
@@ -0,0 +1 @@
#include "textcanvas.h"
@@ -0,0 +1 @@
#include "textrootwidget.h"
1 change: 1 addition & 0 deletions doomsday/tools/shell/libshell/include/de/shell/TextWidget
@@ -0,0 +1 @@
#include "textwidget.h"
Expand Up @@ -16,14 +16,17 @@
* http://www.gnu.org/licenses</small>
*/

#ifndef TEXTCANVAS_H
#define TEXTCANVAS_H
#ifndef LIBSHELL_TEXTCANVAS_H
#define LIBSHELL_TEXTCANVAS_H

#include <QChar>
#include <QFlags>
#include <de/Vector>
#include <de/Rectangle>

namespace de {
namespace shell {

/**
* Text-based, device-independent drawing surface.
*/
Expand Down Expand Up @@ -157,4 +160,7 @@ class TextCanvas

Q_DECLARE_OPERATORS_FOR_FLAGS(TextCanvas::Char::Attribs)

#endif // TEXTCANVAS_H
} // namespace shell
} // namespace de

#endif // LIBSHELL_TEXTCANVAS_H
Expand Up @@ -16,15 +16,18 @@
* http://www.gnu.org/licenses</small>
*/

#ifndef TEXTROOTWIDGET_H
#define TEXTROOTWIDGET_H
#ifndef LIBSHELL_TEXTROOTWIDGET_H
#define LIBSHELL_TEXTROOTWIDGET_H

#include <de/RootWidget>
#include "textcanvas.h"
#include "TextCanvas"

namespace de {
namespace shell {

class TextWidget;

class TextRootWidget : public de::RootWidget
class TextRootWidget : public RootWidget
{
public:
/**
Expand All @@ -47,7 +50,7 @@ class TextRootWidget : public de::RootWidget
*
* @param viewSize New size.
*/
void setViewSize(de::Vector2i const &viewSize);
void setViewSize(Vector2i const &viewSize);

TextWidget *focus() const;

Expand All @@ -58,4 +61,7 @@ class TextRootWidget : public de::RootWidget
bool _drawRequest;
};

#endif // TEXTROOTWIDGET_H
} // namespace shell
} // namespace de

#endif // LIBSHELL_TEXTROOTWIDGET_H
Expand Up @@ -16,13 +16,16 @@
* http://www.gnu.org/licenses</small>
*/

#ifndef TEXTWIDGET_H
#define TEXTWIDGET_H
#ifndef LIBSHELL_TEXTWIDGET_H
#define LIBSHELL_TEXTWIDGET_H

#include <de/Widget>
#include <de/RectangleRule>
#include <QObject>
#include "textcanvas.h"
#include "TextCanvas"

namespace de {
namespace shell {

class TextRootWidget;

Expand All @@ -34,12 +37,12 @@ class TextRootWidget;
*
* QObject is a base class for signals and slots.
*/
class TextWidget : public QObject, public de::Widget
class TextWidget : public QObject, public Widget
{
Q_OBJECT

public:
TextWidget(de::String const &name = "");
TextWidget(String const &name = "");
virtual ~TextWidget();

TextRootWidget &root() const;
Expand All @@ -54,21 +57,24 @@ class TextWidget : public QObject, public de::Widget
* @param rule Rectangle that the widget occupied.
* Widget takes ownership.
*/
void setRule(de::RectangleRule *rule);
void setRule(RectangleRule *rule);

de::RectangleRule &rule();
RectangleRule &rule();

/**
* Returns the position of the cursor for the widget. If the widget
* has focus, this is where the cursor will be positioned.
*
* @return Cursor position.
*/
virtual de::Vector2i cursorPosition();
virtual Vector2i cursorPosition();

private:
struct Instance;
Instance *d;
};

#endif // TEXTWIDGET_H
} // namespace shell
} // namespace de

#endif // LIBSHELL_TEXTWIDGET_H
34 changes: 31 additions & 3 deletions doomsday/tools/shell/libshell/libshell.pro
Expand Up @@ -5,16 +5,44 @@
# version 2 (or, at your option, any later version). Please visit
# http://www.gnu.org/licenses/gpl.html for details.

include(../../../config.pri)

TEMPLATE = lib
TARGET = deng_shell
VERSION = 0.1.0

VERSION = 0.1.0
include(../../../dep_deng2.pri)

INCLUDEPATH += include

# Public headers.
HEADERS +=
HEADERS += \
include/de/shell/TextCanvas \
include/de/shell/TextRootWidget \
include/de/shell/TextWidget \
include/de/shell/textcanvas.h \
include/de/shell/textrootwidget.h \
include/de/shell/textwidget.h

# Sources and private headers.
SOURCES += \
src/deng_shell.cpp
src/deng_shell.cpp \
src/textcanvas.cpp \
src/textrootwidget.cpp \
src/textwidget.cpp

# Installation ---------------------------------------------------------------

macx {
linkDylibToBundledLibdeng2(libdeng_shell)

doPostLink("install_name_tool -id @executable_path/../Frameworks/libdeng_shell.0.dylib libdeng_shell.0.dylib")

# Update the library included in the main app bundle.
doPostLink("mkdir -p ../../../client/Doomsday.app/Contents/Frameworks")
doPostLink("cp -fRp libdeng_shell*dylib ../../../client/Doomsday.app/Contents/Frameworks")
}
else {
INSTALLS += target
target.path = $$DENG_LIB_DIR
}
Expand Up @@ -16,10 +16,13 @@
* http://www.gnu.org/licenses</small>
*/

#include "textcanvas.h"
#include "de/shell/TextCanvas"
#include <QList>
#include <QDebug>

namespace de {
namespace shell {

struct TextCanvas::Instance
{
Size size;
Expand Down Expand Up @@ -144,10 +147,10 @@ void TextCanvas::markDirty()

void TextCanvas::clear(Char const &ch)
{
fill(de::Rectanglei(de::Vector2i(0, 0), d->size), ch);
fill(Rectanglei(Vector2i(0, 0), d->size), ch);
}

void TextCanvas::fill(de::Rectanglei const &rect, Char const &ch)
void TextCanvas::fill(Rectanglei const &rect, Char const &ch)
{
for(int y = rect.top(); y < rect.bottom(); ++y)
{
Expand All @@ -159,18 +162,18 @@ void TextCanvas::fill(de::Rectanglei const &rect, Char const &ch)
}
}

void TextCanvas::put(de::Vector2i const &pos, Char const &ch)
void TextCanvas::put(Vector2i const &pos, Char const &ch)
{
if(isValid(pos))
{
at(pos) = ch;
}
}

void TextCanvas::drawText(de::Vector2i const &pos, de::String const &text, Char::Attribs const &attribs)
void TextCanvas::drawText(Vector2i const &pos, String const &text, Char::Attribs const &attribs)
{
de::Vector2i p = pos;
DENG2_FOR_EACH_CONST(de::String, i, text)
Vector2i p = pos;
DENG2_FOR_EACH_CONST(String, i, text)
{
if(isValid(p))
{
Expand Down Expand Up @@ -201,5 +204,8 @@ void TextCanvas::show()
d->markAllAsDirty(false);
}

void TextCanvas::setCursorPosition(const de::Vector2i &)
void TextCanvas::setCursorPosition(Vector2i const &)
{}

} // namespace shell
} // namespace de
Expand Up @@ -16,10 +16,13 @@
* http://www.gnu.org/licenses</small>
*/

#include "textrootwidget.h"
#include "textwidget.h"
#include "de/shell/TextRootWidget"
#include "de/shell/TextWidget"

TextRootWidget::TextRootWidget(TextCanvas *cv) : de::RootWidget(), _canvas(cv), _drawRequest(false)
namespace de {
namespace shell {

TextRootWidget::TextRootWidget(TextCanvas *cv) : RootWidget(), _canvas(cv), _drawRequest(false)
{
DENG2_ASSERT(cv != 0);
setViewSize(cv->size());
Expand All @@ -35,7 +38,7 @@ TextCanvas &TextRootWidget::rootCanvas()
return *_canvas;
}

void TextRootWidget::setViewSize(de::Vector2i const &viewSize)
void TextRootWidget::setViewSize(Vector2i const &viewSize)
{
_canvas->resize(viewSize);
RootWidget::setViewSize(viewSize);
Expand Down Expand Up @@ -66,3 +69,6 @@ void TextRootWidget::draw()
_canvas->show();
_drawRequest = false;
}

} // namespace shell
} // namespace de
Expand Up @@ -16,24 +16,27 @@
* http://www.gnu.org/licenses</small>
*/

#include "textwidget.h"
#include "textrootwidget.h"
#include "de/shell/TextWidget"
#include "de/shell/TextRootWidget"

namespace de {
namespace shell {

struct TextWidget::Instance
{
TextCanvas *canvas;
de::RectangleRule *rule;
RectangleRule *rule;

Instance() : canvas(0), rule(new de::RectangleRule)
Instance() : canvas(0), rule(new RectangleRule)
{}

~Instance()
{
de::releaseRef(rule);
releaseRef(rule);
}
};

TextWidget::TextWidget(de::String const &name) : de::Widget(name), d(new Instance)
TextWidget::TextWidget(String const &name) : Widget(name), d(new Instance)
{}

TextWidget::~TextWidget()
Expand Down Expand Up @@ -63,20 +66,23 @@ TextCanvas *TextWidget::targetCanvas() const
return d->canvas;
}

void TextWidget::setRule(de::RectangleRule *rule)
void TextWidget::setRule(RectangleRule *rule)
{
de::releaseRef(d->rule);
d->rule = de::holdRef(rule);
releaseRef(d->rule);
d->rule = holdRef(rule);
}

de::RectangleRule &TextWidget::rule()
RectangleRule &TextWidget::rule()
{
DENG2_ASSERT(d->rule != 0);
return *d->rule;
}

de::Vector2i TextWidget::cursorPosition()
Vector2i TextWidget::cursorPosition()
{
return de::Vector2i(de::floor(rule().left()->value()),
de::floor(rule().top()->value()));
return Vector2i(floor(rule().left()->value()),
floor(rule().top()->value()));
}

} // namespace shell
} // namespace de

0 comments on commit 42c7135

Please sign in to comment.