forked from craigcabrey/math-hurdler
-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhanced the UI and added Keyboard Support for options #14
Open
jriyyya
wants to merge
14
commits into
sugarlabs:master
Choose a base branch
from
jriyyya:patch-ui
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ecdf3d5
shifted horse and hurdle downwards
jriyyya f503ddf
Added option_button class
jriyyya 95d325c
use the new option_button for options
jriyyya b50a106
Added keyboard support
jriyyya 0b71861
Update sugargame to have keyboard keys press detection
jriyyya ddcb7cf
fix key events
Dimi20cen 2200fc1
Merge pull request #1 from Dimi20cen/fix-key-events
jriyyya 0469be9
Change divion operators to floor division
jriyyya e4f5e24
Add liscense in option_button.py
jriyyya 8a006b1
change input parameter clr to color
jriyyya e797c16
remove redundant comment
jriyyya cb05ab4
Made option_button argument list more readable
jriyyya 4eb4063
Improve readability of arguments in option_button
jriyyya ba76b93
Remove redundant comment
jriyyya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Copyright (C) 2023 Riya Jain | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
|
||
import pygame | ||
jriyyya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
class Option_Button: | ||
|
||
def __init__(self, x, y, width, height, text, value): | ||
self.text = text | ||
self.text_rect = text.get_rect() | ||
self.value = value | ||
|
||
self.rect = pygame.Rect(x, y, width, height) | ||
|
||
self.gameDisplay = pygame.display.get_surface() | ||
|
||
self.color = (255, 255, 255) | ||
self.selected_color = (180, 180, 180) | ||
|
||
self.press = False | ||
self.draw() | ||
|
||
def set_text(self, text): | ||
self.text = text | ||
self.text_rect = text.get_rect() | ||
|
||
def draw(self): | ||
c_radius = self.rect.height // 2 | ||
c_center = [self.rect.x, self.rect.y + c_radius] | ||
pygame.draw.circle(self.gameDisplay, self.color, c_center, c_radius) | ||
c_center[0] += self.rect.width | ||
pygame.draw.circle(self.gameDisplay, self.color, c_center, c_radius) | ||
pygame.draw.rect(self.gameDisplay, self.color, self.rect) | ||
m_x = self.rect.x + self.rect.width // 2 - self.text_rect.width // 2 | ||
m_y = self.rect.y + self.rect.height // 2 - self.text_rect.height // 2 | ||
self.gameDisplay.blit(self.text, (m_x, m_y)) | ||
|
||
def set_color(self, color): | ||
self.color = color | ||
|
||
def hovered(self): | ||
return self.rect.collidepoint(pygame.mouse.get_pos()) | ||
|
||
def mouse_click(self, mouse, action, *args): | ||
if self.rect.collidepoint(mouse): | ||
action(*args) | ||
|
||
def set_selected(self, selected): | ||
if selected: | ||
self.set_color(self.selected_color) | ||
else: | ||
self.set_color((255, 255, 255)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,23 @@ | ||
# | ||
# Copyright (c) 2020 Wade Brainerd | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
# | ||
|
||
__version__ = '1.3' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this wasn't your change but could you please remove redundant comments like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes yes, sure