| Zeile 37: | Zeile 37: | ||
* GUIs verbrauchen viele Ressourcen. Daher wird insbesondere auf Servern nur ein einfaches GUI eingesetzt oder oft auch ganz auf ein GUI verzichtet. | * GUIs verbrauchen viele Ressourcen. Daher wird insbesondere auf Servern nur ein einfaches GUI eingesetzt oder oft auch ganz auf ein GUI verzichtet. | ||
* Last but not least ist der Aufwand der Entwicklung oder Portierung eines GUI enorm. Desweiteren braucht eine GUI besonders viel Infrastruktur, wie z.B. Grafik- oder Maustreiber. Von der Entwicklung eines GUI ohne einen stabilen und relativ ausgereiften [[Kernel]] ist also abzuraten. | * Last but not least ist der Aufwand der Entwicklung oder Portierung eines GUI enorm. Desweiteren braucht eine GUI besonders viel Infrastruktur, wie z.B. Grafik- oder Maustreiber. Von der Entwicklung eines GUI ohne einen stabilen und relativ ausgereiften [[Kernel]] ist also abzuraten. | ||
| + | |||
| + | == Nützliches für die GUI-Programmierung == | ||
| + | Wer nicht gleich ein Library portieren will um schiefe Linien zu zeichnen kann diesen Beispielcode verwenden. | ||
| + | '''Der Beispielcode setzt voraus das es die Funktion setpixel(int x,int y, unsigned char color) gibt.(die Funktion sollte einen Pixel zeichnen)''' | ||
| + | <c> | ||
| + | #define sgn(x) ((x<0)?-1:((x>0)?1:0)) | ||
| + | void line(int x1, int y1, int x2, int y2, unsigned char color) { | ||
| + | int dx,dy,sdx,sdy,px,py,dxabs,dyabs,i; | ||
| + | int slope; | ||
| + | |||
| + | dx = x2-x1; | ||
| + | dy = y2-y1; | ||
| + | dxabs = abs(dx); | ||
| + | dyabs = abs(dy); | ||
| + | sdx = sgn(dx); | ||
| + | sdy = sgn(dy); | ||
| + | if(dxabs >= dyabs) { | ||
| + | slope = dy / dx; | ||
| + | for(i=0;i!=dx;i+=sdx) { | ||
| + | px = i + x1; | ||
| + | py = slope * i + y1; | ||
| + | setpixel(px, py, color); | ||
| + | } | ||
| + | } else { | ||
| + | slope = dx / dy; | ||
| + | for(i=0;i!=dy;i+=sdy) { | ||
| + | px = slope * i + x1; | ||
| + | py = i + y1; | ||
| + | setpixel(px, py, color); | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | </c> | ||
| + | Hat man diese Funktion ist vieles getan.<br /> | ||
| + | Eine leichte Übung wäre jetzt eine Funktion um ein Rechteck zu zeichnen: | ||
| + | <c> | ||
| + | void rectangle(int x, int y, int w, int h, unsigned char color) { | ||
| + | line(x, y, x + h, y, color); | ||
| + | line(x, y, x, y + w, color); | ||
| + | line(x, y + w, x + h, y + w, color); | ||
| + | line(x + h, y, x + h, y + w, color); | ||
| + | } | ||
| + | </c> | ||
== Links == | == Links == | ||