commit e3a05cb1bc0182f5749f0866c8d9570d090ee552 Author: sojamo Date: Tue Jul 22 14:12:30 2014 +0800 moving repository from google code to github. diff --git a/.buildpath b/.buildpath new file mode 100644 index 0000000..5fc1f8e --- /dev/null +++ b/.buildpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..c00c3d4 --- /dev/null +++ b/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.externalToolBuilders/cp5-build.launch b/.externalToolBuilders/cp5-build.launch new file mode 100644 index 0000000..b444e7c --- /dev/null +++ b/.externalToolBuilders/cp5-build.launch @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9d82a80 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/bin/ +/distribution/src/ +/distribution/tmp/ +/distribution/web/ +/src-js/ +.svn/ diff --git a/.project b/.project new file mode 100644 index 0000000..f480853 --- /dev/null +++ b/.project @@ -0,0 +1,33 @@ + + + controlp5 + + + + + + org.eclipse.vjet.eclipse.core.builder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.ui.externaltools.ExternalToolBuilder + auto,full,incremental, + + + LaunchConfigHandle + <project>/.externalToolBuilders/cp5-build.launch + + + + + + org.eclipse.vjet.core.nature + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..a3e53a2 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,291 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.formatter.align_type_members_on_columns=false +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_assignment=0 +org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 +org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 +org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0 +org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 +org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0 +org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 +org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=0 +org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=0 +org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80 +org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16 +org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=0 +org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=0 +org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=0 +org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=0 +org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16 +org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 +org.eclipse.jdt.core.formatter.blank_lines_after_package=1 +org.eclipse.jdt.core.formatter.blank_lines_before_field=0 +org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 +org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 +org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 +org.eclipse.jdt.core.formatter.blank_lines_before_method=1 +org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 +org.eclipse.jdt.core.formatter.blank_lines_before_package=0 +org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1 +org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1 +org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false +org.eclipse.jdt.core.formatter.comment.format_block_comments=true +org.eclipse.jdt.core.formatter.comment.format_header=true +org.eclipse.jdt.core.formatter.comment.format_html=true +org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=false +org.eclipse.jdt.core.formatter.comment.format_line_comments=false +org.eclipse.jdt.core.formatter.comment.format_source_code=true +org.eclipse.jdt.core.formatter.comment.indent_parameter_description=false +org.eclipse.jdt.core.formatter.comment.indent_root_tags=true +org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert +org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert +org.eclipse.jdt.core.formatter.comment.line_length=140 +org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=false +org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true +org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=true +org.eclipse.jdt.core.formatter.compact_else_if=true +org.eclipse.jdt.core.formatter.continuation_indentation=2 +org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 +org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off +org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on +org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false +org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true +org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true +org.eclipse.jdt.core.formatter.indent_empty_lines=false +org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true +org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true +org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true +org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false +org.eclipse.jdt.core.formatter.indentation.size=4 +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert +org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=insert +org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert +org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert +org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert +org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert +org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert +org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=insert +org.eclipse.jdt.core.formatter.join_lines_in_comments=false +org.eclipse.jdt.core.formatter.join_wrapped_lines=true +org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false +org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false +org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false +org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false +org.eclipse.jdt.core.formatter.lineSplit=250 +org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false +org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false +org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 +org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 +org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true +org.eclipse.jdt.core.formatter.tabulation.char=tab +org.eclipse.jdt.core.formatter.tabulation.size=2 +org.eclipse.jdt.core.formatter.use_on_off_tags=false +org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=true +org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true +org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true +org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true diff --git a/.settings/org.eclipse.jdt.ui.prefs b/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 0000000..f41123e --- /dev/null +++ b/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +formatter_profile=_sojamo +formatter_settings_version=12 diff --git a/.settings/org.eclipse.vjet.eclipse.core.prefs b/.settings/org.eclipse.vjet.eclipse.core.prefs new file mode 100644 index 0000000..6e8a644 --- /dev/null +++ b/.settings/org.eclipse.vjet.eclipse.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +initialized_project_from_v4classpath=true diff --git a/README.md b/README.md new file mode 100644 index 0000000..9a2d88f --- /dev/null +++ b/README.md @@ -0,0 +1,67 @@ +# ControlP5 + +ControlP5 is a library written by Andreas Schlegel for the programming environment [processing](http://www.processing.org). ControlP5 is a GUI and controller library for processing that can be used in authoring, application mode. + +The range of available controllers includes Slider, Button, Toggle, Knob, Textfield, RadioButton, Checkbox, Lists amongst others. These controllers can be easily added to a processing sketch, or displayed inside a separate control window. They can be organized in tabs or groups as well as rendered into PGraphics buffers. The state of a controller can be saved to file in JSON format. + + +## Getting Started + +To get started, a simple example that will create a slider and automatically link its value to variable v1. + +```java + + import controlP5.*; + + ControlP5 cp5; + int v1; + + void setup() { + size(400,400); + noStroke(); + cp5 = new ControlP5(this); + cp5.addSlider("v1") + .setPosition(40,40) + .setSize(200,20) + .setRange(100,300) + .setValue(250) + .setColorCaptionLabel(0xff111111); + } + + void draw() { + background(0xffdddddd); + pushMatrix(); + fill(0xffffdc00); + rect(v1,100,60,200); + fill(0xff01ff70); + rect(40,v1,320,40); + translate(200,200); + rotate(map(v1,100,300,-PI,PI)); + fill(0xff39cccc); + rect(0,0,100,100); + popMatrix(); + } +``` + + + +## History + +ControlP5 is a project that started in 2006 as a very simple UI for controlling Processing parameters for better debugging, testing and interaction purposes. Starting from only 3 controllers its controller base has grown up to around 30 controllers and over 70 examples. A history of controlP5 versions is available at [google code downloads](https://code.google.com/p/controlp5/downloads/list?can=1&q=&colspec=Filename+Summary+Uploaded+ReleaseDate+Size+DownloadCount). This library has been widely used by processing user in academic, research and professional environments for prototyping and tool development. + + +### Why is controlP5's source code so convoluted and bloated + +ControlP5 has been in development for over 9 years and started as a small GUI library for Processing. Over the years both Processing and ControlP5 have grown substantially and as part of that journey many changes have been applied to both. From a ControlP5 perspective some changes were due to changes made to Processing's API and source code, other changes were due to additional controller implementations, extended functionality, user feedback and reuqests. Since writing controlP5 from scratch was a learning process for myself in itself, a proper initial strategy for the software architecture of the library was missing. When it became apparent that a proper architecture would have made the development much easier and comfortable it was already too late, I had to comply to the piles of code I had created. Would I do things differently now? yes I would. + + +## Font rendering + +Why is the bit-font so blurry? it used to be crisp. Let me blame this on the OpenGL texture rendering. If you have a suggestion or a simple and easy to implement solution, please let me know inside the issues section. + + + +## Javascript + +Currently there is no javascript version of ControlP5, though I had started implementing a slimmed down version for processing.js but since it is currently unclear which javascript version - processing.js or p5.js - will become the default js version of processing, controlP5.js is on hold. There is a tendency that p5.js will become the primary javascript environment + diff --git a/distribution/library/controlP5.jar b/distribution/library/controlP5.jar new file mode 100644 index 0000000..46ca82d Binary files /dev/null and b/distribution/library/controlP5.jar differ diff --git a/distribution/library/controlP5.js b/distribution/library/controlP5.js new file mode 100644 index 0000000..e2edb02 --- /dev/null +++ b/distribution/library/controlP5.js @@ -0,0 +1,1159 @@ + +(function(){ + + var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/; + // The base Class implementation (does nothing) + this.Class = function(){}; + // Create a new Class that inherits from this class + Class.extend = function(prop) { + var _super = this.prototype; + // Instantiate a base class (but only create the instance, + // don't run the init constructor) + initializing = true; + var prototype = new this(); + initializing = false; + // Copy the properties over onto the new prototype + for (var name in prop) { + // Check if we're overwriting an existing function + prototype[name] = typeof prop[name] == "function" && + typeof _super[name] == "function" && fnTest.test(prop[name]) ? + (function(name, fn){ + return function() { + var tmp = this._super; + // Add a new ._super() method that is the same method + // but on the super-class + this._super = _super[name]; + // The method only need to be bound temporarily, so we + // remove it when we're done executing + var ret = fn.apply(this, arguments); + this._super = tmp; + return ret; + }; + })(name, prop[name]) : + prop[name]; + } + + // The dummy class constructor + function Class() { + // All construction is actually done in the init method + if ( !initializing && this.init ) + this.init.apply(this, arguments); + } + + // Populate our constructed prototype object + Class.prototype = prototype; + + // Enforce the constructor to be what we expect + Class.prototype.constructor = Class; + + // And make this class extendable + Class.extend = arguments.callee; + return Class; + }; + })(); + +if(!C) { + + var C = (function() { + + var cp5; + + + // this is taken from processing.js + // ------------------------------------- + var stylePaddingLeft, stylePaddingTop, styleBorderLeft, styleBorderTop; + + var setStyleValues = function ( curElement ) { + if ( document.defaultView && document.defaultView.getComputedStyle ) { + var style = document.defaultView.getComputedStyle(curElement, null); + stylePaddingLeft = parseInt( style['paddingLeft'], 10 ) || 0; + stylePaddingTop = parseInt( style['paddingTop'], 10 ) || 0; + styleBorderLeft = parseInt( style['borderLeftWidth'], 10 ) || 0; + styleBorderTop = parseInt( style['borderTopWidth'], 10 ) || 0; + } + } + + function calculateOffset(curElement, event) { + + var element = curElement , offsetX = 0 , offsetY = 0; + + // Find element offset + if (element.offsetParent) { + do { + offsetX += element.offsetLeft; + offsetY += element.offsetTop; + } while (!!(element = element.offsetParent)); + } + + // Find Scroll offset + element = curElement; + do { + offsetX -= element.scrollLeft || 0; + offsetY -= element.scrollTop || 0; + } while (!!(element = element.parentNode)); + + // Add padding and border style widths to offset + offsetX += stylePaddingLeft; + offsetY += stylePaddingTop; + + offsetX += styleBorderLeft; + offsetY += styleBorderTop; + + // Take into account any scrolling done + offsetX += window.pageXOffset; + offsetY += window.pageYOffset; + + return {X:offsetX, Y:offsetY}; + } + // ------------------------------------- + + + var addEventListenerImpl = function( target, event, callback ) { + if ( 'addEventListener' in target ) { + target.addEventListener( event, callback ); + } else { + var originalEvent = target["on"+event]; + target["on"+event] = function ( evt ) { + var bubble = callback.apply( evt.target, [evt] ); + if ( originalEvent ) originalEvent.apply( target, [evt] ); + return bubble; + }; + } + }; + + var opts; + + var C = function() { + + opts = arguments[ 0 ]; + + this.target = opts.target; + + setStyleValues( this.target ); + + this.pointer = { x: 0 , y: 0 , px: 0 , py: 0 , dx: 0 , dy: 0 }; + + this.controllers = []; /* all controllers including groups */ + + this.root = new Root(); + + this.fontsize = 10; + + this.papplet = opts.papplet; + + this.font = this.papplet.createFont( "" , this.fontsize ); + + this.target.addEventListener('mousewheel',function(event){ + event.preventDefault(); + return false; + }, false); + + if ( this.papplet && 'draw' in this.papplet ) { + var drawStored = this.papplet.draw; + this.papplet.draw = (function( ia , pa , ds ){ + return function(){ + ia.preDraw( pa ); + ds.apply( pa ); + ia.postDraw( pa ); + }; + })( this , this.papplet , drawStored ); + } + + var events = [ + "mousemove", "mousedown", "mouseup", "click", "dblclick", + "mouseover", "mouseout", "mouseenter", "mouseleave", "mousewheel", + "DOMMouseScroll", "keydown" , "keyup", "keypress" + ]; + + var eventDests = { + "mousemove": "mouseMoved", + "mousedown": "mousePressed", + "dblclick": "mouseDoubleClicked", + "mouseup": "mouseReleased", + "mousewheel": "mouseScrolled", + "DOMMouseScroll": "mouseScrolled", + "keypress": "keyPressed", + "keydown": "keyDown", + "keyup": "keyReleased" + }; + + for ( var e in events ) { + + (function( control , target , event , m ){ + + addEventListenerImpl( target , event , function( evt ) { + + var offset = calculateOffset( target, evt ); + + control.pointer.px = control.pointer.x ; control.pointer.py = control.pointer.y ; + + control.pointer.x = evt.pageX - offset.X ; control.pointer.y = evt.pageY - offset.Y ; + + control.pointer.dx = control.pointer.x - control.pointer.px ; control.pointer.dy = control.pointer.y - control.pointer.py ; + + var collection = [ ]; + + traverse( collection , control.root.children , 0 , 0 , control.pointer.x , control.pointer.y ); + + /* TODO + * when mouse is dragged outside of a controller and passes through another controller, this controller gets activated. + * to avoid this behavior, only register the dragged controller when traversing and ignore all others. + */ + + if(evt instanceof KeyboardEvent) { + /* key events */ + for(c in control.controllers) { + if ( m in control.controllers[ c ] ) { + control.controllers[ c ][ m ]( evt ); + } + } + } else if (evt instanceof MouseEvent){ + /* mouse events */ + //for(item in collection) { + if(collection.length > 0) { + var item = collection.pop(); + var c = item.controller.name; + if ( m in control.controllers[ c ] ) { + var pointer = { type: m, + ax: control.pointer.x , + ay: control.pointer.y , + apx: control.pointer.px , + apy: control.pointer.py , + rx: item.x , + ry: item.y , + dx: control.pointer.dx , + dy: control.pointer.dy + } + + control.controllers[ c ][ m ]( pointer ); + control.controllers[ c ]['callback'].map( function( item ) { if(m==item.ev) { item.fn( pointer )} } ); + collection = []; + } + + if (evt instanceof WheelEvent) { /* Chrome */ + /* http://phrogz.net/JS/wheeldelta.html */ + console.log( "mouseWheel event detected (1) : " + evt +" / "+ c ); + } + } + //} + + } else { + if (evt instanceof WheelEvent) { /* Safari */ + /* http://phrogz.net/JS/wheeldelta.html */ + if(collection.length > 0 ) { + var item = collection.pop(); + var c = item.controller.name; + console.log( "mouseWheel event detected (2) : " + evt +" / "+c); + } + } + } + // else if (evt instanceof TouchEvent){ + // /* tbd, does cause a breakpoint in Safari */ + // } + }); + })( this , this.target , events[ e ] , eventDests[ events[ e ] ] ); + } + + var inside = function( mx , my , x0 , y0 , x1 , y1 ) { return ( mx > x0 && mx < x1 && my > y0 && my < y1 ); } + + var traverse = function( col , a , x0 , y0 , mx , my ) { + for(c in a) { + var x = x0 + a[ c ].x; + var y = y0 + a[ c ].y; + var b = ( !a[ c ].state.visible ) ? false : inside( mx , my , x , y + a[ c ].yoff , x + a[ c ].getWidth() , y + a[ c ].getHeight() ); + b = ( a[ c ].state.active ) ? true : b; + if( b ) { col.push( { controller: a[ c ], x: mx - x, y: my - y } ) }; + if(a[ c ].state.open ) { traverse( col , a[ c ].children , x , y , mx , my ); } + } + } + + + this.add = function( c ) { + this.controllers[ c.name ] = c ; + c.parent = this.root; + this.root.children.push( c ); + return c; + } + + this.remove = function( c ) { + c.parent.remove( c ); + this.controllers.splice( this.controllers.indexOf( c ) , 1 ); + return this; + } + + this.draw = function ( papplet ) { } + this.preDraw = function ( papplet ) { } + this.postDraw = function ( papplet ) { papplet.textFont( this.font ); this.root.draw( papplet ); } + } + + C.papplet = function ( ) { return cp5.papplet; } + C.font = function ( ) { return cp5.font; } + C.pointer = function ( c ) { return cp5.pointer; } + C.add = function ( c ) { return cp5.add( c ); } + C.get = function ( c ) { return cp5.controllers[ c ]; } + + C.remove = function ( c ) { return cp5.remove( c ); } + C.test = function ( m , v ) { var target = opts.papplet; C.invoke( target , m , v ); } + C.event = function ( ev ) { var target = opts.papplet; var method = 'controlEvent'; C.invoke( target , method , ev ) ; } + C.make = function ( t ) { cp5 = new C({ target: t.externals.canvas, papplet: t }); } + C.invoke = function ( target , method , event ) { + if( ! ( target == undefined ) ) { + if ( ! ( target[method] == undefined ) ) { + if(event==undefined) { + target[method]( ); + } else { + target[method](event); + } + } + } + } + + return C; +})(); + + + var CENTER = 3 + var LEFT = 37 + var RIGHT = 39 + var TOP = 101 + var BOTTOM = 102 + var BASELINE = 0 + var UP = 38 + var DOWN = 40 + var LEFT_OUTSIDE = 10 + var RIGHT_OUTSIDE = 11 + var TOP_OUTSIDE = 12 + var BOTTOM_OUTSIDE = 13 + + var clip = function ( theValue , theMin , theMax ) { return theValue < theMin ? theMin : ( theValue > theMax ? theMax : theValue ); } + var norm = function ( theValue , theStart , theStop ) { return ( theValue - theStart ) / ( theStop - theStart ); } + var map = function ( theValue ,theStart0 , theStop0 , theStart1 , theStop1 ) { return theStart1 + ( theStop1 - theStart1 ) * ( ( theValue - theStart0 ) / ( theStop0 - theStart0 ) ); } + var constrain = function ( theValue , theStart0 , theStop0 , theStart1 , theStop1 ) { return clip( map( theValue , theStart0 , theStop0 , theStart1 , theStop1 ) , theStart1 , theStop1 ); } + var remove = function ( theArray , theItem ) { if( theArray.indexOf( theItem ) > -1 ) { theArray.splice(theArray.indexOf( theItem ) , 1 ); } } + var add = function ( theArray , theItem ) { theArray.push( theItem ); } + + /* Root */ + + var Root = Class.extend({ + children: [ ] + , x: 0 + , y: 0 + , draw: function ( p ) { p.pushStyle(); for ( var c in this.children ) { this.children[ c ].draw( p ); }; p.popStyle(); } + , remove: function ( elem ) { this.children.splice( this.children.indexOf( elem ) , 1 ); } + }); + + + /* ControlListener */ + var ControlListener = Class.extend({ + controlEvent: function( l ) { } + }); + + + /* ControlView */ + var ControllerView = Class.extend({ + display: function( p , c ) { } + }); + + /* Label */ + var Label = Class.extend({ + alignX: LEFT + , alignY: CENTER + , text: "" + , x: 0 + , y: 0 + , init: function( theIndex ) { this.margin = {top:0, right:0, bottom:0, left:0 } } + , align: function( x , y ) { this.alignX = x; this.alignY = y; return this; } + , set: function( s ) { this.setText( s ); return this; } + , setText: function( s ) { this.text = s; return this; } + , getText: function( s ) { return this.text; } + , setMargin: function( which , value ) { this.margin[which] = value; console.log(this.margin); return this; } + , draw: function( p , c ) { + + var x = 0 + var ax = this.alignX + switch(this.alignX) { + case(CENTER) : x = c.getWidth() / 2; break; + case(RIGHT_OUTSIDE) : ax = LEFT; x = c.getWidth() + this.margin.left; break; + case(RIGHT) : x = c.getWidth() - this.margin.right; break; + case(LEFT_OUTSIDE) : ax = RIGHT; x = - this.margin.right; break; + case(LEFT) : x = this.margin.left; break; + } + + var y = 0; + var ay = this.alignY; + switch(this.alignY) { + case(CENTER) : y = c.getHeight() / 2; break; + case(BOTTOM_OUTSIDE) : ay = TOP; y = c.getHeight() + this.margin.bottom; break; + case(BOTTOM) : y = c.getHeight() - this.margin.bottom; break; + case(TOP_OUTSIDE) : ay = BOTTOM; y = this.margin.top; break; + case(TOP) : y = this.margin.top; break; + } + + + txtalign( p , this.getText() , x , y , ax , ay ); + } + }); + + /* Controller */ + var Controller = Class.extend({ + init: function( theIndex ) { + this.view = new ControllerView(); + this.event = { }; + this.x = 0; + this.y = 0; + this.yoff = 0; /* necessary for groups, the group's bar is in the negative for the y position */ + this.value = 0; + this.name = theIndex; + this.label = theIndex; + this.decimalPrecision = 1 + this.valueLabel = new Label().set( theIndex ) + this.captionLabel = new Label().set( theIndex ) + this.state = { broadcast: true + , inside: false + , visible: true + , active: false + , pressed: false + , dragged: false + , open: true + } + + this.color = { colorBackground: 0xff003652 + , colorForeground: 0xff009bd7 + , colorActive: 0xff00c5ff + , colorCaptionLabel: 0xffffffff + , colorValueLabel: 0xffffffff + } + + this.event = { onLeave: function( c , pointer ) { } + , onEnter: function( c , pointer ) { } + , onMove: function( c , pointer ) { } + , onStartDrag: function( c , pointer ) { } + , onDrag: function( c , pointer ) { } + , onEndDrag: function( c , pointer ) { } + , onPress: function( c , pointer ) { } + , onRelease: function( c , pointer ) { } + , onReleaseOutside: function( c , pointer ) { } + , onWheel: function( c , pointer ) { } + } + + this.callback = [ ]; + + this.listeners = [ ]; + + this.children = [ ]; + + this.parent = undefined; + + this.id = -1; + + this.setup( ); + + } + + , draw: function( p ) { + if(this.state.visible) { + p.pushMatrix( ); + p.pushStyle(); + p.translate( this.x , this.y ); + this.view.display( p , this ); + if(this.state.open) { + for( var c in this.children ) { this.children[ c ].draw( p ); } + } + p.popStyle(); + p.popMatrix( ); + } + } + , broadcast: function ( ) { + if( this.state.broadcast ) { + var ev = new ControlEvent( this ); + C.event( ev ); + C.test( this.getName() , this.getValue() ); + this.listeners.map( function( item ) { C.invoke( item , 'controlEvent' , ev ) } ); + } + } + , addCallback: function ( c , ev , fn ) { this.callback.push( {'c':c , 'ev':ev , 'fn':fn } ); return this; } + , addListener: function( l ) { add( this.listeners , l ); return this; } + , removeListener: function( l ) { remove( this.listeners , l ); return this; } + , setup: function ( ) { } + , setPosition: function ( theX , theY ) { this.x = theX; this.y = theY; return this; } + , setSize: function ( theW , theH ) { this.setWidth( theW ); this.setHeight( theH ); return this; } + , setWidth: function ( theW ) { this.width = theW; return this; } + , setHeight: function ( theH ) { this.height = theH; return this; } + , setCaptionLabel: function ( theString ) { this.label = theString; return this; } + , inside: function ( theX0 , theY0 ) { return (theX0 >= 0 && theX0 <= ( this.getWidth( ) ) && theY0 >= 0 + this.yoff && theY0 <= ( this.getHeight( ) ) ) ; } + , setColorActive: function ( theCol ) { this.color.colorActive = theCol; return this; } + , setColorBackground: function ( theCol ) { this.color.colorBackground = theCol; return this;} + , setColorForeground: function ( theCol ) { this.color.colorForeground = theCol; return this; } + , setColorCaptionLabel: function ( theCol ) { this.color.colorCaptionLabel = theCol; return this; } + , setColorValueLabel: function ( theCol ) { this.color.colorValueLabel = theCol; return this; } + , getColor: function ( ) { return this.color; } + , getId: function ( ) { return this.id; } + , getName: function ( ) { return this.name; } + , getValue: function ( ) { return this.value; } + , getWidth: function ( ) { return this.width; } + , getHeight: function ( ) { return this.height; } + , getDecimalPrecision: function ( ) { return this.decimalPrecision; } + , getView: function ( ) { return this.view; } + , setValue: function ( val ) { this.value = val; return this; } + , setVisible: function ( b ) { this.state.visible = ( b == true ) ? true : false ; return this; } + , setDecimalPrecision: function ( i ) { this.decimalPrecision = i; } + , setId: function ( theId ) { this.id = theId; return this; } + , moveTo: function ( theParent ) { this.parent.remove( this ); this.parent = theParent; theParent.children.push( this ) ; return this; } + , remove: function ( theElement ) { this.children.splice(this.children.indexOf( theElement ), 1); } + , hide: function ( ) { this.state.visible = false; return this; } + , show: function ( ) { this.state.visible = true; return this; } + , setCaptionLabel: function ( theLabel ) { this.captionLabel.set( theLabel ); return this; } + , setBroadcast: function ( b ) { this.state.broadcast = (b === true) ? true : false; return this; } + , setView: function ( theView ) { this.view = theView; return this; } + , remove: function ( ) { C.remove( this ); } + , isVisible: function ( ) { return this.state.visible; } + , mousePressed: function ( pointer ) { this.event.onPress( this , pointer ); this.state.pressed = true ; } + , mouseReleased: function ( pointer ) { if( this.state.dragged ) { this.onEndDrag( pointer ) } else { this.event.onRelease( this , pointer ); }; if(!this.state.inside) { this.event.onReleaseOutside( this , pointer ); this.state.active = false; } this.state.dragged = false ; this.state.pressed = false ; } + , onDrag: function ( pointer ) { if( !this.state.dragged ) { this.onStartDrag( pointer ) }; this.event.onDrag( this , pointer ); this.state.dragged = true ; } + , onMove: function ( pointer ) { this.event.onMove( this , pointer ); } + , onStartDrag: function ( pointer ) { this.event.onStartDrag( this , pointer ); } + , onEndDrag: function ( pointer ) { this.event.onEndDrag( this , pointer ); } + , onEnter: function ( pointer ) { this.event.onEnter( this , pointer ); } + , onLeave: function ( pointer ) { this.event.onLeave( this , pointer ); } + , mouseMoved: function ( pointer ) { + this.state.inside = this.inside( pointer.rx , pointer.ry ); + this.onMove( pointer ); + if ( this.state.active && this.state.pressed ) { + this.onDrag( pointer ); + } else { + if ( this.state.active != this.state.inside ) { if ( this.state.active ) { this.onLeave( pointer ); } else { this.onEnter( pointer ); } } + this.state.active = this.state.inside; + } + } + , setImage: function( ) { console.log("setImage is not implemented for this controller."); } + , setView: function ( theView ) { return this; } + }); + + + /* Slider */ + var Slider = Controller.extend({ + normalized: 0 + , min: 0 + , max: 100 + , setup: function( ) { + + this.captionLabel.align( RIGHT_OUTSIDE , CENTER ).setMargin('left' , 4 ); + + this.valueLabel.align( LEFT , CENTER ).setMargin( 'left' , 4 ); + + this.view.display = function( p , c ) { + p.noStroke(); + p.fill( c.color.colorBackground ); + p.rect( 0 , 0 , c.getWidth( ) , c.getHeight( ) ); + p.noStroke(); + p.fill( c.state.inside | c.state.dragged ? c.color.colorActive : c.color.colorForeground ); + p.rect( 0 , 0 , c.getWidth( ) * c.normalized , c.getHeight( ) ); + p.fill( c.color.colorValueLabel ); + c.valueLabel.set( c.getValue().toFixed( c.getDecimalPrecision( ) ) ); + c.valueLabel.draw( p , c ); + p.fill( c.color.colorCaptionLabel ); + c.captionLabel.draw( p , c ); + } + + this.event['onPress'] = function( c , pointer ) { + c.normalized = constrain( pointer.rx, 0 , c.getWidth( ) , 0 , 1 ) ; + c.state.active = true ; + c.broadcast( ); + } + + this.event['onDrag'] = function( c , pointer ) { + c.normalized = constrain( pointer.rx , 0 , c.getWidth( ) , 0 , 1 ) ; + c.broadcast( ) ; + } + } + + , getValue: function ( ) { return map( this.normalized , 0 , 1 , this.min , this.max ) ; } + , setRange: function ( theMin , theMax ) { this.min = theMin ; this.max = theMax ; return this ; } + }); + + + /* Button */ + var Button = Controller.extend({ + + setup: function( ) { + + this.view.display = function( p , c ) { + p.noStroke( ); + p.fill( c.state.inside | c.state.dragged ? ( c.state.pressed | c.state.dragged ? c.color.colorActive : c.color.colorForeground ) : c.color.colorBackground ); + p.rect( 0 , 0 , c.getWidth( ) , c.getHeight( ) ); + + p.fill( c.color.colorCaptionLabel ); + txtalign( p , c.label.toUpperCase() , c.getWidth() / 2 , c.getHeight() / 2 , p.CENTER , p.CENTER ); + } + + this.event['onPress'] = function( c , pointer ) { c.broadcast( ); } + } + , setImage: function ( img ) { + this.setSize( img.width , img.height ); + this.view['image'] = function( p , c ) { if( c.getWidth( )==0 ) { c.setSize( img0.width , img0.height ); } p.image(img, 0 , 0); } + this.seq = [ 'image' ]; + + } + , setImages: function ( img0, img1, img2 ) { + this.setSize( img0.width , img0.height ); + this.view.display = function( p , c ) { + if( c.getWidth( )==0 ) { c.setSize( img0.width , img0.height ); } + if( c.state.active ) { if(c.state.pressed) { p.image( img2 , 0 , 0 ); } else { p.image( img1 , 0 , 0 ); } } else { p.image( img0 , 0 , 0 ); } + } + } + }); + + + /* Toggle */ + var Toggle = Button.extend({ + + setup: function( ) { + + this.value = 0; + + this.captionLabel.align( CENTER , CENTER ); + + this.view.display = function( p , c ) { + p.noStroke( ); + p.fill( ( c.getValue() == 0 ) ? c.state.inside ? c.color.colorForeground : c.color.colorBackground : c.color.colorActive ); + p.rect( 0 , 0 , c.getWidth( ) , c.getHeight( ) ); + + p.fill( c.color.colorCaptionLabel ); + c.captionLabel.draw( p , c ); + } + + this.event['onPress'] = function( c , pointer ) { + c.setValue( (c.getValue() == 0) ? 1 : 0 ) ; + c.broadcast( ); + } + } + }); + + + /* Bang */ + var Bang = Button.extend({ + + setup: function( ) { + + this.value = undefined; + + this.view.display = function( p , c ) { + p.noStroke( ); + p.fill( ( c.state.pressed ) ? c.color.colorActive : c.color.colorBackground ); + p.rect( 0 , 0 , c.getWidth( ) , c.getHeight( ) ); + + p.fill( c.color.colorCaptionLabel ); + txtalign(p, c.label , c.getWidth() / 2 , c.getHeight() / 2 , p.CENTER , p.CENTER ); + } + + this.event['onPress'] = function( c , pointer ) { + c.broadcast( ); + } + } + }); + + + /* Numberbox */ + var Numberbox = Controller.extend({ + min: -100 + , max: 100 + , setup: function( ) { + + this.value = 0; + + this.view.display = function( p , c ) { + p.noStroke( ); + p.fill( c.color.colorBackground ); + p.rect( 0 , 0 , c.getWidth( ) , c.getHeight( ) ); + p.fill( ( c.state.pressed ) ? c.color.colorActive : c.color.colorForeground ); + var h = c.getHeight() / 2; + p.triangle( 0 , h - 6 , 6 , h , 0 , h + 6 ); + + p.fill( c.color.colorValueLabel ); + c.valueLabel.set( c.getValue().toFixed( c.getDecimalPrecision( ) ) ); + c.valueLabel.draw( p , c ); + + p.fill( c.color.colorCaptionLabel ); + c.captionLabel.draw( p , c ); + } + + this.event['onPress'] = function( c , pointer ) { + c.broadcast( ); + } + + this.event['onDrag'] = function( c , pointer ) { + c.value += pointer.dy; + c.value = Math.min( c.max , Math.max( c.min , c.value ) ); + c.broadcast( ) ; + } + } + + , setRange: function ( theMin , theMax ) { this.min = theMin ; this.max = theMax ; return this ; } + }); + + + + /* Slider2D */ + var Slider2D = Controller.extend({ + cursorX: 0 + , cursorY: 0 + , cursorWidth: 10 + , cursorHeight: 10 + , isCrosshairs: true + , minX: 0 + , minY: 0 + , maxX: 100 + , maxY: 100 + , setup: function( ) { + + this.value = 0; + + this.view.display = function( p , c ) { + p.noStroke( ); + p.fill( c.color.colorBackground ); + p.rect( 0 , 0 , c.getWidth( ) , c.getHeight( ) ); + + p.noStroke( ); + p.fill( c.state.dragged ? c.color.colorActive : c.color.colorForeground ); + p.rect( c.cursorX , c.cursorY , c.cursorWidth , c.cursorHeight ); + + p.fill( c.color.colorValueLabel ); + c.valueLabel.set( c.getValue()['x'].toFixed( c.getDecimalPrecision( ) ) ); + c.valueLabel.draw( p , c ); + + p.fill( c.color.colorCaptionLabel ); + c.captionLabel.draw( p , c ); + } + + this.event['onPress'] = function( c , pointer ) { + //this.event['onDrag']( c, pointer ); + } + + this.event['onDrag'] = function( c , pointer ) { + c.cursorX = Math.max( 0, Math.min( pointer.rx , c.getWidth() - c.cursorWidth ) ); + c.cursorY = Math.max( 0, Math.min( pointer.ry , c.getHeight() - c.cursorHeight ) ); + c.broadcast( ) ; + } + } + , getValue: function( ) {return { 'x' : map( this.cursorX , 0 , this.getWidth()-this.cursorWidth , this.minX , this.maxX ) , 'y' : map( this.cursorY , 0 , this.getHeight()-this.cursorHeight , this.minY , this.maxY) }; } + , setRange: function( theMinX , theMaxX , theMinY , theMaxY ) { this.minX = theMinX ; this.maxX = theMaxX ; this.minY = theMinY ; this.maxY = theMaxY ; return this ; } + , setMinX: function( theMinX ) { this.minX = theMinX; return this; } + , setMinY: function( theMinY ) { this.minY = theMinY; return this; } + , setMaxX: function( theMaxX ) { this.maxX = theMaxX; return this; } + , setMaxY: function( theMaxY ) { this.maxY = theMaxY; return this; } + , getMinX: function( ) { return this.minX; } + , getMinY: function( ) { return this.minY; } + , getMaxX: function( ) { return this.maxX; } + , getMaxY: function( ) { return this.maxY; } + , getCursorX: function( ) { return this.cursorX; } + , getCursorY: function( ) { return this.cursorY; } + , getCursorWidth: function( ) { return this.cursorWidth; } + , getCursorHeight: function( ) { return this.cursorHeight; } + , disableCrosshair: function( ) { this.isCrosshairs = false; return this; } + , enableCrosshair: function( ) { this.isCrosshairs = true; return this; } + }); + + + + var Knob = Controller.extend({ + normalized: 0 + , min: 0 + , max: 100 + , startAngle: Math.PI / 2 + Math.PI * 0.25 + , angleRange: Math.PI + Math.PI / 2 + , setup: function( ) { + + this.view.display = function( p , c ) { + + p.noStroke( ); + p.ellipseMode(p.CENTER); + p.fill( c.color.colorBackground ); + p.ellipse( c.getWidth( ) / 2 , c.getHeight( ) / 2 , c.getWidth( ) , c.getHeight( ) ); + + p.fill( ( c.state.pressed ) ? c.color.colorActive : c.color.colorForeground ); + p.arc( c.getWidth( ) / 2 , c.getHeight( ) / 2 , c.getWidth( ) , c.getHeight( ) , c.startAngle , c.startAngle + c.angleRange * 0.01 ); + p.arc( c.getWidth( ) / 2 , c.getHeight( ) / 2 , c.getWidth( ) , c.getHeight( ) , c.startAngle , c.startAngle + map( c.normalized , 0 , 1 , 0 , c.angleRange ) ); + p.fill( c.color.colorBackground ); + p.ellipse( c.getWidth( ) / 2 , c.getHeight( ) / 2 , c.getWidth( ) * 0.75 , c.getHeight( ) * 0.75 ); + + p.fill( c.color.colorCaptionLabel ); + txtalign(p, c.getValue().toFixed( c.getDecimalPrecision( ) ) , c.getWidth() / 2 , c.getHeight() / 2 , p.CENTER , p.CENTER ); + + p.fill( c.color.colorValueLabel ); + txtalign(p, c.label , c.getWidth() / 2 , c.getHeight() + 2 , p.CENTER , p.TOP ); + } + + this.event['onPress'] = function( c , pointer ) { + c.normalized = constrain( pointer.rx, 0 , c.getWidth( ) , 0 , 1 ) ; + c.state.active = true ; + c.broadcast( ); + } + + this.event['onDrag'] = function( c , pointer ) { + c.normalized = constrain( pointer.rx , 0 , c.getWidth( ) , 0 , 1 ) ; + c.broadcast( ) ; + } + + } + , setRadius: function( theRadius ) { this.setSize( theRadius * 2 , theRadius * 2 ); return this; } + , getValue: function ( ) { return map( this.normalized , 0 , 1 , this.min , this.max ) ; } + , setRange: function ( theMin , theMax ) { this.min = theMin ; this.max = theMax ; return this ; } + }); + + + /* Listbox */ + + var ListBox = Controller.extend( { + + setup: function( ) { + + this.state.open = true; + this.barHeight = 20; + this.items = [ ]; + this.itemHeight = 30; + this.itemHover = -1; + this.itemIndex = 0; + this.itemRange = 6; + + + for(var i = 0 ; i<100;i++ ) { + this.items.push("item "+i); + } + + + + var listboxitem = function ( p , c , i ) { + p.fill( c.color.colorBackground , (i==c.itemHover ? 255 : 120 ) ); + p.rect( 0 , 0 , c.getWidth( ), c.itemHeight - 1 ); + p.fill( c.color.colorCaptionLabel ); + p.text( c.items[ i ] , 4 , 20 ); + } + + this.view.display = function( p , c ) { + + p.noStroke( ); + p.fill( c.color.colorBackground ); + p.rect( 0 , 0 , c.getWidth( ) , c.barHeight ); + + p.fill( c.color.colorForeground ); + p.pushMatrix(); + p.translate( c.getWidth( ) - 8 , c.barHeight / 2 -2 ); + if( c.state.open ) { p.triangle( -3 , 0 , 3 , 0 , 0 , 3 ); } else { p.triangle( -3 , 3 , 3 , 3 , 0 , 0 ); } + p.popMatrix(); + + p.fill( 255 ); + txt(p, c.label , 4 , 15 ); /* TODO */ + + if( c.state.open ) { + p.fill( c.color.colorBackground , 120 ); + p.rect( 0 , c.barHeight , c.width , c.getHeight( ) - c.barHeight ); + p.pushMatrix(); + p.translate( 0 , c.barHeight + 1 ); + for(var i = c.itemIndex; i < ( c.itemIndex + c.itemRange ) ; i++ ) { + listboxitem( p , c , i ); + p.translate( 0 , c.itemHeight ); + } + p.popMatrix( ); + } + + if(c.state.active && c.state.open) { + p.fill( c.color.colorForeground , 120 ); + p.pushMatrix(); + p.translate( c.width - 8 , c.barHeight + 4 ); + var len = 20; + var pos = Math.floor( map( c.itemIndex, 0, c.items.length, 0, c.getHeight( ) - c.barHeight - len ) ); + p.rect( 0 , pos , 4, len ); + p.popMatrix(); + } + } + + + this.event['onRelease'] = function( c , pointer ) { + var n = Math.floor( ( pointer.ry - c.barHeight ) / c.itemHeight ); + if( n == -1 ) { c.state.open = !c.state.open; c.height = c.state.open ? c.barHeight + c.itemRange * c.itemHeight : c.barHeight; } + c.setValue( c.itemIndex + n ); + c.broadcast( ); + } + + this.event['onDrag'] = function( c , pointer ) { + c.itemIndex += pointer.dy * 0.5; + c.itemIndex = Math.floor( Math.max( 0 , Math.min(c.itemIndex, c.items.length - c.itemRange ) ) ); + c.itemHover = -1; + } + + this.event['onLeave'] = function( c , pointer ) { c.itemHover = -1; } + + this.event['onEnter'] = this.event['onMove'] = this.event['onEndDrag'] = function( c , pointer ) { + var n = Math.floor( ( pointer.ry - c.barHeight ) / c.itemHeight ); + c.itemHover = c.itemIndex + n ; + } + + } + , setHeight: function( h ) { this.height = this.barHeight + this.itemRange * this.itemHeight; } + }); + + /* Textfield */ + + var Textfield = Controller.extend({ + + strindex : 0 + + , setup: function( ) { + + this.text = ""; + + this.strindex = 0; + + this.captionLabel.align(LEFT , BOTTOM_OUTSIDE).setMargin('left' , 0 ) + + this.valueLabel.setMargin('left' , 4 ).setMargin('right' , 4 ) + + this.view.display = function( p , c ) { + p.noStroke( ); + p.fill( c.state.active ? c.color.colorActive : c.color.colorForeground ); + p.rect( 0 , 0 , c.getWidth( ) , c.getHeight( ) ); + p.fill( c.color.colorBackground ); + p.rect( 1 , 1 , c.getWidth( ) - 2 , c.getHeight( ) - 2 ); + + p.fill( c.color.colorCaptionLabel ); + c.captionLabel.draw( p , c ); + + + var t = c.text; + n = 0; + + while(p.textWidth( t ) > ( c.getWidth() - ( c.valueLabel.margin.left + c.valueLabel.margin.right ) ) ) { + n++; t = t.substring(1, t.length); + } + + c.valueLabel.set( t ); + p.fill( c.color.colorValueLabel ); + c.valueLabel.draw( p , c ); + + } + + } + , keyPressed: function ( theKeyEvent ) { + if(this.state.active) { + switch(theKeyEvent.keyCode) { + case(13): this.broadcast(); this.text = ""; this.strindex = 0; break; + default: this.text += String.fromCharCode( theKeyEvent.charCode ); this.strindex++; break; + } + } + } + , keyDown: function ( theKeyEvent ) { + if(this.state.active) { + switch(theKeyEvent.keyCode) { + /* delete is not working in Safari */ + case(8): this.text = this.text.slice(0, Math.max( 0 , this.strindex-1 ) ) + this.text.slice(this.strindex, this.text.len); this.strindex--; this.strindex = Math.max( 0 , this.strindex); break; + case(37): this.strindex--; this.strindex = Math.max( 0 , this.strindex ); break; + case(39): this.strindex++; this.strindex = Math.min( this.text.length , this.strindex ); break; + } + } + } + , mouseMoved: function ( pointer ) { } + , mousePressed: function ( pointer ) { this.state.active = true ; this.state.pressed = true; } + , mouseReleased: function ( pointer ) { this.color.colorForeground = 0xff009bd7 ; this.state.active = this.inside( pointer.rx , pointer.ry ) ? this.state.active : false ; this.state.pressed = false ; } + + }); + + var CheckBox = Controller.extend({ + spacingRow: 1 + , spacingColumn: 1 + , itemsPerRow: -1 + , isMultipleChoice: false + , itemHeight: 9 + , itemWidth: 9 + , items: [ ] + , setup: function( ) { + + this.addItem( "a" , "b" ); + + } + , sayHello: function( ) { + console.log("hello.."); + } + , addItem: function( theName , theValue ) { + var target = this; + var t = C.add( new Toggle( this.name+"-"+theName ).setSize( this.itemWidth , this.itemHeight ).setPosition( 0 , 0 ) ).setCaptionLabel( theName ); + t.captionLabel.align( RIGHT_OUTSIDE , CENTER ).margin.left = 4; + t.addCallback( t , 'mouseReleased' , function( ev ) { target.sayHello(); } ); + t.moveTo( this ); + return this; + } + }); + + var Group = Controller.extend({ + + setup: function( ) { + + this.state.open = true; + + this.barHeight = 20; + + this.yoff = -this.barHeight; + + this.captionLabel.align( LEFT , TOP ).setMargin('left' , 4 ).setMargin( 'top' , -this.barHeight + 4 ); + + + this.view.display = function( p , c ) { + if( c.state.open ) { + p.fill(c.color.colorBackground , 100); + p.noStroke(); + p.rect(0 , 0 , c.getWidth() , c.getHeight() ); + } + + p.noStroke( ); + p.fill( c.color.colorBackground ); + p.rect( 0 , -c.barHeight , c.getWidth() , c.barHeight ); + + p.fill( c.color.colorForeground ); + p.pushMatrix(); + p.translate( c.width - 8 , -c.barHeight / 2 -2 ); + if( c.state.open ) { p.triangle( -3 , 0 , 3 , 0 , 0 , 3 ); } else { p.triangle( -3 , 3 , 3 , 3 , 0 , 0 ); } + p.popMatrix(); + + p.fill( this.colorCaptionLabel ); + c.captionLabel.draw( p , c ); + } + + this.event['onRelease'] = function( c , pointer ) { c.state.open = pointer.ry >= 0 ^ !c.state.open; } + this.event['onDrag'] = function( c , pointer ) { c.x += pointer.dx; c.y += pointer.dy; } + } + , getHeight: function() { return (this.state.open ? this.height : 0 ); } + }); + + + + // DropdownList, ListBox + // Tab, Group + // Slider2D + // Textfield + // Range + // CheckBox, RadioButton + // Numberbox + + // Callback + // ControllerPlug + // ControllerView + // Canvas + + var ControlEvent = Class.extend({ + c: undefined + , init: function ( c ) { this.c = c; } + , getValue: function ( ) { return this.c.getValue(); } + , getController: function ( ) { return this.c; } + , getGroup: function ( ) { return this.c; } + , getName: function ( ) { return this.c.getName( ); } + , getId: function ( ) { return this.c.getId( ); } + , isFrom: function ( cc ) { if(C.get( cc ) !== undefined ) { return C.get( cc ).getName( ) === this.c.getName( ); } return this.c === cc; } + }); + + + var ControlP5 = Class.extend({ + + init: function ( t ) { C.make( t ); } + , addSlider: function ( theIndex ) { return C.add( new Slider( theIndex ).setPosition( 0 , 0 ).setSize( 100 , 15 ) ); } + , addButton: function ( theIndex ) { return C.add( new Button( theIndex ).setPosition( 0 , 0 ).setSize( 50 , 30 ) ); } + , addBang: function ( theIndex ) { return C.add( new Bang( theIndex ).setPosition( 0 , 0 ).setSize( 50 , 30 ) ); } + , addToggle: function ( theIndex ) { return C.add( new Toggle( theIndex ).setPosition( 0 , 0 ).setSize( 40 , 20 ) ); } + , addNumberbox: function ( theIndex ) { return C.add( new Numberbox( theIndex ).setPosition( 0 , 0 ).setSize( 100 , 20 ) ); } + , addRange: function ( theIndex ) { } /* TODO */ + , addKnob: function ( theIndex ) { return C.add( new Knob( theIndex ).setPosition( 0 , 0 ).setSize( 40 , 40 ) ); } + , addSlider2D: function ( theIndex ) { return C.add( new Slider2D( theIndex ).setPosition( 0 , 0 ).setSize( 50 , 50 ) ); } + , addTextfield: function ( theIndex ) { return C.add( new Textfield( theIndex ).setPosition( 0 , 0 ).setSize( 200 , 20 ) ); } + , addRadioButton: function ( theIndex ) { } /* TODO */ + , addCheckBox: function ( theIndex ) { return C.add( new CheckBox( theIndex ).setPosition( 0 , 0 ).setSize( 200 , 20 ) ); } + , addTab: function ( theIndex ) { } /* TODO */ + , addGroup: function ( theIndex ) { return C.add( new Group( theIndex ).setPosition( 0 , 0 ).setSize( 200 , 200 ) ); } + , addDropdownList: function ( theIndex ) { } /* TODO */ + , addListBox: function ( theIndex ) { return C.add( new ListBox( theIndex ).setPosition( 0 , 0 ).setSize( 200 , 185 ) ); } + , addCanvas: function ( theIndex ) { } /* TODO */ + , get: function ( theIndex ) { return C.get( theIndex ); } + , getAll: function ( ) { return C.get( ).controllers; } + , getAll: function ( theType ) { /* returns a list of all registered controllers of type theType */ } + , getFont: function ( ) { return C.get( ).font; } + , getListener: function ( theIndex ) { } /* TODO */ + , getValue: function ( theIndex ) {return C.get( theIndex ).getValue( ); } + , isAutoDraw: function ( ) { return true; } + , isMouseOver: function ( ) { return false; } + , isMouseOver: function ( theController ) { return false; } + , isMoveable: function ( ) { return true ;} + , isShortcuts: function ( ) { return false; } + , addCallback: function ( theListener ) { } + , addCanvas: function ( theCanvas ) { } + , remove: function ( theIndex ) { } + , removeCallback: function ( theController ) { } + , removeCanvas: function ( theCanvas ) { } + , removeListener: function ( theListener ) { } + , setBroadcast: function ( b ) { } + , setMoveable: function ( b ) { } + , setFont: function ( thePFont ) { C.get( ).font = thePFont; return this; } + , setFont: function ( thePFont , theFontsize ) { C.get( ).font = thePFont; C.get( ).fontsize = theFontsize; return this; } + , setColor: function ( theColor ) { return this; } + , setColorActive: function ( theColor ) { return this; } + , setColorBackground: function ( theColor ) { return this; } + , setColorCaptionLabel: function ( theColor ) { return this; } + , setColorForeground: function ( theColor ) { return this; } + , setColorValueLabel: function ( theColor ) { return this; } + , disableShortcuts: function ( ) { return this; } + , enableShortcuts: function ( ) { return this; } + , hide: function ( ) { return this; } + , show: function ( ) { return this; } + , setAutoDraw: function ( b ) { return this; } + }); + + + var txtboxed = function( p , theText , theX , theY , theAlignX , theAlignY , theW , theH ) { + p.pushMatrix( ); + p.translate( theX , theY ); + p.textAlign( theAlignX , theAlignY ); + p.text( theText , 0 , 0 , theW , theH ); + p.popMatrix() ; + } + + + + var txtalign = function( p , theText , theX , theY , theAlignX , theAlignY ) { + p.pushMatrix( ); + p.translate( theX , theY ); + p.textAlign( theAlignX , theAlignY ); + p.text( theText , 0 , 0 ); + p.popMatrix() ; + } + + + + var txt = function( p , theText , theX , theY ) { + p.pushMatrix( ); + p.translate( theX , theY ); + p.text( theText , 0 , 0 ); + p.popMatrix() ; + } + + +}; + + + +// function numDecimals(x) { +// x = x.toString(); +// if (x.indexOf('.') > -1) { +// return x.length - x.indexOf('.') - 1; +// } else { +// return 0; +// } +// } + + +//, setSize: function ( theW, theH ) { this.buffer = C.papplet( ).createGraphics( theW - 8 , theH); return this._super(theW, theH); } + + // c.buffer.beginDraw(); + // c.buffer.background( c.colorBackground ); + // c.buffer.smooth(); + // c.buffer.textFont( C.font( )); + // var off = -p.max( 0 , p.textWidth( c.text ) - c.buffer.width ); + // c.buffer.fill( 255 ); + // c.buffer.text(c.text , off , c.height/2 + 5 ); + // c.buffer.endDraw(); + // p.image(c.buffer, 4 , 0 ); \ No newline at end of file diff --git a/examples/controllers/ControlP5ButtonBar/ControlP5ButtonBar.pde b/examples/controllers/ControlP5ButtonBar/ControlP5ButtonBar.pde new file mode 100644 index 0000000..3c8d457 --- /dev/null +++ b/examples/controllers/ControlP5ButtonBar/ControlP5ButtonBar.pde @@ -0,0 +1,44 @@ +/** + * ControlP5 ButtonBar + * + * work-in-progress + * + * by Andreas Schlegel, 2012 + * www.sojamo.de/libraries/controlp5 + * + */ + + +import controlP5.*; + +ControlP5 cp5; + + +void setup() { + size(400, 400); + cp5 = new ControlP5(this); + ButtonBar b = cp5.addButtonBar("bar") + .setPosition(0, 0) + .setSize(400, 20) + .addItems(split("a b c d e f g h i j"," ")) + ; + println(b.getItem("a")); + b.changeItem("a","text","first"); + b.changeItem("b","text","second"); + b.changeItem("c","text","third"); + b.onMove(new CallbackListener(){ + public void controlEvent(CallbackEvent ev) { + ButtonBar bar = (ButtonBar)ev.getController(); + println("hello ",bar.hover()); + } + }); +} + +void bar(int n) { + println("bar clicked, item-value:", n); +} + +void draw() { + background(220); +} + diff --git a/examples/controllers/ControlP5ColorWheel/ControlP5ColorWheel.pde b/examples/controllers/ControlP5ColorWheel/ControlP5ColorWheel.pde new file mode 100644 index 0000000..17befc6 --- /dev/null +++ b/examples/controllers/ControlP5ColorWheel/ControlP5ColorWheel.pde @@ -0,0 +1,175 @@ +/** + * ColorWheel is working but still under development as of 22.April 2014. + * for API see source code of controlP5/ColorWheel.java +*/ + +import controlP5.*; + +ControlP5 cp5; + +void setup() { + size(500, 500); + cp5 = new ControlP5( this ); + cp5.printPublicMethodsFor(ColorWheel.class); + cp5.addColorWheel("c" , 250 , 10 , 200 ).setRGB(color(128,0,255)); + noStroke(); +} + +int c = color(100); + +void draw() { + background(50); + fill( c ); + rect(0,240,width,200); + println(cp5.get(ColorWheel.class,"c").getRGB()); +} + + +/** +* ControlP5 ColorWheel +* +* +* find a list of public methods available for the ColorWheel Controller +* at the bottom of this sketch. +* +* by Andreas Schlegel, 2012 +* www.sojamo.de/libraries/controlp5 +* +*/ + +/* +a list of all methods available for the ColorWheel Controller +use ControlP5.printPublicMethodsFor(ColorWheel.class); +to print the following list into the console. + +You can find further details about class ColorWheel in the javadoc. + +Format: +ClassName : returnType methodName(parameter type) + +controlP5.ColorWheel : ColorWheel setAlpha(int) +controlP5.ColorWheel : ColorWheel setHSL(double, double, double) +controlP5.ColorWheel : ColorWheel setRGB(int) +controlP5.ColorWheel : double[] RGBtoHSL(int) +controlP5.ColorWheel : double[] RGBtoHSL(int, int, int) +controlP5.ColorWheel : int HSLtoRGB(double, double, double) +controlP5.ColorWheel : int HSLtoRGB(double[]) +controlP5.ColorWheel : int HSVtoRGB(double, double, double) +controlP5.ColorWheel : int HSVtoRGB(double[]) +controlP5.ColorWheel : int a() +controlP5.ColorWheel : int b() +controlP5.ColorWheel : int g() +controlP5.ColorWheel : int r() +controlP5.ColorWheel : int getRGB() +controlP5.ColorWheel : void setHue(double) +controlP5.ColorWheel : void setLightness(double) +controlP5.ColorWheel : void setSaturation(double) +controlP5.Controller : CColor getColor() +controlP5.Controller : ColorWheel addCallback(CallbackListener) +controlP5.Controller : ColorWheel addListener(ControlListener) +controlP5.Controller : ColorWheel align(int, int, int, int) +controlP5.Controller : ColorWheel bringToFront() +controlP5.Controller : ColorWheel bringToFront(ControllerInterface) +controlP5.Controller : ColorWheel hide() +controlP5.Controller : ColorWheel linebreak() +controlP5.Controller : ColorWheel listen(boolean) +controlP5.Controller : ColorWheel lock() +controlP5.Controller : ColorWheel plugTo(Object) +controlP5.Controller : ColorWheel plugTo(Object, String) +controlP5.Controller : ColorWheel plugTo(Object[]) +controlP5.Controller : ColorWheel plugTo(Object[], String) +controlP5.Controller : ColorWheel registerProperty(String) +controlP5.Controller : ColorWheel registerProperty(String, String) +controlP5.Controller : ColorWheel registerTooltip(String) +controlP5.Controller : ColorWheel removeBehavior() +controlP5.Controller : ColorWheel removeCallback() +controlP5.Controller : ColorWheel removeCallback(CallbackListener) +controlP5.Controller : ColorWheel removeListener(ControlListener) +controlP5.Controller : ColorWheel removeProperty(String) +controlP5.Controller : ColorWheel removeProperty(String, String) +controlP5.Controller : ColorWheel setArrayValue(float[]) +controlP5.Controller : ColorWheel setArrayValue(int, float) +controlP5.Controller : ColorWheel setBehavior(ControlBehavior) +controlP5.Controller : ColorWheel setBroadcast(boolean) +controlP5.Controller : ColorWheel setCaptionLabel(String) +controlP5.Controller : ColorWheel setColor(CColor) +controlP5.Controller : ColorWheel setColorActive(int) +controlP5.Controller : ColorWheel setColorBackground(int) +controlP5.Controller : ColorWheel setColorCaptionLabel(int) +controlP5.Controller : ColorWheel setColorForeground(int) +controlP5.Controller : ColorWheel setColorValueLabel(int) +controlP5.Controller : ColorWheel setDecimalPrecision(int) +controlP5.Controller : ColorWheel setDefaultValue(float) +controlP5.Controller : ColorWheel setHeight(int) +controlP5.Controller : ColorWheel setId(int) +controlP5.Controller : ColorWheel setLabelVisible(boolean) +controlP5.Controller : ColorWheel setLock(boolean) +controlP5.Controller : ColorWheel setMax(float) +controlP5.Controller : ColorWheel setMin(float) +controlP5.Controller : ColorWheel setMouseOver(boolean) +controlP5.Controller : ColorWheel setMoveable(boolean) +controlP5.Controller : ColorWheel setPosition(PVector) +controlP5.Controller : ColorWheel setPosition(float, float) +controlP5.Controller : ColorWheel setSize(PImage) +controlP5.Controller : ColorWheel setSize(int, int) +controlP5.Controller : ColorWheel setStringValue(String) +controlP5.Controller : ColorWheel setUpdate(boolean) +controlP5.Controller : ColorWheel setValue(float) +controlP5.Controller : ColorWheel setValueLabel(String) +controlP5.Controller : ColorWheel setValueSelf(float) +controlP5.Controller : ColorWheel setView(ControllerView) +controlP5.Controller : ColorWheel setVisible(boolean) +controlP5.Controller : ColorWheel setWidth(int) +controlP5.Controller : ColorWheel show() +controlP5.Controller : ColorWheel unlock() +controlP5.Controller : ColorWheel unplugFrom(Object) +controlP5.Controller : ColorWheel unplugFrom(Object[]) +controlP5.Controller : ColorWheel unregisterTooltip() +controlP5.Controller : ColorWheel update() +controlP5.Controller : ColorWheel updateSize() +controlP5.Controller : ControlBehavior getBehavior() +controlP5.Controller : ControlWindow getControlWindow() +controlP5.Controller : ControlWindow getWindow() +controlP5.Controller : ControllerProperty getProperty(String) +controlP5.Controller : ControllerProperty getProperty(String, String) +controlP5.Controller : ControllerView getView() +controlP5.Controller : Label getCaptionLabel() +controlP5.Controller : Label getValueLabel() +controlP5.Controller : List getControllerPlugList() +controlP5.Controller : PVector getAbsolutePosition() +controlP5.Controller : PVector getPosition() +controlP5.Controller : Pointer getPointer() +controlP5.Controller : String getAddress() +controlP5.Controller : String getInfo() +controlP5.Controller : String getName() +controlP5.Controller : String getStringValue() +controlP5.Controller : String toString() +controlP5.Controller : Tab getTab() +controlP5.Controller : boolean isActive() +controlP5.Controller : boolean isBroadcast() +controlP5.Controller : boolean isInside() +controlP5.Controller : boolean isLabelVisible() +controlP5.Controller : boolean isListening() +controlP5.Controller : boolean isLock() +controlP5.Controller : boolean isMouseOver() +controlP5.Controller : boolean isMousePressed() +controlP5.Controller : boolean isMoveable() +controlP5.Controller : boolean isUpdate() +controlP5.Controller : boolean isVisible() +controlP5.Controller : float getArrayValue(int) +controlP5.Controller : float getDefaultValue() +controlP5.Controller : float getMax() +controlP5.Controller : float getMin() +controlP5.Controller : float getValue() +controlP5.Controller : float[] getArrayValue() +controlP5.Controller : int getDecimalPrecision() +controlP5.Controller : int getHeight() +controlP5.Controller : int getId() +controlP5.Controller : int getWidth() +controlP5.Controller : int listenerSize() +controlP5.Controller : void remove() +controlP5.Controller : void setView(ControllerView, int) +java.lang.Object : String toString() +java.lang.Object : boolean equals(Object) +*/ + diff --git a/examples/controllers/ControlP5accordion/ControlP5accordion.pde b/examples/controllers/ControlP5accordion/ControlP5accordion.pde new file mode 100644 index 0000000..9749bd5 --- /dev/null +++ b/examples/controllers/ControlP5accordion/ControlP5accordion.pde @@ -0,0 +1,271 @@ +/** + * ControlP5 Accordion + * arrange controller groups in an accordion like style. + * + * find a list of public methods available for the Accordion Controller + * at the bottom of this sketch. In the example below 3 groups with controllers + * are created and added to an accordion controller. Furthermore several key + * combinations are mapped to control individual settings of the accordion. + * An accordion comes in 2 modes, Accordion.SINGLE and Accordion.MULTI where the + * latter allows to open multiple groups of an accordion and the SINGLE mode only + * allows 1 group to be opened at a time. + * + * by Andreas Schlegel, 2012 + * www.sojamo.de/libraries/controlp5 + * + */ + +import controlP5.*; + +ControlP5 cp5; + +Accordion accordion; + +color c = color(0, 160, 100); + +void setup() { + size(400, 600); + noStroke(); + smooth(); + gui(); +} + +void gui() { + + cp5 = new ControlP5(this); + + // group number 1, contains 2 bangs + Group g1 = cp5.addGroup("myGroup1") + .setBackgroundColor(color(0, 64)) + .setBackgroundHeight(150) + ; + + cp5.addBang("bang") + .setPosition(10,20) + .setSize(100,100) + .moveTo(g1) + .plugTo(this,"shuffle"); + ; + + // group number 2, contains a radiobutton + Group g2 = cp5.addGroup("myGroup2") + .setBackgroundColor(color(0, 64)) + .setBackgroundHeight(150) + ; + + cp5.addRadioButton("radio") + .setPosition(10,20) + .setItemWidth(20) + .setItemHeight(20) + .addItem("black", 0) + .addItem("red", 1) + .addItem("green", 2) + .addItem("blue", 3) + .addItem("grey", 4) + .setColorLabel(color(255)) + .activate(2) + .moveTo(g2) + ; + + // group number 3, contains a bang and a slider + Group g3 = cp5.addGroup("myGroup3") + .setBackgroundColor(color(0, 64)) + .setBackgroundHeight(150) + ; + + cp5.addBang("shuffle") + .setPosition(10,20) + .setSize(40,50) + .moveTo(g3) + ; + + cp5.addSlider("hello") + .setPosition(60,20) + .setSize(100,20) + .setRange(100,500) + .setValue(100) + .moveTo(g3) + ; + + cp5.addSlider("world") + .setPosition(60,50) + .setSize(100,20) + .setRange(100,500) + .setValue(200) + .moveTo(g3) + ; + + // create a new accordion + // add g1, g2, and g3 to the accordion. + accordion = cp5.addAccordion("acc") + .setPosition(40,40) + .setWidth(200) + .addItem(g1) + .addItem(g2) + .addItem(g3) + ; + + cp5.mapKeyFor(new ControlKey() {public void keyEvent() {accordion.open(0,1,2);}}, 'o'); + cp5.mapKeyFor(new ControlKey() {public void keyEvent() {accordion.close(0,1,2);}}, 'c'); + cp5.mapKeyFor(new ControlKey() {public void keyEvent() {accordion.setWidth(300);}}, '1'); + cp5.mapKeyFor(new ControlKey() {public void keyEvent() {accordion.setPosition(0,0);accordion.setItemHeight(190);}}, '2'); + cp5.mapKeyFor(new ControlKey() {public void keyEvent() {accordion.setCollapseMode(ControlP5.ALL);}}, '3'); + cp5.mapKeyFor(new ControlKey() {public void keyEvent() {accordion.setCollapseMode(ControlP5.SINGLE);}}, '4'); + cp5.mapKeyFor(new ControlKey() {public void keyEvent() {cp5.remove("myGroup1");}}, '0'); + + accordion.open(0,1,2); + + // use Accordion.MULTI to allow multiple group + // to be open at a time. + accordion.setCollapseMode(Accordion.MULTI); + + // when in SINGLE mode, only 1 accordion + // group can be open at a time. + // accordion.setCollapseMode(Accordion.SINGLE); +} + + +void radio(int theC) { + switch(theC) { + case(0):c=color(0,200);break; + case(1):c=color(255,0,0,200);break; + case(2):c=color(0, 200, 140,200);break; + case(3):c=color(0, 128, 255,200);break; + case(4):c=color(50,128);break; + } +} + + +void shuffle() { + c = color(random(255),random(255),random(255),random(128,255)); +} + + +void draw() { + background(220); + + fill(c); + + float s1 = cp5.getController("hello").getValue(); + ellipse(200,400,s1,s1); + + float s2 = cp5.getController("world").getValue(); + ellipse(300,100,s2,s2); +} + + + + + +/* +a list of all methods available for the Accordion Controller +use ControlP5.printPublicMethodsFor(Accordion.class); +to print the following list into the console. + +You can find further details about class Accordion in the javadoc. + +Format: +ClassName : returnType methodName(parameter type) + + +controlP5.Accordion : Accordion addItem(ControlGroup) +controlP5.Accordion : Accordion remove(ControllerInterface) +controlP5.Accordion : Accordion removeItem(ControlGroup) +controlP5.Accordion : Accordion setItemHeight(int) +controlP5.Accordion : Accordion setMinItemHeight(int) +controlP5.Accordion : Accordion setWidth(int) +controlP5.Accordion : Accordion updateItems() +controlP5.Accordion : int getItemHeight() +controlP5.Accordion : int getMinItemHeight() +controlP5.ControlGroup : Accordion activateEvent(boolean) +controlP5.ControlGroup : Accordion addListener(ControlListener) +controlP5.ControlGroup : Accordion hideBar() +controlP5.ControlGroup : Accordion removeListener(ControlListener) +controlP5.ControlGroup : Accordion setBackgroundColor(int) +controlP5.ControlGroup : Accordion setBackgroundHeight(int) +controlP5.ControlGroup : Accordion setBarHeight(int) +controlP5.ControlGroup : Accordion showBar() +controlP5.ControlGroup : Accordion updateInternalEvents(PApplet) +controlP5.ControlGroup : String getInfo() +controlP5.ControlGroup : String toString() +controlP5.ControlGroup : boolean isBarVisible() +controlP5.ControlGroup : int getBackgroundHeight() +controlP5.ControlGroup : int getBarHeight() +controlP5.ControlGroup : int listenerSize() +controlP5.ControllerGroup : Accordion add(ControllerInterface) +controlP5.ControllerGroup : Accordion bringToFront() +controlP5.ControllerGroup : Accordion bringToFront(ControllerInterface) +controlP5.ControllerGroup : Accordion close() +controlP5.ControllerGroup : Accordion disableCollapse() +controlP5.ControllerGroup : Accordion enableCollapse() +controlP5.ControllerGroup : Accordion hide() +controlP5.ControllerGroup : Accordion moveTo(ControlWindow) +controlP5.ControllerGroup : Accordion moveTo(PApplet) +controlP5.ControllerGroup : Accordion open() +controlP5.ControllerGroup : Accordion registerProperty(String) +controlP5.ControllerGroup : Accordion registerProperty(String, String) +controlP5.ControllerGroup : Accordion remove(CDrawable) +controlP5.ControllerGroup : Accordion remove(ControllerInterface) +controlP5.ControllerGroup : Accordion removeCanvas(ControlWindowCanvas) +controlP5.ControllerGroup : Accordion removeProperty(String) +controlP5.ControllerGroup : Accordion removeProperty(String, String) +controlP5.ControllerGroup : Accordion setAddress(String) +controlP5.ControllerGroup : Accordion setArrayValue(float[]) +controlP5.ControllerGroup : Accordion setColor(CColor) +controlP5.ControllerGroup : Accordion setColorActive(int) +controlP5.ControllerGroup : Accordion setColorBackground(int) +controlP5.ControllerGroup : Accordion setColorForeground(int) +controlP5.ControllerGroup : Accordion setColorLabel(int) +controlP5.ControllerGroup : Accordion setColorValue(int) +controlP5.ControllerGroup : Accordion setHeight(int) +controlP5.ControllerGroup : Accordion setId(int) +controlP5.ControllerGroup : Accordion setLabel(String) +controlP5.ControllerGroup : Accordion setMouseOver(boolean) +controlP5.ControllerGroup : Accordion setMoveable(boolean) +controlP5.ControllerGroup : Accordion setOpen(boolean) +controlP5.ControllerGroup : Accordion setPosition(PVector) +controlP5.ControllerGroup : Accordion setPosition(float, float) +controlP5.ControllerGroup : Accordion setStringValue(String) +controlP5.ControllerGroup : Accordion setUpdate(boolean) +controlP5.ControllerGroup : Accordion setValue(float) +controlP5.ControllerGroup : Accordion setVisible(boolean) +controlP5.ControllerGroup : Accordion setWidth(int) +controlP5.ControllerGroup : Accordion show() +controlP5.ControllerGroup : Accordion update() +controlP5.ControllerGroup : Accordion updateAbsolutePosition() +controlP5.ControllerGroup : CColor getColor() +controlP5.ControllerGroup : ControlWindow getWindow() +controlP5.ControllerGroup : ControlWindowCanvas addCanvas(ControlWindowCanvas) +controlP5.ControllerGroup : Controller getController(String) +controlP5.ControllerGroup : ControllerProperty getProperty(String) +controlP5.ControllerGroup : ControllerProperty getProperty(String, String) +controlP5.ControllerGroup : Label getCaptionLabel() +controlP5.ControllerGroup : Label getValueLabel() +controlP5.ControllerGroup : PVector getPosition() +controlP5.ControllerGroup : String getAddress() +controlP5.ControllerGroup : String getInfo() +controlP5.ControllerGroup : String getName() +controlP5.ControllerGroup : String getStringValue() +controlP5.ControllerGroup : String toString() +controlP5.ControllerGroup : Tab getTab() +controlP5.ControllerGroup : boolean isCollapse() +controlP5.ControllerGroup : boolean isMouseOver() +controlP5.ControllerGroup : boolean isMoveable() +controlP5.ControllerGroup : boolean isOpen() +controlP5.ControllerGroup : boolean isUpdate() +controlP5.ControllerGroup : boolean isVisible() +controlP5.ControllerGroup : boolean setMousePressed(boolean) +controlP5.ControllerGroup : float getValue() +controlP5.ControllerGroup : float[] getArrayValue() +controlP5.ControllerGroup : int getHeight() +controlP5.ControllerGroup : int getId() +controlP5.ControllerGroup : int getWidth() +controlP5.ControllerGroup : void remove() +java.lang.Object : String toString() +java.lang.Object : boolean equals(Object) + + +*/ + + + diff --git a/examples/controllers/ControlP5bang/ControlP5bang.pde b/examples/controllers/ControlP5bang/ControlP5bang.pde new file mode 100644 index 0000000..8c3f156 --- /dev/null +++ b/examples/controllers/ControlP5bang/ControlP5bang.pde @@ -0,0 +1,206 @@ +/** + * ControlP5 Bang + * A bang triggers an event that can be received by a function named after the bang. + * By default a bang is triggered when pressed, this can be changed to 'release' + * using theBang.setTriggerEvent(Bang.RELEASE). + * + * find a list of public methods available for the Bang Controller + * at the bottom of this sketch. + * + * by Andreas Schlegel, 2012 + * www.sojamo.de/libraries/controlp5 + * + */ + +import controlP5.*; + +ControlP5 cp5; + +int myColorBackground = color(0, 0, 0); + +color[] col = new color[] { + color(100), color(150), color(200), color(250) +}; + + +void setup() { + size(400, 600); + noStroke(); + cp5 = new ControlP5(this); + for (int i=0;i presets = new ArrayList(); + int currentPreset = 0; + Thread update; + + CustomMatrix(ControlP5 cp5, String theName) { + super(cp5, theName); + stop(); // stop the default sequencer and + // create our custom sequencer thread. Here we + // check if the sequencer has reached the end and if so + // we updated to the next preset. + update = new Thread(theName) { + public void run( ) { + while ( true ) { + cnt++; + cnt %= _myCellX; + if (cnt==0) { + // we reached the end and go back to start and + // update the preset + next(); + } + trigger(cnt); + try { + sleep( _myInterval ); + } + catch ( InterruptedException e ) { + } + } + } + }; + update.start(); + } + + + void next() { + currentPreset++; + currentPreset %= presets.size(); + setCells(presets.get(currentPreset)); + } + + // initialize some random presets. + void initPresets() { + for (int i=0;i<4;i++) { + presets.add(createPreset(_myCellX, _myCellY)); + } + setCells(presets.get(0)); + } + + // create a random preset + int[][] createPreset(int theX, int theY) { + int[][] preset = new int[theX][theY]; + for (int x=0;x0.5 ? 1:0; + } + } + return preset; + } + +} + diff --git a/examples/experimental/ControlP5MenuList/ControlP5MenuList.pde b/examples/experimental/ControlP5MenuList/ControlP5MenuList.pde new file mode 100644 index 0000000..651c1e2 --- /dev/null +++ b/examples/experimental/ControlP5MenuList/ControlP5MenuList.pde @@ -0,0 +1,187 @@ + +/** + * ControlP5 MenuList + * + * A custom Controller, a scrollable Menu List, using a PGraphics buffer. + * Allows custom designs for List Item. + * + * by Andreas Schlegel, 2013 + * www.sojamo.de/libraries/controlp5 + * + */ + +import controlP5.*; +import static controlP5.ControlP5.*; +import java.util.*; +import java.util.Map.Entry; + + +ControlP5 cp5; + +PFont f1, f2; +void setup() { + size(800, 500, P3D ); + f1 = createFont("Helvetica", 20); + f2 = createFont("Helvetica", 12); + + cp5 = new ControlP5( this ); + + + /* create a custom MenuList with name menu, notice that function + * menu will be called when a menu item has been clicked. + */ + MenuList m = new MenuList( cp5, "menu", 200, 368 ); + + m.setPosition(40, 40); + // add some items to our menuList + for (int i=0;i<100;i++) { + m.addItem(makeItem("headline-"+i, "subline", "some copy lorem ipsum ", createImage(50, 50, RGB))); + } +} + +/* a convenience function to build a map that contains our key-value pairs which we will + * then use to render each item of the menuList. + */ +Map makeItem(String theHeadline, String theSubline, String theCopy, PImage theImage) { + Map m = new HashMap(); + m.put("headline", theHeadline); + m.put("subline", theSubline); + m.put("copy", theCopy); + m.put("image", theImage); + return m; +} + +void menu(int i) { + println("got some menu event from item with index "+i); +} + +public void controlEvent(ControlEvent theEvent) { + if(theEvent.isFrom("menu")){ + Map m = ((MenuList)theEvent.getController()).getItem(int(theEvent.getValue())); + println("got a menu event from item : "+m); + } +} + +void draw() { + background( 40 ); +} + + +/* A custom Controller that implements a scrollable menuList. Here the controller + * uses a PGraphics element to render customizable list items. The menuList can be scrolled + * using the scroll-wheel, touchpad, or mouse-drag. Items are triggered by a click. clicking + * the scrollbar to the right makes the list scroll to the item correspoinding to the + * click-location. + */ +class MenuList extends Controller { + + float pos, npos; + int itemHeight = 100; + int scrollerLength = 40; + List< Map> items = new ArrayList< Map>(); + PGraphics menu; + boolean updateMenu; + + MenuList(ControlP5 c, String theName, int theWidth, int theHeight) { + super( c, theName, 0, 0, theWidth, theHeight ); + c.register( this ); + menu = createGraphics(getWidth(), getHeight() ); + + setView(new ControllerView() { + + public void display(PGraphics pg, MenuList t ) { + if (updateMenu) { + updateMenu(); + } + if (inside() ) { + menu.beginDraw(); + int len = -(itemHeight * items.size()) + getHeight(); + int ty = int(map(pos, len, 0, getHeight() - scrollerLength - 2, 2 ) ); + menu.fill(255 ); + menu.rect(getWidth()-4, ty, 4, scrollerLength ); + menu.endDraw(); + } + pg.image(menu, 0, 0); + } + } + ); + updateMenu(); + } + + /* only update the image buffer when necessary - to save some resources */ + void updateMenu() { + int len = -(itemHeight * items.size()) + getHeight(); + npos = constrain(npos, len, 0); + pos += (npos - pos) * 0.1; + menu.beginDraw(); + menu.noStroke(); + menu.background(255, 64 ); + menu.textFont(cp5.getFont().getFont()); + menu.pushMatrix(); + menu.translate( 0, pos ); + menu.pushMatrix(); + + int i0 = PApplet.max( 0, int(map(-pos, 0, itemHeight * items.size(), 0, items.size()))); + int range = ceil((float(getHeight())/float(itemHeight))+1); + int i1 = PApplet.min( items.size(), i0 + range ); + + menu.translate(0, i0*itemHeight); + + for (int i=i0;i0.01 ? true:false; + } + + /* when detecting a click, check if the click happend to the far right, if yes, scroll to that position, + * otherwise do whatever this item of the list is supposed to do. + */ + public void onClick() { + if (getPointer().x()>getWidth()-10) { + npos= -map(getPointer().y(), 0, getHeight(), 0, items.size()*itemHeight); + updateMenu = true; + } + else { + int len = itemHeight * items.size(); + int index = int( map( getPointer().y() - pos, 0, len, 0, items.size() ) ) ; + setValue(index); + } + } + + public void onMove() { + } + + public void onDrag() { + npos += getPointer().dy() * 2; + updateMenu = true; + } + + public void onScroll(int n) { + npos += ( n * 4 ); + updateMenu = true; + } + + void addItem(Map m) { + items.add(m); + updateMenu = true; + } + + Map getItem(int theIndex) { + return items.get(theIndex); + } +} + diff --git a/examples/experimental/ControlP5SliderList/ControlP5SliderList.pde b/examples/experimental/ControlP5SliderList/ControlP5SliderList.pde new file mode 100644 index 0000000..5413cfb --- /dev/null +++ b/examples/experimental/ControlP5SliderList/ControlP5SliderList.pde @@ -0,0 +1,257 @@ + +/** + * ControlP5 SilderList + * + * A custom Controller, a scrollable Menu List, using a PGraphics buffer. + * Allows custom designs for List Item. + * + * you will need a controlP5 version >= 2.1.5 + * you can download a copy from + * http://sojamo.de/files/archive/controlP5-2.1.5.zip + * + * by Andreas Schlegel, 2013 + * www.sojamo.de/libraries/controlp5 + * + */ + +import controlP5.*; +import java.util.*; + + +ControlP5 cp5; + +PFont f1; +int NUM = 100; +float[] rotation = new float[NUM]; + + +void setup() { + size(800, 500 ,P3D); + f1 = createFont("Helvetica", 12); + + cp5 = new ControlP5( this ); + + + // create a custom SilderList with name menu, notice that function + // menu will be called when a menu item has been clicked. + + SilderList m = new SilderList( cp5, "menu", 250, 350 ); + + m.setPosition(40, 40); + // add some items to our SilderList + for (int i=0;i makeItem(String theLabel, float theValue, float theMin, float theMax) { + Map m = new HashMap(); + m.put("label", theLabel); + m.put("sliderValue", theValue); + m.put("sliderValueMin", theMin); + m.put("sliderValueMax", theMax); + return m; +} + +void menu(int i) { + println("got some slider-list event from item with index "+i); +} + +public void controlEvent(ControlEvent theEvent) { + if (theEvent.isFrom("menu")) { + int index = int(theEvent.getValue()); + Map m = ((SilderList)theEvent.getController()).getItem(index); + println("got a slider event from item : "+m); + rotation[index] = f(m.get("sliderValue")); + } +} + +void draw() { + background( 255 ); + fill(0, 128, 255); + noStroke(); + pushMatrix(); + translate(width/2, 50 ); + for (int i=0;i { + + float pos, npos; + int itemHeight = 60; + int scrollerLength = 40; + int sliderWidth = 150; + int sliderHeight = 15; + int sliderX = 10; + int sliderY = 25; + + int dragMode = 0; + int dragIndex = -1; + + List< Map> items = new ArrayList< Map>(); + PGraphics menu; + boolean updateMenu; + + SilderList(ControlP5 c, String theName, int theWidth, int theHeight) { + super( c, theName, 0, 0, theWidth, theHeight ); + c.register( this ); + menu = createGraphics(getWidth(), getHeight()); + + setView(new ControllerView() { + + public void display(PGraphics pg, SilderList t ) { + if (updateMenu) { + updateMenu(); + } + if (inside() ) { // draw scrollbar + menu.beginDraw(); + int len = -(itemHeight * items.size()) + getHeight(); + int ty = int(map(pos, len, 0, getHeight() - scrollerLength - 2, 2 ) ); + menu.fill( 128 ); + menu.rect(getWidth()-6, ty, 4, scrollerLength ); + menu.endDraw(); + } + pg.image(menu, 0, 0); + } + } + ); + updateMenu(); + } + + // only update the image buffer when necessary - to save some resources + void updateMenu() { + int len = -(itemHeight * items.size()) + getHeight(); + npos = constrain(npos, len, 0); + pos += (npos - pos) * 0.1; + + /// draw the SliderList + menu.beginDraw(); + menu.noStroke(); + menu.background(240); + menu.textFont(cp5.getFont().getFont()); + menu.pushMatrix(); + menu.translate( 0, int(pos) ); + menu.pushMatrix(); + + int i0 = PApplet.max( 0, int(map(-pos, 0, itemHeight * items.size(), 0, items.size()))); + int range = ceil((float(getHeight())/float(itemHeight))+1); + int i1 = PApplet.min( items.size(), i0 + range ); + + menu.translate(0, i0*itemHeight); + + for (int i=i0;i0.01 ? true:false; + } + + // when detecting a click, check if the click happend to the far right, + // if yes, scroll to that position, otherwise do whatever this item of + // the list is supposed to do. + public void onClick() { + if (getPointer().x()>getWidth()-10) { + npos= -map(getPointer().y(), 0, getHeight(), 0, items.size()*itemHeight); + updateMenu = true; + } + } + + + public void onPress() { + int x = getPointer().x(); + int y = (int)(getPointer().y()-pos)%itemHeight; + boolean withinSlider = within(x, y, sliderX, sliderY, sliderWidth, sliderHeight); + dragMode = withinSlider ? 2:1; + if (dragMode==2) { + dragIndex = getIndex(); + float min = f(items.get(dragIndex).get("sliderValueMin")); + float max = f(items.get(dragIndex).get("sliderValueMax")); + float val = constrain(map(getPointer().x()-sliderX, 0, sliderWidth, min, max), min, max); + items.get(dragIndex).put("sliderValue", val); + setValue(dragIndex); + } + updateMenu = true; + } + + public void onDrag() { + switch(dragMode) { + case(1): // drag and scroll the list + npos += getPointer().dy() * 2; + updateMenu = true; + break; + case(2): // drag slider + float min = f(items.get(dragIndex).get("sliderValueMin")); + float max = f(items.get(dragIndex).get("sliderValueMax")); + float val = constrain(map(getPointer().x()-sliderX, 0, sliderWidth, min, max), min, max); + items.get(dragIndex).put("sliderValue", val); + setValue(dragIndex); + updateMenu = true; + break; + } + } + + public void onScroll(int n) { + npos += ( n * 4 ); + updateMenu = true; + } + + void addItem(Map m) { + items.add(m); + updateMenu = true; + } + + Map getItem(int theIndex) { + return items.get(theIndex); + } + + private int getIndex() { + int len = itemHeight * items.size(); + int index = int( map( getPointer().y() - pos, 0, len, 0, items.size() ) ) ; + return index; + } +} + +public static float f( Object o ) { + return ( o instanceof Number ) ? ( ( Number ) o ).floatValue( ) : Float.MIN_VALUE; +} + +public static boolean within(int theX, int theY, int theX1, int theY1, int theW1, int theH1) { + return (theX>theX1 && theXtheY1 && theY midimapper = new HashMap(); + +void setup() { + + size( 600, 400 ); + + cp5 = new ControlP5( this ); + + cp5.begin(cp5.addTab("a")); + cp5.addSlider("a-1").setPosition(20, 120).setSize(200, 20); + cp5.addSlider("a-2").setPosition(20, 160).setSize(200, 20); + cp5.addSlider("a-3").setPosition(20, 200).setSize(200, 20); + cp5.addToggle("a-4").setPosition(280, 120).setSize(100, 20); + cp5.addButton("a-5").setPosition(280, 160).setSize(100, 20); + cp5.addBang("a-6").setPosition(280, 200).setSize(100, 20); + cp5.end(); + + cp5.begin(cp5.addTab("b")); + cp5.addSlider("b-1").setPosition(20, 120).setSize(200, 20); + cp5.addSlider("b-2").setPosition(20, 160).setSize(200, 20); + cp5.addSlider("b-3").setPosition(20, 200).setSize(200, 20); + cp5.end(); + + final String device = "SLIDER/KNOB"; + + //midimapper.clear(); + + midimapper.put( ref( device, 0 ), "a-1" ); + midimapper.put( ref( device, 1 ), "a-2" ); + midimapper.put( ref( device, 2 ), "a-3" ); + midimapper.put( ref( device, 32 ), "a-4" ); + midimapper.put( ref( device, 48 ), "a-5" ); + midimapper.put( ref( device, 64 ), "a-6" ); + + midimapper.put( ref( device, 16 ), "b-1" ); + midimapper.put( ref( device, 17 ), "b-2" ); + midimapper.put( ref( device, 18 ), "b-3" ); + + boolean DEBUG = false; + + if (DEBUG) { + new MidiSimple( device ); + } + else { + new MidiSimple( device , new Receiver() { + + @Override public void send( MidiMessage msg, long timeStamp ) { + + byte[] b = msg.getMessage(); + + if ( b[ 0 ] != -48 ) { + + Object index = ( midimapper.get( ref( device , b[ 1 ] ) ) ); + + if ( index != null ) { + + Controller c = cp5.getController(index.toString()); + if (c instanceof Slider ) { + float min = c.getMin(); + float max = c.getMax(); + c.setValue(map(b[ 2 ], 0, 127, min, max) ); + } else if ( c instanceof Button ) { + if ( b[ 2 ] > 0 ) { + c.setValue( c.getValue( ) ); + c.setColorBackground( 0xff08a2cf ); + } else { + c.setColorBackground( 0xff003652 ); + } + } else if ( c instanceof Bang ) { + if ( b[ 2 ] > 0 ) { + c.setValue( c.getValue( ) ); + c.setColorForeground( 0xff08a2cf ); + } else { + c.setColorForeground( 0xff00698c ); + } + } else if ( c instanceof Toggle ) { + if ( b[ 2 ] > 0 ) { + ( ( Toggle ) c ).toggle( ); + } + } + } + } + } + + @Override public void close( ) { + } + } + ); + } +} + + +String ref(String theDevice, int theIndex) { + return theDevice+"-"+theIndex; +} + + +void draw() { + background( 0 ); +} + + diff --git a/examples/experimental/MidiMapper/MidiSimple.java b/examples/experimental/MidiMapper/MidiSimple.java new file mode 100644 index 0000000..f23252f --- /dev/null +++ b/examples/experimental/MidiMapper/MidiSimple.java @@ -0,0 +1,107 @@ +import java.util.HashMap; +import java.util.Map; + +import javax.sound.midi.MidiDevice; +import javax.sound.midi.MidiMessage; +import javax.sound.midi.MidiSystem; +import javax.sound.midi.MidiUnavailableException; +import javax.sound.midi.Receiver; +import javax.sound.midi.Transmitter; + +public class MidiSimple { + + public MidiSimple( String theDeviceName , Receiver theReceiver ) { + + MidiDevice.Info[] aInfos = MidiSystem.getMidiDeviceInfo(); + for ( int i = 0; i < aInfos.length; i++ ) { + try { + MidiDevice device = MidiSystem.getMidiDevice( aInfos[ i ] ); + boolean bAllowsInput = ( device.getMaxTransmitters() != 0 ); + boolean bAllowsOutput = ( device.getMaxReceivers() != 0 ); + System.out.println( "" + i + " " + ( bAllowsInput ? "IN " : " " ) + ( bAllowsOutput ? "OUT " : " " ) + aInfos[ i ].getName() + ", " + aInfos[ i ].getVendor() + ", " + + aInfos[ i ].getVersion() + ", " + aInfos[ i ].getDescription() ); + } + catch ( MidiUnavailableException e ) { + // device is obviously not available... + // out(e); + } + } + + try { + MidiDevice device; + device = MidiSystem.getMidiDevice( getMidiDeviceInfo( theDeviceName, false ) ); + device.open(); + Transmitter conTrans = device.getTransmitter(); + conTrans.setReceiver( theReceiver ); + } + catch ( MidiUnavailableException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NullPointerException e) { + System.out.println("No Midi device ( "+theDeviceName+" ) is available."); + } + + } + + public MidiSimple( String theDeviceName ) { + new MidiSimple(theDeviceName , new MidiInputReceiver( theDeviceName ) ); + } + + + public MidiDevice.Info getMidiDeviceInfo( String strDeviceName, boolean bForOutput ) { + MidiDevice.Info[] aInfos = MidiSystem.getMidiDeviceInfo(); + for ( int i = 0; i < aInfos.length; i++ ) { + if ( aInfos[ i ].getName().equals( strDeviceName ) ) { + try { + MidiDevice device = MidiSystem.getMidiDevice( aInfos[ i ] ); + boolean bAllowsInput = ( device.getMaxTransmitters() != 0 ); + boolean bAllowsOutput = ( device.getMaxReceivers() != 0 ); + if ( ( bAllowsOutput && bForOutput ) || ( bAllowsInput && !bForOutput ) ) { + return aInfos[ i ]; + } + } + catch ( MidiUnavailableException e ) { + // TODO: + } + } + } + return null; + } + + class MidiInputReceiver implements Receiver { + public String name; + Map< Byte, String > commandMap = new HashMap< Byte, String >(); + + public MidiInputReceiver( String name ) { + this.name = name; + commandMap.put( ( byte ) -112, "Note On" ); + commandMap.put( ( byte ) -128, "Note Off" ); + commandMap.put( ( byte ) -48, "Channel Pressure" ); + commandMap.put( ( byte ) -80, "Continuous Controller" ); + } + + public void send( MidiMessage msg, long timeStamp ) { + System.out.println( "midi received (" + name + ")" ); + System.out.println( "Timestamp: " + timeStamp ); + byte[] b = msg.getMessage(); + + if ( b[ 0 ] != -48 ) { + // System.out.println("Message length: " + msg.getLength()); + System.out.println( "Note command: " + commandMap.get( b[ 0 ] ) ); + System.out.println( "Which note: " + b[ 1 ] ); + System.out.println( "Note pressure: " + b[ 2 ] ); + System.out.println( "---------------------" ); + } + else { + // System.out.println("Message length: " + msg.getLength()); + System.out.println( "Note command: " + commandMap.get( b[ 0 ] ) ); + System.out.println( "Note Pressure: " + b[ 1 ] ); + System.out.println( "---------------------" ); + } + } + + public void close( ) { + } + } +} + diff --git a/examples/extra/ControlP5AutoDetectFields/ControlP5AutoDetectFields.pde b/examples/extra/ControlP5AutoDetectFields/ControlP5AutoDetectFields.pde new file mode 100644 index 0000000..bd405bb --- /dev/null +++ b/examples/extra/ControlP5AutoDetectFields/ControlP5AutoDetectFields.pde @@ -0,0 +1,58 @@ +/** + * ControlP5 Autodetect Fields + * + * test sketch, controller values will automatically be set + * to its corresponding sketch fields. + * + * by Andreas Schlegel, 2011 + * www.sojamo.de/libraries/controlp5 + * + */ + + +import controlP5.*; + +int s1 = 50; +int s2 = 50; + +int nb1 = 50; +int nb2 = 50; + +int k1 = 50; +int k2 = 50; + +boolean t1 = false; +boolean t2 = false; + +int r1 = 20; +int r2 = 50; + +void setup() { + size(400,400); + ControlP5 cp5 = new ControlP5(this); + cp5.addSlider("s1",10,150,10,10,100,15).setLabel("50"); + cp5.addSlider("s2",10,150,20,150,10,100,15).setLabel("20"); + + cp5.addNumberbox("nb1",10,50,100,15).setLabel("50"); + cp5.addNumberbox("nb2",20,150,50,100,15).setLabel("20"); + + cp5.addKnob("k1",10,150,10,150,50).setLabel("50"); + cp5.addKnob("k2",10,150,20,150,150,50).setLabel("20"); + + cp5.addToggle("t1",10,240,100,15).setLabel("false"); + cp5.addToggle("t2",true,150,240,100,15).setLabel("true"); + + cp5.addButton("b1",50,10,280,100,15).setLabel("50"); + cp5.addButton("b2",20,150,280,100,15).setLabel("20"); + + cp5.addRange("r1",10,150,r1,r2,10,320,100,15).setLabel("50"); + +} + +void draw() { + background(0); +} + +void controlEvent(ControlEvent c) { + println(c.getValue()); +} diff --git a/examples/extra/ControlP5ControllerInsideClass/ControlP5ControllerInsideClass.pde b/examples/extra/ControlP5ControllerInsideClass/ControlP5ControllerInsideClass.pde new file mode 100644 index 0000000..5213218 --- /dev/null +++ b/examples/extra/ControlP5ControllerInsideClass/ControlP5ControllerInsideClass.pde @@ -0,0 +1,31 @@ +import controlP5.*; + +ControlP5 cp5; +Test t; +void setup() { + cp5 = new ControlP5( this ); + t = new Test( "test" ); +} + +void draw() { + println( t.value ); +} + +class Test { + + int value; + + Test( String thePrefix ) { + cp5.addSlider( "value-"+thePrefix ) + .setRange( 0, 255 ) + .plugTo( this, "setValue" ) + .setValue( 127 ) + .setLabel("value") + ; + } + + void setValue(int theValue) { + value = theValue; + } +} + diff --git a/examples/extra/ControlP5canvasDrawIntoCanvas/ControlP5canvasDrawIntoCanvas.pde b/examples/extra/ControlP5canvasDrawIntoCanvas/ControlP5canvasDrawIntoCanvas.pde new file mode 100644 index 0000000..5b9f962 --- /dev/null +++ b/examples/extra/ControlP5canvasDrawIntoCanvas/ControlP5canvasDrawIntoCanvas.pde @@ -0,0 +1,72 @@ +/** + * ControlP5 DrawIntoCanvas + * + * this example demonstrates how to draw into a Canvas. + * Click and drag the mouse to show and draw into the Canvas. + * + * by Andreas Schlegel, 2011 + * www.sojamo.de/libraries/controlp5 + * + */ + +import controlP5.*; + +ControlP5 cp5; + +Canvas cc; + +// your controlWindowCanvas class +class MyCanvas extends Canvas { + + boolean mousePressed; + int mouseX, mouseY; + public void update(PApplet theApplet) { + mousePressed = theApplet.mousePressed; + mouseX = theApplet.mouseX; + mouseY = theApplet.mouseY; + } + + public void draw(PGraphics theApplet) { + theApplet.background(255); + // a rectangle will be drawn if the mouse has been + // pressed inside the main sketch window. + // mousePressed here refers to the mousePressed + // variable of your main sketch + if(mousePressed) { + theApplet.fill(255,0,0); + theApplet.rect(10,10,100,100); + theApplet.fill(0); + theApplet.ellipse(mouseX,mouseY,20,20); + } + // will draw a rectangle into the controlWindow + // if the mouse has been pressed inside the controlWindow itself. + // theApplet.mousePressed here refers to the + // mousePressed variable of the controlWindow. + if(mousePressed) { + theApplet.fill(0); + theApplet.rect(10,10,100,100); + theApplet.fill(255,0,0); + theApplet.ellipse(mouseX,mouseY,20,20); + } + + } + +} + + +void setup() { + size(400,400); + frameRate(30); + cp5 = new ControlP5(this); + + cc = new MyCanvas(); + cc.pre(); + cp5.addCanvas(cc); + +} + +void draw(){ + background(0); +} + + diff --git a/examples/extra/ControlP5console/ControlP5console.pde b/examples/extra/ControlP5console/ControlP5console.pde new file mode 100644 index 0000000..c5b5f38 --- /dev/null +++ b/examples/extra/ControlP5console/ControlP5console.pde @@ -0,0 +1,71 @@ +/** + * ControlP5 Println + * + * + * a console like textarea which captures the output from the System.out stream + * + * by Andreas Schlegel, 2012 + * www.sojamo.de/libraries/controlp5 + * + */ + +import controlP5.*; + +ControlP5 cp5; + +Textarea myTextarea; + +int c = 0; + +Println console; + +void setup() { + size(700, 400); + cp5 = new ControlP5(this); + cp5.enableShortcuts(); + frameRate(50); + myTextarea = cp5.addTextarea("txt") + .setPosition(100, 100) + .setSize(200, 200) + .setFont(createFont("", 10)) + .setLineHeight(14) + .setColor(color(200)) + .setColorBackground(color(0, 100)) + .setColorForeground(color(255, 100)); + ; + + console = cp5.addConsole(myTextarea);// +} + + +void draw() { + background(128); + noStroke(); + ellipseMode(CENTER); + float n = sin(frameCount*0.01)*300; + fill(110, 255,220); + ellipse(width/2, height/2, n , n); + + println(frameCount+"\t"+String.format("%.2f", frameRate)+"\t"+String.format("%.2f", n)); +} + +void keyPressed() { + switch(key) { + case('1'): + console.pause(); + break; + case('2'): + console.play(); + break; + case('3'): + console.setMax(8); + break; + case('4'): + console.setMax(-1); + break; + case('5'): + console.clear(); + break; + } +} + diff --git a/examples/extra/ControlP5controllerOnTop3D/ControlP5controllerOnTop3D.pde b/examples/extra/ControlP5controllerOnTop3D/ControlP5controllerOnTop3D.pde new file mode 100644 index 0000000..cd28d9d --- /dev/null +++ b/examples/extra/ControlP5controllerOnTop3D/ControlP5controllerOnTop3D.pde @@ -0,0 +1,148 @@ +/** + * ControlP5 Controller on top of 3D + * demonstrates how to use controlP5 controllers on top of a + * OpenGL 3D scene. + * + * by Andreas Schlegel, 2011 + * www.sojamo.de/libraries/controlP5 + * + */ + + + +import controlP5.*; +import processing.opengl.*; + +ControlP5 cp5; +ControlGroup messageBox; +int messageBoxResult = -1; +String messageBoxString = ""; +float t; + +void setup() { + size(640,480,P3D); + cp5 = new ControlP5(this); + noStroke(); + createMessageBox(); + Button b = cp5.addButton("toggleBox",1,20,20,100,20); + b.setLabel("Toggle Box"); + textFont(createFont("",30)); +} + + +void draw() { + hint(ENABLE_DEPTH_TEST); + pushMatrix(); + if(messageBox.isVisible()) { + background(128); + } else { + background(0); + fill(255); + text(messageBoxString,20,height-40); + } + + translate(width/2,height/2,mouseX); + rotateY(t+=0.1); + fill(255); + rect(-50,-50,100,100); + popMatrix(); + hint(DISABLE_DEPTH_TEST); + // in case yo uare using the camera or you have + // changed the default camera setting, reset the camera + // to default by uncommenting the following line. + // camera(); +} + + + +void toggleBox(int theValue) { + if(messageBox.isVisible()) { + messageBox.hide(); + } else { + messageBox.show(); + } +} + + +void createMessageBox() { + // create a group to store the messageBox elements + messageBox = cp5.addGroup("messageBox",width/2 - 150,100,300); + messageBox.setBackgroundHeight(120); + messageBox.setBackgroundColor(color(0,100)); + messageBox.hideBar(); + + // add a TextLabel to the messageBox. + Textlabel l = cp5.addTextlabel("messageBoxLabel","Some MessageBox text goes here.",20,20); + l.moveTo(messageBox); + + // add a textfield-controller with named-id inputbox + // this controller will be linked to function inputbox() below. + Textfield f = cp5.addTextfield("inputbox",20,36,260,20); + f.getCaptionLabel().setVisible(false); + f.moveTo(messageBox); + f.setColorForeground(color(20)); + f.setColorBackground(color(20)); + f.setColorActive(color(100)); + // add the OK button to the messageBox. + // the name of the button corresponds to function buttonOK + // below and will be triggered when pressing the button. + Button b1 = cp5.addButton("buttonOK",0,65,80,80,24); + b1.moveTo(messageBox); + b1.setColorBackground(color(40)); + b1.setColorActive(color(20)); + // by default setValue would trigger function buttonOK, + // therefore we disable the broadcasting before setting + // the value and enable broadcasting again afterwards. + // same applies to the cancel button below. + b1.setBroadcast(false); + b1.setValue(1); + b1.setBroadcast(true); + b1.setCaptionLabel("OK"); + // centering of a label needs to be done manually + // with marginTop and marginLeft + //b1.captionLabel().style().marginTop = -2; + //b1.captionLabel().style().marginLeft = 26; + + // add the Cancel button to the messageBox. + // the name of the button corresponds to function buttonCancel + // below and will be triggered when pressing the button. + Button b2 = cp5.addButton("buttonCancel",0,155,80,80,24); + b2.moveTo(messageBox); + b2.setBroadcast(false); + b2.setValue(0); + b2.setBroadcast(true); + b2.setCaptionLabel("Cancel"); + b2.setColorBackground(color(40)); + b2.setColorActive(color(20)); + //b2.captionLabel().toUpperCase(false); + // centering of a label needs to be done manually + // with marginTop and marginLeft + //b2.captionLabel().style().marginTop = -2; + //b2.captionLabel().style().marginLeft = 16; +} + +// function buttonOK will be triggered when pressing +// the OK button of the messageBox. +void buttonOK(int theValue) { + println("a button event from button OK."); + messageBoxString = ((Textfield)cp5.getController("inputbox")).getText(); + messageBoxResult = theValue; + messageBox.hide(); +} + + +// function buttonCancel will be triggered when pressing +// the Cancel button of the messageBox. +void buttonCancel(int theValue) { + println("a button event from button Cancel."); + messageBoxResult = theValue; + messageBox.hide(); +} + +// inputbox is called whenever RETURN has been pressed +// in textfield-controller inputbox +void inputbox(String theString) { + println("got something from the inputbox : "+theString); + messageBoxString = theString; + messageBox.hide(); +} diff --git a/examples/extra/ControlP5frame/ControlP5frame.pde b/examples/extra/ControlP5frame/ControlP5frame.pde new file mode 100644 index 0000000..0b597ac --- /dev/null +++ b/examples/extra/ControlP5frame/ControlP5frame.pde @@ -0,0 +1,98 @@ +/** + * ControlP5 Controlframe + * with controlP5 2.0 all java.awt dependencies have been removed + * as a consequence the option to display controllers in a separate + * window had to be removed as well. + * this example shows you how to create a java.awt.frame and use controlP5 + * + * by Andreas Schlegel, 2012 + * www.sojamo.de/libraries/controlp5 + * + */ + +import java.awt.Frame; +import java.awt.BorderLayout; +import controlP5.*; + +private ControlP5 cp5; + +ControlFrame cf; + +int def; + +void setup() { + size(400, 400); + cp5 = new ControlP5(this); + + // by calling function addControlFrame() a + // new frame is created and an instance of class + // ControlFrame is instanziated. + cf = addControlFrame("extra", 200,200); + + // add Controllers to the 'extra' Frame inside + // the ControlFrame class setup() method below. + + +} + +void draw() { + background(def); +} + +ControlFrame addControlFrame(String theName, int theWidth, int theHeight) { + Frame f = new Frame(theName); + ControlFrame p = new ControlFrame(this, theWidth, theHeight); + f.add(p); + p.init(); + f.setTitle(theName); + f.setSize(p.w, p.h); + f.setLocation(100, 100); + f.setResizable(false); + f.setVisible(true); + return p; +} + + +// the ControlFrame class extends PApplet, so we +// are creating a new processing applet inside a +// new frame with a controlP5 object loaded +public class ControlFrame extends PApplet { + + int w, h; + + int abc = 100; + + public void setup() { + size(w, h); + frameRate(25); + cp5 = new ControlP5(this); + cp5.addSlider("abc").setRange(0, 255).setPosition(10,10); + cp5.addSlider("def").plugTo(parent,"def").setRange(0, 255).setPosition(10,30); + } + + public void draw() { + background(abc); + } + + private ControlFrame() { + } + + public ControlFrame(Object theParent, int theWidth, int theHeight) { + parent = theParent; + w = theWidth; + h = theHeight; + } + + + public ControlP5 control() { + return cp5; + } + + + ControlP5 cp5; + + Object parent; + + +} + diff --git a/examples/extra/ControlP5frameRate/ControlP5frameRate.pde b/examples/extra/ControlP5frameRate/ControlP5frameRate.pde new file mode 100644 index 0000000..f956e3d --- /dev/null +++ b/examples/extra/ControlP5frameRate/ControlP5frameRate.pde @@ -0,0 +1,28 @@ +/** + * ControlP5 FrameRate + * + * + * uses a textlabel to display the current or average + * framerate of the sketch. + * + * by Andreas Schlegel, 2012 + * www.sojamo.de/libraries/controlp5 + * + */ + + +import controlP5.*; + +ControlP5 cp5; + +void setup() { + size(400,500); + frameRate(60); + cp5 = new ControlP5(this); + cp5.addFrameRate().setInterval(10).setPosition(0,height - 10); + +} + +void draw() { + background(129); +} diff --git a/examples/extra/ControlP5frames/ControlP5frames.pde b/examples/extra/ControlP5frames/ControlP5frames.pde new file mode 100644 index 0000000..1c1979d --- /dev/null +++ b/examples/extra/ControlP5frames/ControlP5frames.pde @@ -0,0 +1,134 @@ + +import java.awt.*; +import java.awt.event.*; +import controlP5.*; + +private ControlP5 cp5; + +ControlFrame cf1, cf2; + +int bgColor; + +void setup() { + size(400, 400 ,P3D ); + /* add a controlP5 instance for the main sketch window (not required for other ControlFrames to work) */ + cp5 = new ControlP5( this ); + cp5.addSlider( "s2" ); + + + /* Add a controlframe */ + + cf1 = addControlFrame( "hello", 200, 200, 20, 20, color( 100 ) ); + + // add a slider with an EventListener. When dragging the slider, + // variable bgColor will change accordingly. + cf1.control().addSlider( "s1" ).setRange( 0, 255 ).addListener( new ControlListener() { + public void controlEvent( ControlEvent ev ) { + bgColor = color( ev.getValue() ); + } + } + ); + + + /* Add a second controlframe */ + + cf2 = addControlFrame( "world", 200, 200, 20, 240, color( 100 ) ); + + // add a button with an EventListener. When releasing the button, + // variable bgColor will change to color( 255 ); + cf2.control().addButton( "b1" ).addListener( new ControlListener() { + public void controlEvent( ControlEvent ev ) { + bgColor = color( 255 ); + } + } + ); + + cf2.control().addButton( "b2" ).addListener( new ControlListener() { + public void controlEvent(ControlEvent ev) { + bgColor = color( random( 255 ), random( 255 ), random( 255 ) ); + } + } + ); +} + +void draw() { + background( bgColor ); +} + + +/* no changes required below */ + + +ControlFrame addControlFrame(String theName, int theWidth, int theHeight) { + return addControlFrame(theName, theWidth, theHeight, 100, 100, color( 0 ) ); +} + +ControlFrame addControlFrame(String theName, int theWidth, int theHeight, int theX, int theY, int theColor ) { + final Frame f = new Frame( theName ); + final ControlFrame p = new ControlFrame( this, theWidth, theHeight, theColor ); + + f.add( p ); + p.init(); + f.setTitle(theName); + f.setSize( p.w, p.h ); + f.setLocation( theX, theY ); + f.addWindowListener( new WindowAdapter() { + @Override + public void windowClosing(WindowEvent we) { + p.dispose(); + f.dispose(); + } + } + ); + f.setResizable( false ); + f.setVisible( true ); + // sleep a little bit to allow p to call setup. + // otherwise a nullpointerexception might be caused. + try { + Thread.sleep( 100 ); + } + catch(Exception e) { + } + return p; +} + + +// the ControlFrame class extends PApplet, so we +// are creating a new processing applet inside a +// new frame with a controlP5 object loaded +public class ControlFrame extends PApplet { + + int w, h; + + int bg; + + public void setup() { + size(w, h); + frameRate(25); + cp5 = new ControlP5( this ); + } + + public void draw() { + background( bg ); + } + + private ControlFrame() { + } + + public ControlFrame(Object theParent, int theWidth, int theHeight, int theColor) { + parent = theParent; + w = theWidth; + h = theHeight; + bg = theColor; + } + + + public ControlP5 control() { + return this.cp5; + } + + ControlP5 cp5; + + Object parent; +} + diff --git a/examples/extra/ControlP5groupCanvas/ControlP5groupCanvas.pde b/examples/extra/ControlP5groupCanvas/ControlP5groupCanvas.pde new file mode 100644 index 0000000..73c2bb7 --- /dev/null +++ b/examples/extra/ControlP5groupCanvas/ControlP5groupCanvas.pde @@ -0,0 +1,51 @@ +/** + * ControlP5 Canvas + * + * by andreas schlegel, 2011 + * www.sojamo.de/libraries/controlp5 + * + */ + +import controlP5.*; + +ControlP5 cp5; + +void setup() { + size(400,600); + smooth(); + + cp5 = new ControlP5(this); + cp5.addGroup("myGroup") + .setLabel("Testing Canvas") + .setPosition(100,200) + .setWidth(200) + .addCanvas(new TestCanvas()) + ; +} + +void draw() { + background(0); +} + + +class TestCanvas extends Canvas { + + float n; + float a; + + public void setup(PGraphics pg) { + println("starting a test canvas."); + n = 1; + } + public void draw(PGraphics pg) { + n += 0.01; + pg.ellipseMode(CENTER); + pg.fill(lerpColor(color(0,100,200),color(0,200,100),map(sin(n),-1,1,0,1))); + pg.rect(0,0,200,200); + pg.fill(255,150); + a+=0.01; + ellipse(100,100,abs(sin(a)*150),abs(sin(a)*150)); + ellipse(40,40,abs(sin(a+0.5)*50),abs(sin(a+0.5)*50)); + ellipse(60,140,abs(cos(a)*80),abs(cos(a)*80)); + } +} diff --git a/examples/extra/ControlP5imageButton/ControlP5imageButton.pde b/examples/extra/ControlP5imageButton/ControlP5imageButton.pde new file mode 100644 index 0000000..309ea21 --- /dev/null +++ b/examples/extra/ControlP5imageButton/ControlP5imageButton.pde @@ -0,0 +1,38 @@ +import controlP5.*; + +ControlP5 cp5; + +int myColor = color(0); + + +void setup() { + size(400,600); + cp5 = new ControlP5(this); + + // replace the default controlP5 button with an image. + // button.setImages(defaultImage, rolloverImage, pressedImage); + // use button.updateSize() to adjust the size of the button and + // resize to the dimensions of the defaultImage + + cp5.addButton("buttonA") + .setPosition(175,275) + .setImages(loadImage("Arrow-Left.png"), loadImage("Arrow-Right.png"), loadImage("Refresh.png")) + .updateSize(); +} + +void draw() { + background(myColor); +} + +public void controlEvent(ControlEvent theEvent) { + println(theEvent.getController().getName()); + +} + +// function buttonA will receive changes from +// controller with name buttonA +public void buttonA(int theValue) { + println("a button event from buttonA: "+theValue); + myColor = color(128); +} + diff --git a/examples/extra/ControlP5imageButton/data/Arrow-Left.png b/examples/extra/ControlP5imageButton/data/Arrow-Left.png new file mode 100755 index 0000000..33ab6ee Binary files /dev/null and b/examples/extra/ControlP5imageButton/data/Arrow-Left.png differ diff --git a/examples/extra/ControlP5imageButton/data/Arrow-Right.png b/examples/extra/ControlP5imageButton/data/Arrow-Right.png new file mode 100755 index 0000000..5afff9b Binary files /dev/null and b/examples/extra/ControlP5imageButton/data/Arrow-Right.png differ diff --git a/examples/extra/ControlP5imageButton/data/Refresh.png b/examples/extra/ControlP5imageButton/data/Refresh.png new file mode 100755 index 0000000..6582a31 Binary files /dev/null and b/examples/extra/ControlP5imageButton/data/Refresh.png differ diff --git a/examples/extra/ControlP5key/ControlP5key.pde b/examples/extra/ControlP5key/ControlP5key.pde new file mode 100644 index 0000000..095b7e4 --- /dev/null +++ b/examples/extra/ControlP5key/ControlP5key.pde @@ -0,0 +1,50 @@ +/** + * ControlP5 ControlKey + * use ControlKeys to map key combinations to particular events. + * multi-keypress supported. + * + * by Andreas Schlegel, 2012 + * www.sojamo.de/libraries/controlp5 + * + */ + +import controlP5.*; + +ControlP5 cp5; + +int col; +int colEllipse; +boolean visible; + +void setup() { + size(400, 600); + smooth(); + noStroke(); + col = color(0); + colEllipse = color(0,255,90); + cp5 = new ControlP5(this); + + // press key 1 to change background to white + cp5.mapKeyFor(new ControlKey() {public void keyEvent() {col = color(255);}}, '1'); + + // press key 2 to change background to black + cp5.mapKeyFor(new ControlKey() {public void keyEvent() {col = color(0);}}, '2'); + + // press key 1 and ALT to make circles visible + cp5.mapKeyFor(new ControlKey() {public void keyEvent() {visible = true;}}, ALT,'1'); + + // press key 2 and ALT to hide circles + cp5.mapKeyFor(new ControlKey() {public void keyEvent() {visible = false;}}, ALT,'2'); + + // press key 1 and ALT and SHIFT to change the color of circles + cp5.mapKeyFor(new ControlKey() {public void keyEvent() {colEllipse = color(random(255));}}, ALT,'1',SHIFT); +} + +void draw() { + background(col); + if(visible) { + fill(colEllipse); + ellipse(100,100,50,50); + ellipse(150,400,200,200); + } +} diff --git a/examples/extra/ControlP5listBoxClear/ControlP5listBoxClear.pde b/examples/extra/ControlP5listBoxClear/ControlP5listBoxClear.pde new file mode 100644 index 0000000..177d019 --- /dev/null +++ b/examples/extra/ControlP5listBoxClear/ControlP5listBoxClear.pde @@ -0,0 +1,74 @@ +import controlP5.*; + +String[][] s = new String[3][]; +ControlP5 controlP5; +ListBox l; + +void setup() { + size(400,400); + controlP5 = new ControlP5(this); + l = controlP5.addListBox("myList",100,100,120,150); + // l.actAsPulldownMenu(true); + l.setItemHeight(23); + + + s[0] = new String[] { + "a","b","c","d" + }; + s[1] = new String[] { + "a","b","c","d","e","f","g","h","i","j","k","l","m","n" + }; + s[2] = new String[] { + "l","m","n" + }; + + for(int i=0;i "+theEvent.getGroup().getValue()); + int n = int(theEvent.getGroup().getValue()); + println("\t\t group:"+(n >> 8 & 0xff)+", item:"+(n >> 0 & 0xff)); + } +} diff --git a/examples/extra/ControlP5mouseWheel/ControlP5mouseWheel.pde b/examples/extra/ControlP5mouseWheel/ControlP5mouseWheel.pde new file mode 100644 index 0000000..74904e8 --- /dev/null +++ b/examples/extra/ControlP5mouseWheel/ControlP5mouseWheel.pde @@ -0,0 +1,94 @@ +/** + * ControlP5 KeyEventAndWheel + * + * with controlP5 2.0 all java.awt dependencies have been removed + * as a consequence the option to use the MouseWheel for some controllers + * has been removed. But the following example shows how to manually add + * the mouseWheel support. + * + * With early versions of the processing 2.0 beta releases the keyEvent forwarding + * does not work as expected and needs to be forwarded manually. + * + * by Andreas Schlegel, 2012 + * www.sojamo.de/libraries/controlp5 + * + */ + + +import controlP5.*; +import java.util.*; + +ControlP5 cp5; + +void setup() { + size(700, 300); + cp5 = new ControlP5(this); + + + cp5.addNumberbox("numberbox") + .setPosition(20, 20) + .setSize(100, 20) + ; + + cp5.addSlider("slider") + .setPosition(20, 70) + .setSize(200, 20) + ; + + cp5.addKnob("knob") + .setPosition(20, 120) + .setRadius(50) + ; + + List drops = new ArrayList(); + for(int i=0;i<100;i++) { + drops.add("item "+i); + } + + cp5.addDropdownList("drop") + .setPosition(300, 30) + .setWidth(200) + .addItems(drops) + ; + + cp5.addListBox("list") + .setPosition(520, 30) + .setSize(150,200) + .addItems(drops) + ; + + cp5.addTextarea("area") + .setPosition(300, 150) + .setSize(200,100) + .setLineHeight(10) + .setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam feugiat porttitor tempus. Donec hendrerit aliquam mauris, a interdum ante pellentesque et. In dui erat, condimentum et sodales eget, scelerisque quis libero. Nam non nibh vitae enim auctor fringilla sit amet quis magna. Quisque ultricies mi at arcu vulputate imperdiet tristique purus adipiscing. Maecenas pretium odio ac leo aliquam id commodo nulla eleifend. Aenean in pharetra mauris. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla suscipit, nisl vitae eleifend tincidunt, dolor justo sollicitudin nunc, sit amet rhoncus odio purus eu purus. Cras bibendum placerat elementum. Donec in lorem libero. Praesent auctor, felis quis volutpat facilisis, neque turpis tempor nisi, interdum viverra enim purus vel mi. Nam faucibus accumsan lorem, convallis consectetur elit vulputate ut."); + ; + // add mousewheel support, now hover the slide with your mouse + // and use the mousewheel (or trackpad on a macbook) to change the + // value of the slider. + addMouseWheelListener(); +} + + +void draw() { + background(0); +} + + +void controlEvent(ControlEvent event) { + println(event); +} + +// When working in desktop mode, you can add mousewheel support for +// controlP5 by using java.awt.event.MouseWheelListener and +// java.awt.event.MouseWheelEvent + +void addMouseWheelListener() { + frame.addMouseWheelListener(new java.awt.event.MouseWheelListener() { + public void mouseWheelMoved(java.awt.event.MouseWheelEvent e) { + cp5.setMouseWheelRotation(e.getWheelRotation()); + } + } + ); +} + diff --git a/examples/extra/ControlP5pointer/ControlP5pointer.pde b/examples/extra/ControlP5pointer/ControlP5pointer.pde new file mode 100644 index 0000000..4b7cb65 --- /dev/null +++ b/examples/extra/ControlP5pointer/ControlP5pointer.pde @@ -0,0 +1,57 @@ +/** +* ControlP5 Pointer +* +* Default mouse actions use the Pointer class to trigger events. +* you can manipulate the x and y fields of the Pointer class +* for customizing input events for example when using a +* different input than the mouse. +* Here in this example the mouse coordiates are reveresed. +* +* by Andreas Schlegel, 2012 +* www.sojamo.de/libraries/controlp5 +* +*/ + +import controlP5.*; + +ControlP5 cp5; + +void setup() { + size(400, 600); + + cp5 = new ControlP5(this); + // disable outodraw because we want to draw our + // custom cursor on to of controlP5 + cp5.setAutoDraw(false); + + cp5.addSlider("hello", 0, 100, 50, 40, 40, 100, 20); + + // enable the pointer (and disable the mouse as input) + cp5.getPointer().enable(); + cp5.getPointer().set(width/2, height/2); +} + + +void draw() { + background(cp5.get("hello").getValue()); + // first draw controlP5 + cp5.draw(); + + // the draw our pointer + cp5.getPointer().set(width - mouseX, height - mouseY); + pushMatrix(); + translate(cp5.getPointer().getX(), cp5.getPointer().getY()); + stroke(255); + line(-10,0,10,0); + line(0,-10,0,10); + popMatrix(); + println(cp5.isMouseOver()); +} + +void mousePressed() { + cp5.getPointer().pressed(); +} + +void mouseReleased() { + cp5.getPointer().released(); +} diff --git a/examples/extra/ControlP5propertiesSets/ControlP5propertiesSets.pde b/examples/extra/ControlP5propertiesSets/ControlP5propertiesSets.pde new file mode 100644 index 0000000..17e21a9 --- /dev/null +++ b/examples/extra/ControlP5propertiesSets/ControlP5propertiesSets.pde @@ -0,0 +1,134 @@ +/** + * ControlP5 properties sets. + * + * saves/loads controller values into/from properties-file. + * this example shows how to make property sets of controllers that can be loaded and + * saved individually. By default property files come in a serialized format + * with a .ser extension. + * + * + * default properties load/save key combinations are + * alt+shift+l to load properties + * alt+shift+s to save properties + * + * + * find a list of public methods available for the ControllerPropererties Controller + * at the bottom of this sketch's source code + * + * by andreas schlegel, 2011 + * www.sojamo.de/libraries/controlp5 + * + */ + +import controlP5.*; + +ControlP5 cp5; + +public int slider1 = 32; +public int slider2 = 64; +public int slider3 = 128; +public int slider4 = 255; + + +void setup() { + size(400, 600); + cp5 = new ControlP5(this); + + // add a vertical slider + cp5.addSlider("slider1", 0, 255, 20, 100, 128, 20); + cp5.addSlider("slider2", 0, 255, 20, 150, 128, 20); + cp5.addSlider("slider3", 0, 255, 20, 200, 128, 20); + cp5.addSlider("slider4", 0, 255, 20, 250, 128, 20); + + cp5.addButton("b1", 0, 20, 350, 80, 12).setCaptionLabel("save setA"); + cp5.addButton("b2", 0, 101, 350, 80, 12).setCaptionLabel("load setA").setColorBackground(color(0, 100, 50)); + + cp5.addButton("b3", 0, 200, 350, 80, 12).setCaptionLabel("save default"); + cp5.addButton("b4", 0, 281, 350, 80, 12).setCaptionLabel("load default").setColorBackground(color(0, 100, 50)); + + + // add a new properties set 'setA' + cp5.getProperties().addSet("setA"); + + // move controller 'slider' from the default set to setA + // the 3 parameters read like this: move controller(1) from set(2) to set(3) + cp5.getProperties().move(cp5.getController("slider1"), "default", "setA"); + // use copy instead of move to register 'slider' with both sets (default and setA) + + // prints the current list of properties registered and the set(s) they belong to + cp5.getProperties().print(); + + /* by default properties are saved in JSON format, if you want to change to the old default (java's serialized format), un-comment line below*/ + // cp5.getProperties().setFormat(ControlP5.SERIALIZED); +} + +void draw() { + background(0); + + fill(slider1); + rect(250, 100, 100, 20); + + fill(slider2); + rect(250, 150, 100, 20); + + fill(slider3); + rect(250, 200, 100, 20); + + fill(slider4); + rect(250, 250, 100, 20); +} + +void b1(float v) { + cp5.saveProperties("setA", "setA"); +} + +void b2(float v) { + cp5.loadProperties(("setA")); +} + +void b3(float v) { + cp5.saveProperties("default", "default"); +} + +void b4(float v) { + cp5.loadProperties(("default.json")); +} + + + + + +/* + + a list of all methods available for the ControllerProperties class + use ControlP5.printPublicMethodsFor(ControllerProperties.class); + to print the following list into the console. + + You can find further details about class ControllerProperties in the javadoc. + + Format: + ClassName : returnType methodName(parameter type) + +controlP5.ControllerProperties : ControllerProperties remove(ControllerInterface) +controlP5.ControllerProperties : ControllerProperties remove(ControllerInterface, String) +controlP5.ControllerProperties : ControllerProperties remove(ControllerInterface, String, String) +controlP5.ControllerProperties : ControllerProperty getProperty(ControllerInterface, String) +controlP5.ControllerProperties : ControllerProperty getProperty(ControllerInterface, String, String) +controlP5.ControllerProperties : ControllerProperty register(ControllerInterface, String) +controlP5.ControllerProperties : ControllerProperty register(ControllerInterface, String, String) +controlP5.ControllerProperties : HashSet addSet(String) +controlP5.ControllerProperties : HashSet getPropertySet(ControllerInterface) +controlP5.ControllerProperties : List get(ControllerInterface) +controlP5.ControllerProperties : Map get() +controlP5.ControllerProperties : String toString() +controlP5.ControllerProperties : boolean load() +controlP5.ControllerProperties : boolean load(String) +controlP5.ControllerProperties : void delete(ControllerProperty) +controlP5.ControllerProperties : void move(ControllerInterface, String, String) +controlP5.ControllerProperties : void move(ControllerProperty, String, String) +controlP5.ControllerProperties : void only(ControllerProperty, String) +controlP5.ControllerProperties : void print() +controlP5.ControllerProperties : void setFormat(Format) +java.lang.Object : String toString() +java.lang.Object : boolean equals(Object) +*/ diff --git a/examples/extra/ControlP5propertiesSets/default.json b/examples/extra/ControlP5propertiesSets/default.json new file mode 100644 index 0000000..01a3398 --- /dev/null +++ b/examples/extra/ControlP5propertiesSets/default.json @@ -0,0 +1,17 @@ +{ + "/slider3": { + "min": 0, + "max": 255, + "value": 0 + }, + "/slider2": { + "min": 0, + "max": 255, + "value": 0 + }, + "/slider4": { + "min": 0, + "max": 255, + "value": 0 + } +} \ No newline at end of file diff --git a/examples/extra/ControlP5propertiesSets/setA.json b/examples/extra/ControlP5propertiesSets/setA.json new file mode 100644 index 0000000..8a50c9b --- /dev/null +++ b/examples/extra/ControlP5propertiesSets/setA.json @@ -0,0 +1,5 @@ +{"/slider1": { + "min": 0, + "max": 255, + "value": 255 +}} \ No newline at end of file diff --git a/examples/extra/ControlP5renderIntoPGraphics/ControlP5renderIntoPGraphics.pde b/examples/extra/ControlP5renderIntoPGraphics/ControlP5renderIntoPGraphics.pde new file mode 100644 index 0000000..0c11bc9 --- /dev/null +++ b/examples/extra/ControlP5renderIntoPGraphics/ControlP5renderIntoPGraphics.pde @@ -0,0 +1,51 @@ +/** +* ControlP5 RenderIntoPGraphics +* +* +* experimental +* +* by Andreas Schlegel, 2013 +* www.sojamo.de/libraries/controlp5 +* +*/ + + +import controlP5.*; + +ControlP5 c1 , c2; +PGraphics panel1 , panel2; + +void setup() { + size( 1024, 500 , P3D ); // + panel1 = createGraphics( 200 , height/2 ); + panel2 = createGraphics( 200 , height/2 ); + c1 = new ControlP5( this ); + c1.enableShortcuts(); + c1.setBackground( color( 0 , 50 ) ); + c1.addButton("hello").setSize(200,20).setPosition( 0 , 0 ); + c1.addButton("world").setSize(200,100).setPosition( 0 , 70 ); + c1.addSlider("slider").setSize(50,20).setPosition( 0 , 40 ); + c1.setGraphics( panel1 , 0 , 0 ); + + c2 = new ControlP5( this ); + c2.enableShortcuts(); + c2.setBackground( color( 0 , 50 ) ); + c2.addButton("hello").setSize(200,20).setPosition( 0 , 0 ); + c2.addButton("world").setSize(200,100).setPosition( 0 , 70 ); + c2.addSlider("slider").setSize(50,20).setPosition( 0 , 40 ); + c2.setGraphics( panel2 , 220 , 0 ); + +} + + +void draw() { + background( 100 , 0 , 0 ); + + /* TODO update mouseevent when using setGraphics */ + c1.setGraphics( panel1 , 100 + int(sin(frameCount*0.1) * 100) , 250 ); +} + + +void controlEvent( ControlEvent ce) { + println(ce); +} diff --git a/examples/extra/ControlP5style/ControlP5style.pde b/examples/extra/ControlP5style/ControlP5style.pde new file mode 100644 index 0000000..01147c0 --- /dev/null +++ b/examples/extra/ControlP5style/ControlP5style.pde @@ -0,0 +1,110 @@ +/** +* ControlP5 ControllerStyle +* +* +* find a list of public methods available for the ControllerStyle Controller +* at the bottom of this sketch. +* +* by Andreas Schlegel, 2011 +* www.sojamo.de/libraries/controlp5 +* +*/ + +import controlP5.*; + +ControlP5 cp5; + +float v1 = 50, v2 = 100, v3 = 100, v4 = 100; + +void setup() { + size(400,600); + smooth(); + noStroke(); + cp5 = new ControlP5(this); + + cp5.begin(100,100); + cp5.addSlider("v1",0,255).linebreak(); + cp5.addSlider("v2",0,200).linebreak(); + cp5.addSlider("v3",0,300).linebreak(); + cp5.addSlider("v4",0,400); + cp5.end(); + + // change the caption label for controller v1 and apply styles + cp5.getController("v1").setCaptionLabel("Background"); + style("v1"); + + // change the caption label for controller v2 and apply styles + cp5.getController("v2").setCaptionLabel("Ellipse A"); + style("v2"); + + // change the caption label for controller v3 and apply styles + cp5.getController("v3").setCaptionLabel("Ellipse B"); + style("v3"); + + // change the caption label for controller v3 and apply styles + cp5.getController("v4").setCaptionLabel("Ellipse C"); + style("v4"); + + +} + +void style(String theControllerName) { + Controller c = cp5.getController(theControllerName); + // adjust the height of the controller + c.setHeight(15); + + // add some padding to the caption label background + c.getCaptionLabel().getStyle().setPadding(4,4,3,4); + + // shift the caption label up by 4px + c.getCaptionLabel().getStyle().setMargin(-4,0,0,0); + + // set the background color of the caption label + c.getCaptionLabel().setColorBackground(color(10,20,30,140)); +} + +void draw() { + background(v1); + fill(255,255,220,100); + ellipse(width/2-100, height/2-100,v2 + 50,v2 + 50); + ellipse(width/2+100, height/2,v3,v3); + ellipse(width/2, height/2+100,v4,v4); +} + + + +/* +a list of all methods available for the ControllerStyle Controller +use ControlP5.printPublicMethodsFor(ControllerStyle.class); +to print the following list into the console. + +You can find further details about class ControllerStyle in the javadoc. + +Format: +ClassName : returnType methodName(parameter type) + + + + +controlP5.ControllerStyle : ControllerStyle margin(int) +controlP5.ControllerStyle : ControllerStyle margin(int, int, int, int) +controlP5.ControllerStyle : ControllerStyle moveMargin(int, int, int, int) +controlP5.ControllerStyle : ControllerStyle movePadding(int, int, int, int) +controlP5.ControllerStyle : ControllerStyle padding(int) +controlP5.ControllerStyle : ControllerStyle padding(int, int, int, int) +controlP5.ControllerStyle : ControllerStyle setMargin(int, int, int, int) +controlP5.ControllerStyle : ControllerStyle setMarginBottom(int) +controlP5.ControllerStyle : ControllerStyle setMarginLeft(int) +controlP5.ControllerStyle : ControllerStyle setMarginRight(int) +controlP5.ControllerStyle : ControllerStyle setMarginTop(int) +controlP5.ControllerStyle : ControllerStyle setPadding(int, int, int, int) +controlP5.ControllerStyle : ControllerStyle setPaddingBottom(int) +controlP5.ControllerStyle : ControllerStyle setPaddingLeft(int) +controlP5.ControllerStyle : ControllerStyle setPaddingRight(int) +controlP5.ControllerStyle : ControllerStyle setPaddingTop(int) +java.lang.Object : String toString() +java.lang.Object : boolean equals(Object) + + +*/ + diff --git a/examples/extra/ControlP5textfieldAdvanced/ControlP5textfieldAdvanced.pde b/examples/extra/ControlP5textfieldAdvanced/ControlP5textfieldAdvanced.pde new file mode 100644 index 0000000..61899bd --- /dev/null +++ b/examples/extra/ControlP5textfieldAdvanced/ControlP5textfieldAdvanced.pde @@ -0,0 +1,114 @@ +/** + * ControlP5 textfield (advanced) + * + * demonstrates how to use keepFocus, setText, getText, getTextList, + * clear, setAutoClear, isAutoClear and submit. + * + * by andreas schlegel, 2012 + * www.sojamo.de/libraries/controlp5 + * + */ + +import controlP5.*; + +ControlP5 cp5; + +String textValue = ""; + +Textfield myTextfield; + +void setup() { + size(400, 600); + + cp5 = new ControlP5(this); + myTextfield = cp5.addTextfield("textinput") + .setPosition(100, 200) + .setSize(200, 20) + .setFocus(true) + ; + + cp5.addTextfield("textValue") + .setPosition(100, 300) + .setSize(200, 20) + ; + + // use setAutoClear(true/false) to clear a textfield or keep text displayed in + // a textfield after pressing return. + myTextfield.setAutoClear(true).keepFocus(true); + + cp5.addButton("clear", 0, 20, 200, 70, 20); + cp5.addButton("submit", 0, 310, 200, 60, 20); + cp5.addButton("performTextfieldActions", 0, 20, 100, 150, 20); + cp5.addToggle("toggleAutoClear", true, 180, 100, 90, 20).setCaptionLabel("Auto Clear"); + cp5.addToggle("toggleKeepFocus", true, 280, 100, 90, 20).setCaptionLabel("Keep Focus"); + + +} + +void draw() { + background(0); +} + +void toggleAutoClear(boolean theFlag) { + myTextfield.setAutoClear(theFlag); +} + +void toggleKeepFocus(boolean theFlag) { + myTextfield.keepFocus(theFlag); +} + +void clear(int theValue) { + myTextfield.clear(); +} + +void submit(int theValue) { + myTextfield.submit(); +} + + +void controlEvent(ControlEvent theEvent) { + if (theEvent.isAssignableFrom(Textfield.class)) { + Textfield t = (Textfield)theEvent.getController(); + + println("controlEvent: accessing a string from controller '" + +t.getName()+"': "+t.getStringValue() + ); + + // Textfield.isAutoClear() must be true + print("controlEvent: trying to setText, "); + + t.setText("controlEvent: changing text."); + if (t.isAutoClear()==false) { + println(" success!"); + } + else { + println(" but Textfield.isAutoClear() is false, could not setText here."); + } + } +} + +void performTextfieldActions() { + println("\n"); + // Textfield.getText(); + println("the current text of myTextfield: "+myTextfield.getText()); + println("the current value of textValue: "+textValue); + // Textfield.setText(); + myTextfield.setText("changed the text of a textfield"); + println("changing text of myTextfield to: "+myTextfield.getText()); + // Textfield.getTextList(); + println("the textlist of myTextfield has "+myTextfield.getTextList().length+" items."); + for (int i=0;i + * After initializing controlP5 you can add controllers to controlP5. + * Here we use three numberboxes, one slider and one textfield. + * The numberbox with name numberboxC will trigger function numberboxC() + * in the example below. Whenever controlP5 detects a function in your + * sketch that corresponds to the name of a controller, it will forward + * an event to that function. Any event triggered by a controller + * will be forwarded to function controlEvent in your sketch. + * related examples ControlP5numberbox, ControlP5slider, ControlP5textfield + * + * by Andreas Schlegel, 2011 + * www.sojamo.de/libraries/controlp5 + * + */ + + +import controlP5.*; + +ControlP5 cp5; +public int myColorRect = 200; +public int myColorBackground = 100; + +void setup() { + size(400, 400); + noStroke(); + + cp5 = new ControlP5(this); + + // create a slider + // parameters: + // name, minValue, maxValue, defaultValue, x, y, width, height + cp5.addSlider("sliderA", 100, 200, 100, 100, 260, 100, 14); + + + // create 3 numberboxes and assign an id for each + cp5.addNumberbox("numberboxA", myColorRect, 100, 140, 100, 14).setId(1); + cp5.addNumberbox("numberboxB", myColorBackground, 100, 180, 100, 14).setId(2); + cp5.addNumberbox("numberboxC", 0, 100, 220, 100, 14).setId(3); + + + // create a texfield + cp5.addTextfield("textA", 100, 290, 100, 20); + + // change individual settings for a controller + cp5.getController("numberboxA").setMax(255); + cp5.getController("numberboxA").setMin(0); +} + +void draw() { + background(myColorBackground); + fill(myColorRect); + rect(0, 0, width, 100); +} + + +// events from controller numberboxC are received here +public void numberboxC(int theValue) { + println("### got an event from numberboxC : "+theValue); +} + + +// an event from slider sliderA will change the value of textfield textA here +public void sliderA(int theValue) { + Textfield txt = ((Textfield)cp5.getController("textA")); + txt.setValue(""+theValue); +} + + +// for every change (a textfield event confirmed with a return) in textfield textA, +// function textA will be invoked +public void textA(String theValue) { + println("### got an event from textA : "+theValue); +} + + +// function controlEvent will be invoked with every value change +// in any registered controller +public void controlEvent(ControlEvent theEvent) { + println("got a control event from controller with id "+theEvent.getId()); + switch(theEvent.getId()) { + case(1): // numberboxA is registered with id 1 + myColorRect = (int)(theEvent.getController().getValue()); + break; + case(2): // numberboxB is registered with id 2 + myColorBackground = (int)(theEvent.getController().getValue()); + break; + } +} + diff --git a/examples/use/ControlP5beginEnd/ControlP5beginEnd.pde b/examples/use/ControlP5beginEnd/ControlP5beginEnd.pde new file mode 100644 index 0000000..954ddd2 --- /dev/null +++ b/examples/use/ControlP5beginEnd/ControlP5beginEnd.pde @@ -0,0 +1 @@ +// TBD diff --git a/examples/use/ControlP5behavior/ControlP5behavior.pde b/examples/use/ControlP5behavior/ControlP5behavior.pde new file mode 100644 index 0000000..6f76b82 --- /dev/null +++ b/examples/use/ControlP5behavior/ControlP5behavior.pde @@ -0,0 +1,125 @@ +/** + * ControlP5 Behavior + * ControlBehavior is an abstract class that can be extended using your + * custom control behaviors. What is a control behavior? Control Behaviors + * allow you to automate and dynamically change the state or value of a + * controller. One behavior per controller is currently supported. i case you + * need to use more that one bahavior, the implementation has to happen + * on your side - inside your control behavior. + * + * find a list of public methods available for the ControlBehavior Controller + * at the bottom of this sketch. + * + * by Andreas Schlegel, 2012 + * www.sojamo.de/libraries/controlp5 + * + */ + +import controlP5.*; + + +ControlP5 cp5; + +int myColorBackground = color(0, 0, 0); + +public int sliderValue = 100; + +void setup() { + size(400, 400); + noStroke(); + + cp5 = new ControlP5(this); + cp5.addSlider("sliderValue") + .setRange(0,255) + .setValue(128) + .setPosition(100, 50 + height/2) + .setSize(40, 100); + + cp5.addSlider("slider") + .setRange(100, 255) + .setValue(128) + .setPosition(100, 50) + .setSize(100, 40); + + + cp5.addBang("bang") + .setPosition(40, 50 + height/2) + .setSize(40, 40); + + // add a custom ControlBehavior to controller bang, + // class TimerEvent is included in this sketch at the bottom + // and extends abstract class ControlBehavior. + cp5.getController("bang").setBehavior(new TimedEvent()); + + // use an anonymous class of type ControlBehavior. + cp5.getController("slider").setBehavior(new ControlBehavior() { + float a = 0; + public void update() { + setValue(sin(a += 0.1) * 50 + 150); + } + } + ); +} + +void draw() { + background(myColorBackground); + fill(sliderValue); + rect(0, 0, width, height/2); +} + +void slider(float theColor) { + myColorBackground = color(theColor); + println("# a slider event. setting background to "+theColor); +} + +public void bang() { + println("# an event received from controller bang."); + // a bang will set the value of controller sliderValue + // to a random number between 0 and 255. + cp5.getController("sliderValue").setValue(random(0, 255)); +} + +// custom ControlBehavior +class TimedEvent extends ControlBehavior { + long myTime; + int interval = 200; + + public TimedEvent() { + reset(); + } + void reset() { + myTime = millis() + interval; + } + + public void update() { + if (millis()>myTime) { + setValue(1); + reset(); + } + } +} + + + + +/* +a list of all methods available for the ControlBehavior Controller +use ControlP5.printPublicMethodsFor(ControlBehavior.class); +to print the following list into the console. + +You can find further details about class ControlBehavior in the javadoc. + +Format: +ClassName : returnType methodName(parameter type) + + +controlP5.ControlBehavior : Controller controller() +controlP5.ControlBehavior : boolean isActive() +controlP5.ControlBehavior : void setActive(boolean) +controlP5.ControlBehavior : void setValue(float) +java.lang.Object : String toString() +java.lang.Object : boolean equals(Object) + + +*/ + diff --git a/examples/use/ControlP5callback/ControlP5callback.pde b/examples/use/ControlP5callback/ControlP5callback.pde new file mode 100644 index 0000000..aad21b0 --- /dev/null +++ b/examples/use/ControlP5callback/ControlP5callback.pde @@ -0,0 +1,191 @@ +/** + * ControlP5 Callback + * + * The following example demonstrates the CallbackListener and CallbackEvent. + * Here additional information about each available slider will be show when + * hovering the controller with the mouse. The info will fade out when leaving + * the controller. + * + * When hovering a controller, the mouse pointer will change as well. + * + * find a list of public methods available for the CallbackEvent Controller + * at the bottom of this sketch. + * + * by Andreas Schlegel, 2012 + * www.sojamo.de/libraries/controlp5 + * + */ + +import controlP5.*; + +ControlP5 cp5; +Slider s1, s2; +Info info; +CallbackListener cb; + +void setup() { + size(800, 400); + + cp5 = new ControlP5(this); + + + // create a new instance of class Info + // info will be used to display a controller's information and + // will fade in when a CallbackEvent is invoked. + info = new Info(); + + + // add 2 sliders + s1 = cp5.addSlider("hello") + .setRange(0, 100) + .setValue(50) + .setPosition(40, 40) + .setSize(100, 20); + + s2 = cp5.addSlider("world") + .setRange(0, 100) + .setValue(10) + .setPosition(40, 70) + .setSize(100, 20); + + + // the following CallbackListener will listen to any controlP5 + // action such as enter, leave, pressed, released, releasedoutside, broadcast + // see static variables starting with ACTION_ inside class controlP5.ControlP5Constants + + cb = new CallbackListener() { + public void controlEvent(CallbackEvent theEvent) { + switch(theEvent.getAction()) { + case(ControlP5.ACTION_ENTER): + info.n = 1; + info.label.setText(theEvent.getController().getInfo()); + cursor(HAND); + break; + case(ControlP5.ACTION_LEAVE): + case(ControlP5.ACTION_RELEASEDOUTSIDE): + info.n = 0; + cursor(ARROW); + break; + } + } + }; + + // add the above callback to controlP5 + cp5.addCallback(cb); + + // add another callback to slider s1, callback event will only be invoked for this + // particular controller. + s1.addCallback(new CallbackListener() { + public void controlEvent(CallbackEvent theEvent) { + if (theEvent.getAction()==ControlP5.ACTION_BROADCAST) { + s2.setValue(s2.getMax() - s1.getValue()); + } + } + } + ); +} + +void draw() { + background(0); + info.update(); +} + + +void controlEvent(ControlEvent theEvent) { + println("Got a ControlEvent for "+theEvent.name()+" = "+theEvent.value()); + info.label.setText(theEvent.getController().getInfo()); +} + +void keyPressed() { + // uncomment the line below to remove callback cb from controlP5 + // when a key is pressed. + //controlP5.removeCallback(cb); +} + +// controlEvent(CallbackEvent) is called whenever a callback +// has been triggered. controlEvent(CallbackEvent) is detected by +// controlP5 automatically. +void controlEvent(CallbackEvent theEvent) { + if (theEvent.getController().equals(s2)) { + switch(theEvent.getAction()) { + case(ControlP5.ACTION_ENTER): + println("Action:ENTER"); + break; + case(ControlP5.ACTION_LEAVE): + println("Action:LEAVE"); + break; + case(ControlP5.ACTION_PRESSED): + println("Action:PRESSED"); + break; + case(ControlP5.ACTION_RELEASED): + println("Action:RELEASED"); + break; + case(ControlP5.ACTION_RELEASEDOUTSIDE): + println("Action:RELEASED OUTSIDE"); + break; + case(ControlP5.ACTION_BROADCAST): + println("Action:BROADCAST"); + break; + } + } +} + + + +class Info { + float a; + float n = 0; + String txt = ""; + Textarea label; + + Info() { + label = cp5.addTextarea("Hello\nWorld") + .setSize(200,200) + .setPosition(300,40) + .setColor(color(255)) + .setColorBackground(color(100,0)) + .setLineHeight(12); + + } + + void update() { + a += (n-a)*0.1; + label.setColorBackground(color(100,255*a)); + } +} + + + + + + + + + + + + + + + +/* +a list of all methods available for the CallbackEvent Controller + use ControlP5.printPublicMethodsFor(CallbackEvent.class); + to print the following list into the console. + + You can find further details about class CallbackEvent in the javadoc. + + Format: + ClassName : returnType methodName(parameter type) + + + controlP5.CallbackEvent : Controller getController() + controlP5.CallbackEvent : int getAction() + java.lang.Object : String toString() + java.lang.Object : boolean equals(Object) + + + */ + + + diff --git a/examples/use/ControlP5controlEvent/ControlP5controlEvent.pde b/examples/use/ControlP5controlEvent/ControlP5controlEvent.pde new file mode 100644 index 0000000..b7b44df --- /dev/null +++ b/examples/use/ControlP5controlEvent/ControlP5controlEvent.pde @@ -0,0 +1,112 @@ +/** + * ControlP5 ControlEvent. + * every control event is automatically forwarded to the function controlEvent(ControlEvent) + * inside a sketch if such function is available. For further details about the API of + * the ControlEvent class, please refer to the documentation. + * + * + * find a list of public methods available for ControlEvent + * at the bottom of this sketch's source code + * + * by Andreas Schlegel, 2012 + * www.sojamo.de/libraries/controlP5 + * + */ + +import controlP5.*; + +ControlP5 cp5; + +public int myColorRect1 = 200; + +public int myColorRect2 = 100; + + +void setup() { + size(400, 400); + noStroke(); + + cp5 = new ControlP5(this); + cp5.addNumberbox("n1") + .setValue(myColorRect1) + .setPosition(20, 20) + .setSize(100, 20) + .setMin(0) + .setMax(255) + .setId(1); + + cp5.addNumberbox("n2") + .setValue(myColorRect2) + .setPosition(20, 60) + .setSize(100, 20) + .setMin(0) + .setMax(255) + .setId(2); + + cp5.addTextfield("n3") + .setPosition(20, 100) + .setSize(100, 20) + .setId(3); + +} + +void draw() { + background(ControlP5.MAROON); + fill(ControlP5.RED, myColorRect1); + rect(140, 20, 240, 170); + fill(ControlP5.FUCHSIA, myColorRect2); + rect(140, 210, 240, 170); +} + + +void controlEvent(ControlEvent theEvent) { + println("got a control event from controller with id "+theEvent.getController().getId()); + + if (theEvent.isFrom(cp5.getController("n1"))) { + println("this event was triggered by Controller n1"); + } + + switch(theEvent.getController().getId()) { + case(1): + myColorRect1 = (int)(theEvent.getController().getValue()); + break; + case(2): + myColorRect2 = (int)(theEvent.getController().getValue()); + break; + case(3): + println(theEvent.getController().getStringValue()); + break; + } +} + + +/* + a list of all methods available for ControlEvent + use ControlP5.printPublicMethodsFor(ControlEvent.class); + to print the following list into the console. + + You can find further details about class ControlEvent in the javadoc. + + Format: + ClassName : returnType methodName(parameter type) + + controlP5.ControlEvent : ControlGroup getGroup() + controlP5.ControlEvent : Controller getController() + controlP5.ControlEvent : String getLabel() + controlP5.ControlEvent : String getName() + controlP5.ControlEvent : String getStringValue() + controlP5.ControlEvent : Tab getTab() + controlP5.ControlEvent : boolean isController() + controlP5.ControlEvent : boolean isFrom(ControllerInterface) + controlP5.ControlEvent : boolean isFrom(String) + controlP5.ControlEvent : boolean isGroup() + controlP5.ControlEvent : boolean isTab() + controlP5.ControlEvent : float getValue() + controlP5.ControlEvent : float[] getArrayValue() + controlP5.ControlEvent : int getId() + controlP5.ControlEvent : int getType() + java.lang.Object : String toString() + java.lang.Object : boolean equals(Object) + */ + + diff --git a/examples/use/ControlP5controlFont/ControlP5controlFont.pde b/examples/use/ControlP5controlFont/ControlP5controlFont.pde new file mode 100644 index 0000000..3f14de9 --- /dev/null +++ b/examples/use/ControlP5controlFont/ControlP5controlFont.pde @@ -0,0 +1,100 @@ +/** + * ControlP5 controlFont. + * + * this example shows how to create a button with controlP5 (1), how to + * load and use a PFont with controlP5 (2), apply a ControlFont to + * the caption label of a button (3), and adjust the location of a + * caption label using the style() property of a controller. + * + * by andreas schlegel, 2012 + */ +import controlP5.*; + +ControlP5 cp5; + +controlP5.Button b; + +int buttonValue = 1; + +boolean isOpen; + +int myColorBackground = color(0,0,0); + + +void setup() { + size(700,400); + smooth(); + + cp5 = new ControlP5(this); + // (1) + // create some controllers + cp5.addButton("button") + .setValue(10) + .setPosition(20,20) + .setSize(100,50) + .setId(1); + + b = cp5.addButton("buttonValue") + .setValue(4) + .setPosition(100,190) + .setSize(200,200) + .setId(2); + + // (2) + // load a new font. ControlFont is a wrapper for processing's PFont + // with processing 1.1 ControlFont.setSmooth() is not supported anymore. + // to display a font as smooth or non-smooth, use true/false as 3rd parameter + // when creating a PFont: + + PFont pfont = createFont("Arial",20,true); // use true/false for smooth/no-smooth + ControlFont font = new ControlFont(pfont,241); + + + + // (3) + // change the font and content of the captionlabels + // for both buttons create earlier. + cp5.getController("button") + .getCaptionLabel() + .setFont(font) + .toUpperCase(false) + .setSize(24) + ; + + b.getCaptionLabel() + .setFont(font) + .setSize(50) + .toUpperCase(false) + .setText("hello") + ; +// + // (4) + // adjust the location of a catiption label using the + // style property of a controller. + b.getCaptionLabel().getStyle().marginLeft = 20; + b.getCaptionLabel().getStyle().marginTop = 40; + +} + +void draw() { + background(ControlP5.SILVER); + // animate button b + float x = b.x(b.getPosition()); + x += ((isOpen==true ? 0:-200) - x) * 0.2;; + float y = b.y(b.getPosition()); + b.setPosition(x,y); +} + +public void controlEvent(ControlEvent theEvent) { + println(theEvent.getController().getId()); +} + +public void button(float theValue) { + println("a button event. "+theValue); + isOpen = !isOpen; + cp5.getController("button").setCaptionLabel((isOpen==true) ? "close":"open"); +} + + + + diff --git a/examples/use/ControlP5customView/ControlP5customView.pde b/examples/use/ControlP5customView/ControlP5customView.pde new file mode 100644 index 0000000..4db2e6f --- /dev/null +++ b/examples/use/ControlP5customView/ControlP5customView.pde @@ -0,0 +1,101 @@ +/** +* ControlP5 Custom View +* +* +* find a list of public methods available for the ControllerDisplay Controller +* at the bottom of this sketch. +* +* by Andreas Schlegel, 2012 +* www.sojamo.de/libraries/controlp5 +* +*/ + + +import controlP5.*; + + +ControlP5 cp5; + + +void setup() { + size(400, 400); + smooth(); + cp5 = new ControlP5(this); + cp5.addButton("hello") + .setPosition(50, 100) + .setSize(150,150) + .setView(new CircularButton()) + ; + + cp5.addButton("world") + .setPosition(250, 100) + .setSize(50,50) + .setView(new CircularButton()) + ; +} + + +void draw() { + background(ControlP5.BLACK); +} + +public void hello(int theValue) { + println("Hello pressed"); +} + +public void world(int theValue) { + println("World pressed"); +} + +/** + * to define a custom View for a controller use the ContollerView interface + * T here must be replace by the name of the Controller class your custom View will be + * applied to. In our example T is replace by Button since we are aplpying the View + * to the Button instance create in setup. The ControllerView interface requires + * you to implement the display(PApplet, T) method. Same here, T must be replaced by + * the Controller class you are designing the custom view for, for us this is the + * Button class. + */ + +class CircularButton implements ControllerView