🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: de.comp.lang.c++
Article #180

Re: "Gummiband"

#180
From: Andreas Scherer
Date: Tue, 01 Aug 1995 10:41
75 lines
2209 bytes
>ich tüftele an einem Graphikeditor und mir stellt sich nun das Problem 
>die von mir erstellten Vektorgarphiken mit sogenannten 
>"Gumiband"-Funktionen auszustatten. Soll heißen: ich klicke auf den DC 
>und ziehe dann gemütlich z.B. ein Rechteck auf. Anschließend wird dieses 
>dann direkt markiert, so daß ich es noch verschieben oder skalieren kann.
>In der MFC und bei VB 3.0 gibt´s wohl mittlerweile ne Klasse dafür, 
>gibt´s sowas denn nicht auch in der OWL 2.x?


#include <window.h>
#include <dc.h>

class TMyWin: public TWindow {
  TClientDC *dc;
  TPoint startPoint, endPoint;
  ...

public:
  TMyWin(TWindow *);
  void DrawRect();
  void EvLButtonDown(UINT,TPoint &);
  void EvMouseMove(UINT,TPoint &);
  void EvLButtonUp(UINT,TPoint &);
  ...
  DECLARE_RESPONSE_TABLE(TMyWin);
}

DEFINE_RESPONSE_TABLE1(TMyWin,TWindow)
  EV_WM_LBUTTONDOWN,
  EV_WM_MOUSEMOVE,
  EV_WM_LBUTTONUP,
  ...
END_RESPONSE_TABLE;

TMyWin::TMyWin(TWindow *parent): TWindow(parent), dc(0) {...}

void TMyWin::DrawRect() {
  if (startPoint != endPoint) {
    dc->MoveTo(startPoint);
    dc->LineTo(startPoint.x,endPoint.y);
    dc->LineTo(endPoint);
    dc->LineTo(endPoint.x,startPoint.y);
    dc->LineTo(startPoint);
    // nicht mit FrameRect(...);
  }
}

void TMyWin::EvLButtonDown(UINT,TPoint &point) {
  dc = new TClientDC(*this);
  dc->SetROP2(R2_NOT);
  startPoint = point;
  endPoint = point;
  SetCapture();
}

void TMyWin::EvMouseMove(UINT,TPoint &point) {
  if (dc) {
    DrawRect();
    endPoint = point;
    DrawRect();
  }
}

void TMyWin::EvLButtonUp(UINT,TPoint &point) {
  if (dc) {
    ReleaseCapture();
    DrawRect();
    delete dc;
    endPoint = point;
    // Rechteck: (startPoint,endPoint)
  }
}

Gruss Andreas.
Technical Details
Message-ID: <3vl0c2$d37@zdi.informatik.uni-stuttgart.de>
Path: arc1-ca.pugleaf.net!news.informatik.uni-stuttgart.de!scherer

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.informatik.uni-stuttgart.de!scherer
From: scherer@track.informatik.uni-stuttgart.de (Andreas Scherer)
Newsgroups: de.comp.lang.c++
Subject: Re: "Gummiband"
Date: 1 Aug 1995 10:41:06 GMT
Organization: Fakultaet Informatik
Distribution: world
Message-ID: <3vl0c2$d37@zdi.informatik.uni-stuttgart.de>
NNTP-Posting-Host: track.informatik.uni-stuttgart.de
Keywords: BC4.0
X-newsreader: xrn 7.03