Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS and multi-touch support, use TextureFont and AppNative #1

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
# Windows cruft
*.suo
*.ncb
*.sdf
Debug/
Release/

# xcode noise
*.mode1v3
*.mode2v3
*.pbxuser
*.perspective
*.perspectivev3
*.pyc
*~.nib/
build
build/*
*.user
*.xcworkspace/
xcuserdata/

# osx noise
.DS_Store
profile
profile
30 changes: 26 additions & 4 deletions SimpleGUI/include/SimpleGUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
#pragma once

#include <vector>
#include "cinder/app/App.h"
#include "cinder/app/AppNative.h"
#include "cinder/Text.h"
#include "cinder/gl/Texture.h"
#include "cinder/gl/TextureFont.h"

using namespace ci;
using namespace ci::app;
Expand Down Expand Up @@ -59,12 +60,16 @@ class SimpleGUI {
Vec2f mousePos;
std::vector<Control*> controls;
Control* selectedControl;
std::map<uint64_t, Control*> selectedControls; // for multitouch

CallbackId cbMouseDown;
CallbackId cbMouseUp;
CallbackId cbMouseDrag;
CallbackId cbTouchesBegan;
CallbackId cbTouchesEnded;
CallbackId cbTouchesMoved;

void init(App* app);
void init(AppNative* app);
public:
static ColorA darkColor;
static ColorA lightColor;
Expand All @@ -75,20 +80,25 @@ class SimpleGUI {
static Vec2f sliderSize;
static Vec2f labelSize;
static Vec2f separatorSize;
static Vec2f textOffset;
static Font textFont;
static gl::TextureFontRef textureFont;

enum {
RGB,
HSV
};
public:
SimpleGUI(App* app);
bool isSelected() { return selectedControl != NULL; }
SimpleGUI(AppNative* app);
bool isSelected() { return selectedControl != NULL || !selectedControls.empty(); }
std::vector<Control*>& getControls() { return controls; }

bool onMouseDown(MouseEvent event);
bool onMouseUp(MouseEvent event);
bool onMouseDrag(MouseEvent event);
bool onTouchesBegan(TouchEvent event);
bool onTouchesEnded(TouchEvent event);
bool onTouchesMoved(TouchEvent event);

void draw();
void dump();
Expand Down Expand Up @@ -151,6 +161,9 @@ class Control {
virtual void onMouseDown(MouseEvent event) {};
virtual void onMouseUp(MouseEvent event) {};
virtual void onMouseDrag(MouseEvent event) {};
virtual void onTouchBegan(TouchEvent::Touch touch) {};
virtual void onTouchMoved(TouchEvent::Touch touch) {};
virtual void onTouchEnded(TouchEvent::Touch touch) {};
};

//-----------------------------------------------------------------------------
Expand All @@ -169,6 +182,8 @@ class FloatVarControl : public Control {
void fromString(std::string& strValue);
void onMouseDown(MouseEvent event);
void onMouseDrag(MouseEvent event);
void onTouchBegan(TouchEvent::Touch touch);
void onTouchMoved(TouchEvent::Touch touch);
};

//-----------------------------------------------------------------------------
Expand All @@ -187,6 +202,8 @@ class IntVarControl : public Control {
void fromString(std::string& strValue);
void onMouseDown(MouseEvent event);
void onMouseDrag(MouseEvent event);
void onTouchBegan(TouchEvent::Touch touch);
void onTouchMoved(TouchEvent::Touch touch);
};

//-----------------------------------------------------------------------------
Expand All @@ -201,6 +218,7 @@ class BoolVarControl : public Control {
std::string toString();
void fromString(std::string& strValue);
void onMouseDown(MouseEvent event);
void onTouchBegan(TouchEvent::Touch touch);
};

//-----------------------------------------------------------------------------
Expand All @@ -221,6 +239,8 @@ class ColorVarControl : public Control {
void fromString(std::string& strValue); //expecting "r g b a"
void onMouseDown(MouseEvent event);
void onMouseDrag(MouseEvent event);
void onTouchBegan(TouchEvent::Touch touch);
void onTouchMoved(TouchEvent::Touch touch);
};

//-----------------------------------------------------------------------------
Expand All @@ -234,6 +254,8 @@ class ButtonControl : public Control {
Vec2f draw(Vec2f pos);
void onMouseDown(MouseEvent event);
void onMouseUp(MouseEvent event);
void onTouchBegan(TouchEvent::Touch touch);
void onTouchEnded(TouchEvent::Touch touch);

//! Registers a callback for Click events. Returns a unique identifier which can be used as a parameter to unregisterClick().
CallbackId registerClick( std::function<bool (MouseEvent)> callback ) { return callbacksClick.registerCb( callback ); }
Expand Down
Binary file added SimpleGUI/samples/Basic/resources/Icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 14 additions & 3 deletions SimpleGUI/samples/Basic/src/BasicApp.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "cinder/app/AppBasic.h"
#include "cinder/app/AppNative.h"
#include "SimpleGUI.h"
#include <list>
using namespace ci;
Expand All @@ -9,7 +9,7 @@ using namespace mowa::sgui;
#define RENDER_TYPE_GROUP 1
#define CONFIG_FILE "settings.sgui.txt"

class BasicApp : public AppBasic {
class BasicApp : public AppNative {
private:
SimpleGUI* gui;
float rotation;
Expand All @@ -23,6 +23,9 @@ class BasicApp : public AppBasic {
float prevTime;

public:
#if defined( CINDER_GLES )
void prepareSettings( Settings *settings );
#endif
void mouseDown( MouseEvent event );
void mouseDrag( MouseEvent event );
void mouseUp( MouseEvent event );
Expand All @@ -31,6 +34,14 @@ class BasicApp : public AppBasic {
void setup();
};

#if defined( CINDER_GLES )
void BasicApp::prepareSettings( Settings *settings )
{
// use MouseEvent simulation on iOS:
settings->enableMultiTouch(false);
}
#endif

void BasicApp::setup() {
gui = new SimpleGUI(this);
gui->lightColor = ColorA(1, 1, 0, 1);
Expand Down Expand Up @@ -115,4 +126,4 @@ void BasicApp::draw() {
}


CINDER_APP_BASIC( BasicApp, RendererGl )
CINDER_APP_NATIVE( BasicApp, RendererGl(0) )
2 changes: 2 additions & 0 deletions SimpleGUI/samples/Basic/xcode/Basic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@
C01FCF4B08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CINDER_PATH = ../../../../..;
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_FIX_AND_CONTINUE = YES;
Expand All @@ -286,6 +287,7 @@
C01FCF4C08A954540054247B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CINDER_PATH = ../../../../..;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_FAST_MATH = YES;
Expand Down
32 changes: 32 additions & 0 deletions SimpleGUI/samples/Basic/xcode_iOS/Basic-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string>Icon.png</string>
<key>CFBundleIdentifier</key>
<string>org.libcinder.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSMainNibFile</key>
<string></string>
<key>UIStatusBarHidden</key>
<true/>
</dict>
</plist>
Loading