[Vala] interface and inherance (vala 0.7.5)
- From: Frederic LEGER <fredator26 gmail com>
- To: vala-list gnome org
- Subject: [Vala] interface and inherance (vala 0.7.5)
- Date: Thu, 13 Aug 2009 10:45:30 +0200
Hi List,
I found a problem with the interface and the inherance. Possibly the problem
is mine, not in the compiler.
Anyway that would have been great if it was working as I was expecting...
some days ago I created the class Rectangle, and interface Affichable...
today, I created the class RectangleG which derives from Rectangle and
implements the interface Affichable
And stupidly, Rectangle implemented a few methods of the Affichable
interface..... that raises in a strange case for me....
using Gtk;
public interface G2VF_Affichable {
public abstract void afficher(Cairo.Context ctx);
public abstract bool estDans(int x,int y);
public abstract G2VF_Point renvoyerCentre();
}
class Rectangle has an implementation of both methods renvoyerCentre() and
estDans()
class Rectangle howether don't have the method afficher(Cairo.Context ctx)
which is only implemented in graphical stuff like RectangleG
I know that normaly I have to implement the abstract methods coming from the
interface Affichable in the class RectangeG.
Anyway I was expecting that RectangleG would link automaticaly both methods
estDans() and renvoyerCentre() to SuperClass Rectangle ones.
Instead of this : no warning from valac 0.7.5 at compile time.
at runtime:
line 3: 9083 Erreur de segmentation ./G2VForge
Then for each methods I had to add the lines below in RectangleG :
public new G2VF_Point renvoyerCentre() {
return ((G2VF_Rectangle)this).renvoyerCentre();
}
My understanding is that these lines could have be written by valac for me.
Best regards,
Frederic
public class G2VF_Rectangle {
public G2VF_Point p1;
public G2VF_Point p2;
public G2VF_Rectangle() {
this.p1= new G2VF_Point();
this.p2= new G2VF_Point();
}
public G2VF_Rectangle.selon_points(G2VF_Point p1,G2VF_Point p2) {
this.p1= new G2VF_Point.de_coordonnees(p1.x,p1.y);
this.p2= new G2VF_Point.de_coordonnees(p2.x,p2.y);
}
public G2VF_Rectangle.clone(G2VF_Rectangle r) {
this.p1= new G2VF_Point.clone(r.p1);
this.p2= new G2VF_Point.clone(r.p2);
}
public G2VF_Rectangle.de_centre_largeur_et_hauteur(G2VF_Point p,int
largeur,int hauteur) {
this.p1= new G2VF_Point.de_coordonnees(p.x-largeur/2,p.y-hauteur/2);
this.p2= new G2VF_Point.de_coordonnees(p.x+largeur/2,p.y+hauteur/2);
}
public G2VF_Point renvoyerCentre() {
G2VF_Point p = new G2VF_Point();
if (p1.x > p2.x)
p.x=(p1.x-p2.x)/2+p2.x;
else
p.x=(p2.x-p1.x)/2+p1.x;
if (p1.y > p2.y)
p.y=(p1.y-p2.y)/2+p2.y;
else
p.x=(p2.y-p1.y)/2+p1.y;
return p;
}
public bool estDans(int x,int y) {
bool resultat = false;
if (p1.x<p2.x) {
resultat = (p1.x<x)&(x<p2.x);
}
else {
resultat = (p2.x<x)&(x<p1.x);
}
if (p1.y<p2.y) {
resultat &= (p1.y<y)&(y<p2.y);
}
else {
resultat &= (p2.y<y)&(y<p1.y);
}
return resultat;
}
public int largeur() {
int resultat = 0;
if (p1.x<p2.x) {
resultat = (p2.x-p1.x);
}
else {
resultat = (p1.x-p2.x);
}
return resultat;
}
public int hauteur() {
int resultat = 0;
if (p1.y<p2.y) {
resultat = (p2.y-p1.y);
}
else {
resultat = (p1.y-p2.y);
}
return resultat;
}
public void translater(int x, int y) {
p1.translater(x,y);
p2.translater(x,y);
}
}
using Gtk;
using Cairo;
public class G2VF_RectangleG: G2VF_Rectangle, G2VF_Affichable {
public bool plein;
public G2VF_RectangleG() {
this.p1= new G2VF_Point();
this.p2= new G2VF_Point();
plein = false;
}
public G2VF_RectangleG.selon_points(G2VF_Point p1,G2VF_Point p2) {
G2VF_Rectangle.selon_points(p1,p2);
plein = false;
}
public G2VF_RectangleG.selon_rectangle(G2VF_Rectangle r) {
G2VF_Rectangle.clone(r);
plein = false;
}
public G2VF_RectangleG.de_centre_largeur_et_hauteur(G2VF_Point p,int
largeur,int hauteur) {
G2VF_Rectangle.de_centre_largeur_et_hauteur(p,largeur,hauteur);
plein=false;
}
public G2VF_RectangleG.clone(G2VF_RectangleG r) {
G2VF_Rectangle.clone(r);
plein = r.plein;
}
public new G2VF_Point renvoyerCentre() {
return ((G2VF_Rectangle)this).renvoyerCentre();
}
public new bool estDans(int x,int y) {
return ((G2VF_Rectangle)this).estDans(x,y);
}
public new void translater(int x, int y) {
((G2VF_Rectangle)this).translater(x,y);
}
public void afficher(Cairo.Context ctx) {
ctx.save();
ctx.new_path ();
ctx.move_to (p1.x, p1.y);
ctx.line_to (p2.x, p1.y);
ctx.line_to (p2.x, p2.y);
ctx.line_to (p1.x, p2.y);
ctx.close_path ();
if (plein==false) {
ctx.stroke();
}
else {
ctx.fill();
}
ctx.restore();
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]