www.pudn.com > screensaver.rar > DoShapes.c
#include "DoShapes.h"
#include "commonlib.h"
#include "genlib.h"
#include "simpio.h"
#include "graphics.h"
#include "extgraph.h"
#include "random.h"
#include "GUILib.h"
#include "strlib.h"
#include "vkey.h"
#include "Label.h"
#define SHAPE_MAX 4
#define SHAPE_RECTANGLE 1
#define SHAPE_TRIPANGLE 2
#define SHAPE_CIRCLE 3
#define SHAPE_TEXT 4
#define RANGE_LOW 0.3
#define RANGE_HIGH 0.9
#define GEN_BUTTON(L,T,W,H,C,E) GenWindow(L, T, W, H, C, E, NULL, NULL, NULL, NULL, NULL)
#define GEN_EVENT(N) void N(handle_t win)
void DoDrawRectAngle(double x, double y, double dblSolidlity);
void DoDrawTripangle(double x, double y, double dblSolidlity);
void DoDrawCircle(double x, double y, double dblSolidlity);
void DoDrawText(double x, double y, string strText);
void DoDrawShape(double dblSolidlity, string strText);
GEN_EVENT(btnOk_OnClick);
GEN_EVENT(btnIncrease_OnClick);
GEN_EVENT(btnDecrease_OnClick);
GEN_EVENT(btnBackspace_OnClick);
GEN_EVENT(btnCancel_OnClick);
GEN_EVENT(btnDrawShape_OnClick);
void OnKeyPress(char c);
static handle_t lblText, lblDentisy;
static handle_t txtText, txtDentisy;
static handle_t btnOk, btnIncrease, btnDecrease, btnBackspace, btnCancel, btnDrawShape;
static string strPhrase;
static double dblDentisy;
static bool blnExit;
void DoShapes (void)
{
// Left Top Width Height Text OnClick
lblText = GEN_BUTTON( 1, WINDOW_HEIGHT - 1, 1, 0.3, "PHRASE:", NULL);
lblDentisy = GEN_BUTTON( 1, WINDOW_HEIGHT - 1.4, 1, 0.3, "DENTISY:", NULL);
txtText = GEN_BUTTON( 2.1, WINDOW_HEIGHT - 1, 4, 0.3, "", NULL);
txtDentisy = (handle_t)GEN_LABEL( 2.1, WINDOW_HEIGHT - 1.4, 1, 0.3, "0.5", ALIGN_CENTER);
btnOk = GEN_BUTTON( 1, WINDOW_HEIGHT - 1.8, 1, 0.3, "OK", btnOk_OnClick);
btnIncrease = GEN_BUTTON( 3.2, WINDOW_HEIGHT - 1.4, 1, 0.3, "INCREASE", btnIncrease_OnClick);
btnDecrease = GEN_BUTTON( 4.3, WINDOW_HEIGHT - 1.4, 1, 0.3, "DECREASE", btnDecrease_OnClick);
btnBackspace = GEN_BUTTON( 6.2, WINDOW_HEIGHT - 1, 1.5, 0.3, "BACKSPACE", btnBackspace_OnClick);
btnCancel = GEN_BUTTON( 2.1, WINDOW_HEIGHT - 1.8, 1, 0.3, "Cancel", btnCancel_OnClick);
btnDrawShape = GEN_BUTTON( 3.2, WINDOW_HEIGHT - 1.8, 1, 0.3, "DoDrawShape()",btnDrawShape_OnClick);
((label_h)txtDentisy)->bgcolor = "Blue";
((label_h)txtDentisy)->bgdentisy = 0.5;
CreateWindow(lblText);
CreateWindow(lblDentisy);
CreateWindow(txtText);
CreateWindow(txtDentisy);
CreateWindow(btnOk);
CreateWindow(btnIncrease);
CreateWindow(btnDecrease);
CreateWindow(btnBackspace);
CreateWindow(btnCancel);
CreateWindow(btnDrawShape);
blnExit = FALSE;
SetupKeyboard(OnKeyPress);
StartGUI();
DrawFilledRectangle(0, 0, GetWindowWidth(), GetWindowHeight(), "White");
while(!blnExit)
{
blnExit = MouseButtonIsDown();
DoDrawShape(dblDentisy, strPhrase);
Wait(10);
}
}
void DoDrawRectAngle(double x, double y, double dblSolidlity)
{
double dblWidth, dblHeight;
dblWidth = RandomReal(RANGE_LOW, RANGE_HIGH);
dblHeight = RandomReal(RANGE_LOW, RANGE_HIGH);
SetPenColor(GetRandomColor());
StartFilledRegion(dblSolidlity);
DrawBoxEx(x, y, dblWidth, dblHeight);
EndFilledRegion();
UpdateDisplay();
}
void DoDrawTripangle(double x, double y, double dblSolidlity)
{
//double dblX2, dblY2, dblX3, dblY3;
double dblD, dblH;
dblD = RandomReal(RANGE_LOW, RANGE_HIGH);
dblH = RandomReal(RANGE_LOW, RANGE_HIGH);
/*dblX2 = RandomReal(RANGE_LOW, RANGE_HIGH);
dblY2 = RandomReal(RANGE_LOW, RANGE_HIGH);
dblX3 = RandomReal(RANGE_LOW, RANGE_HIGH);
dblY3 = RandomReal(RANGE_LOW, RANGE_HIGH);*/
SetPenColor(GetRandomColor());
StartFilledRegion(dblSolidlity);
MovePen(x, y);
DrawLine(dblD / 2, - dblH);
DrawLine(- dblD, 0);
DrawLine(dblD / 2, dblH);
EndFilledRegion();
UpdateDisplay();
}
void DoDrawCircle(double x, double y ,double dblSolidlity)
{
double dblR;
dblR = RandomReal(RANGE_LOW, RANGE_HIGH);
SetPenColor(GetRandomColor());
StartFilledRegion(dblSolidlity);
MovePen(x, y);
DrawArc(dblR, 0, 360);
EndFilledRegion();
}
void DoDrawText(double x, double y, string strText)
{
MovePen(x, y);
SetPenColor(GetRandomColor());
DrawTextString(strText);
}
void DoDrawShape(double dblSolidlity, string strText)
{
int intShape;
double x, y;
x = RandomReal(0, GetWindowWidth());
y = RandomReal(0, GetWindowHeight());
intShape = RandomInteger(1, SHAPE_MAX);
printf("%d\n", intShape);
switch(intShape)
{
case 1:
DoDrawRectAngle(x, y, dblSolidlity);
case 2:
DoDrawTripangle(x, y, dblSolidlity);
case 3:
DoDrawCircle(x, y, dblSolidlity);
case 4:
DoDrawText(x, y, strText);
}
}
GEN_EVENT(btnOk_OnClick)
{
RemoveKeyboard();
strPhrase = txtText->text;
dblDentisy = StringToReal(txtDentisy->text);
ExitGUI();
}
GEN_EVENT(btnIncrease_OnClick)
{
double dblCurDentisy;
dblCurDentisy = StringToReal(txtDentisy->text);
if (dblCurDentisy <= 0.9)
{
dblCurDentisy += 0.1;
}
txtDentisy->text = RealToString(dblCurDentisy);
((label_h)txtDentisy)->bgdentisy = dblCurDentisy;
InvokeRedraw(txtDentisy);
}
GEN_EVENT(btnDecrease_OnClick)
{
double dblCurDentisy;
dblCurDentisy = StringToReal(txtDentisy->text);
if (dblCurDentisy >= 0.1)
{
dblCurDentisy -= 0.1;
}
txtDentisy->text = RealToString(dblCurDentisy);
((label_h)txtDentisy)->bgdentisy = dblCurDentisy;
InvokeRedraw(txtDentisy);
}
void OnKeyPress(char c)
{
txtText->text=Concat(txtText->text, CharToString(c));
InvokeRedraw(txtText);
}
GEN_EVENT(btnBackspace_OnClick)
{
int intLen;
intLen = StringLength(txtText->text);
if (intLen <= 1)
{
txtText->text = "";
} else
{
txtText->text = SubString(txtText->text, 0, intLen - 2);
}
InvokeRedraw(txtText);
}
GEN_EVENT(btnCancel_OnClick)
{
blnExit = TRUE;
RemoveKeyboard();
ExitGUI();
}
GEN_EVENT(btnDrawShape_OnClick)
{
string strPhrase;
double dblDentisy;
strPhrase = txtText->text;
dblDentisy = StringToReal(txtDentisy->text);
DoDrawShape(dblDentisy, strPhrase);
}