Visual C++ Form Variable Errors - forms

I'm new to Visual C++, have added a form to my project, which has given me a file kamisado_board.h with entirely auto-generated code, which I have included at the bottom of this post for reference. I assume this is fine as it was generated by the program.
I've written a separate file, kamisado_main.cpp, and get the following errors upon compiling:
"Error 1 error C2065: 'KamisadoBoard' : undeclared identifier"
"Error 2 error C2146: syntax error : missing ';' before identifier 'form'"
"Error 3 error C2065: 'form' : undeclared identifier"
"Error 4 error C2061: syntax error : identifier 'KamisadoBoard'"
"Error 5 error C2065: 'form' : undeclared identifier"
"Error 6 error C2227: left of '->Show' must point to class/struct/union/generic type"
I have included the code for this file here:
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <iostream>
#include "kamisado_board.h"
int
main(int argc, char *argv[])
{
bool running = true;
int input = 0;
KamisadoBoard form = gcnew KamisadoBoard;
return(0);
}
I figured that it might be a missing #include from my experience with C (I code C for my job but am new to C++), but it's still complaining even with me including kamisado_board.h. Am I missing a line somewhere? I've included the auto-generated form file kamisado_board.h below for reference though I'm assuming this will be correct! Thanks in advance.
//kamisado_board.h
#pragma once
namespace Project1 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for KamisadoBoard
/// </summary>
public ref class KamisadoBoard : public System::Windows::Forms::Form
{
public:
KamisadoBoard(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~KamisadoBoard()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
protected:
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::Button^ button3;
private: System::Windows::Forms::Button^ button4;
private: System::Windows::Forms::Button^ button5;
private: System::Windows::Forms::Button^ button6;
private: System::Windows::Forms::Button^ button7;
private: System::Windows::Forms::Button^ button8;
private: System::Windows::Forms::Button^ button9;
private: System::Windows::Forms::Button^ button10;
private: System::Windows::Forms::Button^ button11;
private: System::Windows::Forms::Button^ button12;
private: System::Windows::Forms::Button^ button13;
private: System::Windows::Forms::Button^ button14;
private: System::Windows::Forms::Button^ button15;
private: System::Windows::Forms::Button^ button16;
private: System::Windows::Forms::Button^ button17;
private: System::Windows::Forms::Button^ button18;
private: System::Windows::Forms::Button^ button19;
private: System::Windows::Forms::Button^ button20;
private: System::Windows::Forms::Button^ button21;
private: System::Windows::Forms::Button^ button22;
private: System::Windows::Forms::Button^ button23;
private: System::Windows::Forms::Button^ button24;
private: System::Windows::Forms::Button^ button25;
private: System::Windows::Forms::Button^ button26;
private: System::Windows::Forms::Button^ button27;
private: System::Windows::Forms::Button^ button28;
private: System::Windows::Forms::Button^ button29;
private: System::Windows::Forms::Button^ button30;
private: System::Windows::Forms::Button^ button31;
private: System::Windows::Forms::Button^ button32;
private: System::Windows::Forms::Button^ button33;
private: System::Windows::Forms::Button^ button34;
private: System::Windows::Forms::Button^ button35;
private: System::Windows::Forms::Button^ button36;
private: System::Windows::Forms::Button^ button37;
private: System::Windows::Forms::Button^ button38;
private: System::Windows::Forms::Button^ button39;
private: System::Windows::Forms::Button^ button40;
private: System::Windows::Forms::Button^ button41;
private: System::Windows::Forms::Button^ button42;
private: System::Windows::Forms::Button^ button43;
private: System::Windows::Forms::Button^ button44;
private: System::Windows::Forms::Button^ button45;
private: System::Windows::Forms::Button^ button46;
private: System::Windows::Forms::Button^ button47;
private: System::Windows::Forms::Button^ button48;
private: System::Windows::Forms::Button^ button49;
private: System::Windows::Forms::Button^ button50;
private: System::Windows::Forms::Button^ button51;
private: System::Windows::Forms::Button^ button52;
private: System::Windows::Forms::Button^ button53;
private: System::Windows::Forms::Button^ button54;
private: System::Windows::Forms::Button^ button55;
private: System::Windows::Forms::Button^ button56;
private: System::Windows::Forms::Button^ button57;
private: System::Windows::Forms::Button^ button58;
private: System::Windows::Forms::Button^ button59;
private: System::Windows::Forms::Button^ button60;
private: System::Windows::Forms::Button^ button61;
private: System::Windows::Forms::Button^ button62;
private: System::Windows::Forms::Button^ button63;
private: System::Windows::Forms::Button^ button64;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->button3 = (gcnew System::Windows::Forms::Button());
this->button4 = (gcnew System::Windows::Forms::Button());
this->button5 = (gcnew System::Windows::Forms::Button());
this->button6 = (gcnew System::Windows::Forms::Button());
this->button7 = (gcnew System::Windows::Forms::Button());
this->button8 = (gcnew System::Windows::Forms::Button());
this->button9 = (gcnew System::Windows::Forms::Button());
this->button10 = (gcnew System::Windows::Forms::Button());
this->button11 = (gcnew System::Windows::Forms::Button());
this->button12 = (gcnew System::Windows::Forms::Button());
this->button13 = (gcnew System::Windows::Forms::Button());
this->button14 = (gcnew System::Windows::Forms::Button());
this->button15 = (gcnew System::Windows::Forms::Button());
this->button16 = (gcnew System::Windows::Forms::Button());
this->button17 = (gcnew System::Windows::Forms::Button());
this->button18 = (gcnew System::Windows::Forms::Button());
this->button19 = (gcnew System::Windows::Forms::Button());
this->button20 = (gcnew System::Windows::Forms::Button());
this->button21 = (gcnew System::Windows::Forms::Button());
this->button22 = (gcnew System::Windows::Forms::Button());
this->button23 = (gcnew System::Windows::Forms::Button());
this->button24 = (gcnew System::Windows::Forms::Button());
this->button25 = (gcnew System::Windows::Forms::Button());
this->button26 = (gcnew System::Windows::Forms::Button());
this->button27 = (gcnew System::Windows::Forms::Button());
this->button28 = (gcnew System::Windows::Forms::Button());
this->button29 = (gcnew System::Windows::Forms::Button());
this->button30 = (gcnew System::Windows::Forms::Button());
this->button31 = (gcnew System::Windows::Forms::Button());
this->button32 = (gcnew System::Windows::Forms::Button());
this->button33 = (gcnew System::Windows::Forms::Button());
this->button34 = (gcnew System::Windows::Forms::Button());
this->button35 = (gcnew System::Windows::Forms::Button());
this->button36 = (gcnew System::Windows::Forms::Button());
this->button37 = (gcnew System::Windows::Forms::Button());
this->button38 = (gcnew System::Windows::Forms::Button());
this->button39 = (gcnew System::Windows::Forms::Button());
this->button40 = (gcnew System::Windows::Forms::Button());
this->button41 = (gcnew System::Windows::Forms::Button());
this->button42 = (gcnew System::Windows::Forms::Button());
this->button43 = (gcnew System::Windows::Forms::Button());
this->button44 = (gcnew System::Windows::Forms::Button());
this->button45 = (gcnew System::Windows::Forms::Button());
this->button46 = (gcnew System::Windows::Forms::Button());
this->button47 = (gcnew System::Windows::Forms::Button());
this->button48 = (gcnew System::Windows::Forms::Button());
this->button49 = (gcnew System::Windows::Forms::Button());
this->button50 = (gcnew System::Windows::Forms::Button());
this->button51 = (gcnew System::Windows::Forms::Button());
this->button52 = (gcnew System::Windows::Forms::Button());
this->button53 = (gcnew System::Windows::Forms::Button());
this->button54 = (gcnew System::Windows::Forms::Button());
this->button55 = (gcnew System::Windows::Forms::Button());
this->button56 = (gcnew System::Windows::Forms::Button());
this->button57 = (gcnew System::Windows::Forms::Button());
this->button58 = (gcnew System::Windows::Forms::Button());
this->button59 = (gcnew System::Windows::Forms::Button());
this->button60 = (gcnew System::Windows::Forms::Button());
this->button61 = (gcnew System::Windows::Forms::Button());
this->button62 = (gcnew System::Windows::Forms::Button());
this->button63 = (gcnew System::Windows::Forms::Button());
this->button64 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// button1
//
this->button1->BackColor = System::Drawing::Color::Orange;
this->button1->Location = System::Drawing::Point(43, 24);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(23, 23);
this->button1->TabIndex = 0;
this->button1->UseVisualStyleBackColor = false;
//
// button2
//
this->button2->BackColor = System::Drawing::Color::Blue;
this->button2->Location = System::Drawing::Point(72, 24);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(23, 23);
this->button2->TabIndex = 1;
this->button2->UseVisualStyleBackColor = false;
//
// button3
//
this->button3->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(255)), static_cast<System::Int32>(static_cast<System::Byte>(128)),
static_cast<System::Int32>(static_cast<System::Byte>(255)));
this->button3->Location = System::Drawing::Point(129, 24);
this->button3->Name = L"button3";
this->button3->Size = System::Drawing::Size(23, 23);
this->button3->TabIndex = 3;
this->button3->UseVisualStyleBackColor = false;
//
// button4
//
this->button4->BackColor = System::Drawing::Color::Purple;
this->button4->Location = System::Drawing::Point(100, 24);
this->button4->Name = L"button4";
this->button4->Size = System::Drawing::Size(23, 23);
this->button4->TabIndex = 2;
this->button4->UseVisualStyleBackColor = false;
//
// button5
//
this->button5->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(128)), static_cast<System::Int32>(static_cast<System::Byte>(64)),
static_cast<System::Int32>(static_cast<System::Byte>(0)));
this->button5->Location = System::Drawing::Point(244, 24);
this->button5->Name = L"button5";
this->button5->Size = System::Drawing::Size(23, 23);
this->button5->TabIndex = 7;
this->button5->UseVisualStyleBackColor = false;
//
// button6
//
this->button6->BackColor = System::Drawing::Color::Green;
this->button6->Location = System::Drawing::Point(215, 24);
this->button6->Name = L"button6";
this->button6->Size = System::Drawing::Size(23, 23);
this->button6->TabIndex = 6;
this->button6->UseVisualStyleBackColor = false;
//
// button7
//
this->button7->BackColor = System::Drawing::Color::Red;
this->button7->Location = System::Drawing::Point(187, 24);
this->button7->Name = L"button7";
this->button7->Size = System::Drawing::Size(23, 23);
this->button7->TabIndex = 5;
this->button7->UseVisualStyleBackColor = false;
//
// button8
//
this->button8->BackColor = System::Drawing::Color::Yellow;
this->button8->Location = System::Drawing::Point(158, 24);
this->button8->Name = L"button8";
this->button8->Size = System::Drawing::Size(23, 23);
this->button8->TabIndex = 4;
this->button8->UseVisualStyleBackColor = false;
//
// button9
//
this->button9->BackColor = System::Drawing::Color::Purple;
this->button9->Location = System::Drawing::Point(244, 53);
this->button9->Name = L"button9";
this->button9->Size = System::Drawing::Size(23, 23);
this->button9->TabIndex = 15;
this->button9->UseVisualStyleBackColor = false;
//
// button10
//
this->button10->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(128)), static_cast<System::Int32>(static_cast<System::Byte>(64)),
static_cast<System::Int32>(static_cast<System::Byte>(0)));
this->button10->Location = System::Drawing::Point(215, 53);
this->button10->Name = L"button10";
this->button10->Size = System::Drawing::Size(23, 23);
this->button10->TabIndex = 14;
this->button10->UseVisualStyleBackColor = false;
this->button10->Click += gcnew System::EventHandler(this, &KamisadoBoard::button10_Click);
//
// button11
//
this->button11->BackColor = System::Drawing::Color::Yellow;
this->button11->Location = System::Drawing::Point(187, 53);
this->button11->Name = L"button11";
this->button11->Size = System::Drawing::Size(23, 23);
this->button11->TabIndex = 13;
this->button11->UseVisualStyleBackColor = false;
//
// button12
//
this->button12->BackColor = System::Drawing::Color::Blue;
this->button12->Location = System::Drawing::Point(158, 53);
this->button12->Name = L"button12";
this->button12->Size = System::Drawing::Size(23, 23);
this->button12->TabIndex = 12;
this->button12->UseVisualStyleBackColor = false;
this->button12->Click += gcnew System::EventHandler(this, &KamisadoBoard::button12_Click);
//
// button13
//
this->button13->BackColor = System::Drawing::Color::Green;
this->button13->Location = System::Drawing::Point(129, 53);
this->button13->Name = L"button13";
this->button13->Size = System::Drawing::Size(23, 23);
this->button13->TabIndex = 11;
this->button13->UseVisualStyleBackColor = false;
this->button13->Click += gcnew System::EventHandler(this, &KamisadoBoard::button13_Click);
//
// button14
//
this->button14->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(255)), static_cast<System::Int32>(static_cast<System::Byte>(128)),
static_cast<System::Int32>(static_cast<System::Byte>(255)));
this->button14->Location = System::Drawing::Point(100, 53);
this->button14->Name = L"button14";
this->button14->Size = System::Drawing::Size(23, 23);
this->button14->TabIndex = 10;
this->button14->UseVisualStyleBackColor = false;
//
// button15
//
this->button15->BackColor = System::Drawing::Color::Orange;
this->button15->Location = System::Drawing::Point(72, 53);
this->button15->Name = L"button15";
this->button15->Size = System::Drawing::Size(23, 23);
this->button15->TabIndex = 9;
this->button15->UseVisualStyleBackColor = false;
//
// button16
//
this->button16->BackColor = System::Drawing::Color::Red;
this->button16->Location = System::Drawing::Point(43, 53);
this->button16->Name = L"button16";
this->button16->Size = System::Drawing::Size(23, 23);
this->button16->TabIndex = 8;
this->button16->UseVisualStyleBackColor = false;
//
// button17
//
this->button17->BackColor = System::Drawing::Color::Yellow;
this->button17->Location = System::Drawing::Point(244, 111);
this->button17->Name = L"button17";
this->button17->Size = System::Drawing::Size(23, 23);
this->button17->TabIndex = 31;
this->button17->UseVisualStyleBackColor = false;
//
// button18
//
this->button18->BackColor = System::Drawing::Color::Red;
this->button18->Location = System::Drawing::Point(215, 111);
this->button18->Name = L"button18";
this->button18->Size = System::Drawing::Size(23, 23);
this->button18->TabIndex = 30;
this->button18->UseVisualStyleBackColor = false;
//
// button19
//
this->button19->BackColor = System::Drawing::Color::Green;
this->button19->Location = System::Drawing::Point(187, 111);
this->button19->Name = L"button19";
this->button19->Size = System::Drawing::Size(23, 23);
this->button19->TabIndex = 29;
this->button19->UseVisualStyleBackColor = false;
//
// button20
//
this->button20->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(128)), static_cast<System::Int32>(static_cast<System::Byte>(64)),
static_cast<System::Int32>(static_cast<System::Byte>(0)));
this->button20->Location = System::Drawing::Point(158, 111);
this->button20->Name = L"button20";
this->button20->Size = System::Drawing::Size(23, 23);
this->button20->TabIndex = 28;
this->button20->UseVisualStyleBackColor = false;
//
// button21
//
this->button21->BackColor = System::Drawing::Color::Orange;
this->button21->Location = System::Drawing::Point(129, 111);
this->button21->Name = L"button21";
this->button21->Size = System::Drawing::Size(23, 23);
this->button21->TabIndex = 27;
this->button21->UseVisualStyleBackColor = false;
//
// button22
//
this->button22->BackColor = System::Drawing::Color::Blue;
this->button22->Location = System::Drawing::Point(100, 111);
this->button22->Name = L"button22";
this->button22->Size = System::Drawing::Size(23, 23);
this->button22->TabIndex = 26;
this->button22->UseVisualStyleBackColor = false;
//
// button23
//
this->button23->BackColor = System::Drawing::Color::Purple;
this->button23->Location = System::Drawing::Point(72, 111);
this->button23->Name = L"button23";
this->button23->Size = System::Drawing::Size(23, 23);
this->button23->TabIndex = 25;
this->button23->UseVisualStyleBackColor = false;
//
// button24
//
this->button24->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(255)), static_cast<System::Int32>(static_cast<System::Byte>(128)),
static_cast<System::Int32>(static_cast<System::Byte>(255)));
this->button24->Location = System::Drawing::Point(43, 111);
this->button24->Name = L"button24";
this->button24->Size = System::Drawing::Size(23, 23);
this->button24->TabIndex = 24;
this->button24->UseVisualStyleBackColor = false;
//
// button25
//
this->button25->BackColor = System::Drawing::Color::Blue;
this->button25->Location = System::Drawing::Point(244, 82);
this->button25->Name = L"button25";
this->button25->Size = System::Drawing::Size(23, 23);
this->button25->TabIndex = 23;
this->button25->UseVisualStyleBackColor = false;
//
// button26
//
this->button26->BackColor = System::Drawing::Color::Yellow;
this->button26->Location = System::Drawing::Point(215, 82);
this->button26->Name = L"button26";
this->button26->Size = System::Drawing::Size(23, 23);
this->button26->TabIndex = 22;
this->button26->UseVisualStyleBackColor = false;
//
// button27
//
this->button27->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(128)), static_cast<System::Int32>(static_cast<System::Byte>(64)),
static_cast<System::Int32>(static_cast<System::Byte>(0)));
this->button27->Location = System::Drawing::Point(187, 82);
this->button27->Name = L"button27";
this->button27->Size = System::Drawing::Size(23, 23);
this->button27->TabIndex = 21;
this->button27->UseVisualStyleBackColor = false;
//
// button28
//
this->button28->BackColor = System::Drawing::Color::Purple;
this->button28->Location = System::Drawing::Point(158, 82);
this->button28->Name = L"button28";
this->button28->Size = System::Drawing::Size(23, 23);
this->button28->TabIndex = 20;
this->button28->UseVisualStyleBackColor = false;
//
// button29
//
this->button29->BackColor = System::Drawing::Color::Red;
this->button29->Location = System::Drawing::Point(129, 82);
this->button29->Name = L"button29";
this->button29->Size = System::Drawing::Size(23, 23);
this->button29->TabIndex = 19;
this->button29->UseVisualStyleBackColor = false;
//
// button30
//
this->button30->BackColor = System::Drawing::Color::Orange;
this->button30->Location = System::Drawing::Point(100, 82);
this->button30->Name = L"button30";
this->button30->Size = System::Drawing::Size(23, 23);
this->button30->TabIndex = 18;
this->button30->UseVisualStyleBackColor = false;
//
// button31
//
this->button31->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(255)), static_cast<System::Int32>(static_cast<System::Byte>(128)),
static_cast<System::Int32>(static_cast<System::Byte>(255)));
this->button31->Location = System::Drawing::Point(72, 82);
this->button31->Name = L"button31";
this->button31->Size = System::Drawing::Size(23, 23);
this->button31->TabIndex = 17;
this->button31->UseVisualStyleBackColor = false;
//
// button32
//
this->button32->BackColor = System::Drawing::Color::Green;
this->button32->Location = System::Drawing::Point(43, 82);
this->button32->Name = L"button32";
this->button32->Size = System::Drawing::Size(23, 23);
this->button32->TabIndex = 16;
this->button32->UseVisualStyleBackColor = false;
//
// button33
//
this->button33->BackColor = System::Drawing::Color::Orange;
this->button33->Location = System::Drawing::Point(244, 225);
this->button33->Name = L"button33";
this->button33->Size = System::Drawing::Size(23, 23);
this->button33->TabIndex = 63;
this->button33->UseVisualStyleBackColor = false;
//
// button34
//
this->button34->BackColor = System::Drawing::Color::Blue;
this->button34->Location = System::Drawing::Point(215, 225);
this->button34->Name = L"button34";
this->button34->Size = System::Drawing::Size(23, 23);
this->button34->TabIndex = 62;
this->button34->UseVisualStyleBackColor = false;
//
// button35
//
this->button35->BackColor = System::Drawing::Color::Purple;
this->button35->Location = System::Drawing::Point(187, 225);
this->button35->Name = L"button35";
this->button35->Size = System::Drawing::Size(23, 23);
this->button35->TabIndex = 61;
this->button35->UseVisualStyleBackColor = false;
//
// button36
//
this->button36->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(255)), static_cast<System::Int32>(static_cast<System::Byte>(128)),
static_cast<System::Int32>(static_cast<System::Byte>(255)));
this->button36->Location = System::Drawing::Point(158, 225);
this->button36->Name = L"button36";
this->button36->Size = System::Drawing::Size(23, 23);
this->button36->TabIndex = 60;
this->button36->UseVisualStyleBackColor = false;
//
// button37
//
this->button37->BackColor = System::Drawing::Color::Yellow;
this->button37->Location = System::Drawing::Point(129, 225);
this->button37->Name = L"button37";
this->button37->Size = System::Drawing::Size(23, 23);
this->button37->TabIndex = 59;
this->button37->UseVisualStyleBackColor = false;
//
// button38
//
this->button38->BackColor = System::Drawing::Color::Red;
this->button38->Location = System::Drawing::Point(100, 225);
this->button38->Name = L"button38";
this->button38->Size = System::Drawing::Size(23, 23);
this->button38->TabIndex = 58;
this->button38->UseVisualStyleBackColor = false;
//
// button39
//
this->button39->BackColor = System::Drawing::Color::Green;
this->button39->Location = System::Drawing::Point(72, 225);
this->button39->Name = L"button39";
this->button39->Size = System::Drawing::Size(23, 23);
this->button39->TabIndex = 57;
this->button39->UseVisualStyleBackColor = false;
<... truncated - 30k character limit ...>`

Ok, I'm assuming that the kamisado_main.h is your main form, because you have the main routine in the .c++ file.
I cant't see the whole header file, but I think it looks fine, I hope you created the project with the CLI option.
You have to create the form variable like this, you*re missing ^, this should resolve all the errors: KamisadoBoard ^ form = gcnew KamisadoBoard;
I'm not sure if you can use this native main routine for C++/CLI, if it doesn't work try using this code in your kamisado_main.cpp:
#include "kamisado_main.h"
using namespace Project1;
[STAThreadAttribute]
int main(cli::array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew KamisadoBoard ());
return 0;
}

Related

How to prevent picked up object from changing its scale?

I'm facing an issue when I pick up an object in my game. Whenever I pick up an object and look around while holding the object, it stretches based on the perspective. Here is an example of an object before and after picking up:
Before picking up:
After picking up:
How can I maintain the object's scale and prevent it from stretching?
public void PickupObject()
{
physicsObject = lookObject.GetComponentInChildren<PhysicsObjects>();
currentlyPickedUpObject = lookObject;
pickupRB = currentlyPickedUpObject.GetComponent<Rigidbody>();
/* priorConstraints = pickupRB.constraints; // <--- NEW
pickupRB.constraints = RigidbodyConstraints.FreezeAll; // <--- NEW*/
pickupRB.constraints = RigidbodyConstraints.FreezeRotation;
physicsObject.playerInteractions = this;
pickupRB.isKinematic = true;
pickupRB.transform.parent = PickupParent.transform;
// pickupRB.isKinematic = true;
// StartCoroutine(physicsObject.PickUp());
}
The following code snippet is in Update() :
if (currentlyPickedUpObject != null)
{
HoldingItemIcon.SetActive(true);
InteractIcon.SetActive(false);
CenterIcon.SetActive(false);
currentDist = Vector3.Distance(PickupParent.position, pickupRB.position);
currentSpeed = Mathf.SmoothStep(minSpeed, maxSpeed, currentDist / maxDistance);
currentSpeed *= Time.fixedDeltaTime;
pickupRB.transform.position = PickupParent.position;
// pickupRB.transform.SetParent(PickupParent.transform);
Vector3 direction = PickupParent.position - pickupRB.position;
pickupRB.velocity = direction.normalized * currentSpeed;
Vector3 camerDirection = mainCamera.transform.forward;
// Throw object
if (Throw)
{
HoldingItemIcon.SetActive(false);
InteractIcon.SetActive(false);
pickupRB.constraints = RigidbodyConstraints.None;
pickupRB.isKinematic = false;
pickupRB.AddForce(camerDirection * 500);
currentlyPickedUpObject = null;
pickupRB.transform.parent = null;
}
Throw = false;
}
public void BreakConnection()
{
pickupRB.isKinematic = false;
pickupRB.transform.parent = null;
pickupRB.constraints = priorConstraints;
// pickupRB.constraints = RigidbodyConstraints.None;
currentlyPickedUpObject = null;
lookObject = null;
physicsObject.pickedUp = false;
currentDist = 0;
pickupRB.useGravity = true;
}
pickupParent's lossy scale while an object is picked:
What you can do is have an empty gameObject as a child of your player. That object is going to be the pickableObjectsParent and give this parent object the scale values of 1/(player's scale).

Unity3D Custom editor focus change with EditorGUILayout.LabelField

I've an issue working with custom editor, my editing focus is changed without any action from my part.
Basically, this is a screen of my custom editor in a neutral state (just added empty translation entity):
And this is a screen when my focus got change without reason. As you can see, my editor detected that 2 keys was the same and notify it by a message at the top of the box, the issue is that I was actually editing the second box's "key" field, and my focus changed on the first box (highlighted blue). If I don't display the warning message, I don't have any issue so I guess it comes from there..
This is my custom editor script :
[CustomEditor(typeof(InternationalizationDatabaseSO))]
public class InternationalizationDatabaseSOEditor : Editor
{
#region Constantes
private const string ITEMS_PROPERTY_NAME = "_mItems";
private const string ITEM_CATEGORY_NAME = "_mCategory";
private const string ITEM_KEY_NAME = "_mKey";
private const string ITEM_VALUES_NAME = "_mValues";
private const string ITEM_VALUE_LANGUAGE = "_mLanguage";
private const string ITEM_VALUE_VALUE = "_mValue";
#endregion
#region Attributs
private InternationalizationDatabaseSO _mDatabase;
#endregion
#region Methods
private void OnEnable()
{
Init();
}
private void Init()
{
_mDatabase = target as InternationalizationDatabaseSO;
}
public override void OnInspectorGUI()
{
serializedObject.Update();
SerializedProperty itemsProperty = serializedObject.FindProperty(ITEMS_PROPERTY_NAME);
int arraySize = itemsProperty.arraySize;
EditorGUI.BeginDisabledGroup(false);
{
EditorGUILayout.BeginHorizontal();
{
GUILayout.FlexibleSpace();
if (OnInspectorGUIButton("+", 40, 25, Color.white, Color.green))
{
itemsProperty.arraySize++;
itemsProperty.GetArrayElementAtIndex(itemsProperty.arraySize - 1).FindPropertyRelative(ITEM_CATEGORY_NAME).stringValue = "";
itemsProperty.GetArrayElementAtIndex(itemsProperty.arraySize - 1).FindPropertyRelative(ITEM_KEY_NAME).stringValue = "";
serializedObject.ApplyModifiedProperties();
Init();
return;
}
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.Space();
for(int i = 0; i < arraySize; i++)
{
if(OnInspectorGUIItem(i) == false)
{
serializedObject.ApplyModifiedProperties();
Init();
return;
}
}
}
EditorGUI.EndDisabledGroup();
serializedObject.ApplyModifiedProperties();
}
private bool OnInspectorGUIItem(int index)
{
SerializedProperty itemsProperty = serializedObject.FindProperty(ITEMS_PROPERTY_NAME);
SerializedProperty itemCategory = itemsProperty.GetArrayElementAtIndex(index).FindPropertyRelative(ITEM_CATEGORY_NAME);
SerializedProperty itemKey = itemsProperty.GetArrayElementAtIndex(index).FindPropertyRelative(ITEM_KEY_NAME);
EditorGUI.indentLevel += 1;
EditorGUILayout.BeginVertical(GUI.skin.box);
{
EditorGUILayout.Space();
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.BeginVertical();
{
if(KeyAlreadyExist(index, itemKey.stringValue))
{
OnInspectorGUIText("Key already exists", 12, Color.red, FontStyle.Bold, false);
}
OnInspectorGUIText("Key : " + itemKey.stringValue, 12, FontStyle.Normal, false);
}
EditorGUILayout.EndVertical();
GUILayout.FlexibleSpace();
if(OnInspectorGUIButton("-", 40, 25, Color.white, Color.red))
{
itemCategory.stringValue = "";
itemKey.stringValue = "";
itemsProperty.DeleteArrayElementAtIndex(index);
return false;
}
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.Space();
EditorGUILayout.BeginVertical();
{
GUIStyle style = EditorStyles.foldout;
style.fontSize = 15;
style.fontStyle = FontStyle.Bold;
itemCategory.isExpanded = EditorGUILayout.Foldout(itemCategory.isExpanded, "General informations", style);
if(itemCategory.isExpanded)
{
EditorGUILayout.Space();
EditorGUILayout.PropertyField(itemCategory, new GUIContent("Category"));
EditorGUILayout.PropertyField(itemKey, new GUIContent("Key"));
}
if(OnInspectorGUIItemLanguage(index, itemsProperty.GetArrayElementAtIndex(index)) == false)
{
return false;
}
}
EditorGUILayout.EndVertical();
}
EditorGUILayout.EndVertical();
EditorGUI.indentLevel -= 1;
return true;
}
private bool OnInspectorGUIItemLanguage(int index, SerializedProperty propertyItem)
{
EditorGUILayout.BeginVertical();
{
GUIStyle style = EditorStyles.foldout;
style.fontSize = 15;
style.normal.textColor = Color.black;
style.fontStyle = FontStyle.Bold;
SerializedProperty itemValues = propertyItem.FindPropertyRelative(ITEM_VALUES_NAME);
itemValues.isExpanded = EditorGUILayout.Foldout(itemValues.isExpanded, "Languages informations", style);
if(itemValues.isExpanded)
{
EditorGUILayout.Space();
EditorGUILayout.BeginVertical();
{
EditorGUILayout.BeginHorizontal();
{
int nbTranslation = itemValues.arraySize;
EditorGUILayout.LabelField("Nb translation : " + nbTranslation);
GUILayout.FlexibleSpace();
if (OnInspectorGUIButton("+", 20, 20, Color.white, Color.green))
{
itemValues.arraySize++;
itemValues.GetArrayElementAtIndex(itemValues.arraySize - 1).FindPropertyRelative(ITEM_VALUE_LANGUAGE).intValue = 0;
itemValues.GetArrayElementAtIndex(itemValues.arraySize - 1).FindPropertyRelative(ITEM_VALUE_VALUE).stringValue = "";
return false;
}
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.Space();
if (itemValues.arraySize > 0)
{
string translatedLanguages = "{";
foreach (InternationalizationDatabaseItemLanguage item in _mDatabase.Items[index].Values)
{
translatedLanguages += item.Language.ToString() + ", ";
}
if (translatedLanguages.Length > 2)
{
translatedLanguages = translatedLanguages.Remove(translatedLanguages.Length - 2);
}
translatedLanguages += "}";
//EditorStyles.label.stretchHeight = true;
EditorStyles.label.wordWrap = true;
EditorGUILayout.LabelField("Translated : \n" + translatedLanguages);
EditorGUILayout.Space();
for (int i = 0; i < itemValues.arraySize; i++)
{
EditorGUILayout.BeginVertical(GUI.skin.box);
{
EditorGUILayout.Space();
InternationalizationDatabaseItemLanguage item = _mDatabase.Items[index].Values[i];
SerializedProperty propLanguage = itemValues.GetArrayElementAtIndex(i).FindPropertyRelative(ITEM_VALUE_LANGUAGE);
SerializedProperty propValue = itemValues.GetArrayElementAtIndex(i).FindPropertyRelative(ITEM_VALUE_VALUE);
EditorGUILayout.BeginHorizontal();
{
if (LanguageAlreadyExist(index, i, _mDatabase.Items[index].Values[i].Language))
{
OnInspectorGUIText("Warning language translation already exist", 12, Color.red, FontStyle.Bold, false);
}
GUILayout.FlexibleSpace();
if (OnInspectorGUIButton("-", 20, 20, Color.white, Color.red))
{
itemValues.DeleteArrayElementAtIndex(i);
return false;
}
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.Space();
EditorGUILayout.PropertyField(propLanguage, new GUIContent("Language"));
EditorGUILayout.PrefixLabel("Translation");
propValue.stringValue = EditorGUILayout.TextArea(propValue.stringValue, GUILayout.Height(80));
}
EditorGUILayout.Space();
EditorGUILayout.EndVertical();
EditorGUILayout.Space();
}
}
}
EditorGUILayout.EndVertical();
}
}
EditorGUILayout.EndVertical();
EditorGUILayout.Space();
return true;
}
private bool KeyAlreadyExist(int currentIndex, string key)
{
for(int i = 0; i < _mDatabase.Items.Count; i++)
{
InternationalizationDatabaseItem item = _mDatabase.Items[i];
if(currentIndex != i && item.Key == key && string.IsNullOrEmpty(key) == false)
{
return true;
}
}
return false;
}
private bool LanguageAlreadyExist(int indexInDatabase, int currentIndex, SystemLanguage language)
{
for (int i = 0; i < _mDatabase.Items[indexInDatabase].Values.Count; i++)
{
InternationalizationDatabaseItemLanguage item = _mDatabase.Items[indexInDatabase].Values[i];
if (currentIndex != i && item.Language == language)
{
return true;
}
}
return false;
}
private void OnInspectorGUIText(string text, FontStyle fontStyle, bool prefixLabel)
{
GUIStyle style = new GUIStyle();
style.fontStyle = fontStyle;
style.wordWrap = true;
if (prefixLabel)
{
EditorGUILayout.PrefixLabel(text, GUIStyle.none, style);
}
else
{
EditorGUILayout.LabelField(text, style);
}
}
private void OnInspectorGUIText(string text, int fontSize, FontStyle fontStyle, bool prefixLabel)
{
GUIStyle style = new GUIStyle();
style.fontSize = fontSize;
style.fontStyle = fontStyle;
style.wordWrap = true;
if (prefixLabel)
{
EditorGUILayout.PrefixLabel(text, GUIStyle.none, style);
}
else
{
EditorGUILayout.LabelField(text, style);
}
}
private void OnInspectorGUIText(string text, int fontSize, Color textColor, FontStyle fontStyle, bool prefixLabel)
{
GUIStyle style = new GUIStyle();
style.fontSize = fontSize;
style.normal.textColor = textColor;
style.fontStyle = fontStyle;
style.wordWrap = true;
if(prefixLabel)
{
EditorGUILayout.PrefixLabel(text, GUIStyle.none, style);
}
else
{
EditorGUILayout.LabelField(text, style);
}
}
private bool OnInspectorGUIButton(string label, int width, int height, Color textColor, Color backgroundColor)
{
Color saveColor = GUI.backgroundColor;
GUILayoutOption[] options = { GUILayout.Width(width), GUILayout.Height(height) };
GUIStyle style = new GUIStyle(GUI.skin.button);
style.normal.textColor = textColor;
GUI.backgroundColor = backgroundColor;
bool pressed = GUILayout.Button(label, style, options);
GUI.backgroundColor = saveColor;
return pressed;
}
#endregion
}
Have you any suggestion ? Thanks
Have a nice day.
Are you sure you are not sharing reference to the same property in both boxes ?
Ok finally figured it out, I mean, I'm not still totally certain why it happens, but found a workaround thanks to : https://forum.unity.com/threads/editor-gui-inputfield-loses-focus-when-gui-updates.542147/
Basically, I'm just displaying always the LabelField, but if there is no error, I simply set the errorMessage to an empty string

building calendar activity using xamforms.controls.calendar

So, like most, I am still pretty new and am navigating through all things c# and Xamarin.Forms, but it is going exceptionally slow. Using XamarinForms and the XamForms.Controls.Calendar plugin, I am trying to build a calendar that gets a LIST of dates and events that happened and puts a small color code at the bottom. I reviewed all of the source code and topics on this I could find and I have refactored it out and built a VERSION of the code below that does what I want but it is ugly...I want to make it more reuseable and more MVVM than the example they were using earlier and what I did. Essentially my plan is to bind colors to activity based on a bool value (should be able to see in the code). So, the challenge is that I don't really know where to go or what to do, but below is what I THINK needs to happen. Please forgive me if this is a simple question, I am just not seeing it.
XamlPage
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:XamForms.Controls;assembly=XamForms.Controls.Calendar"
x:Class="MyApp.View.LogPageViews.LogPage"
ControlTemplate="{StaticResource MainPageTemplate}">
<ContentPage.Content>
<ScrollView>
<StackLayout>
<controls:Calendar x:Name="calendar Padding="10,0,10,0" SelectedBorderWidth="4" DisabledBorderColor="Black" ShowNumberOfWeek="false" StartDay="Monday TitleRightArrowTextColor="Blue" TitleLabelTextColor="Purple" TitleLeftArrowTextColor="Blue" WeekdaysFontSize="12" SelectedDate="{Binding Date}" SpecialDates="{Binding Workout}" DateCommand="{Binding DateChosen}" >
</controls:Calendar>
</StackLayout>
</ScrollView>
</ContentPage.Content>
</ContentPage>
I am getting my error in the code behind with everything I have tried...which is several probably wrong things...and I don't even know if this is good code. My current error is Severity Code Description Project File Line Suppression State
Error CS1503 Argument 1: cannot convert from 'MyApp.ViewModel.CalendarActivityVM' to 'XamForms.Controls.SpecialDate'
namespace MyApp.View.LogPageViews
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class LogPage : ContentPage
{
public LogPage ()
{
InitializeComponent ();
var Dates = new List<SpecialDate>();
NavigationPage.SetHasNavigationBar(this, false);
DateTime testdate = new DateTime(2018, 06, 26);
//This is where I am getting the errors when I try to do anything like this. Getting errors like "Cannot convert from" and "Cannot use like a method"
//I did have code here that worked, but refactored it out and got stuck
calendar.SpecialDates.Add(new CalendarActivityVM(testdate, true, true, true, true));
calendar.SelectedDate = (DateTime.Now);
}
}
}
My Calendar ActivityVM (I have no idea if this is correct...This is where I am learning and think it is right)
namespace MyApp.ViewModel
{
public class CalendarActivityVM
{
public DateTime Datetime { get; set; }
public bool A { get; set; }
public bool B { get; set; }
public bool C { get; set; }
public bool D { get; set; }
public CalendarActivityVM(DateTime datetime, bool a, bool b, bool c, bool d)
{
Datetime = datetime;
A = a;
B = b;
C = c;
D = d;
var AColor = new Color();
var BColor = new Color();
var CColor = new Color();
var DColor = new Color();
if (A == true) { AColor = Color.Red; } else { AColor = Color.Transparent; };
if (B == true) { BColor = Color.Yellow; } else { BColor = Color.Transparent; };
if (C == true) { CColor = Color.Green; } else { CColor = Color.Transparent; };
if (D == true) { DColor = Color.Blue; } else { DColor = Color.Transparent; };
var white_row = new Pattern { WidthPercent = .1275f, HightPercent = 0.75f, Color = Color.Transparent };
var white_col = new Pattern { WidthPercent = 0.04f, HightPercent = 1f, Color = Color.Transparent };
var aPattern = new Pattern { WidthPercent = 0.22f, HightPercent = 0.22f, Color = AColor };
var bPattern = new Pattern { WidthPercent = 0.22f, HightPercent = 0.22f, Color = BColor };
var cPattern = new Pattern { WidthPercent = 0.22f, HightPercent = 0.22f, Color = CColor };
var dPattern = new Pattern { WidthPercent = 0.22f, HightPercent = 0.22f, Color = DColor };
var activity = new BackgroundPattern(7)
{
Pattern = new List<Pattern>
{
white_row, white_row, white_row, white_row, white_row, white_row, white_row,
aPattern, white_col, bPattern, white_col, cPattern, white_col, dPattern
}
};
}
}
}
a normal "SpecialDate" looks like this according to the example...this is why I am trying to refactor:
calendar.SpecialDates = new List<SpecialDate>{
new SpecialDate(DateTime.Now.AddDays(3))
{
BackgroundColor = Color.White,
TextColor = Color.Black,
Selectable = true,
BackgroundPattern = new BackgroundPattern(7)
{
Pattern = new List<Pattern>
{
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.Red, Text = "X", TextColor=Color.White, TextSize=11, TextAlign=TextAlign.Middle},
white_col,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.Gold, Text = "Y", TextColor=Color.White, TextSize=11, TextAlign=TextAlign.Middle},
white_col,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.Green, Text = "Z", TextColor=Color.White, TextSize=11, TextAlign=TextAlign.Middle},
white_col,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.Purple,Text = "Q", TextColor=Color.White, TextSize=11, TextAlign=TextAlign.Middle},
white_row,white_row,white_row,white_row,white_row,white_row,white_row,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.Blue},
white_col,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.Chocolate},
white_col,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.Cyan},
white_col,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.Fuchsia},
white_row,white_row,white_row,white_row,white_row,white_row,white_row,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.Crimson},
white_col,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.Aquamarine},
white_col,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.OrangeRed},
white_col,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.DarkOrchid},
white_row,white_row,white_row,white_row,white_row,white_row,white_row,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.Black},
white_col,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.DeepSkyBlue},
white_col,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.DarkGoldenrod},
white_col,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.Firebrick},
}
}
}
I appreciate your time and any help is greatly appreciated.
So, after a bit more research (and maybe this will help others) there is a really nice tool to refactor to a method that makes it much easier than trying to do it myself (although I had to play with it a couple of times before I got it correct). Using the example in the code (or the code I got to work), on the left side of the screen there is a little paintbrush (VS2017) that helped me refactor. Here is the code that I eventually generated after playing with it for just a couple minutes. Now I did create it in the codebehind, but now I am pretty certain I can refactor that to my VM.
private static SpecialDate TestMethod(DateTime datetime, bool A, bool B, bool C, bool D)
{
var AColor = new Color();
var BColor = new Color();
var CColor = new Color();
var DColor = new Color();
if (A == true) { AColor = Color.Red; } else { AColor = Color.Transparent; };
if (B == true) { BColor = Color.Yellow; } else { BColor = Color.Transparent; };
if (C == true) { CColor = Color.Green; } else { CColor = Color.Transparent; };
if (D == true) { DColor = Color.Blue; } else { DColor = Color.Transparent; };
var white_row = new Pattern { WidthPercent = .1275f, HightPercent = 0.75f, Color = Color.Transparent };
var white_col = new Pattern { WidthPercent = 0.04f, HightPercent = 1f, Color = Color.Transparent };
var aPattern = new Pattern { WidthPercent = 0.22f, HightPercent = 0.22f, Color = AColor };
var bPattern = new Pattern { WidthPercent = 0.22f, HightPercent = 0.22f, Color = BColor };
var cPattern = new Pattern { WidthPercent = 0.22f, HightPercent = 0.22f, Color = CColor };
var dPattern = new Pattern { WidthPercent = 0.22f, HightPercent = 0.22f, Color = DColor };
return new SpecialDate(datetime)
{
BackgroundColor = Color.White,
TextColor = Color.Black,
Selectable = true,
BackgroundPattern = new BackgroundPattern(7)
{
Pattern = new List<Pattern>
{
white_row, white_row, white_row, white_row, white_row, white_row, white_row,
aPattern, white_col, bPattern, white_col, cPattern, white_col, dPattern
}
}
};
}
I know I answered my own question and marked it as answered, but hopefully it will help someone else...showing how you can refactor much more simply than trying to do it on your own.

Xamarin form: Why there is a gap in between the cells

I have a custom view in side the item on the right highlighted in black.
The each view cell has a big gap because of the black custom view. This black view is a grid which was added in the bindingContextChanged function.
public partial class ShiftTemplate : ViewCell
{
public ShiftTemplate()
{
InitializeComponent();
}
}
public class ShiftView : ContentView
{
protected override void OnBindingContextChanged()
{
base.OnBindingContextChanged();
var model = BindingContext as StaffShiftViewModel;
var grid = new Grid();
var shiftCount = 0;
var index = 0;
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Star });
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Star });
foreach (var shift in model.Shifts)
{
grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
var timeLabel = new Label
{
Text = shift.Time,
VerticalTextAlignment = TextAlignment.Center,
HorizontalTextAlignment = TextAlignment.End
};
var clockButton = new Button
{
Text = shift.ClockStatus,
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Start,
Command = shift.OnClockingPopupCommand
};
var binding = new Binding();
binding.Source = shift;
binding.Path = nameof(shift.ClockStatus);
binding.Mode = BindingMode.OneWay;
clockButton.SetBinding(Button.TextProperty, binding);
var line = new BoxView { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.Center, HeightRequest = 1, BackgroundColor = Color.Gray };
grid.Children.Add(timeLabel, 0, 1, shiftCount, shiftCount+1);
grid.Children.Add(clockButton, 1, 2, shiftCount, shiftCount+1);
index += 1;
if (index < model.Shifts.Count)
grid.Children.Add(line, 0, 2, shiftCount + 1, shiftCount + 2);
shiftCount+=2;
}
Content = grid;
ForceLayout();
}
}

Is there a custom Label widget which supports animated GIF?

I am trying to write a custom Label widget which supports animated GIF, but I found it's hard for me. Is there already such a widget available for use?
Edit---------------------------------------------------------------------------------
When I try to use GifCLabel class, it works fine with a gif picture(animated), but if I try to set a static png picture to it when the animation thread is running, the png picture will not be shown, but a frame of the animated gif is shown, here is my code :
public PageDemo(Shell parentShell) {
super(parentShell);
Composite topComp = new Composite(parentShell, SWT.NONE);
topComp.setLayout(new FormLayout());
final GifCLabel gl = new GifCLabel(topComp, SWT.CENTER);
gl.setText("some message");
gl.setGifImage("c://loading.gif");
Display.getCurrent().timerExec(5000, new Runnable(){
#Override
public void run() {
// gl.setGifImage("c:\\filter.png"); // also not work
gl.setImage(SWTResourceManager.getImage("c:\\filter.png"));
}
});
}
Bug fix--------------------------------------------------------------------------------
I think Sorceror's code is good, but there seems is a little bug:
public void run() {
while (run) {
int delayTime = loader.data[imageNumber].delayTime;
try {
Thread.sleep(delayTime * 10);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (!GifCLabel.this.isDisposed()) {
// if a asynchronous thread is running, this new runnable will be queued
GifCLabel.this.getDisplay().asyncExec(new Runnable() {
public void run() {
if(!run){
return;
}
if (!GifCLabel.this.isDisposed()) {
imageNumber = imageNumber == loader.data.length - 1 ? 0 : imageNumber + 1;
if (!GifCLabel.this.image.isDisposed())
GifCLabel.this.image.dispose();
ImageData nextFrameData = loader.data[imageNumber];
System.out.println("set to frame " + imageNumber);
GifCLabel.this.image = new Image(GifCLabel.this.getDisplay(), nextFrameData);
GifCLabel.this.redraw();
} else
stopRunning();
}
});
} else
stopRunning();
}
}
notice what I added in above :
if(!run){
return;
}
In the article Taking a look at SWT Images - Animation part is whole source code of gif animation for almost any purpose.. It didn't help?
EDIT
So I did the job, and here is a GifCLabel class for you which supports gif animation.. It's derived from SWT CLabel class, see setGifImage(String path), setGifImage(InputStream inputStream) methods and GifThread private class.
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.accessibility.*;
/**
* <p><b>This class supports gif animation in label and is derived from {#link GifCLabel} SWT class (see {#link #setGifImage(InputStream)} or {#link #setGifImage(String)})</b><br />
* <b>Changes by Sorceror, (a)sync.exec(...) call fix by YAMaiDie</b></p>
*/
public class GifCLabel extends Canvas {
/** Gap between icon and text */
private static final int GAP = 5;
/** Left and right margins */
private static final int DEFAULT_MARGIN = 3;
/** a string inserted in the middle of text that has been shortened */
private static final String ELLIPSIS = "..."; //$NON-NLS-1$ // could use the ellipsis glyph on some platforms "\u2026"
/** the alignment. Either CENTER, RIGHT, LEFT. Default is LEFT*/
private int align = SWT.LEFT;
private int leftMargin = DEFAULT_MARGIN;
private int topMargin = DEFAULT_MARGIN;
private int rightMargin = DEFAULT_MARGIN;
private int bottomMargin = DEFAULT_MARGIN;
private String text;
private Image image;
private String appToolTipText;
private boolean ignoreDispose;
private Image backgroundImage;
private Color[] gradientColors;
private int[] gradientPercents;
private boolean gradientVertical;
private Color background;
private GifThread thread = null;
private static int DRAW_FLAGS = SWT.DRAW_MNEMONIC | SWT.DRAW_TAB | SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER;
public GifCLabel(Composite parent, int style) {
super(parent, checkStyle(style));
if ((style & (SWT.CENTER | SWT.RIGHT)) == 0) style |= SWT.LEFT;
if ((style & SWT.CENTER) != 0) align = SWT.CENTER;
if ((style & SWT.RIGHT) != 0) align = SWT.RIGHT;
if ((style & SWT.LEFT) != 0) align = SWT.LEFT;
addPaintListener(new PaintListener() {
public void paintControl(PaintEvent event) {
onPaint(event);
}
});
addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent event) {
if (event.detail == SWT.TRAVERSE_MNEMONIC) {
onMnemonic(event);
}
}
});
addListener(SWT.Dispose, new Listener() {
public void handleEvent(Event event) {
onDispose(event);
}
});
initAccessible();
}
private static int checkStyle (int style) {
if ((style & SWT.BORDER) != 0) style |= SWT.SHADOW_IN;
int mask = SWT.SHADOW_IN | SWT.SHADOW_OUT | SWT.SHADOW_NONE | SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
style = style & mask;
return style |= SWT.NO_FOCUS | SWT.DOUBLE_BUFFERED;
}
public Point computeSize(int wHint, int hHint, boolean changed) {
checkWidget();
Point e = getTotalSize(image, text);
if (wHint == SWT.DEFAULT){
e.x += leftMargin + rightMargin;
} else {
e.x = wHint;
}
if (hHint == SWT.DEFAULT) {
e.y += topMargin + bottomMargin;
} else {
e.y = hHint;
}
return e;
}
private void drawBevelRect(GC gc, int x, int y, int w, int h, Color topleft, Color bottomright) {
gc.setForeground(bottomright);
gc.drawLine(x+w, y, x+w, y+h);
gc.drawLine(x, y+h, x+w, y+h);
gc.setForeground(topleft);
gc.drawLine(x, y, x+w-1, y);
gc.drawLine(x, y, x, y+h-1);
}
char _findMnemonic (String string) {
if (string == null) return '\0';
int index = 0;
int length = string.length ();
do {
while (index < length && string.charAt (index) != '&') index++;
if (++index >= length) return '\0';
if (string.charAt (index) != '&') return Character.toLowerCase (string.charAt (index));
index++;
} while (index < length);
return '\0';
}
public int getAlignment() {
//checkWidget();
return align;
}
public int getBottomMargin() {
//checkWidget();
return bottomMargin;
}
public Image getImage() {
//checkWidget();
return image;
}
public int getLeftMargin() {
//checkWidget();
return leftMargin;
}
public int getRightMargin() {
//checkWidget();
return rightMargin;
}
private Point getTotalSize(Image image, String text) {
Point size = new Point(0, 0);
if (image != null) {
Rectangle r = image.getBounds();
size.x += r.width;
size.y += r.height;
}
GC gc = new GC(this);
if (text != null && text.length() > 0) {
Point e = gc.textExtent(text, DRAW_FLAGS);
size.x += e.x;
size.y = Math.max(size.y, e.y);
if (image != null) size.x += GAP;
} else {
size.y = Math.max(size.y, gc.getFontMetrics().getHeight());
}
gc.dispose();
return size;
}
public int getStyle () {
int style = super.getStyle();
switch (align) {
case SWT.RIGHT: style |= SWT.RIGHT; break;
case SWT.CENTER: style |= SWT.CENTER; break;
case SWT.LEFT: style |= SWT.LEFT; break;
}
return style;
}
public String getText() {
//checkWidget();
return text;
}
public String getToolTipText () {
checkWidget();
return appToolTipText;
}
public int getTopMargin() {
//checkWidget();
return topMargin;
}
private void initAccessible() {
Accessible accessible = getAccessible();
accessible.addAccessibleListener(new AccessibleAdapter() {
public void getName(AccessibleEvent e) {
e.result = getText();
}
public void getHelp(AccessibleEvent e) {
e.result = getToolTipText();
}
public void getKeyboardShortcut(AccessibleEvent e) {
char mnemonic = _findMnemonic(GifCLabel.this.text);
if (mnemonic != '\0') {
e.result = "Alt+"+mnemonic; //$NON-NLS-1$
}
}
});
accessible.addAccessibleControlListener(new AccessibleControlAdapter() {
public void getChildAtPoint(AccessibleControlEvent e) {
e.childID = ACC.CHILDID_SELF;
}
public void getLocation(AccessibleControlEvent e) {
Rectangle rect = getDisplay().map(getParent(), null, getBounds());
e.x = rect.x;
e.y = rect.y;
e.width = rect.width;
e.height = rect.height;
}
public void getChildCount(AccessibleControlEvent e) {
e.detail = 0;
}
public void getRole(AccessibleControlEvent e) {
e.detail = ACC.ROLE_LABEL;
}
public void getState(AccessibleControlEvent e) {
e.detail = ACC.STATE_READONLY;
}
});
}
void onDispose(Event event) {
/* make this handler run after other dispose listeners */
if (ignoreDispose) {
ignoreDispose = false;
return;
}
ignoreDispose = true;
notifyListeners (event.type, event);
event.type = SWT.NONE;
gradientColors = null;
gradientPercents = null;
backgroundImage = null;
text = null;
image = null;
appToolTipText = null;
}
void onMnemonic(TraverseEvent event) {
char mnemonic = _findMnemonic(text);
if (mnemonic == '\0') return;
if (Character.toLowerCase(event.character) != mnemonic) return;
Composite control = this.getParent();
while (control != null) {
Control [] children = control.getChildren();
int index = 0;
while (index < children.length) {
if (children [index] == this) break;
index++;
}
index++;
if (index < children.length) {
if (children [index].setFocus ()) {
event.doit = true;
event.detail = SWT.TRAVERSE_NONE;
}
}
control = control.getParent();
}
}
void onPaint(PaintEvent event) {
Rectangle rect = getClientArea();
if (rect.width == 0 || rect.height == 0) return;
boolean shortenText = false;
String t = text;
Image img = image;
int availableWidth = Math.max(0, rect.width - (leftMargin + rightMargin));
Point extent = getTotalSize(img, t);
if (extent.x > availableWidth) {
img = null;
extent = getTotalSize(img, t);
if (extent.x > availableWidth) {
shortenText = true;
}
}
GC gc = event.gc;
String[] lines = text == null ? null : splitString(text);
// shorten the text
if (shortenText) {
extent.x = 0;
for(int i = 0; i < lines.length; i++) {
Point e = gc.textExtent(lines[i], DRAW_FLAGS);
if (e.x > availableWidth) {
lines[i] = shortenText(gc, lines[i], availableWidth);
extent.x = Math.max(extent.x, getTotalSize(null, lines[i]).x);
} else {
extent.x = Math.max(extent.x, e.x);
}
}
if (appToolTipText == null) {
super.setToolTipText(text);
}
} else {
super.setToolTipText(appToolTipText);
}
// determine horizontal position
int x = rect.x + leftMargin;
if (align == SWT.CENTER) {
x = (rect.width - extent.x)/2;
}
if (align == SWT.RIGHT) {
x = rect.width - rightMargin - extent.x;
}
// draw a background image behind the text
try {
if (backgroundImage != null) {
// draw a background image behind the text
Rectangle imageRect = backgroundImage.getBounds();
// tile image to fill space
gc.setBackground(getBackground());
gc.fillRectangle(rect);
int xPos = 0;
while (xPos < rect.width) {
int yPos = 0;
while (yPos < rect.height) {
gc.drawImage(backgroundImage, xPos, yPos);
yPos += imageRect.height;
}
xPos += imageRect.width;
}
} else if (gradientColors != null) {
// draw a gradient behind the text
final Color oldBackground = gc.getBackground();
if (gradientColors.length == 1) {
if (gradientColors[0] != null) gc.setBackground(gradientColors[0]);
gc.fillRectangle(0, 0, rect.width, rect.height);
} else {
final Color oldForeground = gc.getForeground();
Color lastColor = gradientColors[0];
if (lastColor == null) lastColor = oldBackground;
int pos = 0;
for (int i = 0; i < gradientPercents.length; ++i) {
gc.setForeground(lastColor);
lastColor = gradientColors[i + 1];
if (lastColor == null) lastColor = oldBackground;
gc.setBackground(lastColor);
if (gradientVertical) {
final int gradientHeight = (gradientPercents[i] * rect.height / 100) - pos;
gc.fillGradientRectangle(0, pos, rect.width, gradientHeight, true);
pos += gradientHeight;
} else {
final int gradientWidth = (gradientPercents[i] * rect.width / 100) - pos;
gc.fillGradientRectangle(pos, 0, gradientWidth, rect.height, false);
pos += gradientWidth;
}
}
if (gradientVertical && pos < rect.height) {
gc.setBackground(getBackground());
gc.fillRectangle(0, pos, rect.width, rect.height - pos);
}
if (!gradientVertical && pos < rect.width) {
gc.setBackground(getBackground());
gc.fillRectangle(pos, 0, rect.width - pos, rect.height);
}
gc.setForeground(oldForeground);
}
gc.setBackground(oldBackground);
} else {
if (background != null || (getStyle() & SWT.DOUBLE_BUFFERED) == 0) {
gc.setBackground(getBackground());
gc.fillRectangle(rect);
}
}
} catch (SWTException e) {
if ((getStyle() & SWT.DOUBLE_BUFFERED) == 0) {
gc.setBackground(getBackground());
gc.fillRectangle(rect);
}
}
// draw border
int style = getStyle();
if ((style & SWT.SHADOW_IN) != 0 || (style & SWT.SHADOW_OUT) != 0) {
paintBorder(gc, rect);
}
Rectangle imageRect = null;
int lineHeight = 0, textHeight = 0, imageHeight = 0;
if (img != null) {
imageRect = img.getBounds();
imageHeight = imageRect.height;
}
if (lines != null) {
lineHeight = gc.getFontMetrics().getHeight();
textHeight = lines.length * lineHeight;
}
int imageY = 0, midPoint = 0, lineY = 0;
if (imageHeight > textHeight ) {
if (topMargin == DEFAULT_MARGIN && bottomMargin == DEFAULT_MARGIN) imageY = rect.y + (rect.height - imageHeight) / 2;
else imageY = topMargin;
midPoint = imageY + imageHeight/2;
lineY = midPoint - textHeight / 2;
}
else {
if (topMargin == DEFAULT_MARGIN && bottomMargin == DEFAULT_MARGIN) lineY = rect.y + (rect.height - textHeight) / 2;
else lineY = topMargin;
midPoint = lineY + textHeight/2;
imageY = midPoint - imageHeight / 2;
}
// draw the image
if (img != null) {
gc.drawImage(img, 0, 0, imageRect.width, imageHeight,
x, imageY, imageRect.width, imageHeight);
x += imageRect.width + GAP;
extent.x -= imageRect.width + GAP;
}
// draw the text
if (lines != null) {
gc.setForeground(getForeground());
for (int i = 0; i < lines.length; i++) {
int lineX = x;
if (lines.length > 1) {
if (align == SWT.CENTER) {
int lineWidth = gc.textExtent(lines[i], DRAW_FLAGS).x;
lineX = x + Math.max(0, (extent.x - lineWidth) / 2);
}
if (align == SWT.RIGHT) {
int lineWidth = gc.textExtent(lines[i], DRAW_FLAGS).x;
lineX = Math.max(x, rect.x + rect.width - rightMargin - lineWidth);
}
}
gc.drawText(lines[i], lineX, lineY, DRAW_FLAGS);
lineY += lineHeight;
}
}
}
private void paintBorder(GC gc, Rectangle r) {
Display disp= getDisplay();
Color c1 = null;
Color c2 = null;
int style = getStyle();
if ((style & SWT.SHADOW_IN) != 0) {
c1 = disp.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
c2 = disp.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);
}
if ((style & SWT.SHADOW_OUT) != 0) {
c1 = disp.getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW);
c2 = disp.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
}
if (c1 != null && c2 != null) {
gc.setLineWidth(1);
drawBevelRect(gc, r.x, r.y, r.width-1, r.height-1, c1, c2);
}
}
public void setAlignment(int align) {
checkWidget();
if (align != SWT.LEFT && align != SWT.RIGHT && align != SWT.CENTER) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
if (this.align != align) {
this.align = align;
redraw();
}
}
public void setBackground (Color color) {
super.setBackground (color);
// Are these settings the same as before?
if (backgroundImage == null &&
gradientColors == null &&
gradientPercents == null) {
if (color == null) {
if (background == null) return;
} else {
if (color.equals(background)) return;
}
}
background = color;
backgroundImage = null;
gradientColors = null;
gradientPercents = null;
redraw ();
}
public void setBackground(Color[] colors, int[] percents) {
setBackground(colors, percents, false);
}
public void setBackground(Color[] colors, int[] percents, boolean vertical) {
checkWidget();
if (colors != null) {
if (percents == null || percents.length != colors.length - 1) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
if (getDisplay().getDepth() < 15) {
// Don't use gradients on low color displays
colors = new Color[] {colors[colors.length - 1]};
percents = new int[] { };
}
for (int i = 0; i < percents.length; i++) {
if (percents[i] < 0 || percents[i] > 100) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
if (i > 0 && percents[i] < percents[i-1]) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
}
}
// Are these settings the same as before?
final Color background = getBackground();
if (backgroundImage == null) {
if ((gradientColors != null) && (colors != null) &&
(gradientColors.length == colors.length)) {
boolean same = false;
for (int i = 0; i < gradientColors.length; i++) {
same = (gradientColors[i] == colors[i]) ||
((gradientColors[i] == null) && (colors[i] == background)) ||
((gradientColors[i] == background) && (colors[i] == null));
if (!same) break;
}
if (same) {
for (int i = 0; i < gradientPercents.length; i++) {
same = gradientPercents[i] == percents[i];
if (!same) break;
}
}
if (same && this.gradientVertical == vertical) return;
}
} else {
backgroundImage = null;
}
// Store the new settings
if (colors == null) {
gradientColors = null;
gradientPercents = null;
gradientVertical = false;
} else {
gradientColors = new Color[colors.length];
for (int i = 0; i < colors.length; ++i)
gradientColors[i] = (colors[i] != null) ? colors[i] : background;
gradientPercents = new int[percents.length];
for (int i = 0; i < percents.length; ++i)
gradientPercents[i] = percents[i];
gradientVertical = vertical;
}
// Refresh with the new settings
redraw();
}
public void setBackground(Image image) {
checkWidget();
if (image == backgroundImage) return;
if (image != null) {
gradientColors = null;
gradientPercents = null;
}
backgroundImage = image;
redraw();
}
public void setBottomMargin(int bottomMargin) {
checkWidget();
if (this.bottomMargin == bottomMargin || bottomMargin < 0) return;
this.bottomMargin = bottomMargin;
redraw();
}
public void setFont(Font font) {
super.setFont(font);
redraw();
}
public void setImage(Image image) {
checkWidget();
if(thread != null) {
thread.stopRunning();
try {
thread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if (image != this.image) {
this.image = image;
redraw();
}
}
public void setGifImage(String path) {
try {
this.setGifImage(new FileInputStream(new File(path)));
} catch (FileNotFoundException e) {
this.image = null;
return;
}
}
public void setGifImage(InputStream inputStream) {
checkWidget();
if(thread != null) thread.stopRunning();
ImageLoader loader = new ImageLoader();
try {
loader.load(inputStream);
} catch (Exception e) {
this.image = null;
return;
}
if (loader.data[0] != null)
this.image = new Image(this.getDisplay(), loader.data[0]);
if (loader.data.length > 1) {
thread = new GifThread(loader);
thread.start();
}
redraw();
}
#Override
public void dispose() {
super.dispose();
if(thread != null) thread.stopRunning();
}
private class GifThread extends Thread {
private int imageNumber = 0;
private ImageLoader loader = null;
private boolean run = true;
public GifThread(ImageLoader loader) {
this.loader = loader;
}
public void run() {
while(run) {
int delayTime = loader.data[imageNumber].delayTime;
try {
Thread.sleep(delayTime * 10);
} catch (InterruptedException e) {
e.printStackTrace();
}
if(!GifCLabel.this.isDisposed()) {
GifCLabel.this.getDisplay().asyncExec(new Runnable() {
public void run() {
if(!run){
return;
}
if(!GifCLabel.this.isDisposed()) {
imageNumber = imageNumber == loader.data.length - 1 ? 0 : imageNumber + 1;
if (!GifCLabel.this.image.isDisposed()) GifCLabel.this.image.dispose();
ImageData nextFrameData = loader.data[imageNumber];
GifCLabel.this.image = new Image(GifCLabel.this.getDisplay(), nextFrameData);
GifCLabel.this.redraw();
} else stopRunning();
}
});
} else stopRunning();
}
}
public void stopRunning() {
run = false;
}
}
public void setLeftMargin(int leftMargin) {
checkWidget();
if (this.leftMargin == leftMargin || leftMargin < 0) return;
this.leftMargin = leftMargin;
redraw();
}
public void setMargins (int leftMargin, int topMargin, int rightMargin, int bottomMargin) {
checkWidget();
this.leftMargin = Math.max(0, leftMargin);
this.topMargin = Math.max(0, topMargin);
this.rightMargin = Math.max(0, rightMargin);
this.bottomMargin = Math.max(0, bottomMargin);
redraw();
}
public void setRightMargin(int rightMargin) {
checkWidget();
if (this.rightMargin == rightMargin || rightMargin < 0) return;
this.rightMargin = rightMargin;
redraw();
}
public void setText(String text) {
checkWidget();
if (text == null) text = ""; //$NON-NLS-1$
if (! text.equals(this.text)) {
this.text = text;
redraw();
}
}
public void setToolTipText (String string) {
super.setToolTipText (string);
appToolTipText = super.getToolTipText();
}
public void setTopMargin(int topMargin) {
checkWidget();
if (this.topMargin == topMargin || topMargin < 0) return;
this.topMargin = topMargin;
redraw();
}
protected String shortenText(GC gc, String t, int width) {
if (t == null) return null;
int w = gc.textExtent(ELLIPSIS, DRAW_FLAGS).x;
if (width<=w) return t;
int l = t.length();
int max = l/2;
int min = 0;
int mid = (max+min)/2 - 1;
if (mid <= 0) return t;
TextLayout layout = new TextLayout (getDisplay());
layout.setText(t);
mid = validateOffset(layout, mid);
while (min < mid && mid < max) {
String s1 = t.substring(0, mid);
String s2 = t.substring(validateOffset(layout, l-mid), l);
int l1 = gc.textExtent(s1, DRAW_FLAGS).x;
int l2 = gc.textExtent(s2, DRAW_FLAGS).x;
if (l1+w+l2 > width) {
max = mid;
mid = validateOffset(layout, (max+min)/2);
} else if (l1+w+l2 < width) {
min = mid;
mid = validateOffset(layout, (max+min)/2);
} else {
min = max;
}
}
String result = mid == 0 ? t : t.substring(0, mid) + ELLIPSIS + t.substring(validateOffset(layout, l-mid), l);
layout.dispose();
return result;
}
int validateOffset(TextLayout layout, int offset) {
int nextOffset = layout.getNextOffset(offset, SWT.MOVEMENT_CLUSTER);
if (nextOffset != offset) return layout.getPreviousOffset(nextOffset, SWT.MOVEMENT_CLUSTER);
return offset;
}
private String[] splitString(String text) {
String[] lines = new String[1];
int start = 0, pos;
do {
pos = text.indexOf('\n', start);
if (pos == -1) {
lines[lines.length - 1] = text.substring(start);
} else {
boolean crlf = (pos > 0) && (text.charAt(pos - 1) == '\r');
lines[lines.length - 1] = text.substring(start, pos - (crlf ? 1 : 0));
start = pos + 1;
String[] newLines = new String[lines.length+1];
System.arraycopy(lines, 0, newLines, 0, lines.length);
lines = newLines;
}
} while (pos != -1);
return lines;
}
}
and the possible usage is
final GifCLabel lbl = new GifCLabel(shell, SWT.CENTER);
lbl.setText("texxxxt");
lbl.setGifImage(this.getClass().getResourceAsStream("/8EWoM.gif"));
// lbl.setGifImage("src/8EWoM.gif");
Because of the limit of 30000 chars to answer, the pasted code is without comments, non-trim version could be found on http://pastebin.com/cJA682XD