forked from cocos2d/cocos2d-x
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add UIEditBox support linux platform.
- Loading branch information
Showing
9 changed files
with
310 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# - Try to find GTK3 | ||
# | ||
# $Id: FindGTK3.cmake 39970 2011-11-21 15:39:25Z jmayer $ | ||
# | ||
# Once done this will define | ||
# | ||
# GTK3_FOUND - System has GTK3 | ||
# GTK3_INCLUDE_DIRS - The GTK3 include directory | ||
# GTK3_LIBRARIES - The libraries needed to use GTK3 | ||
# GTK3_DEFINITIONS - Compiler switches required for using GTK3 | ||
#============================================================================= | ||
# Copyright 2011 Duncan Mac-Vicar P. <[email protected]> | ||
# | ||
# Distributed under the OSI-approved BSD License (the "License"); | ||
# see accompanying file COPYING-CMAKE-SCRIPTS for details. | ||
# | ||
# This software is distributed WITHOUT ANY WARRANTY; without even the | ||
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
# See the License for more information. | ||
#============================================================================= | ||
# (To distribute this file outside of CMake, substitute the full | ||
# License text for the above reference.) | ||
|
||
# use pkg-config to get the directories and then use these values | ||
# in the FIND_PATH() and FIND_LIBRARY() calls | ||
find_package(PkgConfig) | ||
pkg_check_modules(PC_GTK3 gtk+-3.0 QUIET) | ||
|
||
# MESSAGE(STATUS "PC_GTK3_LIBRARIES: ${PC_GTK3_LIBRARIES}") | ||
# MESSAGE(STATUS "PC_GTK3_LIBRARY_DIRS: ${PC_GTK3_LIBRARY_DIRS}") | ||
# MESSAGE(STATUS "PC_GTK3_LDFLAGS: ${PC_GTK3_LDFLAGS}") | ||
# MESSAGE(STATUS "PC_GTK3_LDFLAGS_OTHER: ${PC_GTK3_LDFLAGS_OTHER}") | ||
|
||
set(GTK3_DEFINITIONS ${PC_GTK3_CFLAGS_OTHER}) | ||
|
||
#FIND_PATH(GTK3_INCLUDE_DIR NAMES "gtk/gtk.h" | ||
# HINTS | ||
# ${PC_GTK3_INCLUDEDIR} | ||
# ${PC_GTK3_INCLUDE_DIRS} | ||
# PATH_SUFFIXES "gtk-3.0" | ||
# ) | ||
set(GTK3_INCLUDE_DIRS ${PC_GTK3_INCLUDE_DIRS}) | ||
|
||
#FIND_LIBRARY(GTK3_LIBRARIES NAMES gtk-3 gtk3 | ||
# HINTS | ||
# ${PC_GTK3_LIBDIR} | ||
# ${PC_GTK3_LIBRARY_DIRS} | ||
# ) | ||
set(GTK3_LIBRARIES ${PC_GTK3_LIBRARIES}) | ||
|
||
# handle the QUIETLY and REQUIRED arguments and set GTK3_FOUND to TRUE if | ||
# all listed variables are TRUE | ||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args(GTK3 DEFAULT_MSG GTK3_LIBRARIES GTK3_INCLUDE_DIRS) | ||
|
||
mark_as_advanced(GTK3_INCLUDE_DIRS GTK3_LIBRARIES) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/**************************************************************************** | ||
Copyright (c) 2010-2012 cocos2d-x.org | ||
Copyright (c) 2015 hanxi | ||
http://www.cocos2d-x.org | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
****************************************************************************/ | ||
|
||
#include "UIEditBoxImpl-linux.h" | ||
|
||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX) | ||
|
||
#include "UIEditBox.h" | ||
#include "2d/CCLabel.h" | ||
#include "base/ccUTF8.h" | ||
#include <gtk/gtk.h> | ||
|
||
// desoty dialog when lost focus | ||
static void dialogFocusOutCallback(GtkWidget* widget, gpointer user_data) | ||
{ | ||
gtk_widget_destroy(widget); | ||
} | ||
|
||
bool LinuxInputBox(std::string &entryLine) | ||
{ | ||
bool didChange = false; | ||
GtkWidget *dialog; | ||
GtkWidget *entry; | ||
GtkWidget *contentArea; | ||
|
||
gtk_init(0, NULL); | ||
dialog = gtk_dialog_new(); | ||
entry = gtk_entry_new(); | ||
contentArea = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); | ||
|
||
gtk_container_add(GTK_CONTAINER(contentArea), entry); | ||
gtk_dialog_add_button(GTK_DIALOG(dialog), "OK", 0); | ||
gtk_entry_set_text(GTK_ENTRY(entry), entryLine.c_str()); | ||
|
||
g_signal_connect(dialog, "focus-out-event", G_CALLBACK(dialogFocusOutCallback), NULL); | ||
gtk_window_set_keep_above(GTK_WINDOW(dialog), true); | ||
gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_MENU); | ||
gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); | ||
gtk_widget_show_all(dialog); | ||
|
||
gint result = gtk_dialog_run(GTK_DIALOG(dialog)); | ||
switch(result) | ||
{ | ||
case 0: | ||
entryLine = gtk_entry_get_text(GTK_ENTRY(entry)); | ||
didChange = true; | ||
break; | ||
default: | ||
// CCLOG("Undefined. Perhaps dialog was closed"); | ||
break; | ||
} | ||
|
||
gtk_widget_destroy(dialog); | ||
while (g_main_context_iteration(NULL, false)); | ||
return didChange; | ||
} | ||
|
||
NS_CC_BEGIN | ||
|
||
namespace ui { | ||
|
||
EditBoxImpl* __createSystemEditBox(EditBox* pEditBox) | ||
{ | ||
return new EditBoxImplLinux(pEditBox); | ||
} | ||
|
||
EditBoxImplLinux::EditBoxImplLinux(EditBox* pEditText) | ||
: EditBoxImplCommon(pEditText) | ||
{ | ||
|
||
} | ||
|
||
EditBoxImplLinux::~EditBoxImplLinux() | ||
{ | ||
|
||
} | ||
|
||
bool EditBoxImplLinux::isEditing() | ||
{ | ||
return false; | ||
} | ||
|
||
void EditBoxImplLinux::nativeOpenKeyboard() | ||
{ | ||
std::string text = this->getText(); | ||
bool didChange = LinuxInputBox(text); | ||
if (didChange) | ||
{ | ||
this->editBoxEditingDidEnd(text); | ||
} | ||
} | ||
|
||
} | ||
|
||
NS_CC_END | ||
|
||
#endif /* #if (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX) */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/**************************************************************************** | ||
Copyright (c) 2010-2012 cocos2d-x.org | ||
Copyright (c) 2015 hanxi | ||
http://www.cocos2d-x.org | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
****************************************************************************/ | ||
|
||
#ifndef __UIEDITBOXIMPLLINUX_H__ | ||
#define __UIEDITBOXIMPLLINUX_H__ | ||
|
||
#include "platform/CCPlatformConfig.h" | ||
|
||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX) | ||
|
||
#include "UIEditBoxImpl-common.h" | ||
|
||
NS_CC_BEGIN | ||
|
||
class Label; | ||
|
||
namespace ui { | ||
|
||
class EditBox; | ||
|
||
class EditBoxImplLinux: public EditBoxImplCommon | ||
{ | ||
public: | ||
/** | ||
* @js NA | ||
*/ | ||
EditBoxImplLinux(EditBox* pEditText); | ||
/** | ||
* @js NA | ||
* @lua NA | ||
*/ | ||
virtual ~EditBoxImplLinux(); | ||
|
||
|
||
virtual bool isEditing() override; | ||
virtual void createNativeControl(const Rect& frame) override {}; | ||
virtual void setNativeFont(const char* pFontName, int fontSize) override {}; | ||
virtual void setNativeFontColor(const Color4B& color) override {}; | ||
virtual void setNativePlaceholderFont(const char* pFontName, int fontSize) override {}; | ||
virtual void setNativePlaceholderFontColor(const Color4B& color) override {}; | ||
virtual void setNativeInputMode(EditBox::InputMode inputMode) override {}; | ||
virtual void setNativeInputFlag(EditBox::InputFlag inputFlag) override {}; | ||
virtual void setNativeReturnType(EditBox::KeyboardReturnType returnType)override {}; | ||
virtual void setNativeText(const char* pText) override {}; | ||
virtual void setNativePlaceHolder(const char* pText) override {}; | ||
virtual void setNativeVisible(bool visible) override {}; | ||
virtual void updateNativeFrame(const Rect& rect) override {}; | ||
virtual void setNativeContentSize(const Size& size) override {}; | ||
virtual const char* getNativeDefaultFontName() override {}; | ||
virtual void nativeOpenKeyboard() override; | ||
virtual void nativeCloseKeyboard() override {}; | ||
virtual void setNativeMaxLength(int maxLength) {}; | ||
|
||
|
||
private: | ||
virtual void doAnimationWhenKeyboardMove(float duration, float distance)override {} | ||
}; | ||
|
||
|
||
} | ||
|
||
|
||
NS_CC_END | ||
|
||
#endif /* #if (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX) */ | ||
|
||
#endif /* __UIEDITBOXIMPLLINUX_H__ */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
local TextInput = {} | ||
|
||
function TextInput.create() | ||
cclog("TextInput.create") | ||
local layer = cc.Layer:create() | ||
Helper.initWithLayer(layer) | ||
TextInput.layer = layer | ||
|
||
local res = "Images/CyanSquare.png" | ||
local width = 200 | ||
local height = 40 | ||
local back = cc.Scale9Sprite:create(res) | ||
local edit = ccui.EditBox:create(cc.size(width,height),res) | ||
layer:addChild(edit) | ||
edit:setPosition( cc.p(250,200) ) | ||
edit:setPlaceHolder("click to input text") | ||
|
||
local editPasswd = ccui.EditBox:create(cc.size(width,height),res) | ||
editPasswd:setInputFlag(cc.EDITBOX_INPUT_FLAG_PASSWORD) | ||
layer:addChild(editPasswd) | ||
editPasswd:setPosition( cc.p(250,100) ) | ||
editPasswd:setPlaceHolder("click to input password") | ||
return layer | ||
end | ||
|
||
function TextInputTestMain() | ||
cclog("TextInputTestMain") | ||
local scene = cc.Scene:create() | ||
Helper.createFunctionTable = { | ||
TextInput.create, | ||
} | ||
scene:addChild(TextInput.create()) | ||
scene:addChild(CreateBackMenuItem()) | ||
return scene | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters