mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-10-06 00:30:10 -06:00
Merge continued
git-svn-id: svn://ultimatepp.org/upp/trunk@10263 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
2582d7f364
commit
3cd394812c
3860 changed files with 1161787 additions and 438 deletions
89
uppdev/LineClip/main.cpp
Normal file
89
uppdev/LineClip/main.cpp
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
#include "LineClip.h"
|
||||
|
||||
bool LineClip::Clip(Painter& sw, double x1, double y1, double x2, double y2)
|
||||
{
|
||||
if(x1 < cliprect.left) {
|
||||
if(x2 < cliprect.left)
|
||||
return false;
|
||||
y1 = (y2 - y1) * (cliprect.left - x1) / (x2 - x1) + y1;
|
||||
x1 = cliprect.left;
|
||||
}
|
||||
else
|
||||
if(x1 > cliprect.right) {
|
||||
if(x2 > cliprect.right)
|
||||
return false;
|
||||
y1 = (y2 - y1) * (cliprect.right - x1) / (x2 - x1) + y1;
|
||||
x1 = cliprect.right;
|
||||
}
|
||||
if(x2 < cliprect.left) {
|
||||
y2 = (y2 - y1) * (cliprect.left - x1) / (x2 - x1) + y1;
|
||||
x2 = cliprect.left;
|
||||
}
|
||||
else
|
||||
if(x2 > cliprect.right) {
|
||||
y2 = (y2 - y1) * (cliprect.right - x1) / (x2 - x1) + y1;
|
||||
x2 = cliprect.right;
|
||||
}
|
||||
if(y1 < cliprect.top) {
|
||||
if(y2 < cliprect.top)
|
||||
return false;
|
||||
x1 = (x2 - x1) * (cliprect.top - y1) / (y2 - y1) + x1;
|
||||
y1 = cliprect.top;
|
||||
}
|
||||
else
|
||||
if(y1 > cliprect.bottom) {
|
||||
if(y2 > cliprect.bottom)
|
||||
return false;
|
||||
x1 = (x2 - x1) * (cliprect.bottom - y1) / (y2 - y1) + x1;
|
||||
y1 = cliprect.bottom;
|
||||
}
|
||||
if(y2 < cliprect.top) {
|
||||
x2 = (x2 - x1) * (cliprect.top - y1) / (y2 - y1) + x1;
|
||||
y2 = cliprect.top;
|
||||
}
|
||||
else
|
||||
if(y2 > cliprect.bottom) {
|
||||
x2 = (x2 - x1) * (cliprect.bottom - y1) / (y2 - y1) + x1;
|
||||
y2 = cliprect.bottom;
|
||||
}
|
||||
sw.Move(x1, y1).Line(x2, y2).Stroke(1, LtRed());
|
||||
return true;
|
||||
}
|
||||
|
||||
void LineClip::Paint(Draw& w)
|
||||
{
|
||||
ImageBuffer ib(GetSize());
|
||||
BufferPainter sw(ib);
|
||||
sw.Clear(White());
|
||||
sw.Rectangle(100, 100, 100, 100).Fill(WhiteGray());
|
||||
sw.Move(x1, y1).Line(x2, y2).Stroke(1, Gray());
|
||||
if(!Clip(sw, x1, y1, x2, y2))
|
||||
sw.Text(0, 0, "No clip", Arial(20)).Fill(Black());
|
||||
w.DrawImage(0, 0, ib);
|
||||
}
|
||||
|
||||
void LineClip::LeftDown(Point p, dword keyflags)
|
||||
{
|
||||
x1 = p.x;
|
||||
y1 = p.y;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void LineClip::MouseMove(Point p, dword keyflags)
|
||||
{
|
||||
x2 = p.x;
|
||||
y2 = p.y;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
LineClip::LineClip()
|
||||
{
|
||||
cliprect = RectfC(100, 100, 100, 100);
|
||||
x1 = y1 = x2 = y2 = 0;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
LineClip().Run();
|
||||
}
|
||||
Loading…
Reference in a new issue