Browse Source

Update for local widget coordinates

pull/1/head
falkTX 11 years ago
parent
commit
93ddf31259
7 changed files with 43 additions and 60 deletions
  1. +1
    -1
      dpf
  2. +1
    -1
      examples/Makefile
  3. +18
    -24
      examples/demo.cpp
  4. +2
    -4
      examples/widgets/ExampleColorWidget.hpp
  5. +9
    -12
      examples/widgets/ExampleImagesWidget.hpp
  6. +8
    -12
      examples/widgets/ExampleRectanglesWidget.hpp
  7. +4
    -6
      examples/widgets/ExampleShapesWidget.hpp

+ 1
- 1
dpf

@@ -1 +1 @@
Subproject commit 39c93d6aa2beae64e411feaef300e384196c1e64
Subproject commit 3562ad248c032f7906bde90b81d127009c7f3b43

+ 1
- 1
examples/Makefile View File

@@ -45,7 +45,7 @@ app: app.cpp ../dpf/dgl/*
color: color.cpp ../dpf/dgl/*
$(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@

demo: demo.cpp ../dpf/dgl/*
demo: demo.cpp widgets/* ../dpf/dgl/*
$(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@

images: images.cpp images_res/* ../dpf/dgl/*


+ 18
- 24
examples/demo.cpp View File

@@ -67,14 +67,12 @@ public:
protected:
void onDisplay() override
{
const int cx = getX();
const int cy = getY();
const int iconSize = getWidth();

glColor3f(0.027f, 0.027f, 0.027f);
bg.draw();

bgIcon.setY(cy + curPage*iconSize + curPage + 1);
bgIcon.setY(curPage*iconSize + curPage + 1);

glColor3f(0.129f, 0.129f, 0.129f);
bgIcon.draw();
@@ -84,7 +82,7 @@ protected:

if (curHover != curPage && curHover != -1)
{
Rectangle<int> rHover(cx + 1, cy + curHover*iconSize + curHover + 1, iconSize-2, iconSize-2);
Rectangle<int> rHover(1, curHover*iconSize + curHover + 1, iconSize-2, iconSize-2);

glColor3f(0.071f, 0.071f, 0.071f);
rHover.draw();
@@ -102,10 +100,10 @@ protected:

const int pad = iconSize/2 - DemoArtwork::ico1Width/2;

img1.drawAt(cx + pad, cy + pad);
img2.drawAt(cx + pad, cy + pad + 1 + iconSize);
img3.drawAt(cx + pad, cy + pad + 2 + iconSize*2);
img4.drawAt(cx + pad, cy + pad + 3 + iconSize*3);
img1.drawAt(pad, pad);
img2.drawAt(pad, pad + 1 + iconSize);
img3.drawAt(pad, pad + 2 + iconSize*2);
img4.drawAt(pad, pad + 3 + iconSize*3);
}

bool onMouse(int button, bool press, int x, int y) override
@@ -135,7 +133,7 @@ protected:

bool onMotion(int x, int y) override
{
if (getArea().contains(x, y))
if (contains(x, y))
{
const int iconSize = getWidth();

@@ -172,19 +170,15 @@ protected:
}
}

void onReshape(int, int) override
void onReshape(int width, int height) override
{
const int cx = getX();
const int iconSize = getWidth();

bg = getArea();
bg.setSize(width, height);

bgIcon.setX(cx+1);
bgIcon.setWidth(iconSize-2);
bgIcon.setHeight(iconSize-2);
bgIcon.setWidth(width-2);
bgIcon.setHeight(width-2);

lineSep.setStartPos(iconSize+4, getY());
lineSep.setEndPos(iconSize+4, getHeight());
lineSep.setStartX(width+2);
lineSep.setEndPos(width+2, height);
}

private:
@@ -216,10 +210,10 @@ public:
wRects.hide();
wShapes.hide();

wColor.setPos(80, 2);
wImages.setPos(80, 2);
wRects.setPos(80, 2);
wShapes.setPos(80, 2);
wColor.setX(80);
wImages.setX(80);
wRects.setX(80);
wShapes.setX(80);
wLeft.setPos(2, 2);

setSize(600, 500);
@@ -236,7 +230,7 @@ public:
wRects.setSize(size);
wShapes.setSize(size);

wLeft.setSize(73, height);
wLeft.setSize(73, height-4);

Window::onReshape(width, height);
}


+ 2
- 4
examples/widgets/ExampleColorWidget.hpp View File

@@ -116,16 +116,14 @@ protected:

void onReshape(int, int) override
{
const int cx = getX();
const int cy = getY();
const int width = getWidth();
const int height = getHeight();

// full bg
bgFull = getArea();
bgFull = Rectangle<int>(0, 0, width, height);

// small bg, centered 2/3 size
bgSmall = Rectangle<int>(cx+width/6, cy+height/6, width*2/3, height*2/3);
bgSmall = Rectangle<int>(width/6, height/6, width*2/3, height*2/3);
}

char cur;


+ 9
- 12
examples/widgets/ExampleImagesWidget.hpp View File

@@ -144,45 +144,42 @@ private:

void onDisplay() override
{
const int cx = getX();
const int cy = getY();

switch (fImgTop3rd)
{
case 1:
fImg1.drawAt(fImg1x+cx, kImg1y+cy);
fImg1.drawAt(fImg1x, kImg1y);
break;
case 2:
fImg2.drawAt(fImg2x+cx, kImg2y+cy);
fImg2.drawAt(fImg2x, kImg2y);
break;
case 3:
fImg3.drawAt(kImg3x+cx, fImg3y+cy);
fImg3.drawAt(kImg3x, fImg3y);
break;
};

switch (fImgTop2nd)
{
case 1:
fImg1.drawAt(fImg1x+cx, kImg1y+cy);
fImg1.drawAt(fImg1x, kImg1y);
break;
case 2:
fImg2.drawAt(fImg2x+cx, kImg2y+cy);
fImg2.drawAt(fImg2x, kImg2y);
break;
case 3:
fImg3.drawAt(kImg3x+cx, fImg3y+cy);
fImg3.drawAt(kImg3x, fImg3y);
break;
};

switch (fImgTop1st)
{
case 1:
fImg1.drawAt(fImg1x+cx, kImg1y+cy);
fImg1.drawAt(fImg1x, kImg1y);
break;
case 2:
fImg2.drawAt(fImg2x+cx, kImg2y+cy);
fImg2.drawAt(fImg2x, kImg2y);
break;
case 3:
fImg3.drawAt(kImg3x+cx, fImg3y+cy);
fImg3.drawAt(kImg3x, fImg3y);
break;
};
}


+ 8
- 12
examples/widgets/ExampleRectanglesWidget.hpp View File

@@ -48,8 +48,6 @@ public:
protected:
void onDisplay() override
{
const int cx = getX();
const int cy = getY();
const int width = getWidth();
const int height = getHeight();

@@ -61,10 +59,10 @@ protected:
// draw a 3x3 grid
for (int i=0; i<3; ++i)
{
r.setX(cx + 3 + i*width/3);
r.setX(3 + i*width/3);

// 1st
r.setY(cy + 3);
r.setY(3);

if (fClicked[0+i])
glColor3f(0.8f, 0.5f, 0.3f);
@@ -74,7 +72,7 @@ protected:
r.draw();

// 2nd
r.setY(cy + 3 + height/3);
r.setY(3 + height/3);

if (fClicked[3+i])
glColor3f(0.8f, 0.5f, 0.3f);
@@ -84,7 +82,7 @@ protected:
r.draw();

// 3rd
r.setY(cy + 3 + height*2/3);
r.setY(3 + height*2/3);

if (fClicked[6+i])
glColor3f(0.8f, 0.5f, 0.3f);
@@ -100,8 +98,6 @@ protected:
if (button != 1 || ! press)
return false;

const int cx = getX();
const int cy = getY();
const int width = getWidth();
const int height = getHeight();

@@ -113,10 +109,10 @@ protected:
// draw a 3x3 grid
for (int i=0; i<3; ++i)
{
r.setX(cx + 3 + i*width/3);
r.setX(3 + i*width/3);

// 1st
r.setY(cy + 3);
r.setY(3);

if (r.contains(x, y))
{
@@ -126,7 +122,7 @@ protected:
}

// 2nd
r.setY(cy + 3 + height/3);
r.setY(3 + height/3);

if (r.contains(x, y))
{
@@ -136,7 +132,7 @@ protected:
}

// 3rd
r.setY(cy + 3 + height*2/3);
r.setY(3 + height*2/3);

if (r.contains(x, y))
{


+ 4
- 6
examples/widgets/ExampleShapesWidget.hpp View File

@@ -83,22 +83,20 @@ protected:

void onReshape(int, int) override
{
const int cx = getX();
const int cy = getY();
const int width = getWidth();
const int height = getHeight();

// background
bg = getArea();
bg = Rectangle<int>(0, 0, width, height);

// rectangle
rect = Rectangle<int>(cx+20, cy+10, width-40, height-20);
rect = Rectangle<int>(20, 10, width-40, height-20);

// center triangle
tri = Triangle<int>(cx+width*0.5, cy+height*0.1, cx+width*0.1, cy+height*0.9, cx+width*0.9, cy+height*0.9);
tri = Triangle<int>(width*0.5, height*0.1, width*0.1, height*0.9, width*0.9, height*0.9);

// circle
cir = Circle<int>(cx+width/2, cy+height*2/3, height/6, 300);
cir = Circle<int>(width/2, height*2/3, height/6, 300);
}

private:


Loading…
Cancel
Save