Example #1
0
	bool SerializeOpts(GOptionsFile *p, bool Write)
	{
		if (!p) return false;

		p->SetFile(OptionsFile);
		bool Result = p->Serialize(Write);
		if (Write && !Result)
		{
			// Probably because we don't have write access to the install folder?
			LgiMsg(	App,
					"Failed to write options to '%s' (mode=%s)",
					App->Name(),
					MB_OK,
					OptionsFile.Get(),
					Mode == InstallPortable ? "Portable" : "Desktop");
		}
		
		return Result;
	}
Example #2
0
int main(int argc, char* argv[]){

    GApplication::initialize(&argc, argv);
    GWindow* w = GWindow::singleton("Hello World", GPosition2D<int>(), GDimension2D<int>(500, 500));

    w->clearColor(GColor<float>(0, 0, 0, 0));
    w->displayFunction(displayFunction);
    w->closeFunction(closeFunction);
    w->reshapeFunction(GWindow::defaultReshapeFunction);

    w->open();

    return 0;
}
Example #3
0
/*
 * Function: drawSun
 * Usage: if(sun->isSelected()) drawSun(gw,MAX_SUN_RADIUS,(dusk?DUSK_SUN_COLOR:DAY_SUN_COLOR));
 * --------------------------
 * Uses a recursive function to draw the sun/moon as series of concentric circles.
 * Totally unnecessary to do this recursively, but it's the recursive contest. #YOLO
 */
int drawSun(GWindow gw, int radius, int color){
    if(radius<=0){
        return 0;
    }
    GOval *oval;
    if(dusk){
        oval = new GOval(width/4-radius,height*.45-radius,radius*2,radius*2);
    }
    else{
        radius/=2;
        oval = new GOval(2.0*width/3.0-radius,height/3.0-radius,radius*2,radius*2);
        radius*=2;
    }
    oval->setColor(color);
    oval->setFilled(true);
    oval->setColor(color);
    gw.add(oval);
    radius--;
    color -=2;
    return drawSun(gw, radius, color);
}
Example #4
0
//builds two lines from each of two gotten vertex and calls itself recursively until the depth of recursion becomes zero
void drawPythagoreanTree(GWindow &gw, GPoint endPoint1, GPoint endPoint2, double input_length, double theta, int recursion_depth){
        double theta_one = theta - THETA;
        double theta_two = theta + THETA;

        double length = input_length * cos(THETA_RADIAN);

        GPoint branch1_1 = gw.drawPolarLine(endPoint1, length*2, theta_one);
        GPoint branch1_2 = gw.drawPolarLine(endPoint2, length, theta_one);
        gw.setColor("YELLOW");
        gw.drawLine(branch1_1, branch1_2);
        GPoint branch2_1 = gw.drawPolarLine(endPoint1, length, theta_two);
        GPoint branch2_2 = gw.drawPolarLine(endPoint2, length*2, theta_two);
        gw.setColor("GREEN");
        gw.drawLine(branch2_1, branch2_2);

        recursion_depth--;

        if(recursion_depth == 0){
            return;
        }
        drawPythagoreanTree(gw, branch1_1, branch1_2, length, theta_one, recursion_depth);
        drawPythagoreanTree(gw, branch2_1, branch2_2, length, theta_two, recursion_depth);

}
void radioButtonTest() {
    GWindow gw;
    gw.setTitle("Radio Button Test");
    GRadioButton* rb1 = new GRadioButton("Red");
    GRadioButton* rb2 = new GRadioButton("Green", "", true);
    GRadioButton* rb3 = new GRadioButton("Blue");
    gw.addToRegion(rb1, "SOUTH");
    gw.addToRegion(rb2, "SOUTH");
    gw.addToRegion(rb3, "SOUTH");

    // a second group of buttons
    GRadioButton* rb4 = new GRadioButton("Black", "N", true);
    GRadioButton* rb5 = new GRadioButton("White", "N");
    gw.addToRegion(rb4, "NORTH");
    gw.addToRegion(rb5, "NORTH");
    
    gw.setVisible(true);
}
Example #6
0
void drawSierpinskiTriangle(GWindow& gw, double x, double y, int size, int order) {
    gw.drawLine(x, y, x + size, y);
    gw.drawLine(x, y, x + size/2, y + size*sqrt(3)/2);
    gw.drawLine(x + size, y, x + size/2, y + size*sqrt(3)/2);
    drawSierpinskiTriangleHelper(gw, x + size/4, y + size*sqrt(3)/4, size/2, order - 1);
}
void gbufferedImageTest() {
    GWindow gw;
    gw.setSize(900, 700);
    gw.setTitle("Test");

    GButton* button1 = new GButton("Click Me 1");
    gw.add(button1, 250, 80);
    //GButton* button2 = new GButton("Click Me 2");
    //gw.addToRegion(button2, "NORTH");

    GLabel* label = new GLabel("test!");
    gw.add(label, 10, 60);
    
    std::cout << "About to construct GBufferedImage." << std::endl;
    GBufferedImage* img = new GBufferedImage(10, 80, 200, 250);
    std::cout << "Done constructing GBufferedImage." << std::endl;
    gw.add(img, 50, 50);
    // gw.addToRegion(img, "SOUTH");
    gw.setVisible(true);
    
//    GBufferedImage* img2 = new GBufferedImage(20, 20);
//    img2->fill(GBufferedImage::createRgbPixel(255, 0, 255));
//    Grid<int> grid = img2->toGrid();
//    cout << "grid of pixels before: " << grid << endl;
//    for (int y = 4; y <= 18; y++) {
//        for (int x = 2; x <= 9; x++) {
//            grid[y][x] = GBufferedImage::createRgbPixel(0, 255, 0);
//        }
//    }
//    cout << "grid of pixels after: " << grid << endl;
//    img2->fromGrid(grid);
//    gw.add(img2, 350, 20);
    
    GBufferedImage* img3 = new GBufferedImage();
    img3->load("rainbow.png");
    cout << "adding the image!" << endl;
    gw.add(img3, 10, 20);
    // pause(2000);
    
    cout << "start toGrid" << endl;
    Grid<int> grid3 = img3->toGrid();
    cout << "end toGrid, start rgb shit" << endl;
    for (int y = 0; y < grid3.height(); y++) {
        for (int x = 0; x < grid3.width(); x++) {
            int red, green, blue;
            GBufferedImage::getRedGreenBlue(grid3[y][x], red, green, blue);
            grid3[y][x] = GBufferedImage::createRgbPixel(green, red, blue);
        }
    }
    cout << "end rgb shit, start fromGrid" << endl;
    img3->fromGrid(grid3);
    cout << "end fromGrid" << endl;
    
    pause(2000);
    return;

    // fill
    img->fill(0xff00ff);  // purple

    std::cout << "About to setRGB on GBufferedImage." << std::endl;
    for (int y = 2; y < img->getHeight() - 2; y++) {
        for (int x = 5; x <= img->getWidth() - 5; x++) {
            img->setRGB(x, y, 0xffcc33);
        }
    }
    std::cout << "Done setting RGB on GBufferedImage." << std::endl;
    border(img);
    pause(500);
    
    std::cout << "About to resize on GBufferedImage." << std::endl;
    img->resize(100, 50);
    border(img);
    pause(500);
    
    std::cout << "About to resize on GBufferedImage." << std::endl;
    img->resize(200, 80);
    border(img);
    pause(500);
    
    std::cout << "About to setRGB on GBufferedImage." << std::endl;
    for (int y = 10; y < img->getHeight() - 10; y++) {
        for (int x = 10; x <= img->getWidth() - 10; x++) {
            img->setRGB(x, y, 0xff33cc);
        }
    }
    border(img);
    
    std::cout << "About to remove other shit." << std::endl;
    pause(200);
    gw.remove(label);
    gw.remove(button1);
    //gw.removeFromRegion(button2, "NORTH");
    pause(200);
    
    std::cout << "About to remove GBufferedImage." << std::endl;
    pause(200);
    gw.remove(img);
    // gw.removeFromRegion(img, "SOUTH");
    pause(200);
    std::cout << "Test complete." << std::endl;
    std::cout << std::endl;
}
Example #8
0
int main(int argc, char const* const* argv) {
    GWindow* wind = new TestWindow(640, 480);

    return wind->run();
}
Example #9
0
bool isPointInWindow(GWindow & gw, double coordX, double coordY){
    if((coordX >= gw.getWidth()) || (coordX <= 0) || (coordY >= gw.getHeight()) || (coordY <= 0)){
        return false;
    }
    return true;
}
Example #10
0
void gtableTest() {
    GWindow gw;
    gw.setTitle("GTable Test");
    
    GTable* table = new GTable(5, 3);
    // table->setColor("#0000cc");
    // table->setFont("Monospaced-Bold-20");
    // table->setHorizontalAlignment(GTable::Alignment::RIGHT);
    table->select(0, 1);
    gw.addToRegion(table, "NORTH");
    
//    GTable* table2 = new GTable(4, 2, 0, 0, 100, 400);
//    gw.addToRegion(table2, "EAST");
    
    GButton* buttget = new GButton("Get All");
    gw.addToRegion(buttget, "SOUTH");
    
    GButton* buttset = new GButton("Set All");
    gw.addToRegion(buttset, "SOUTH");
    
    GButton* buttclear = new GButton("Clear");
    gw.addToRegion(buttclear, "SOUTH");
    
    GButton* buttrowadd = new GButton("+R");
    gw.addToRegion(buttrowadd, "SOUTH");
    
    GButton* buttrowrem = new GButton("-R");
    gw.addToRegion(buttrowrem, "SOUTH");
    
    GButton* buttcoladd = new GButton("+C");
    gw.addToRegion(buttcoladd, "SOUTH");
    
    GButton* buttcolrem = new GButton("-C");
    gw.addToRegion(buttcolrem, "SOUTH");
    
    GButton* buttwidthadd = new GButton("+W");
    gw.addToRegion(buttwidthadd, "SOUTH");
    
    GButton* buttwidthrem = new GButton("-W");
    gw.addToRegion(buttwidthrem, "SOUTH");
    
    gw.setVisible(true);
    
    while (true) {
        GEvent event = waitForEvent(ACTION_EVENT | TABLE_EVENT | WINDOW_EVENT);
        if (event.getEventClass() == ACTION_EVENT) {
            GActionEvent actionEvent(event);
            if (actionEvent.getSource() == buttget) {
                for (int row = 0; row < table->numRows(); row++) {
                    for (int col = 0; col < table->numCols(); col++) {
                        cout << "R" << row << "C" << col << "=\"" << table->get(row, col) << "\" ";
                    }
                    cout << endl;
                }
                int row, col;
                table->getSelectedCell(row, col);
                cout << "selected: R" << row << "C" << col << endl;
            } else if (actionEvent.getSource() == buttset) {
                for (int row = 0; row < table->numRows(); row++) {
                    for (int col = 0; col < table->numCols(); col++) {
                        std::string value = "R" + integerToString(row) + "C" + integerToString(col);
                        table->set(row, col, value);
                    }
                }
                table->select(1, 2);
            } else if (actionEvent.getSource() == buttclear) {
                table->clear();
            } else if (actionEvent.getSource() == buttrowadd) {
                table->resize(table->numRows() + 1, table->numCols());
            } else if (actionEvent.getSource() == buttrowrem) {
                table->resize(table->numRows() - 1, table->numCols());
            } else if (actionEvent.getSource() == buttcoladd) {
                table->resize(table->numRows(), table->numCols() + 1);
            } else if (actionEvent.getSource() == buttcolrem) {
                table->resize(table->numRows(), table->numCols() - 1);
            } else if (actionEvent.getSource() == buttwidthadd) {
                table->setColumnWidth(1, table->getColumnWidth(1) + 20);
            } else if (actionEvent.getSource() == buttwidthrem) {
                table->setColumnWidth(1, table->getColumnWidth(1) - 20);
            }
        } else if (event.getEventClass() == WINDOW_EVENT) {
            if (event.getEventType() == WINDOW_CLOSED) {
                break;
            }
        } else if (event.getEventClass() == TABLE_EVENT) {
            GTableEvent tableEvent(event);
            std::cout << "cell updated: " << tableEvent.toString() << std::endl;
        }
    }
}
Example #11
0
void person::writeName(GWindow &Gwin)
{
    Gwin.setPenColour(myColour);
    Gwin.writeString(name);
}
Example #12
0
void GWindow::dispatchEvent(XEvent& event) {
    // printf("got event: type=%d\n", event.type);
    GWindow* w = findWindow(event.xany.window);
    if (w == 0) {
        /*
        printf(
            "In dispatchEvent: Could not find a window %d, event type=%d\n",
            (int) event.xany.window, (int) event.type
        );
        */
        return;
    }
    if (event.type == Expose) {
        // printf("Expose event.\n");
        if (w->m_BeginExposeSeries) {
            w->m_ClipRectangle.x = event.xexpose.x;
            w->m_ClipRectangle.y = event.xexpose.y;
            w->m_ClipRectangle.width = event.xexpose.width;
            w->m_ClipRectangle.height = event.xexpose.height;
            w->m_BeginExposeSeries = false;
        } else {
            // Add the current rectangle to the clip rectangle
            if (event.xexpose.x < w->m_ClipRectangle.x)
                w->m_ClipRectangle.x = event.xexpose.x;
            if (event.xexpose.y < w->m_ClipRectangle.y)
                w->m_ClipRectangle.y = event.xexpose.y;
            if (event.xexpose.x + event.xexpose.width >
                w->m_ClipRectangle.x + w->m_ClipRectangle.width) {
                w->m_ClipRectangle.width = event.xexpose.x +
                    event.xexpose.width - w->m_ClipRectangle.x;
            }
            if (event.xexpose.y + event.xexpose.height >
                w->m_ClipRectangle.y + w->m_ClipRectangle.height) {
                w->m_ClipRectangle.height = event.xexpose.y +
                    event.xexpose.height - w->m_ClipRectangle.y;
            }
        }
        if (event.xexpose.count == 0) {
            // Restrict a drawing to clip rectangle
            XSetClipRectangles(
                m_Display, w->m_GC,
                0, 0,                   // Clip origin
                &(w->m_ClipRectangle), 1, Unsorted
            );

            w->onExpose(event);

            // Restore the clip region
            w->m_ClipRectangle.x = 0;
            w->m_ClipRectangle.y = 0;
            w->m_ClipRectangle.width = w->m_IWinRect.width();
            w->m_ClipRectangle.height = w->m_IWinRect.height();
            XSetClipRectangles(
                m_Display, w->m_GC,
                0, 0,                   // Clip origin
                &(w->m_ClipRectangle), 1, Unsorted
            );
            w->m_BeginExposeSeries = true;
        }
    } else if (event.type == KeyPress) {
        // printf("KeyPress event.\n");
        w->onKeyPress(event);
    } else if (event.type == ButtonPress) {
        // printf("ButtonPress event.\n");
        w->onButtonPress(event);
    } else if (event.type == ButtonRelease) {
        // printf("ButtonRelease event.\n");
        w->onButtonRelease(event);
    } else if (event.type == MotionNotify) {
        // printf("MotionNotify event.\n");
        w->onMotionNotify(event);
    } else if (event.type == CreateNotify) {
        // printf("CreateNotify event: m_Window=%d\n", (int) w->m_Window);
        w->onCreateNotify(event);
    } else if (event.type == DestroyNotify) {
        /*
        printf(
            "DestroyNotify event: Event window=%d, window=%d\n",
            (int) event.xdestroywindow.event,
            (int) event.xdestroywindow.window
        );
        */
        // printf("Before: m_NumCreatedWindows=%d\n", m_NumCreatedWindows);

        w->onDestroyNotify(event);

        GWindow* destroyedWindow = findWindow(event.xdestroywindow.window);
        if (destroyedWindow != 0) {
            if (destroyedWindow->m_WindowCreated) {
                destroyedWindow->m_WindowCreated = false;
                m_NumCreatedWindows--;
            }
            // Exclude a window from the window list
            if (destroyedWindow->prev != 0) {
                destroyedWindow->prev->link(*(destroyedWindow->next));
                destroyedWindow->prev = 0;
                destroyedWindow->next = 0;
                m_NumWindows--;
            }
        }

        // printf("After: m_NumCreatedWindows=%d\n", m_NumCreatedWindows);

    } else if (event.type == FocusIn) {
        // printf("FocusIn event.\n");
        w->onFocusIn(event);
    } else if (event.type == FocusOut) {
        // printf("FocusOut event.\n");
        w->onFocusOut(event);
    // } else if (event.type == ResizeRequest) {
    } else if (event.type == ConfigureNotify) {
        int newWidth = event.xconfigure.width;
        int newHeight = event.xconfigure.height;
        // printf("ConfigureNotify: x=%d, y=%d, w=%d, h=%d\n",
        //     event.xconfigure.x, event.xconfigure.y,
        //     event.xconfigure.width, event.xconfigure.height);
        if (
            newWidth != w->m_IWinRect.width() ||
            newHeight != w->m_IWinRect.height()
        ) {
            // printf("Resize: w=%d, h=%d\n",
            //     event.xconfigure.width, event.xconfigure.height);
            w->m_IWinRect.setWidth(newWidth);
            w->m_IWinRect.setHeight(newHeight);
            w->recalculateMap();
            w->onResize(event);
            w->redraw();
        }
    } else if (event.type == ClientMessage) { // Window closing, etc.
        w->onClientMessage(event);
    }
}
Example #13
0
static void drawTree(GWindow& window, int order) {
    GPoint trunkBase(window.getWidth()/2, window.getHeight());
    // GPoint trunkEnd(window.getWidth()/2, window.getHeight() - kTrunkLength);
    drawTree(window, order, trunkBase, kTrunkStartAngle, kTrunkLength);
}
Example #14
0
File: GView.cpp Project: FEI17N/Lgi
void LgiToGtkCursor(GViewI *v, LgiCursor c)
{
	static LgiCursor CurrentCursor = LCUR_Normal;

	if (!v || c == CurrentCursor)
		return;
	
	CurrentCursor = c;
	GdkCursorType type = GDK_ARROW;
	switch (c)
	{
		// No cursor
		#ifdef GDK_BLANK_CURSOR
		case LCUR_Blank:
			type = GDK_BLANK_CURSOR;
			break;
		#endif
		/// Normal arrow
		case LCUR_Normal:
			type = GDK_ARROW;
			break;
		/// Upwards arrow
		case LCUR_UpArrow:
			type = GDK_SB_UP_ARROW;
			break;
		/// Downwards arrow
		case LCUR_DownArrow:
			type = GDK_SB_DOWN_ARROW;
			break;
		/// Left arrow
		case LCUR_LeftArrow:
			type = GDK_SB_LEFT_ARROW;
			break;
		/// Right arrow
		case LCUR_RightArrow:
			type = GDK_SB_RIGHT_ARROW;
			break;
		/// Crosshair
		case LCUR_Cross:
			type = GDK_CROSSHAIR;
			break;
		/// Hourglass/watch
		case LCUR_Wait:
			type = GDK_WATCH;
			break;
		/// Ibeam/text entry
		case LCUR_Ibeam:
			type = GDK_XTERM;
			break;
		/// Vertical resize (|)
		case LCUR_SizeVer:
			type = GDK_DOUBLE_ARROW;
			break;
		/// Horizontal resize (-)
		case LCUR_SizeHor:
			type = GDK_SB_H_DOUBLE_ARROW;
			break;
		/// Diagonal resize (/)
		case LCUR_SizeBDiag:
			type = GDK_BOTTOM_LEFT_CORNER;
			break;
		/// Diagonal resize (\)
		case LCUR_SizeFDiag:
			type = GDK_BOTTOM_RIGHT_CORNER;
			break;
		/// All directions resize
		case LCUR_SizeAll:
			type = GDK_FLEUR;
			break;
		/// A pointing hand
		case LCUR_PointingHand:
			type = GDK_HAND2;
			break;
		/// A slashed circle
		case LCUR_Forbidden:
			type = GDK_X_CURSOR;
			break;

		default:
			type = GDK_ARROW;
			break;

		/*			
		case LCUR_SplitV:
		case LCUR_SplitH:
		case LCUR_DropCopy:
		case LCUR_DropMove:
			LgiAssert(0);
			break;
		*/
	}
	
	GWindow *Wnd = v->GetWindow();
	OsView h = Wnd ? Wnd->Handle() : v->Handle();
	
	LgiAssert(v->InThread());
	LgiAssert(h->window);
	if (type == GDK_ARROW)
	{
		gdk_window_set_cursor(h->window, NULL);
		// printf("gdk_window_set_cursor(%s, NULL)\n", v->GetClass());
	}
	else
	{
		GdkCursor *cursor = gdk_cursor_new_for_display(gdk_display_get_default(), type);
		if (cursor)
		{
			gdk_window_set_cursor(h->window, cursor);
			// printf("gdk_window_set_cursor(%s, cursor)\n", v->GetClass());
		}
		else
		{
			gdk_window_set_cursor(h->window, NULL);
			// printf("gdk_window_set_cursor(%s, gdk_cursor_new_for_display fail)\n", v->GetClass());
		}
	}
}