/*
* GradientBrush.cpp
* Copyright (c) 2009 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL++2000
// 2000.02.16
#include <sol\ApplicationView.h>
#include <sol\PaintDC.h>
#include <sol\Brush.h>
#include <sol\StockObject.h>
#include <sol\Pen.h>
#include <sol\Font.h>
//#include <sol\GradientLabelGadget.h>
namespace SOL {
class AppView :public ApplicationView {
public:
AppView(Application& applet, const TCHAR* label, Args& args)
:ApplicationView(applet, label, args)
{
addEventHandler(WM_PAINT, this, (Handler)&AppView::paint, null);
}
private:
long AppView::paint(Event& event)
{
PaintDC pdc(this);
StockObject pen(NULL_PEN);
pdc.select(&pen);
int width = 300;
if (width <255) {
width = 255;
}
int p =width/255+1;
SIZE size;
const TCHAR* string = _T("Good morning!");
int margin = 8;
pdc.getTextExtent(string, strlen(string), &size);
int height = size.cy + margin*2;
int x = 10;
int y = 100;
//red-gradient background
for(int i = 0; i < 255; i++) {
Brush brush(RGB(255, 128+i/2, 128+i/2));
HGDIOBJ prev = pdc.select(&brush);
pdc.rectangle(x+i*p, y, x+20+i*p, y+height);
pdc.select(prev);
}
pdc.setBkMode(TRANSPARENT);
int yd = (height - size.cy)/2;
int xd = margin;
pdc.textOut(x+xd, y+yd, string, strlen(string));
//blue-gradient background
y = 200;
for(int i = 0; i < 255; i++) {
Brush brush(RGB(128+i/2, 128+i/2, 255) );
HGDIOBJ prev = pdc.select(&brush);
pdc.rectangle(x+i*p, y, x+20+i*p, y+height);
pdc.select(prev);
}
string = _T("Good afternoon!");
pdc.textOut(x+xd, y+yd, string, strlen(string));
//green-gradient background
y = 300;
string = _T("Good evening! Good night!\r\nGood bye.");
RECT r;
pdc.drawText(string, strlen(string), &r, DT_CALCRECT);
int w = r.right - r.left;
if (w >width) {
width = w;
}
p = width/255+1;
r.left = x+xd;
r.right = r.left + width;
int h = r.bottom - r.top;
r.top = y+yd;
r.bottom = r.top + h +10*2;
for(int i = 0; i < 255; i++) {
Brush brush(RGB(128+i/2, 255, 128+i/2) );
HGDIOBJ prev = pdc.select(&brush);
pdc.rectangle(x+i*p, y, x+20+i*p, y+r.bottom-r.top);
pdc.select(prev);
}
pdc.drawText(string, strlen(string), &r, 0);
return 0L;
}
};
}
void Main(int argc, TCHAR** argv)
{
const TCHAR* name = _T("GradientBrush");
Application applet(name, argc, argv);
Args args;
//2009/10/12
args.set(XmNclassStyle, 0);
AppView appview(applet, name, args);
appview.realize();
applet.run();
}
|