00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _ugraph_hpp_
00026 #define _ugraph_hpp_
00027 #include <ubit/uappli.hpp>
00028
00029
00030
00035 class UGraph {
00036 public:
00037 UGraph();
00038 UGraph(class UView*);
00039 UGraph(class UEvent*);
00040 UGraph(class UEvent&);
00072 virtual ~UGraph();
00073
00074
00075
00076 UView *getView() const {return boxview;}
00078
00079 UDisp* getDisp() const;
00081
00082 UAppli* getAppli() const;
00084
00085
00086
00087 void setColor(const UColor*);
00088 void setColor(const UColor&);
00093 void setBgcolor(const UColor*);
00094 void setBgcolor(const UColor&);
00099 void setFont(const UFont*);
00100 void setFont(const UFont&);
00101 void setFont(const UFontDesc&);
00108 void setCursor(const UCursor*);
00109 void setCursor(const UCursor&);
00111
00112 bool isXORMode();
00113 void setXORMode();
00114 void setPaintMode();
00121 void setThickness(int = 0);
00122 int getThickness();
00127
00128
00129 void setClip(const URegion&);
00130 void setClip(u_pos x, u_pos y, u_dim width, u_dim height);
00135 void setWinClip(const URegion&);
00136 void setWinClip(u_pos x, u_pos y, u_dim width, u_dim height);
00141 void flush();
00143
00144 int grabPointer(class UCursor* = null, bool confine_to_window = false);
00149 void ungrabPointer();
00151
00152
00153
00154 u_pos XToXwin(u_pos x_in_view);
00155 u_pos YToYwin(u_pos y_in_view);
00157
00158 u_pos XwinToX(u_pos x_in_win);
00159 u_pos YwintoY(u_pos y_in_win);
00161
00162
00163
00164 void clearRect(u_pos x, u_pos y, u_dim width, u_dim height,
00165 bool repaint_view = false);
00175 void clearView(bool repaint_view = false);
00177
00178 void copyArea(u_pos x, u_pos y, u_dim width, u_dim height,
00179 u_dim delta_x, u_dim delta_y,
00180 bool generate_refresh_events_when_obscured);
00189
00190
00191
00192
00193 void drawArc(u_pos x, u_pos y, u_dim width, u_dim height,
00194 float from_angle, float arc_angle);
00195 void drawEllipse(u_pos x, u_pos y, u_dim width, u_dim height);
00202 void drawLine(u_pos x1, u_pos y1, u_pos x2, u_pos y2);
00204
00205 void drawPoint(u_pos x, u_pos y);
00207
00208 void drawPolyline(u_pos xpoints[], u_pos ypoints[], u_count card);
00209 void drawPolyline(std::vector<u_pos> xpoints,
00210 std::vector<u_pos> ypoints,
00211 u_count card);
00213
00214 void drawPolygon(u_pos xpoints[], u_pos ypoints[], u_count card);
00215 void drawPolygon(std::vector<u_pos> xpoints,
00216 std::vector<u_pos> ypoints,
00217 u_count card);
00219
00220 void drawRect(u_pos x, u_pos y, u_dim width, u_dim height);
00222
00223 void drawString(const UStr&, u_pos x, u_pos y);
00224 void drawString(const UStr*, u_pos x, u_pos y);
00225 void drawString(const char*, int str_length, u_pos x, u_pos y);
00230
00231
00232
00233
00234 void fillArc(u_pos x, u_pos y, u_dim width, u_dim height,
00235 float from_angle, float arc_angle);
00242 void fillPolygon(u_pos xpoints[], u_pos ypoints[],
00243 u_count card, int mode=0);
00244 void fillPolygon(std::vector<u_pos> xpoints,
00245 std::vector<u_pos> ypoints,
00246 u_count card, int mode=0);
00254 void fillRect(u_pos x, u_pos y, u_dim width, u_dim height);
00256
00257 void fillView();
00259
00260
00261
00262
00263 void drawIma(const class UNatIma*, u_pos x, u_pos y);
00264 void drawIma(const class UNatPix*, u_pos x, u_pos y);
00265
00266 static void getImaSize(class UNatIma*, u_dim &w, u_dim &h);
00267 static void getPixSize(class UNatPix*, u_dim &w, u_dim &h);
00268
00269
00270
00271 bool getCharDefaultSize(const UFont&, int& w, int& h) const;
00272 bool getCharDefaultSize(const UFontDesc&, int& w, int& h) const;
00273
00274 void getTextSize(const UFont&, const UStr&,
00275 u_dim& width, u_dim& height) const;
00276 void getTextSize(const UFontDesc&, const char* str, int str_len,
00277 u_dim& width, u_dim& height) const;
00278 u_dim getTextHeight(const UFont&) const;
00279 u_dim getTextHeight(const UFontDesc&) const;
00280 u_dim getTextWidth(const UFont&, const UStr&) const;
00281 u_dim getTextWidth(const UFontDesc&, const char* str, int str_len) const;
00283
00284 int getCharPos(const UFontDesc&, const char* str, int str_len,
00285 u_pos x) const;
00286 int getXPos(const UFontDesc&, const char* str, int str_len,
00287 int char_pos) const;
00289
00290 bool getClippedText(const char*s, int len, u_pos x0, u_pos y0,
00291 int& charpos_begin, int& charpos_end,
00292 u_pos& xpos_begin, u_pos& xpos_end) const;
00294
00295 bool getSubTextSize(const UFontDesc&, const char* str, int str_len,
00296 u_dim& w, u_dim& h, u_dim available_width,
00297 int& sublen, int& change_line) const;
00308 int getSubTextSize(const UFontDesc*, const char* str, int str_len,
00309 u_dim maxwidth, u_dim chw, u_dim *w, u_dim *h) const;
00311
00312
00313
00314
00315 class UNatWin* createBuffer(u_dim width, u_dim height);
00317
00318 void deleteBuffer(class UNatWin*);
00320
00321 class UNatGraph* getNatGraph() const {return natgraph;}
00322 class UWinGraph* getWinGraph() const {return wg;}
00323 class UNatDisp* getNatDisp() const {return natdisp;}
00324 class UNatWin* getNatWin() const;
00331
00332
00333
00334 #ifndef NO_DOC
00335 protected:
00336 friend class UGraphElem;
00337
00338 enum GType {NONE, WIN, CLIENT, SUBWIN, DOUBLEBUF, BLEND};
00339
00340 class UView* boxview;
00341 class UWinGraph* wg;
00342 class UNatGraph* natgraph;
00343 class UNatDisp* natdisp;
00344 struct UGraphElem* gelem;
00345 enum {OPAQUE, UNIFORM_BLEND, PSEUDO_BLEND, TRUE_BLEND} blend_mode;
00346 float alpha;
00347
00348 void constructs(class UView*);
00349 void push(GType, class UNatWin* dest, const URegion &clip,
00350 u_pos _xwin, u_pos _ywin);
00351 void push(GType, bool alloc, const URegion &r);
00352 void pop();
00353 void popAll();
00354
00355 UNatWin* allocBuffer(u_dim width, u_dim height);
00356 void releaseBuffer(UNatWin *buf);
00357 #endif
00358 };
00359
00360
00361
00362
00372 class UWinGraph : public UGraph {
00373 public:
00374 UWinGraph(class UWin*);
00375 virtual ~UWinGraph();
00376
00377 bool init(UDisp*, UView* window_view);
00382 bool isWinRealized() const;
00384
00385 class UDisp* getDisp() const {return disp;}
00386 class UAppli* getAppli() const {return &disp->getAppli();}
00387
00388 class UWin* getHardwin() const {return hardwin;}
00390
00391 class UNatWin* getNatWin() const {return natwin;}
00392 class UNatDisp* getNatDisp() const {return disp->getNatDisp();}
00393
00394 void begin(const URegion& clip);
00400 void end();
00405 void beginDoublebuf(const URegion& clip);
00406 void beginBlend(const URegion& clip, float alpha);
00407 void beginSubwin(const URegion& clip, u_pos xwin, u_pos ywin);
00412 void endBlend();
00413
00414 void blendColor(const URegion& clip, float alpha);
00420 void setClip(const URegion&);
00421 void setClip(u_pos x, u_pos y, u_dim width, u_dim height);
00422 void setWinClip(const URegion &r);
00423 void setWinClip(u_pos x, u_pos y, u_dim width, u_dim height);
00431
00432
00433
00434 #ifndef NO_DOC
00435 private:
00436 friend class UGraph;
00437 friend class UGraphElem;
00438 class UDisp* disp;
00439 class UWin* hardwin;
00440 class UNatWin* natwin;
00441
00442 void blendLayers(UGraphElem* layer1, UGraphElem* layer2);
00443 #endif
00444 };
00445
00446 #endif
00447
00448