Skip to content

Commit

Permalink
Fixed Window Resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtyson123 committed Dec 22, 2023
1 parent 269af90 commit 552ac2e
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 33 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ qemuDebug: build
cd toolchain && ./run_qemu.sh --debug

qemuGDB: build
x-terminal-emulator -e make qemuDebug & gdb -ex 'set remotetimeout 300' -ex 'target remote localhost:1234' -ex 'symbol-file maxOS.sym'
make qemuDebug
gdb -ex 'set remotetimeout 300' -ex 'target remote localhost:1234' -ex 'symbol-file maxOS.sym'

virtualbox: iso
# Run the virtual machine
Expand Down
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,10 @@ Kernel Cleanup
- [x] Kernel Boot Rewrite
- [x] Rewrite Event Handlers
- [x] Cross-Compiler
- [ ] Better Scripts
- [ ] Network Touch Up - Fix Issues with IP, Get it working on QEMU
- [ ] DCHP protocol
- [ ] GUI Bug Fixes
- [x] Better Scripts
- [x] GUI Bug Fixes
- [ ] Better Commenting and Doxygen Documentation
- [ ] Use better c++ coding conventions
- [ ] USB
- [ ] CMAKE Build System (and maybe get it building and debugging in CLion)
- [ ] Clean up all the TODOs
- [ ] Rewrite Readme
Expand Down
5 changes: 4 additions & 1 deletion kernel/include/net/icmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <net/ipv4.h>
#include <stdint.h>
#include <common/outputStream.h>


namespace maxOS{
Expand All @@ -23,8 +24,10 @@ namespace maxOS{

class InternetControlMessageProtocol : InternetProtocolPayloadHandler{

common::OutputStream* errorMessages;

public:
InternetControlMessageProtocol(InternetProtocolHandler* internetProtocolHandler);
InternetControlMessageProtocol(InternetProtocolHandler* internetProtocolHandler, common::OutputStream* errorMessages);
~InternetControlMessageProtocol();

bool handleInternetProtocolPayload(InternetProtocolAddress sourceIP, InternetProtocolAddress destinationIP, uint8_t* payloadData, uint32_t size);
Expand Down
27 changes: 13 additions & 14 deletions kernel/src/common/graphicsContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ uint32_t GraphicsContext::getHeight() {
void GraphicsContext::putPixel(int32_t x, int32_t y, Colour colour) {

// Convert the colour to an integer and then print it
renderPixel(x,y, colourToInt(colour));
putPixel(x,y, colourToInt(colour));
}

/**
Expand All @@ -384,7 +384,6 @@ void GraphicsContext::putPixel(int32_t x, int32_t y, Colour colour) {
*/
void GraphicsContext::putPixel(int32_t x, int32_t y, int32_t colour) {

// Check if the pixel is within the width of the screen
if (0 > x || (uint32_t)x >= width) {
return;
}
Expand Down Expand Up @@ -487,7 +486,7 @@ void GraphicsContext::drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, u
if(yMin < 0) yMin = 0;
if((uint32_t)yMax >= height) yMax = height - 1;

// Mirror the Y axis as directly calling renderPixel will not do this
// Mirror the Y axis as directly calling putPixel will not do this
if(mirrorYAxis)
{
int32_t temp = yMax;
Expand All @@ -502,7 +501,7 @@ void GraphicsContext::drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, u

// Draw the line
for(int32_t y = yMin; y <= yMax; ++y)
renderPixel(x0, y, colour);
putPixel(x0, y, colour);

return;
}
Expand All @@ -514,7 +513,7 @@ void GraphicsContext::drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, u
if(x0 < 0) x0 = 0;
if((uint32_t)x1 >= width) x1 = width-1;

// Mirror the Y axis as directly calling renderPixel will not do this
// Mirror the Y axis as directly calling putPixel will not do this
if(mirrorYAxis)
y0 = height-y0-1;

Expand All @@ -524,7 +523,7 @@ void GraphicsContext::drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, u

// Draw the line
for(int32_t x = x0; x <= x1; ++x)
renderPixel(x,y0,colour);
putPixel(x,y0,colour);
}

// If the line is not horizontal or vertical then it must be a diagonal line
Expand All @@ -539,7 +538,7 @@ void GraphicsContext::drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, u

// Start at minimum x and increment x by 1
for(int32_t x = x0; x <= x1; x++, y+=slope)
renderPixel(x, (int32_t)y, colour);
putPixel(x, (int32_t)y, colour);
}

// If the line is more vertical than horizontal, increment y by 1 and increment x by the inverse of the slope
Expand All @@ -553,7 +552,7 @@ void GraphicsContext::drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, u

// Start at minimum y and increment y by 1
for(int32_t y = yMin; y <= yMax; x+=slope, y++)
renderPixel((int32_t)x, y, colour);
putPixel((int32_t)x, y, colour);
}


Expand Down Expand Up @@ -639,7 +638,7 @@ void GraphicsContext::fillRectangle(int32_t x0, int32_t y0, int32_t x1, int32_t
if(xMin < 0) xMin = 0;
if((uint32_t)xMax > width) xMax = width;

// Mirror the Y axis as directly calling renderPixel will not do this
// Mirror the Y axis as directly calling putPixel will not do this
if(mirrorYAxis)
{
uint32_t temp = y1; // Store the maximum y value
Expand All @@ -650,7 +649,7 @@ void GraphicsContext::fillRectangle(int32_t x0, int32_t y0, int32_t x1, int32_t
// Draw the rectangle
for(int32_t y = y0; y < y1; ++y){
for (int32_t x = xMin; x < xMax; ++x) {
renderPixel(x, y, colour);
putPixel(x, y, colour);
}
}

Expand Down Expand Up @@ -684,7 +683,7 @@ void GraphicsContext::drawCircle(int32_t x0, int32_t y0, int32_t radius, uint32_
if(y0 < 0) y0 = 0;
if((uint32_t)y0 > height) y0 = height;

// Mirror the Y axis as directly calling renderPixel will not do this
// Mirror the Y axis as directly calling putPixel will not do this
if(mirrorYAxis)
y0 = height-y0-1;

Expand All @@ -698,7 +697,7 @@ void GraphicsContext::drawCircle(int32_t x0, int32_t y0, int32_t radius, uint32_

// If the point is within the circle, draw it but make sure it is only part of the outline
if(x*x + y*y <= radius*radius && x*x + y*y >= (radius-1)*(radius-1))
renderPixel(x0+x,y0+y,colour);
putPixel(x0+x,y0+y,colour);
}
}

Expand Down Expand Up @@ -734,7 +733,7 @@ void GraphicsContext::fillCircle(int32_t x0, int32_t y0, int32_t radius, uint32_
if(y0 < 0) y0 = 0;
if((uint32_t)y0 > height) y0 = height;

// Mirror the Y axis as directly calling renderPixel will not do this
// Mirror the Y axis as directly calling putPixel will not do this
if(mirrorYAxis)
y0 = height-y0-1;

Expand All @@ -748,7 +747,7 @@ void GraphicsContext::fillCircle(int32_t x0, int32_t y0, int32_t radius, uint32_

// Only draw the pixel if it is within the circle
if(x*x + y*y <= radius*radius)
renderPixel(x0+x,y0+y,colour);
putPixel(x0+x,y0+y,colour);
}
}

Expand Down
7 changes: 7 additions & 0 deletions kernel/src/gui/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ void Widget::resize(int32_t width, int32_t height) {
Vector<Rectangle<int32_t>> invalidAreasOld = oldPosition.subtract(position);
Vector<Rectangle<int32_t>> invalidAreasNew = position.subtract(oldPosition);

// Right and Bottom require to be fully invalidated
if(position.width > oldPosition.width || position.height > oldPosition.height || oldPosition.width > position.width || oldPosition.height > position.height){
invalidate();
return;
}


//Loop through the areas that need to be redrawn and invalidate them
for(int i = 0; i < invalidAreasOld.size(); i++){
invalidate(invalidAreasOld[i]);
Expand Down
4 changes: 2 additions & 2 deletions kernel/src/gui/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ Window::Window(int32_t left, int32_t top, uint32_t width, uint32_t height, strin
windowAreaColour = Colour(0xff, 0xff, 0xff); // White
windowFrameBorderColour = Colour(0x00, 0x00, 0x00); // Black
windowFrameColour = Colour(0x57,0x57,0x57); // Davy's Grey
title.foregroundColour = Colour(0xff, 0xff, 0xff); // White
title.backgroundColour = windowFrameColour;
title.foregroundColour = Colour(0xff, 0xff, 0xff); // White
title.backgroundColour = windowFrameColour;

// Add the title to the window
Window::addChild(&title);
Expand Down
11 changes: 3 additions & 8 deletions kernel/src/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,6 @@ extern "C" void kernelMain(const multiboot_info& multibootHeader, uint32_t multi
cout << "\n";
activationHeaderStream << "[ DONE ]";


// Make the network setup stream
ConsoleArea networkSetupHeader(&console, 0, cout.cursorY, console.getWidth(), 1, ConsoleColour::LightGrey, ConsoleColour::Black);
ConsoleStream networkSetupHeaderStream(&networkSetupHeader);
Expand All @@ -389,7 +388,7 @@ extern "C" void kernelMain(const multiboot_info& multibootHeader, uint32_t multi
networkSetupHeaderStream << ".";

// Ethernet Frame Handler
EtherFrameProvider ethernetFrameHandler(ethernetDriver, &networkConsoleStream);
EthernetFrameHandler ethernetFrameHandler(ethernetDriver, &networkConsoleStream);
cout << "-- Set Up Ethernet Frame Handler\n";
networkSetupHeaderStream << ".";

Expand Down Expand Up @@ -425,7 +424,7 @@ extern "C" void kernelMain(const multiboot_info& multibootHeader, uint32_t multi


// Run the network
#define NETWORK
//#define NETWORK
#ifdef NETWORK

// TCPtoStream
Expand Down Expand Up @@ -462,18 +461,14 @@ extern "C" void kernelMain(const multiboot_info& multibootHeader, uint32_t multi
*stream << "TCP Connection Closed\n";
}
};
icmp.RequestEchoReply(defaultGateway);
TCPtoStream tcpToStream(&networkConsoleStream);
TransmissionControlProtocolSocket* tcpSocket = tcp.Listen(1234);
tcpSocket -> connectEventHandler(&tcpToStream);
cout << "Listening on TCP Port 1234\n";
// Run in term before boot when using tcp.send : ncat -l 127.0.0.1 1234
// Run in term after boot when using tcp.listen : ncat 127.0.0.1 1234

#endif


//#define GUI
#define GUI
#ifdef GUI
Desktop desktop(videoDriver);
mouse.connectEventHandler(&desktop);
Expand Down
10 changes: 8 additions & 2 deletions kernel/src/net/icmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ using namespace maxOS::common;
using namespace maxOS::net;


InternetControlMessageProtocol::InternetControlMessageProtocol(InternetProtocolHandler *internetProtocolHandler)
InternetControlMessageProtocol::InternetControlMessageProtocol(InternetProtocolHandler *internetProtocolHandler, OutputStream* errorMessages)
: InternetProtocolPayloadHandler(internetProtocolHandler, 0x01)
{

this -> errorMessages = errorMessages;
}


Expand All @@ -36,6 +36,8 @@ bool InternetControlMessageProtocol::handleInternetProtocolPayload(InternetProto
uint32_t size)
{

errorMessages -> write("ICMP received a packet\n");

// Check if the size is at least the size of the header
if(size < sizeof(InternetControlMessageProtocolHeader)){
return false;
Expand Down Expand Up @@ -74,6 +76,8 @@ bool InternetControlMessageProtocol::handleInternetProtocolPayload(InternetProto
*/
void InternetControlMessageProtocol::RequestEchoReply(uint32_t ip_be) {

errorMessages -> write("ICMP: Sending echo request\n");

InternetControlMessageProtocolHeader icmp;
icmp.type = 8; // Echo request
icmp.code = 0; // Code must be 0
Expand All @@ -83,4 +87,6 @@ void InternetControlMessageProtocol::RequestEchoReply(uint32_t ip_be) {
icmp.checksum = InternetProtocolHandler::Checksum((uint16_t *)&icmp, sizeof(InternetControlMessageProtocolHeader));

Send(ip_be, (uint8_t *)&icmp, sizeof(InternetControlMessageProtocolHeader));

errorMessages -> write("ICMP: Echo request sent\n");
}

0 comments on commit 552ac2e

Please sign in to comment.