GUI之CCControlExtension

时间:2023-01-08 13:24:59

Introduction

CCControl is inspired by the UIControl API class from the UIKit library of CocoaTouch. It provides a base class for Cocos2D control such as CCControlButton or CCControlSlider that convey user intent(用户意图) to the application.

The goal of CCControl is to define an interface and a base implementation for preparing action messages and initially dispatching them to their targets when certain events occur.

To use the CCControl class you have to subclass it and implement your own behavior.

How to use them

CCScale9Sprite

9-slice scaling(九切片) allows you to specify how scaling is applied to specific areas of a sprite. With 9-slice scaling (3x3 grid), you can ensure that the sprite does not become distorted(变形) when scaled.

This class allows you to define a cap insets which define the portions of the sprite that should not be stretched. For example if you have rounded corners for a button or a popup on the edges, you can specify that the corners must  not be stretched. The diagram below can help you to visualize how the image is cut:
GUI之CCControlExtension

 

The cap inset describes a rectangle (in the most case the center region) which cuts the sprite into a grid of 3 * 3, which allows the class to know which portions can be stretched or not. In this example, we have defined the cap      insets in such a way that the corners must not be resized. The left and right sides will resize the height only while the top and bottom sides will resize only the length, and the center will stretch the height and the length.

As you can imagine this technique is very useful when you need to dynamically resize elements like popups or buttons. Indeed, here we don’t know the size of the button’s title in advance, and this technique allows the button to fit   the background dynamically under the title.

Now that you know how CCScale9Sprite works, I’m going to show you how to create buttons with CCControlButton.

CCControlButton

Button control for Cocos2D. A button intercepts touch events and sends an action message to a target object when tapped. Methods for setting the target and action are inherited from CCControl.

GUI之CCControlExtension

Samlpe Code:

 1CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
2
3cocos2d::extension::CCScale9Sprite *backgroundButton = cocos2d::extension::CCScale9Sprite::create("button.png");
4cocos2d::extension::CCScale9Sprite *backgroundHighlightedButton = cocos2d::extension::CCScale9Sprite::create("buttonHighlighted.png");
5
6// Creates a button with this string as title
7CCLabelTTF *titleButton = CCLabelTTF::create("hello", "Marker Felt", 30);
8titleButton->setColor(ccc3(159, 168, 176));
9cocos2d::extension::CCControlButton *button = cocos2d::extension::CCControlButton::create(titleButton, backgroundButton);
10button->setBackgroundSpriteForState(backgroundHighlightedButton, cocos2d::extension::CCControlStateHighlighted);
11button->setTitleColorForState(ccWHITE, cocos2d::extension::CCControlStateHighlighted);
12button->setPosition(ccp (screenSize.width / 2, screenSize.height / 2));
13
14addChild(button);
CCControlColourPicker

Colour Picker control for Cocos2D. The color picker is a very useful control tool to preview and test color values.

GUI之CCControlExtension

CCControlPicker

The CCControlPicker class implements objects, called control pickers, that use a spinning-wheel or slot-machine metaphor to show one set of values. Users select values by rotating the wheels so that the desired row of values aligns with a selection indicator.

CCControlPickerRow

The CCControlPickerRow class implements the row node representation for the CCControlPicker.
A row node implements some methods and callbacks to make the CCControlPicker customization more easier.

CCControlPotentiometer

A CCControlPotentiometer object is a visual control used to select a single value in a circular motion from a continuous range of values. An indicator notes the current value of the potentiometer and can be moved by the user to change the setting.

GUI之CCControlExtension

CCControlSlider

A CCControlSlider object is a visual control used to select a single value from a continuous range of values. An indicator, or thumb, notes the current value of the slider and can be moved by the user to change the setting.

GUI之CCControlExtension

CCControlStepper

CCControlStepper is a stepper control which provides a user interface for incrementing or decrementing a value.

If you set stepper behavior to “autorepeat” (which is the default), pressing and holding one of its buttons increments or decrements the stepper’s value repeatedly. The rate of change depends on how long the user continues pressing the control.

GUI之CCControlExtension

CCControlSwitch

The CCControlSwitch class is useful to create and manage On/Off buttons, for example, in the option menus for volume:

GUI之CCControlExtension

The CCControlSwitch class declares a property and a method to control its on/off state. As with CCControlSlider, when the user manipulates the switch control (“flips” it) a CCControlEventValueChanged event is generated, which results in the control (if properly configured) sending an action message.

GUI之CCControlExtension的更多相关文章

  1. JAVA GUI编程学习笔记目录

    2014年暑假JAVA GUI编程学习笔记目录 1.JAVA之GUI编程概述 2.JAVA之GUI编程布局 3.JAVA之GUI编程Frame窗口 4.JAVA之GUI编程事件监听机制 5.JAVA之 ...

  2. 如何通过Git GUI将自己本地的项目上传至Github

    最近在学习node.js和react,顺便复习了下AngluarJS相关的东西,写了些小demo想放在GitHub上,之前仅限于只申请了GitHub账号从没用过,今天花半天时间查资料认真学习Githu ...

  3. git图像化界面GUI的使用

    GIT学习笔记 一.        基础内容 1.git是一个版本控制软件,与svn类似,特点是分布式管理,不需要中间总的服务器,可以增加很多分支. 2.windows下的git叫msysgit,下载 ...

  4. egret GUI 和 egret Wing 是我看到h5 最渣的设计

    一个抄袭FlexLite抄的连自己思想都没有,别人精髓都不懂的垃圾框架.也不学学MornUI,好歹有点自己想法. 先来个最小可用集合吧: 1. egret create legogame --type ...

  5. [C#] 走进异步编程的世界 - 在 GUI 中执行异步操作

    走进异步编程的世界 - 在 GUI 中执行异步操作 [博主]反骨仔 [原文地址]http://www.cnblogs.com/liqingwen/p/5877042.html 序 这是继<开始接 ...

  6. 1&period;JAVA之GUI编程概述

          下列内容为本人看毕向东老师java视频教程学习笔记! JAVA GUI图形用户界面编程: Windows 操作系统提供两种操作方式:                             ...

  7. 2&period;JAVA之GUI编程布局

    布局管理器 容器中的组件排放方式,就是布局 常见的布局管理器: **************************************************** 1.FlowLayout(流式 ...

  8. 3&period;JAVA之GUI编程Frame窗口

    创建图形化界面思路: 1.创建frame窗体: 2.对窗体进行基本设置: 比如大小.位置.布局 3.定义组件: 4.将组件通过add方法添加到窗体中: 5.让窗体显示,通过setVisible(tur ...

  9. 4&period;JAVA之GUI编程事件监听机制

    事件监听机制的特点: 1.事件源 2.事件 3.监听器 4.事件处理 事件源:就是awt包或者swing包中的那些图形用户界面组件.(如:按钮) 事件:每一个事件源都有自己特点有的对应事件和共性事件. ...

随机推荐

  1. mvn exec用法,运行jar后台驻留进程

    java工程如果打包成war,那依赖的jar包都会被包含进去. 不过如果开发java的后台驻留进程,那一般会打包成jar包的形式,要想在运行进程的时候找到所有的依赖包,基本有如下两种方式: 方式一: ...

  2. jsLint配置参数解释

    转自: http://www.cnblogs.com/elementstorm/archive/2013/04/10/3012679.htmlanon :true //匿名函数声明中function关 ...

  3. Vue&period;js学习 Item7 -- 条件渲染与列表渲染

    v-if 在字符串模板中,如 Handlebars,我们得像这样写一个条件块: <!-- Handlebars 模板 --> {{#if ok}} <h1>Yes</h1 ...

  4. Silverlight引用WebService时取消对ServiceReferences&period;ClientConfig文件的依赖

    做过Silverlight项目的朋友都知道一般来说我们在Silverlight项目中都需要引用WebService或是WCF,引用的方式是在Visual Studio窗口中通过“添加服务引用”来添加引 ...

  5. FSPageContentView这个库需要修改源码才能用,否则有黑屏bug

    去掉 - (instancetype)initWithFrame:(CGRect)frame childVCs:(NSArray *)childVCs parentVC:(UIViewControll ...

  6. 【转】Python标准模块--importlib

    [转]Python标准模块--importlib 作者:zhbzz2007 出处:http://www.cnblogs.com/zhbzz2007 欢迎转载,也请保留这段声明.谢谢! 1 模块简介 P ...

  7. java代码示例(4)

    /** * 需求分析:计算100以内的和,用while * @author chenyanlong * 日期:2017/10/14 */ package com.hp.test04; public c ...

  8. sqler sql 转rest api 数据校验的处理

    早期版本(2.0 之前)使用rules 进行数据校验处理,2.0 之后进行了修改使用 validators,这样更加明确 参考格式   addpost {    // if any rule retu ...

  9. BZOJ&period;4407&period;于神之怒加强版&lpar;莫比乌斯反演&rpar;

    题目链接 Description 求\[\sum_{i=1}^n\sum_{j=1}^m\gcd(i,j)^K\ \mod\ 10^9+7\] Solution 前面部分依旧套路. \[\begin{ ...

  10. struct的初始化

    1.struct的初始化可以使用类似数组的方式,如下:struct Student{ int _Age; string _Name;};Student stu = {26,"Andy&quo ...