Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
18 KB
Referenced Files
None
Subscribers
None
diff --git a/util/debug.cpp b/util/debug.cpp
index 45b5e02a..ca3a56cd 100644
--- a/util/debug.cpp
+++ b/util/debug.cpp
@@ -1,39 +1,134 @@
#include "debug.h"
#include <iostream>
#include <string>
+#ifdef ANDROID
+#include <android/log.h>
+#define ANDROID_LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, "paintown", __VA_ARGS__)
+#endif
+
using namespace std;
static int global_debug_level = 0;
+namespace Global{
+#ifdef ANDROID
+
+android_ostream::android_ostream(bool enabled):
+enabled(enabled){
+}
+
+android_ostream & operator<<(android_ostream & stream, const std::string & input){
+ stream.buffer << input;
+ return stream;
+}
+
+android_ostream & operator<<(android_ostream & stream, const char * input){
+ stream.buffer << input;
+ return stream;
+}
+
+android_ostream & operator<<(android_ostream & stream, const char input){
+ stream.buffer << input;
+ return stream;
+}
+
+android_ostream & operator<<(android_ostream & stream, const double input){
+ stream.buffer << input;
+ return stream;
+}
+
+android_ostream & operator<<(android_ostream & stream, const int input){
+ stream.buffer << input;
+ return stream;
+}
+
+android_ostream & operator<<(android_ostream & stream, const short int input){
+ stream.buffer << input;
+ return stream;
+}
+
+android_ostream & operator<<(android_ostream & stream, const short unsigned int input){
+ stream.buffer << input;
+ return stream;
+}
+
+android_ostream & operator<<(android_ostream & stream, const unsigned int input){
+ stream.buffer << input;
+ return stream;
+}
+
+android_ostream & operator<<(android_ostream & stream, const bool input){
+ stream.buffer << input;
+ return stream;
+}
+
+android_ostream & operator<<(android_ostream & stream, const long int input){
+ stream.buffer << input;
+ return stream;
+}
+
+android_ostream & operator<<(android_ostream & stream, const unsigned long int input){
+ stream.buffer << input;
+ return stream;
+}
+
+android_ostream & operator<<(android_ostream & stream, const void * input){
+ stream.buffer << input;
+ return stream;
+}
+
+android_ostream & operator<<(android_ostream & stream, std::ostream & (*f)(std::ostream &)){
+ if (stream.enabled){
+ ANDROID_LOGV("%s\n", stream.buffer.str().c_str());
+ }
+ stream.buffer.str("");
+ stream.buffer.rdbuf()->pubseekoff(0, ios_base::end, ios_base::out);
+ stream.buffer.clear();
+ return stream;
+}
+
+android_ostream android_ostream::stream;
+static android_ostream nullcout(false);
+#else
class nullstreambuf_t: public std::streambuf {
public:
nullstreambuf_t():std::streambuf(){
}
};
static nullstreambuf_t nullstreambuf;
class nullcout_t: public std::ostream {
public:
nullcout_t():std::ostream(&nullstreambuf){
}
};
static nullcout_t nullcout;
+#endif
+
+#ifdef ANDROID
+stream_type & default_stream = android_ostream::stream;
+#else
+stream_type & default_stream = std::cout;
+#endif
+
+}
-ostream & Global::debug(int i, const string & context){
- if ( global_debug_level >= i ){
- std::cout << "[" << i << ":" << context << "] ";
- return std::cout;
+Global::stream_type & Global::debug(int i, const string & context){
+ if (global_debug_level >= i){
+ Global::stream_type & out = default_stream;
+ out << "[" << i << ":" << context << "] ";
+ return out;
}
return nullcout;
}
void Global::setDebug( int i ){
global_debug_level = i;
}
int Global::getDebug(){
return global_debug_level;
}
diff --git a/util/debug.h b/util/debug.h
index be2212ac..6634e7b3 100644
--- a/util/debug.h
+++ b/util/debug.h
@@ -1,14 +1,44 @@
#ifndef _paintown_debug_h
#define _paintown_debug_h
#include <ostream>
+#include <sstream>
namespace Global{
+#ifdef ANDROID
+class android_ostream: public std::ostream {
+public:
+ android_ostream(bool enabled = true);
+ static android_ostream stream;
+ /* make these private at some point */
+public:
+ bool enabled;
+ std::ostringstream buffer;
+};
+
+typedef android_ostream stream_type;
+android_ostream & operator<<(android_ostream & stream, const std::string & input);
+android_ostream & operator<<(android_ostream & stream, const char * input);
+android_ostream & operator<<(android_ostream & stream, const char);
+android_ostream & operator<<(android_ostream & stream, const double);
+android_ostream & operator<<(android_ostream & stream, const int);
+android_ostream & operator<<(android_ostream & stream, const short int);
+android_ostream & operator<<(android_ostream & stream, const short unsigned int);
+android_ostream & operator<<(android_ostream & stream, const unsigned int);
+android_ostream & operator<<(android_ostream & stream, const bool);
+android_ostream & operator<<(android_ostream & stream, const long int);
+android_ostream & operator<<(android_ostream & stream, const unsigned long int);
+android_ostream & operator<<(android_ostream & stream, const void *);
+android_ostream & operator<<(android_ostream & stream, std::ostream & (*f)(std::ostream &));
+#else
+typedef std::ostream stream_type;
+#endif
+
void setDebug( int i );
int getDebug();
-std::ostream & debug(int i, const std::string & context = "paintown");
+stream_type & debug(int i, const std::string & context = "paintown");
}
#endif
diff --git a/util/gui/keyinput_manager.cpp b/util/gui/keyinput_manager.cpp
index fa246741..dd0cad84 100644
--- a/util/gui/keyinput_manager.cpp
+++ b/util/gui/keyinput_manager.cpp
@@ -1,149 +1,149 @@
/*
SAGGUI (Simplified All Gaming Graphical User Interface)
Copyright (c) 2005-2007, Miguel A. Gavidia
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the following
disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
* Neither the name of the "SAGGUI" nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "al_keyinput.h"
#include "keyinput_manager.h"
#include <iostream>
#include "globals.h"
#include "util/debug.h"
-static std::ostream & debug( int level ){
- Global::debug( level ) << "[key input manager] ";
- return Global::debug( level );
+static Global::stream_type & debug(int level){
+ Global::debug(level) << "[key input manager] ";
+ return Global::debug(level);
}
#ifdef USE_ALLEGRO
allegroKeyInput keyInputManager::input;
#endif
guiTimer keyInputManager::dTimer[keys::MAX];
unsigned int keyInputManager::delay[keys::MAX];
bool keyInputManager::keyHolder[keys::MAX];
bool keyInputManager::keyBlocker[keys::MAX];
sigslot::signal1<const keys &> keyInputManager::pressed;
sigslot::signal1<const keys &> keyInputManager::released;
// Mouse Manager Constructor
keyInputManager::keyInputManager(){
//dTimer.reset();
//delay = 0;
keyHolder[keys::SPACE]=false;
keyHolder[keys::TAB]=false;
keyHolder[keys::ENTER]=false;
keyBlocker[keys::SPACE]=false;
keyBlocker[keys::TAB]=false;
keyBlocker[keys::ENTER]=false;
for(int i=0;i<keys::MAX;++i)
{
dTimer[i].reset();
delay[i]=0;
keyHolder[i]=false;
keyBlocker[i]=false;
}
}
// Mouse Manager Destructor
keyInputManager::~keyInputManager(){
// nothing
}
void keyInputManager::clear(){
#ifdef USE_ALLEGRO
input.clear();
#endif
}
// Check mouse for changes and fire events
void keyInputManager::update(){
//if(delay<=dTimer.msecs())dTimer.reset();
#ifdef USE_ALLEGRO
// update the keyboard
input.update();
//if(dTimer.msecs()<=delay)
//{
// Do pressed queue
while(!input.pressedEmpty()){
keys k = input.checkNextPressed();
if(delay[k.getValue()]<=dTimer[k.getValue()].msecs())dTimer[k.getValue()].reset();
if(dTimer[k.getValue()].msecs()<=delay[k.getValue()])
{
input.dequeuePressed();
keyHolder[k.getValue()] = true;
debug( 5 ) << "Pressed key " << k.getValue() << std::endl;
pressed.emit(k);
}
}
// Do released queue
while(!input.releasedEmpty())
{
keys k = input.dequeueReleased();
keyHolder[k.getValue()] = false;
released.emit(k);
}
//}
#endif
}
// Key state
bool keyInputManager::keyState(int unicode, bool blocking){
//if(unicode>255 || unicode<0)return false;
if(blocking)
{
if(keyHolder[unicode] && !(keyBlocker[unicode]))
{
keyBlocker[unicode]=true;
return true;
}
else if(!keyHolder[unicode] && keyBlocker[unicode])
{
keyBlocker[unicode]=false;
return false;
}
return false;
}
return keyHolder[unicode];
}
//! Set delay in milleseconds (doesn't effect the keyStates)
void keyInputManager::setDelay(unsigned int msecs, const keys::keyTypes key){
delay[key] = msecs;
}
diff --git a/util/gui/lineedit.cpp b/util/gui/lineedit.cpp
index 2600f5d4..8dc3c73a 100644
--- a/util/gui/lineedit.cpp
+++ b/util/gui/lineedit.cpp
@@ -1,338 +1,338 @@
#include "util/bitmap.h"
#include "util/trans-bitmap.h"
#include "util/font.h"
#include "lineedit.h"
#include "keys.h"
#include "globals.h"
#include "util/debug.h"
#include <iostream>
using namespace Gui;
-static std::ostream & debug( int level ){
+static Global::stream_type & debug(int level){
Global::debug(level) << "[line edit] ";
return Global::debug(level);
}
LineEdit::LineEdit() :
currentSetFont(0),
hAlignment(T_Middle),
hAlignMod(T_Middle),
vAlignment(T_Middle),
inputTypeValue(inputGeneral),
changed_(0),
autoResizable(0),
textX(0),
textY(0),
cursorX(0),
cursorY(0),
cursorIndex(0),
textColor(Graphics::makeColor(0, 0, 0)),
textSizeH(0),
limit(0),
blinkRate(500),
blink(false),
focused(false),
changeCounter(0){
cursorTime.reset();
}
LineEdit::~LineEdit(){
if (focused){
input.disable();
}
}
void LineEdit::hookKey(int key, void (*callback)(void *), void * arg){
input.addBlockingHandle(key, callback, arg);
}
bool LineEdit::didChanged(unsigned long long & counter){
bool did = counter < changeCounter;
counter = changeCounter;
return did;
}
// If the font size changes
void LineEdit::fontChange(){
changed();
}
// Update
void LineEdit::act(const Font & font){
if (cursorTime.msecs() >= blinkRate){
cursorTime.reset();
blink = !blink;
changed();
}
/*
if ((blinkRate * 2) <= cursorTime.msecs()){
cursorTime.reset();
changed();
}
*/
if (input.doInput()){
changed();
cursorIndex = input.getText().size();
}
if (changed_){
textSizeH = currentSetFont->getHeight();
if (autoResizable) {
location.setDimensions(textSizeH+2, currentSetFont->textLength(input.getText().c_str()) + 4);
} else {
if (hAlignMod==T_Left){
if (currentSetFont->textLength(input.getText().c_str())>location.getWidth()){
hAlignment = T_Right;
} else {
hAlignment = T_Left;
}
}
}
switch (hAlignment) {
case T_Left:
textX = 2;
cursorX = textX + currentSetFont->textLength(input.getText().substr(0,cursorIndex).c_str()) + 1;
break;
case T_Middle:
textX = (location.getWidth()/2) - (currentSetFont->textLength(input.getText().c_str())/2);
cursorX = (textX) + currentSetFont->textLength(input.getText().substr(0,cursorIndex).c_str()) + 1;
break;
case T_Right:
textX = location.getWidth() - currentSetFont->textLength(input.getText().c_str());//(position.width - 1)-2;
cursorX = location.getWidth() - currentSetFont->textLength(input.getText().substr(0, input.getText().length()-cursorIndex).c_str());
break;
case T_Bottom:
case T_Top:
break;
}
switch (vAlignment) {
case T_Top:
textY = 1;
cursorY = 1;
break;
case T_Middle:
textY = cursorY = (location.getHeight() - textSizeH-(5))/2;
break;
case T_Bottom:
textY = (location.getHeight() - 1) - textSizeH - 1;
cursorY = textY - textSizeH;
break;
case T_Right:
case T_Left:
break;
}
//textY++;
//textX++;
stable();
}
}
// Draw
void LineEdit::render(const Graphics::Bitmap & work){
Util::ReferenceCount<Graphics::Bitmap> workArea = checkWorkArea(work);
/* Check if we are using a rounded box */
if (transforms.getRadius() > 0){
workArea->translucent(0, 0, 0, colors.bodyAlpha).roundRectFill((int)transforms.getRadius(), 0, 0, location.getWidth()-1, location.getHeight()-1, colors.body );
workArea->translucent(0, 0, 0, colors.borderAlpha).roundRect((int)transforms.getRadius(), 0, 0, location.getWidth()-1, location.getHeight()-1, colors.border);
} else {
workArea->translucent(0, 0, 0, colors.bodyAlpha).rectangleFill(0, 0, location.getWidth()-1, location.getHeight()-1, colors.body);
workArea->translucent(0, 0, 0, colors.borderAlpha).rectangle(0, 0, location.getWidth()-1, location.getHeight()-1, colors.border);
}
if (currentSetFont){
currentSetFont->printf(textX, textY, textColor, *workArea, input.getText(), 0);
}
if (focused){
if (blink){
workArea->line(cursorX, cursorY, cursorX, cursorY+textSizeH-5, textColor);
}
}
}
#if 0
// Keypresses
sigslot::slot LineEdit::keyPress(const keys &k)
{
debug( 5 ) << "Received key press " << k.getValue() << std::endl;
if(focused)
{
if(k.isCharacter())
{
char keyValue = k.getValue();
bool addValue = false;
switch(inputTypeValue){
case inputNumerical:
if ( k.isNumber() ) addValue = !addValue;
break;
case inputNoCaps:
keyValue = tolower(keyValue);
addValue = !addValue;
break;
case inputAllCaps:
keyValue = toupper(keyValue);
addValue = !addValue;
break;
case inputGeneral:
default:
addValue = !addValue;
break;
}
if(addValue){
if(limit!=0)
{
if(currentSetText.length()<limit)
{
//currentSetText += k.getValue();
currentSetText.insert(cursorIndex, std::string(1,keyValue));
++cursorIndex;
changed();
}
}
else
{
//currentSetText += k.getValue();
currentSetText.insert(cursorIndex, std::string(1,keyValue));
++cursorIndex;
changed();
}
}
}
else
{
switch(k.getValue())
{
case keys::DEL:
if(cursorIndex<currentSetText.length())
{
currentSetText.erase(cursorIndex,1);
}
break;
case keys::BACKSPACE:
if(cursorIndex>0)
{
currentSetText.erase(cursorIndex - 1, 1);
--cursorIndex;
}
break;
case keys::RIGHT:
if(cursorIndex<currentSetText.length())++cursorIndex;
break;
case keys::LEFT:
if(cursorIndex>0)--cursorIndex;
break;
case keys::INSERT:
break;
}
changed();
}
}
}
#endif
// Set text
void LineEdit::setText(const std::string & text){
input.setText(text);
if (limit!=0) {
if (input.getText().length() > limit) {
while (input.getText().length() > limit){
// currentSetText.erase(currentSetText.begin()+currentSetText.length()-1);
}
}
}
cursorIndex = input.getText().length();
changed();
}
//! Get text
const std::string LineEdit::getText(){
return input.getText();
}
//! Clear text
void LineEdit::clearText(){
input.clearInput();
cursorIndex=0;
changed();
}
//! Set text limit
void LineEdit::setLimit(unsigned int l){
limit = l;
if (limit!=0){
if (input.getText().length()>limit){
while (input.getText().length()>limit){
// currentSetText.erase(currentSetText.begin()+currentSetText.length()-1);
}
}
}
cursorIndex = input.getText().length();
changed();
}
// Set Horizontal Alignment
void LineEdit::setHorizontalAlign(const textAlign & a){
hAlignment = hAlignMod = a;
changed();
}
// Set Vertical Alignment
void LineEdit::setVerticalAlign(const textAlign & a){
vAlignment = a;
changed();
}
//! Set the type of input default general
void LineEdit::setInputType(const inputType i){
inputTypeValue = i;
}
// Set textColor
void LineEdit::setTextColor(const Graphics::Color color){
textColor = color;
}
//! Set textColor
void LineEdit::setCursorColor(const Graphics::Color color){
textColor = color;
}
// Set font
void LineEdit::setFont(const Font *f){
currentSetFont = f;
if (currentSetFont) changed();
}
// Set autoResizeable
void LineEdit::setAutoResize(bool r){
autoResizable = r;
}
// Set the cursor blink rate in miliseconds (default 500)
void LineEdit::setCursorBlinkRate(unsigned int msecs){
blinkRate = msecs;
}
//! set Focus
void LineEdit::setFocused(bool focus){
focused = focus;
if (focus){
input.enable();
} else {
input.disable();
}
}
//! check Focus
bool LineEdit::isFocused(){
return focused;
}

File Metadata

Mime Type
text/x-diff
Expires
Thu, Jun 11, 9:53 AM (3 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
68219
Default Alt Text
(18 KB)

Event Timeline