> Can you make a very minimal hack of your code (i.e. missing out the
> clever bit about dictionary lookups as such) and post that here?=20
> You know, just the GUI bits, really...
>
> Assuming that it still manifests the bug, of course...=20
Yeah, that's what i was going to do :P
/* --------- CODE ---------
// the header file
#ifndef GRAPHICS_H
#define GRAPHICS_H
#include <cstdlib>
#include <fltk/run.h>
#include <fltk/Window.h>
#include <fltk/Widget.h>
#include <fltk/Button.h>
#include <fltk/Input.h>
#include <fltk/Browser.h>
#include <fltk/TextDisplay.h>
#include <fltk/ask.h>
#include "target.h"
using namespace fltk;
// input grid is the nine letter grid
class inputGrid {
Input* inbox[TARGET_LENGTH];
void inputCallBack(Input* w);
static void inputCallBack(Widget* w, void* v){
((inputGrid*)v)->inputCallBack((Input*)w); }
public:
inputGrid(int x, int y, int width, int height, const char* label = 0);
bool isLegal();
void setTarget();
};
class TargetWindow : public Window {
inputGrid* inbox;
Button* go;
TextDisplay *outputDisplay;
void buttonCallBack();
static void buttonCallBack(Widget*, void* v){
((TargetWindow*)v)->buttonCallBack();
}
inline void windowCallBack(TargetWindow* v) const {
v->hide();
}
static void windowCallBack(Widget*, void* v) {
((TargetWindow*)v)->windowCallBack((TargetWindow*)v);
}
public:
// constructor
TargetWindow(const char* label) :
Window(USEDEFAULT, USEDEFAULT, 720, 300, label, true)
{
begin();
// inbox is the grid of letters
inbox = new inputGrid(330, 20, 90, 90);
go = new Button(470, 50, 150, 25, "Generate words!");
outputDisplay = new TextDisplay(150, 130, 470, 120, "Valid
words:");
go->callback((Callback*)buttonCallBack, this);
callback(windowCallBack, this);
end();
}
};
#endif
// the .cpp file
#include "target.h"
#include "graphics.h"
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cstring>
#include <climits>
// basic cropping of the input boxes and alphabetical sanity checking
void inputGrid::inputCallBack(Input* w) {
char current;
if (w->size() > 1) {
w->cut(w->size() - 1, w->size());
}
if (w->size() > 0) {
current = w->value()[w->size() - 1];
if (!(isalpha(current))) {
w->cut(w->size() - 1, w->size());
}
}
}
// checking to make sure each box has a character
bool inputGrid::isLegal() {
int idx;
bool legal = true;
for (idx = 0; (idx < TARGET_LENGTH) && (legal == true); idx++) {
if (this->inbox[idx]->size() != 1) {
legal = false;
}
}
return legal;
}
// does some non-gui stuff here
// create the input grid
inputGrid::inputGrid (int x, int y, int width, int height, const char* label) {
int idx;
for (idx = 0; idx < TARGET_LENGTH; idx++) {
if (idx < NUM_COLS) {// first row
inbox[idx] = new Input ((x + ((idx % NUM_COLS) * (width / NUM_COLS))),
y, (width / NUM_COLS), (height / NUM_ROWS));
} else if (idx < (2 * NUM_COLS)) { // second row
if (idx == NUM_COLS) { // first col in second row
inbox[idx] = new Input ((x + ((idx % NUM_COLS) * (width /
NUM_COLS))), (y + (height / NUM_ROWS)), (width / NUM_COLS), (height /
NUM_ROWS), "Input your Target Word here:");
} else {
inbox[idx] = new Input((x + ((idx % NUM_COLS) * (width /
NUM_COLS))), (y + (height / NUM_ROWS)), (width / NUM_COLS), (height /
NUM_ROWS));
}
} else { //third row
inbox[idx] = new Input((x + ((idx % NUM_COLS) * (width / NUM_COLS))),
y + (2 * (height / NUM_ROWS)), (width / NUM_COLS), (height / NUM_ROWS));
}
inbox[idx]->callback(inputCallBack, this);
inbox[idx]->when(WHEN_CHANGED);
inbox[idx]->color(BLACK); // cell colours are black
inbox[idx]->textcolor(WHITE); // cell text colours are white
}
inbox[MIN_LENGTH]->color(RED); // middle grid cell colour is red
}
// go button callback
void TargetWindow::buttonCallBack(){
int idx;
if (!(this->inbox->isLegal())) {
alert("You need to make sure all the boxes contain text!");
} else {
this->inbox->setTarget();
// continue with the non-GUI stuff
this->outputDisplay->buffer()->remove(0, INT_MAX);
for (idx = 0; idx < numValidWords; idx++){
char text[15];
sprintf(text, "%s\n", validWords[idx]);
this->outputDisplay->append(text);
}
this->outputDisplay->clear();
}
}
---------/CODE------*/
Sorry about the mass of code and lack of comments.
I suppose this is why so many people still use 1.1/1.3, huh? :)
Regards,
Ben
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk