Skip to content

Commit

Permalink
MAUI-revamp, optimized some stuff (we need to figure out what to do w…
Browse files Browse the repository at this point in the history
…ith the isTransparent virtual call in Widget). Made it possible to have nested listboxes.

git-svn-id: svn://localhost/public/MoSync/branches/MAUI-revamp@2055 6ad7a17e-d552-4a1e-ace4-f958fe14b117
  • Loading branch information
nummelin committed Sep 22, 2010
1 parent e07f1fc commit 5444c8b
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 38 deletions.
6 changes: 4 additions & 2 deletions libs/MAUI/Button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ bool Button::pointerPressed(MAPoint2d p, int id) {
}

bool Button::pointerMoved(MAPoint2d p, int id) {
//MAUI_LOG("Button moved! %x", this);
p.x-=mStartX;
p.y-=mStartY;

if((abs(p.x)<(mBounds.width>>2)) && (abs(p.y)<(mBounds.height>>2))) return true;
int length = sqrt(p.x*p.x+p.y*p.y);
if(length<15) return true;
else return false;
}

bool Button::pointerReleased(MAPoint2d p, int id) {
//MAUI_LOG("Button released! %x", this);
//MAUI_LOG("Button released! %x", this);
mPressed = false;
fireTriggered();
requestRepaint();
Expand Down
1 change: 1 addition & 0 deletions libs/MAUI/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ namespace MAUI {
}

void Engine::requestUIUpdate() {
//maReportCallStack();
Environment::getEnvironment().addIdleListener(this);
}

Expand Down
12 changes: 3 additions & 9 deletions libs/MAUI/Label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,20 +205,14 @@ namespace MAUI {

void Label::drawWidget() {
const char* wStr = mCaption.c_str();

//int textX=mPaddedBounds.x, textY=mPaddedBounds.y;
int textX=0, textY=0;
//calcStrSize();

getTextStart(&textX, &textY);

Rect tempRect = Rect(0, 0, mPaddedBounds.width, mPaddedBounds.height);

if(mFont) {

if(mMultiLine)
if(mMultiLine) {
Rect tempRect = Rect(0, 0, mPaddedBounds.width, mPaddedBounds.height);
mFont->drawBoundedString(wStr, textX, textY, tempRect);
else {
} else {

if(mAutoSizeX)
mFont->drawString(wStr, textX, textY);
Expand Down
102 changes: 89 additions & 13 deletions libs/MAUI/ListBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,11 +673,20 @@ namespace MAUI {
}

Widget* lastChild = mChildren[mChildren.size() - 1];
int bound = (lastChild->getPosition().y + lastChild->getBounds().height)
- this->getBounds().height;
if(bound<0) bound = 0;
if (ofs < -bound) {
ofs = -bound;
if(mOrientation==LBO_VERTICAL) {
int bound = (lastChild->getPosition().y + lastChild->getBounds().height)
- this->getBounds().height;
if(bound<0) bound = 0;
if (ofs < -bound) {
ofs = -bound;
}
} else {
int bound = (lastChild->getPosition().x + lastChild->getBounds().width)
- this->getBounds().width;
if(bound<0) bound = 0;
if (ofs < -bound) {
ofs = -bound;
}
}

mYOffset = ofs << 16;
Expand All @@ -694,48 +703,73 @@ namespace MAUI {
mTouchMotionTracker.reset();
mTouchMotionTracker.addPoint(p);

int x = (mOrientation==LBO_HORIZONTAL)?(p.x-(mYOffset>>16)):p.x;
int y = (mOrientation==LBO_VERTICAL)?(p.y-(mYOffset>>16)):p.y;
/*
if(mOrientation == LBO_HORIZONTAL)
MAUI_LOG("Horizontal ListBoxPressed!");
*/

int xx = (mOrientation==LBO_HORIZONTAL)?(p.x-(mYOffset>>16)):p.x;
int yy = (mOrientation==LBO_VERTICAL)?(p.y-(mYOffset>>16)):p.y;
Vector_each(Widget *, it, mChildren) {
Widget *ret = (*it)->focusableWidgetAt(x, y);
Widget *ret = (*it)->focusableWidgetAt(xx, yy);
if(ret) {
p.x = xx;
p.y = yy;
//MAUI_LOG("Found focusable!");
if(ret->pointerPressed(p, id)) {
setFocusedWidget(ret);
return true;
}
break;
}
}

return false;
return true;
}

bool ListBox::pointerMoved(MAPoint2d p, int id) {
//MAUI_LOG("Got event %d, %d", p.x, p.y);
if(mFocusedWidget) {
int xx = (mOrientation==LBO_HORIZONTAL)?(p.x-(mYOffset>>16)):p.x;
int yy = (mOrientation==LBO_VERTICAL)?(p.y-(mYOffset>>16)):p.y;

/*
MAPoint2d s = mTouchMotionTracker.getStartPoint();
if((mOrientation == LBO_HORIZONTAL && abs(p.y-s.y)>10) || (mOrientation == LBO_VERTICAL && abs(p.x-s.x)>10)) {
mFocusedWidget->setFocused(false);
mFocusedWidget = NULL;
return false;
}
*/

p.x = xx;
p.y = yy;
if(!mFocusedWidget->pointerMoved(p, id)) {
mFocusedWidget->setFocused(false);
mFocusedWidget = NULL;
return true;
}
return false;
//MAUI_LOG("moved!!!");
return true;
}
if(id==0) {
int relX, relY;
mTouchMotionTracker.addPoint(p, relX, relY);
if(relX==0 && relY == 0) return false;
if(relX==0 && relY == 0) return true;
if(mOrientation == LBO_VERTICAL)
setScrollOffset((mYOffset>>16)+relY);
else
setScrollOffset((mYOffset>>16)+relX);
}
return false;
return true;
}

bool ListBox::pointerReleased(MAPoint2d p, int id) {
if(mFocusedWidget) {
mFocusedWidget->pointerReleased(p, id);
mFocusedWidget->setFocused(false);
mFocusedWidget = NULL;
return false;
//return false;
}

if(id==0) {
Expand All @@ -746,4 +780,46 @@ namespace MAUI {
return false;
}

Widget* ListBox::widgetAt(int x, int y) {
int xx = (mOrientation==LBO_HORIZONTAL)?(x-(mYOffset>>16)):x;
int yy = (mOrientation==LBO_VERTICAL)?(y-(mYOffset>>16)):y;
Vector_each(Widget *, it, mChildren) {
Widget *ret = (*it)->widgetAt(xx, yy);
if(ret) {
return ret;
}
}

if(mBounds.contains(x, y)) {
return this;
}

return NULL;
}


Widget* ListBox::focusableWidgetAt(int x, int y) {
if(!isFocusable()) {
int xx = (mOrientation==LBO_HORIZONTAL)?(x-(mYOffset>>16)):x;
int yy = (mOrientation==LBO_VERTICAL)?(y-(mYOffset>>16)):y;
Vector_each(Widget *, it, mChildren) {
Widget *ret = (*it)->focusableWidgetAt(xx, yy);
if(ret) {
return ret;
}
}
} else {
if(mBounds.contains(x, y)) {
return this;
}
}
return NULL;
}

void ListBox::setEnabled(bool enabled) {
if(enabled==false) {
Environment::getEnvironment().removeTimer(this);
}
Widget::setEnabled(enabled);
}
}
5 changes: 5 additions & 0 deletions libs/MAUI/ListBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ namespace MAUI {
virtual bool pointerReleased(MAPoint2d p, int id);

void setFocusedWidget(Widget *w);
virtual Widget* focusableWidgetAt(int x, int y);
virtual Widget* widgetAt(int x, int y);

virtual void setEnabled(bool enabled=true);


protected:
void runTimerEvent();
Expand Down
7 changes: 5 additions & 2 deletions libs/MAUI/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ namespace MAUI {
sCurrentScreen = this;
Engine::getSingleton().setMain(mMain);
mMain->setEnabled(true);
mMain->setDirty(true);
//mMain->setDirty(true);
mMain->requestRepaint();

//printf("Requesting UI update...!\n");
Engine::getSingleton().requestUIUpdate();
//Engine::getSingleton().requestUIUpdate();
Environment::getEnvironment().addKeyListener(this);
Environment::getEnvironment().addPointerListener(this);
}
Expand Down Expand Up @@ -74,6 +76,7 @@ namespace MAUI {
env.removePointerListener(this);
if(mMain)
mMain->setEnabled(false);
sCurrentScreen = NULL;
}

Screen::~Screen() {
Expand Down
4 changes: 4 additions & 0 deletions libs/MAUI/TouchMotionTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA

#include "TouchMotionTracker.h"
#include <madmath.h>
#include <mastdlib.h>

namespace MAUI {

Expand Down Expand Up @@ -98,5 +99,8 @@ void TouchMotionTracker::calculateVelocity(double &directionX, double &direction
velocityY = mDiry/time;
}

MAPoint2d TouchMotionTracker::getStartPoint() const {
return mStart;
}

} // namespace MAUI
3 changes: 3 additions & 0 deletions libs/MAUI/TouchMotionTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ class TouchMotionTracker {
void addPoint(MAPoint2d p);
void addPoint(MAPoint2d p, int &relX, int &relY);
void calculateVelocity(double &dirx, double &diry, double &velocityX, double &velocityY);

MAPoint2d getStartPoint() const;
private:
int mStartTime;
MAPoint2d mStart;
MAPoint2d mLast;
double mDirx, mDiry;
bool mStarted;

};

} // namespace MAUI
Expand Down
31 changes: 24 additions & 7 deletions libs/MAUI/Widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ namespace MAUI {
}

Vector_each(Widget*, it, mChildren)
(*it)->draw();
(*it)->draw();

}
// This commented out to match removal of above intersectClipRect() call.
Expand Down Expand Up @@ -264,30 +264,47 @@ namespace MAUI {
}

void Widget::requestRepaint() {
Engine::getSingleton().requestUIUpdate();
//if(mDirty) return;

setDirty();


// TODO: Something like this this should be used, but isTransparent can't be called from the constructor.
//if(isTransparent()) {
//MAUI_LOG("bäh? 2");
/*
if(mParent) {
mParent->requestRepaint();
mParent->setDirty(true, this);
}
*/
//}

}

bool Widget::isDirty() const {
return mDirty;
}

void Widget::setDirty(bool d) {
void Widget::setDirty(bool d, Widget* caller) {
if(mDirty == d) return;

mDirty = d;

if(d == true) {
Vector_each(Widget*, it, mChildren)
Engine::getSingleton().requestUIUpdate();

Vector_each(Widget*, it, mChildren) {
if(caller && caller == (*it)) continue;
(*it)->setDirty(d);
}

if(mParent) {
Widget* parent = mParent;
Widget* prevParent = this;
do {
parent->setDirty(true, prevParent);
prevParent = parent;
parent = parent->getParent();
} while(parent);
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions libs/MAUI/Widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ namespace MAUI {
* surrounding the point. Returns NULL if no widget is found.
*/
Widget* widgetAt(const Point& p);
Widget* widgetAt(int x, int y);
virtual Widget* widgetAt(int x, int y);

Widget* focusableWidgetAt(const Point& p);
Widget* focusableWidgetAt(int x, int y);
virtual Widget* focusableWidgetAt(int x, int y);

// Properties, geometry

Expand Down Expand Up @@ -402,7 +402,7 @@ namespace MAUI {
/**
* Sets the dirty state of the widget.
*/
void setDirty(bool d=true);
void setDirty(bool d=true, Widget* caller=NULL);

virtual void restyle();

Expand Down
11 changes: 9 additions & 2 deletions libs/MAUI/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,19 @@ class CalculatorScreen : public Screen, public WidgetListener {
}

for(int i = 0; i < 16; i++) {
button = new Button(0, 0, 50, 50, mainListbox, "graph");
button = new Button(0, 0, 50, 100, mainListbox, "graph");
button->addWidgetListener(this);
}

ListBox *testListbox = new ListBox(0, 0, 240, 320, mainListbox, ListBox::LBO_HORIZONTAL, ListBox::LBA_LINEAR, true);
testListbox->setAutoSize(true);
for(int i = 0; i < 16; i++) {
button = new Button(0, 0, 100, 50, testListbox, "graph");
button->addWidgetListener(this);
}

NativeEditBox *native = new NativeEditBox(0, 0, 50, 50, mainListbox);
button = new Button(0, 0, 50, 50, mainListbox, "exit");
button = new Button(0, 0, 50, 100, mainListbox, "exit");
button->addWidgetListener(this);


Expand Down

0 comments on commit 5444c8b

Please sign in to comment.