⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cexample.c

📁 Gambas is a graphical development environment based on a Basic interpreter, like Visual Basic. It us
💻 C
📖 第 1 页 / 共 2 页
字号:
  h = THIS->height;  d = THIS->data;  d2 = &d[(h - 1) * w];  for (j = 0; j < (h / 2); j++)  {    for (i = 0; i < w; i++)    {      c = d[i];      d[i] = d2[i];      d2[i] = c;    }    d += w;    d2 -= w;  }END_METHOD/* This is the implementation of a method used in a virtual class.   Note how we can use the THIS macro, as the virtual object is in   reality the real main object.*/BEGIN_METHOD(CEXAMPLE_pixels_get, GB_INTEGER x; GB_INTEGER y)  int x = VARG(x);  int y = VARG(y);  if ((x < 0) || (y < 0) || (x >= THIS->width) || (y >= THIS->height))    GB.ReturnInteger(-1);  else    GB.ReturnInteger(*(THIS->data + (y * THIS->width) + x));END_METHOD/* The last part of the class implementation file is the declaration of its   description.   A class description is an array of GB_DESC struct filled with special macros   declared in gambas.h*/GB_DESC CExampleDesc[] ={  /* The first macro to use is GB_DECLARE. This macro takes two parameters :     the class name, and the size of its object structure.     If the class is virtual, or static (i.e. not creatable), you must pass 0     to the size parameter.  */  GB_DECLARE("Example", sizeof(CEXAMPLE)),  /* If you want this class to inherits another class, you can use the     GB_INHERITS macro.     Be careful : the object structure of your class must begin with the     same field than the object structure of the inherited class.  */  #ifndef THIS_IS_JUST_AN_EXAMPLE  GB_INHERITS("ExampleMother"),  #endif  /* If the class is virtual, you must use the GB_VIRTUAL_CLASS macro */  #ifndef THIS_IS_JUST_AN_EXAMPLE  GB_VIRTUAL_CLASS(),  #endif  /* Then you can declare methods, constants, properties, and events.     The order of the declarations is not important.     The datatypes of Gambas properties, constants, method return values     are specified with a string following this convention :     - "b" is the Boolean datatype.     - "i" is the Integer datatype.     - "f" is the Float datatype     - "d" is the Date datatype.     - "s" is the String datatype.     - "v" is the Variant datatype.     - "o" is the Object datatype.     To specify a class datatype, give the name of the class followed by a     semicolon : "Class;" for example.  */  /*     You declare a constant with the GB_CONSTANT macro.     The syntax is : GB_CONSTANT(Name, Type, Value)     - Name is the name of the constant.     - Type is a string given the datatype of the constant.       "i" indicates an integer constant, "f" a float constant, and "s" a string       constant.     - Value is the value of the constant: an integer if the constant is an       integer, a string if the constant is a string, and the string represenation       of the number if the constant is a float.  */  #ifndef THIS_IS_JUST_AN_EXAMPLE  GB_CONSTANT("AnIntegerConstant", "i", 1972),  GB_CONSTANT("AStringConstant", "s", "Gambas"),  GB_CONSTANT("AFloatConstant", "f", "3.1415"),  #endif  /*     You declare a method with the GB_METHOD macro, or GB_STATIC_METHOD     if the method is static.     The syntax is : GB_METHOD(Name, Type, Function, Parameters)     - Name is the name of the method.     - Type is the datatype of the value returned by the method. If the method       returns no value, then you must put NULL there.     - Function is the name of the function implementing the method.     - Parameters is the string signature of the method.     A signature is a catenated string of each parameter datatypes like     "iiExample;s", but with the following extensions :     - [ and ] delimit optional parameters.     - ( and ) give a name to the first following parameter.     - < and > indicates the possible constant values that the last integer       parameter can take. It is mainly used with property declaration.     If the method takes no parameters, then you must put NULL there.  */  #ifndef THIS_IS_JUST_AN_EXAMPLE  GB_METHOD("AMethodThatReturnsNoValue", NULL, do_the_job,    "(FirstParameter)i(SecondParameter)s[(FirstOptionalParameter)ClassName;(SecondOptionalParameter)v]"),  GB_METHOD("AMethodThatReturnsAStringAndTakesNoParameter", "s", do_another_job, NULL),  #endif  /*     You declare a property with the GB_PROPERTY macro, or GB_STATIC_PROPERTY     if the property is static.     If the property is read-only, you must use the GB_READ_PROPERTY and     GB_STATIC_READ_PROPERTY macros.     The syntax is : GB_PROPERTY(Name, Type, Function)     - Name is the name of the property.     - Type is a string that specifies the Gambas datatype of the property.     - Function is the name of the function implementing the property.  */  #ifndef THIS_IS_JUST_AN_EXAMPLE  GB_PROPERTY("AProperty", "s", do_AProperty),  GB_STATIC_PROPERTY("AStaticProperty", "i", do_AStaticProperty),  GB_READ_PROPERTY("AReadOnlyProperty", "i", do_AReadOnlyProperty),  /* Note that the following property takes its value in the symbols defined in     the Border class. Consequently, all these symbols must be constant.  */  GB_PROPERTY("AnotherProperty", "i<Border>", do_AnotherProperty),  /* To be more precise, you can specify exactly which symbols are useful     with this property.  */  GB_PROPERTY("AWellDefinedProperty", "i<Border,None,Plain>", do_AWellDefinedProperty),  #endif  /*     You declare that the object can raise an event with the GB_EVENT macro.     The syntax is : GB_EVENT(Name, Type, Signature, Identifier)     - Name is the name of the event.     - Type is the datatype returned by the event handler. It can be "b" for a       Boolean or NULL for a handler returning no value.     - Signature is the signature of the event, like the Signature parameter of       the GB_METHOD macro.     - Identifier is a pointer to a previously declared variable where the       interpreter will put a value uniquely identifying this event.              To declare an event identifier, use the DECLARE_EVENT macros.       This identifier will be used with the GB.Raise() function to raise the       event.  */  #ifndef THIS_IS_JUST_AN_EXAMPLE  GB_EVENT("FirstEvent", NULL, "(Parameter)i", &FirstEvent),  GB_EVENT("SecondEvent", "b", NULL, &SecondEvent),  #endif  /*     There are special methods, whose name begins with an underscore     characters. These special methods are called by interpreter in     particular contexts.  */  /* The _new method is called when the class is instanciated. In this     method, you must initialize the newly created object.     The parameters of the method come from the parameters of the NEW     instruction.          This class manipulate the pixels data of an image Picture. You     must pass to the constructor the width and the height of Picture,     and the value returned by the Data property of the Pixels property     of the Picture.  */  GB_METHOD("_new", NULL, CEXAMPLE_new, "(Width)i(Height)i(Data)i"),  /* The _free method is called just before an object is destroyed. In this     method, you must release every string and references used by the object.  */  GB_METHOD("_free", NULL, CEXAMPLE_free, NULL),  /* The _get method is the read implementation of the [] operator. The     parameters of this method come from the parameters of the operator.     This method can be static or dynamic.  */  #ifndef THIS_IS_JUST_AN_EXAMPLE  GB_METHOD("_get", "i", CEXAMPLE_get, "(X)i(Y)i"),  #endif  /* The _put method is the write implementation of the [] operator. The     parameters of this method come from the parameters of the operator.     The first parameter of this method is always the value that must be     stored.     This method can be static or dynamic.  */  #ifndef THIS_IS_JUST_AN_EXAMPLE  GB_METHOD("_put", NULL, CEXAMPLE_put, "(Value)i(X)i(Y)i"),  #endif  /* The _call method is executed when the class or the object is used as     a method. A good example of a static use of this feature is the class     Message, and a good example of a dynamic use of this feature is the     virtual class .TextSelection of the TextBox or TextArea controls.     For example, you can type Example("Show me !")  */  #ifndef THIS_IS_JUST_AN_EXAMPLE  GB_STATIC_METHOD("_call", NULL, CEXAMPLE_call, "(Message)s"),  #endif  GB_PROPERTY_READ("Width", "i", CEXAMPLE_width),  GB_PROPERTY_READ("Height", "i", CEXAMPLE_height),  /* Here is an example of the use of a virtual class. The Data property     will return a virtual representation of the Example object that will     be used for getting the pixel datas passed to the Example constructor.  */  GB_PROPERTY_SELF("Pixels", ".ExamplePixels"),  GB_METHOD("HFlip", NULL, CEXAMPLE_hflip, NULL),  GB_METHOD("VFlip", NULL, CEXAMPLE_vflip, NULL),  /* The declaration structure must end with the GB_END_DECLARE macro. */  GB_END_DECLARE};/* Now we declare the virtual class used by the Data property */GB_DESC CExamplePixelsDesc[] ={  /* We declare the name of the class, with a dot as first character. We tell     the interpreter that the size of the object is 0 and that it is a virtual     class.  */  GB_DECLARE(".ExamplePixels", 0), GB_VIRTUAL_CLASS(),  /* This method will return the color of a pixel */  GB_METHOD("_get", "i", CEXAMPLE_pixels_get, "(X)i(Y)i"),  GB_END_DECLARE};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -